file_path
stringlengths 20
207
| content
stringlengths 5
3.85M
| size
int64 5
3.85M
| lang
stringclasses 9
values | avg_line_length
float64 1.33
100
| max_line_length
int64 4
993
| alphanum_fraction
float64 0.26
0.93
|
---|---|---|---|---|---|---|
daniel-kun/omni/source/omni/tests/core/model/test_while_statement.cpp
|
#include <omni/core/model/while_statement.hpp>
#include <omni/core/model/do_while_statement.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/variable_assignment_expression.hpp>
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/binary_operator_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_file_manager.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/auto_unit_test.hpp>
namespace {
/**
Builds and runs a example program that increments a variable that has been initialized with 1 with the exit-condition "variable < 10".
**/
template <typename WhileStatement>
int buildAndRunWhileTest (std::string testFileName)
{
using namespace omni::core;
context c;
model::module m (c, "test");
auto body = std::make_shared <model::block> ();
auto variableDeclaration = std::make_shared <model::variable_declaration_expression> (std::make_shared <model::builtin_literal_expression <int>> (c, 1));
body->appendStatement (variableDeclaration);
auto whileCondition = std::make_shared <model::binary_operator_expression> (
c,
model::binary_operator_expression::binary_operation::binary_lessthan_operation,
std::make_shared <model::variable_expression> (variableDeclaration),
std::make_shared <model::builtin_literal_expression <int>> (c, 10));
auto whileBody = std::make_shared <model::block> ();
whileBody->appendStatement (
std::make_shared <model::variable_assignment_expression> (
variableDeclaration,
std::make_shared <model::binary_operator_expression> (
c,
model::binary_operator_expression::binary_operation::binary_plus_operation,
std::make_shared <model::variable_expression> (variableDeclaration),
std::make_shared <model::builtin_literal_expression <int>> (c, 1))));
auto whileStatement = std::make_shared <WhileStatement> (whileCondition, whileBody);
body->appendStatement (whileStatement);
body->appendStatement (std::make_shared <model::return_statement> (std::make_shared <model::variable_expression> (variableDeclaration)));
auto func = m.createFunction (testFileName, variableDeclaration->getType (), body);
omni::tests::test_file_manager testFileManager;
return omni::tests::runFunction <int> (func, testFileManager, testFileName);
}
}
/**
Tests the while_statement and do_while_statement.
**/
BOOST_AUTO_TEST_SUITE (whileStatementTests)
BOOST_AUTO_TEST_CASE (ctor)
{
using namespace omni::core;
context c;
model::module m (c, "test");
model::while_statement whileStatement (std::make_shared <model::builtin_literal_expression <bool>> (c, true), std::make_shared <model::block> ());
}
BOOST_AUTO_TEST_CASE (metaInfoWhile)
{
using namespace omni::core::model;
meta_info & meta = while_statement::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "while_statement");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_CASE (metaInfoDoWhile)
{
using namespace omni::core::model;
meta_info & meta = do_while_statement::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "do_while_statement");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_CASE (whileStatement)
{
int result = buildAndRunWhileTest <omni::core::model::while_statement> ("whileStatementTest");
BOOST_CHECK_EQUAL (result, 10);
}
/*
// TODO: This test creates a broken COFF obj file:
// See the test llvmTests/llvmPlaygroundDoWhile for a trimmed-down, baremetal version.
// See http://llvm.org/bugs/show_bug.cgi?id=18308
BOOST_AUTO_TEST_CASE (doWhileStatement)
{
int result = buildAndRunWhileTest <omni::core::do_while_statement> ("doWhileStatementTest");
BOOST_CHECK_EQUAL (result, 10);
}
*/
BOOST_AUTO_TEST_SUITE_END ()
| 4,344 |
C++
| 36.782608 | 157 | 0.710175 |
daniel-kun/omni/source/omni/tests/core/model/test_literal_expression.cpp
|
#include <omni/core/model/literal_expression.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (literalExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = literal_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "literal_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & pure_expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 1u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& builtin_literal_expression <int>::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 779 |
C++
| 28.999999 | 83 | 0.713736 |
daniel-kun/omni/source/omni/tests/core/model/test_domain.cpp
|
#include <omni/core/domain.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/binary_operator_expression.hpp>
#include <omni/core/model/bitcast_expression.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/do_while_statement.hpp>
#include <omni/core/model/external_function.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/function_call_expression.hpp>
#include <omni/core/model/if_statement.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/parameter.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/type.hpp>
#include <omni/core/model/variable_assignment_expression.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/while_statement.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (domainTests)
BOOST_AUTO_TEST_CASE (allDomains)
{
using namespace omni::core;
using namespace omni::core::model;
context c;
auto literal1 = std::make_shared <builtin_literal_expression <int>> (c, 10);
auto literal2 = std::make_shared <builtin_literal_expression <int>> (c, 20);
BOOST_CHECK_EQUAL (domain::binary_operator_expression,
binary_operator_expression (c, binary_operator_expression::binary_operation::binary_plus_operation, literal1, literal2).getDomain ());
BOOST_CHECK_EQUAL (domain::bitcast_expression,
bitcast_expression (nullptr, nullptr).getDomain ());
BOOST_CHECK_EQUAL (domain::block,
block ().getDomain ());
BOOST_CHECK_EQUAL (domain::builtin_literal_expression,
literal1->getDomain ());
BOOST_CHECK_EQUAL (domain::do_while_statement,
do_while_statement ().getDomain ());
BOOST_CHECK_EQUAL (domain::external_function,
external_function (std::string (), std::string (), nullptr).getDomain ());
BOOST_CHECK_EQUAL (domain::function,
function (std::string (), nullptr, nullptr).getDomain ());
BOOST_CHECK_EQUAL (domain::function_call_expression,
function_call_expression ().getDomain ());
BOOST_CHECK_EQUAL (domain::if_statement,
if_statement (nullptr, nullptr, nullptr).getDomain ());
BOOST_CHECK_EQUAL (domain::module,
module (c).getDomain ());
BOOST_CHECK_EQUAL (domain::parameter,
parameter (nullptr, std::string ()).getDomain ());
BOOST_CHECK_EQUAL (domain::return_statement,
return_statement ().getDomain ());
BOOST_CHECK_EQUAL (domain::type,
type (c, type_class::t_boolean).getDomain ());
BOOST_CHECK_EQUAL (domain::variable_assignment_expression,
variable_assignment_expression (std::make_shared <variable_declaration_expression> (literal1->getType ()), literal1).getDomain ());
BOOST_CHECK_EQUAL (domain::variable_declaration_expression,
variable_declaration_expression ().getDomain ());
BOOST_CHECK_EQUAL (domain::variable_expression,
variable_expression (std::make_shared <variable_declaration_expression> (c.sharedBasicType (type_class::t_boolean))).getDomain ());
BOOST_CHECK_EQUAL (domain::while_statement,
while_statement ().getDomain ());
}
BOOST_AUTO_TEST_SUITE_END ()
| 3,534 |
C++
| 50.231883 | 157 | 0.661007 |
daniel-kun/omni/source/omni/tests/core/model/test_parameter.cpp
|
#include <omni/core/model/parameter.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (parameterTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = parameter::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "parameter");
BOOST_CHECK_EQUAL (meta.getParent (), & scope::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 502 |
C++
| 25.473683 | 73 | 0.701195 |
daniel-kun/omni/source/omni/tests/core/model/test_statement.cpp
|
#include <omni/core/model/statement.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/expression.hpp>
#include <omni/core/model/if_statement.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/while_statement.hpp>
#include <omni/core/model/do_while_statement.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (statementTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = statement::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "statement");
BOOST_CHECK_EQUAL (meta.getParent (), & scope::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 6u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& block::getStaticMetaInfo (),
& expression::getStaticMetaInfo (),
& if_statement::getStaticMetaInfo (),
& return_statement::getStaticMetaInfo (),
& while_statement::getStaticMetaInfo (),
& do_while_statement::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 1,158 |
C++
| 31.194444 | 73 | 0.696028 |
daniel-kun/omni/source/omni/tests/core/model/test_entity.cpp
|
#include <omni/core/model/entity.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/type.hpp>
#include <omni/core/model/scope.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/while_statement.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/auto_unit_test.hpp>
/**
Implements the necessary methods that are abstract in entity, so entity can be unit-tested (of course not the abstract parts).
**/
class testable_entity : public omni::core::model::entity {
public:
testable_entity () :
entity ()
{
}
testable_entity (std::string const & name) :
entity (name)
{
}
testable_entity (omni::core::id entityId, std::string const & name) :
entity (entityId, name)
{
}
omni::core::model::meta_info & getMetaInfo () const override
{
return entity::getMetaInfo ();
}
void setComponent (omni::core::domain domain, std::string name, std::shared_ptr <entity> entity) override {
entity::setComponent (domain, name, entity);
}
omni::core::domain getDomain () const override {
throw std::runtime_error ("testable_entity:getDomain (): Not implemented");
}
};
class test_entity_fixture {
public:
test_entity_fixture () :
c (),
mod (c),
varDecl (std::make_shared <omni::core::model::variable_declaration_expression> ()),
varBlock (std::make_shared <omni::core::model::block> ()),
whileStmt (std::make_shared <omni::core::model::while_statement> ()),
entity ()
{
entity.setComponent (varDecl->getDomain (), "varDecl", varDecl);
entity.setComponent (varBlock->getDomain (), "varBlock", varBlock);
entity.setComponent (whileStmt->getDomain (), "whileStmt", whileStmt);
}
protected:
omni::core::context c;
omni::core::model::module mod;
std::shared_ptr <omni::core::model::variable_declaration_expression> varDecl;
std::shared_ptr <omni::core::model::block> varBlock;
std::shared_ptr <omni::core::model::while_statement> whileStmt;
testable_entity entity;
};
BOOST_FIXTURE_TEST_SUITE (entityTests, test_entity_fixture)
/*
Tests the default-constructors of entity.
*/
BOOST_AUTO_TEST_CASE (ctor1)
{
using namespace omni::core;
testable_entity e1;
BOOST_CHECK_EQUAL (e1.getMetaInfo ().getName (), "entity");
BOOST_CHECK_EQUAL (e1.getName (), std::string ());
BOOST_CHECK_EQUAL (e1.getId (), id ());
BOOST_CHECK (! e1.getId ().isValid ());
}
/*
Tests the constructors of entity that specifies a name.
*/
BOOST_AUTO_TEST_CASE (ctor2)
{
using namespace omni::core;
std::string name = "Hello, World";
testable_entity e1 (name);
BOOST_CHECK_EQUAL (e1.getName (), name);
BOOST_CHECK_EQUAL (e1.getId (), id ());
BOOST_CHECK (! e1.getId ().isValid ());
}
/*
Tests the constructors of entity that specifies a name and an id.
*/
BOOST_AUTO_TEST_CASE (ctor3)
{
using namespace omni::core;
std::string name = "Hello, World";
id i = id (domain::function, "ABCDEFG");
testable_entity e1 (i, name);
BOOST_CHECK_EQUAL (e1.getName (), name);
BOOST_CHECK_EQUAL (e1.getId (), i);
BOOST_CHECK_EQUAL (e1.getId ().isValid (), i.isValid ());
}
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
testable_entity e;
meta_info & meta = entity::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (& meta, & e.getMetaInfo ());
BOOST_CHECK_EQUAL (meta.getName (), "entity");
BOOST_CHECK (meta.getParent () == nullptr);
BOOST_CHECK_EQUAL (meta.getChildCount (), 2u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& type::getStaticMetaInfo (),
& scope::getStaticMetaInfo (),
}));
}
/**
Tests the const and non-const versions of entity::getContext ().
**/
BOOST_AUTO_TEST_CASE (getContext)
{
using namespace omni::core;
using namespace omni::core::model;
context c;
module mod (c);
auto body = std::make_shared <block> ();
auto entity = std::make_shared <function> ("foo", c.sharedBasicType (type_class::t_boolean), body);
BOOST_CHECK_EQUAL (entity->getContext (), static_cast <context *> (nullptr));
BOOST_CHECK_EQUAL (static_cast <const function &> (* entity).getContext (), static_cast <const context *> (nullptr));
BOOST_CHECK_EQUAL (body->getContext (), static_cast <context *> (nullptr));
BOOST_CHECK_EQUAL (static_cast <const block &> (* body).getContext (), static_cast <const context *> (nullptr));
mod.addFunction (entity);
BOOST_CHECK_EQUAL (entity->getContext (), & c);
BOOST_CHECK_EQUAL (static_cast <const function &> (* entity).getContext (), & c);
BOOST_CHECK_EQUAL (body->getContext (), & c);
BOOST_CHECK_EQUAL (static_cast <const block &> (* body).getContext (), & c);
}
/**
Tests the const and non-const versions of entity::getModule ().
**/
BOOST_AUTO_TEST_CASE (getModule)
{
using namespace omni::core;
using namespace omni::core::model;
context c;
module mod (c);
auto body = std::make_shared <block> ();
auto entity = std::make_shared <function> ("foo", c.sharedBasicType (type_class::t_boolean), body);
BOOST_CHECK_EQUAL (entity->getModule (), static_cast <module *> (nullptr));
BOOST_CHECK_EQUAL (static_cast <const function &> (* entity).getModule (), static_cast <const module *> (nullptr));
BOOST_CHECK_EQUAL (body->getModule (), static_cast <module *> (nullptr));
BOOST_CHECK_EQUAL (static_cast <const block &> (* body).getModule (), static_cast <const module *> (nullptr));
mod.addFunction (entity);
BOOST_CHECK_EQUAL (entity->getModule (), & mod);
BOOST_CHECK_EQUAL (static_cast <const function &> (* entity).getModule (), & mod);
BOOST_CHECK_EQUAL (body->getModule (), & mod);
BOOST_CHECK_EQUAL (static_cast <const block &> (* body).getModule (), & mod);
}
/**
Tests the const and non-const versions of entity::getId ().
It especially tests whether an id is created as soon as an entity becomes part of a context.
**/
BOOST_AUTO_TEST_CASE (getId)
{
using namespace omni::core;
using namespace omni::core::model;
context c;
module mod (c);
auto body = std::make_shared <block> ();
auto entity = std::make_shared <function> ("foo", c.sharedBasicType (type_class::t_boolean), body);
BOOST_CHECK_EQUAL (entity->getId (), id ());
BOOST_CHECK_EQUAL (static_cast <const function &> (* entity).getId (), id ());
BOOST_CHECK_EQUAL (body->getId (), id ());
BOOST_CHECK_EQUAL (static_cast <const block &> (* body).getId (), id ());
mod.addFunction (entity);
BOOST_CHECK (entity->getId ().isValid ());
BOOST_CHECK (static_cast <const function &> (* entity).getId ().isValid ());
BOOST_CHECK (body->getId ().isValid ());
BOOST_CHECK (static_cast <const block &> (* body).getId ().isValid ());
}
/*
Tests various functions that implement the `components' concept.
*/
BOOST_AUTO_TEST_CASE (getComponent)
{
using namespace omni::core;
using namespace omni::core::model;
BOOST_CHECK_EQUAL (entity.getComponent (varDecl->getDomain (), "varDecl"), varDecl);
BOOST_CHECK_EQUAL (entity.getComponent (varBlock->getDomain (), "varBlock"), varBlock);
BOOST_CHECK_EQUAL (entity.getComponent (whileStmt->getDomain (), "whileStmt"), whileStmt);
BOOST_CHECK (entity.getComponent (domain::while_statement, "varDecl") == nullptr);
BOOST_CHECK (entity.getComponent (varDecl->getDomain (), "varDecl2") == nullptr);
const omni::core::model::entity & constEntity = entity;
BOOST_CHECK (constEntity.getComponent (domain::while_statement, "varDecl") == nullptr);
BOOST_CHECK (constEntity.getComponent (varDecl->getDomain (), "varDecl2") == nullptr);
}
BOOST_AUTO_TEST_CASE (getComponents)
{
using namespace omni::core;
using namespace omni::core::model;
BOOST_CHECK (entity.getComponents (domain::while_statement).find ("whileStmt")->second != nullptr);
BOOST_CHECK (entity.getComponents ().find (domain::while_statement)->second.find ("whileStmt")->second != nullptr);
const omni::core::model::entity & constEntity = entity;
BOOST_CHECK (constEntity.getComponents (domain::while_statement).find ("whileStmt")->second != nullptr);
BOOST_CHECK (constEntity.getComponents ().find (domain::while_statement)->second.find ("whileStmt")->second != nullptr);
}
BOOST_AUTO_TEST_CASE (getComponentAs)
{
using namespace omni::core;
using namespace omni::core::model;
const omni::core::model::entity & constEntity = entity;
// correct type, correct domain, correct name:
BOOST_CHECK (constEntity.getComponentAs <variable_declaration_expression> (domain::variable_declaration_expression, "varDecl") != nullptr);
BOOST_CHECK (constEntity.getComponentAs <block> (domain::block, "varBlock") != nullptr);
BOOST_CHECK (constEntity.getComponentAs <while_statement> (domain::while_statement, "whileStmt") != nullptr);
// correct type, correct domain, incorrect name:
BOOST_CHECK (constEntity.getComponentAs <variable_declaration_expression> (domain::variable_declaration_expression, "varDecl2") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <block> (domain::block, "varBlock2") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <while_statement> (domain::while_statement, "whileStmt2") == nullptr);
// correct type, incorrect domain, correct name:
BOOST_CHECK (constEntity.getComponentAs <variable_declaration_expression> (domain::block, "varDecl") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <block> (domain::while_statement, "varBlock") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <while_statement> (domain::variable_declaration_expression, "whileStmt") == nullptr);
// incorrect type, correct domain, correct name:
BOOST_CHECK (constEntity.getComponentAs <block> (domain::variable_declaration_expression, "varDecl") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <while_statement> (domain::block, "varBlock") == nullptr);
BOOST_CHECK (constEntity.getComponentAs <variable_declaration_expression> (domain::while_statement, "whileStmt") == nullptr);
}
BOOST_AUTO_TEST_CASE (getComponentsStartingWith)
{
using namespace omni::core;
using namespace omni::core::model;
variable_declaration_expression * found1 = nullptr;
// we expect to find exactly one result:
for (auto i : entity.getComponentsStartingWith (domain::variable_declaration_expression, "var")) {
BOOST_CHECK (found1 == nullptr);
if (found1 == nullptr) {
found1 = dynamic_cast <variable_declaration_expression *> (i.second.get ());
BOOST_CHECK (found1 != nullptr);
}
}
BOOST_CHECK (found1 == varDecl.get ());
auto varDecl2 = std::make_shared <variable_declaration_expression> ();
entity.setComponent (domain::variable_declaration_expression, "varDecl2", varDecl2);
found1 = nullptr;
variable_declaration_expression * found2 = nullptr;
for (auto i : entity.getComponentsStartingWith (domain::variable_declaration_expression, "varDecl")) {
auto iDecl = dynamic_cast <variable_declaration_expression *> (i.second.get ());
if (iDecl == varDecl.get ()) {
found1 = iDecl;
}
if (iDecl == varDecl2.get ()) {
found2 = iDecl;
}
}
BOOST_CHECK_EQUAL (found1, varDecl.get ());
BOOST_CHECK_EQUAL (found2, varDecl2.get ());
auto varDecl3 = std::make_shared <variable_declaration_expression> ();
entity.setComponent (domain::variable_declaration_expression, "varDecl3", varDecl3);
found1 = nullptr;
found2 = nullptr;
variable_declaration_expression * found3 = nullptr;
for (auto i : entity.getComponentsStartingWith (domain::variable_declaration_expression, "varDecl")) {
auto iDecl = dynamic_cast <variable_declaration_expression *> (i.second.get ());
if (iDecl == varDecl.get ()) {
found1 = iDecl;
}
if (iDecl == varDecl2.get ()) {
found2 = iDecl;
}
if (iDecl == varDecl3.get ()) {
found3 = iDecl;
}
}
BOOST_CHECK_EQUAL (found1, varDecl.get ());
BOOST_CHECK_EQUAL (found2, varDecl2.get ());
BOOST_CHECK_EQUAL (found3, varDecl3.get ());
}
BOOST_AUTO_TEST_CASE (getComponentsStartingWithAs)
{
using namespace omni::core;
using namespace omni::core::model;
variable_declaration_expression * found1 = nullptr;
// we expect to find exactly one result:
for (auto i : entity.getComponentsStartingWithAs <variable_declaration_expression> (domain::variable_declaration_expression, "var")) {
BOOST_CHECK (found1 == nullptr);
if (found1 == nullptr) {
found1 = i.second.get ();
BOOST_CHECK (found1 != nullptr);
}
}
BOOST_CHECK (found1 == varDecl.get ());
auto varDecl2 = std::make_shared <variable_declaration_expression> ();
entity.setComponent (domain::variable_declaration_expression, "varDecl2", varDecl2);
found1 = nullptr;
variable_declaration_expression * found2 = nullptr;
for (auto i : entity.getComponentsStartingWithAs <variable_declaration_expression> (domain::variable_declaration_expression, "varDecl")) {
auto iDecl = i.second.get ();
if (iDecl == varDecl.get ()) {
found1 = iDecl;
}
if (iDecl == varDecl2.get ()) {
found2 = iDecl;
}
}
BOOST_CHECK_EQUAL (found1, varDecl.get ());
BOOST_CHECK_EQUAL (found2, varDecl2.get ());
auto varDecl3 = std::make_shared <variable_declaration_expression> ();
entity.setComponent (domain::variable_declaration_expression, "varDecl3", varDecl3);
found1 = nullptr;
found2 = nullptr;
variable_declaration_expression * found3 = nullptr;
for (auto i : entity.getComponentsStartingWithAs <variable_declaration_expression> (domain::variable_declaration_expression, "varDecl")) {
auto iDecl = i.second.get ();
if (iDecl == varDecl.get ()) {
found1 = iDecl;
}
if (iDecl == varDecl2.get ()) {
found2 = iDecl;
}
if (iDecl == varDecl3.get ()) {
found3 = iDecl;
}
}
BOOST_CHECK_EQUAL (found1, varDecl.get ());
BOOST_CHECK_EQUAL (found2, varDecl2.get ());
BOOST_CHECK_EQUAL (found3, varDecl3.get ());
}
BOOST_AUTO_TEST_CASE (clearComponents)
{
BOOST_CHECK_EQUAL (entity.getComponents ().size (), 3u);
entity.clearComponents ();
BOOST_CHECK_EQUAL (entity.getComponents ().size (), 0u);
}
BOOST_AUTO_TEST_CASE (clearComponentsByDomain)
{
using namespace omni::core;
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 1u);
entity.clearComponents (domain::block);
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 0u);
}
BOOST_AUTO_TEST_CASE (removeComponentByDomainAndName)
{
using namespace omni::core;
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 1u);
BOOST_CHECK (entity.removeComponent (domain::block, "varBlock"));
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 0u);
}
BOOST_AUTO_TEST_CASE (removeComponentByDomainAndPointer)
{
using namespace omni::core;
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 1u);
BOOST_CHECK (entity.removeComponent (domain::block, varBlock));
BOOST_CHECK_EQUAL (entity.getComponents (domain::block).size (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ()
| 15,759 |
C++
| 37.439024 | 144 | 0.660131 |
daniel-kun/omni/source/omni/tests/core/model/test_module.cpp
|
#include <omni/core/model/module.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (moduleTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = module::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "module");
BOOST_CHECK_EQUAL (meta.getParent (), & scope::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 490 |
C++
| 24.842104 | 73 | 0.693878 |
daniel-kun/omni/source/omni/tests/core/model/test_expression.cpp
|
#include <omni/core/model/expression.hpp>
#include <omni/core/model/pure_expression.hpp>
#include <omni/core/model/modifying_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (expressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "expression");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 2u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& pure_expression::getStaticMetaInfo (),
& modifying_expression::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 820 |
C++
| 28.321428 | 77 | 0.704878 |
daniel-kun/omni/source/omni/tests/core/model/test_function.cpp
|
#include <omni/core/context.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/type.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (funcionTests)
BOOST_AUTO_TEST_CASE (ctor)
{
using namespace omni::core;
context c;
model::module mod (c, "test");
std::shared_ptr <model::type> returnType (model::type::sharedBasicType (c, model::type_class::t_signedInt));
model::function func ("hello", returnType, nullptr);
}
BOOST_AUTO_TEST_CASE (getReturnType)
{
using namespace omni::core;
context c;
model::module mod (c, "test");
std::shared_ptr <model::type> returnType (model::type::sharedBasicType (c, model::type_class::t_signedInt));
model::function func ("hello", returnType, nullptr);
BOOST_CHECK (func.getReturnType ()->getTypeClass () == model::type_class::t_signedInt);
}
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = function::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "function");
BOOST_CHECK_EQUAL (meta.getParent (), & function_prototype::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 1,325 |
C++
| 30.571428 | 112 | 0.69283 |
daniel-kun/omni/source/omni/tests/core/model/test_type.cpp
|
#include <omni/core/model/type.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/context.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_SUITE (typeTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core;
using namespace omni::core::model;
context c;
type t (c, type_class::t_signedInt);
meta_info & meta = t.getMetaInfo ();
BOOST_CHECK_EQUAL (& meta, & type::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getName (), "type");
BOOST_CHECK_EQUAL (meta.getParent (), & entity::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ()
| 661 |
C++
| 25.479999 | 74 | 0.677761 |
daniel-kun/omni/source/omni/tests/core/model/test_return_statement.cpp
|
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (returnStatementTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = return_statement::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "return_statement");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 533 |
C++
| 27.105262 | 77 | 0.712946 |
daniel-kun/omni/source/omni/tests/core/model/test_native_type_to_type_class.cpp
|
#include <omni/core/model/native_type_to_type_class.hpp>
#include <omni/core/model/type_class.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(nativeTypeToTypeClassTests)
BOOST_AUTO_TEST_CASE (all)
{
using namespace omni::core::model;
static_assert (native_type_to_type_class <void>::typeClass == type_class::t_void, "void != t_void");
static_assert (native_type_to_type_class <bool>::typeClass == type_class::t_boolean, "bool != t_boolean");
static_assert (native_type_to_type_class <unsigned char>::typeClass == type_class::t_unsignedByte, "unsigned char != t_unsignedByte");
static_assert (native_type_to_type_class <signed char>::typeClass == type_class::t_signedByte, "signed char != t_signedByte");
static_assert (native_type_to_type_class <unsigned short>::typeClass == type_class::t_unsignedShort, "unsigned short != t_unsignedShort");
static_assert (native_type_to_type_class <signed short>::typeClass == type_class::t_signedShort, "signed short != t_signedShort");
static_assert (native_type_to_type_class <unsigned int>::typeClass == type_class::t_unsignedInt, "unsigned int != t_unsignedInt");
static_assert (native_type_to_type_class <signed int>::typeClass == type_class::t_signedInt, "signed int != t_signedInt");
static_assert (native_type_to_type_class <unsigned long>::typeClass == type_class::t_unsignedLong, "unsigned long != t_unsignedLong");
static_assert (native_type_to_type_class <signed long>::typeClass == type_class::t_signedLong, "signed long != t_signedLong");
static_assert (native_type_to_type_class <unsigned long long>::typeClass == type_class::t_unsignedLongLong, "unsigned long long != t_unsignedLongLong");
static_assert (native_type_to_type_class <signed long long>::typeClass == type_class::t_signedLongLong, "signed long long != t_signedLongLong");
static_assert (native_type_to_type_class <char>::typeClass == type_class::t_char, "char != t_char");
static_assert (native_type_to_type_class <std::string>::typeClass == type_class::t_string, "std::string != t_string");
}
BOOST_AUTO_TEST_SUITE_END ()
| 2,119 |
C++
| 72.103446 | 156 | 0.714016 |
daniel-kun/omni/source/omni/tests/core/model/test_meta_info.cpp
|
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/entity.hpp>
#include <omni/core/model/type.hpp>
#include <omni/core/model/scope.hpp>
#include <omni/core/model/function_prototype.hpp>
#include <omni/core/model/external_function.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/parameter.hpp>
#include <omni/core/model/statement.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/expression.hpp>
#include <omni/core/model/modifying_expression.hpp>
#include <omni/core/model/function_call_expression.hpp>
#include <omni/core/model/variable_assignment_expression.hpp>
#include <omni/core/model/pure_expression.hpp>
#include <omni/core/model/binary_operator_expression.hpp>
#include <omni/core/model/cast_expression.hpp>
#include <omni/core/model/bitcast_expression.hpp>
#include <omni/core/model/literal_expression.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/if_statement.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/while_statement.hpp>
#include <omni/core/model/do_while_statement.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <memory>
BOOST_AUTO_TEST_SUITE (metaInfoTests)
BOOST_AUTO_TEST_CASE (ctor1)
{
using namespace omni::core::model;
meta_info m ("hello");
BOOST_CHECK_EQUAL (m.getName (), "hello");
BOOST_CHECK (m.getParent () == nullptr);
BOOST_CHECK_EQUAL (m.getChildCount (), 0u);
BOOST_CHECK (m.getExtension ("foo") == nullptr);
}
BOOST_AUTO_TEST_CASE (ctor2_getName_getParent_getChildAt_getChildCount)
{
using namespace omni::core::model;
meta_info parent ("parent");
meta_info m (parent, "hello");
BOOST_CHECK_EQUAL (m.getName (), "hello");
BOOST_CHECK (m.getParent () == & parent);
BOOST_CHECK_EQUAL (parent.getChildCount (), 1u);
BOOST_CHECK_EQUAL (& parent.getChildAt (0u), & m);
BOOST_CHECK_EQUAL (m.getChildCount (), 0u);
BOOST_CHECK (m.getExtension ("foo") == nullptr);
}
BOOST_AUTO_TEST_CASE (getChildAt_getChildCount)
{
using namespace omni::core::model;
meta_info parent ("parent");
meta_info m1 (parent, "child1");
meta_info m2 (parent, "child2");
meta_info m3 (parent, "child3");
BOOST_CHECK (parent.getParent () == nullptr);
BOOST_CHECK (m1.getParent () == & parent);
BOOST_CHECK (m2.getParent () == & parent);
BOOST_CHECK (m3.getParent () == & parent);
BOOST_CHECK_EQUAL (parent.getChildCount (), 3u);
BOOST_CHECK_EQUAL (& parent.getChildAt (0u), & m1);
BOOST_CHECK_EQUAL (& parent.getChildAt (1u), & m2);
BOOST_CHECK_EQUAL (& parent.getChildAt (2u), & m3);
}
BOOST_AUTO_TEST_CASE (setExtension_getExtension)
{
using namespace omni::core::model;
meta_info m ("extendable");
class test_extension : public meta_info_extension {
public:
test_extension (int foo) : _foo (foo) { }
int _foo;
};
auto ext1 = std::make_shared <test_extension> (-1);
auto ext2 = std::make_shared <test_extension> (0);
auto ext3 = std::make_shared <test_extension> (1);
m.setExtension ("ext1", ext1);
m.setExtension ("ext2", ext2);
m.setExtension ("ext3", ext3);
BOOST_CHECK_EQUAL (m.getExtension ("ext1"), ext1.get ());
BOOST_CHECK_EQUAL (m.getExtension ("ext2"), ext2.get ());
BOOST_CHECK_EQUAL (m.getExtension ("ext3"), ext3.get ());
}
BOOST_AUTO_TEST_CASE (staticInit)
{
#define OMNI_TEST_CHECK_META_INFO_NAME(A) \
BOOST_CHECK_EQUAL (omni::core::model::A::getStaticMetaInfo ().getName (), #A);
OMNI_TEST_CHECK_META_INFO_NAME (entity);
OMNI_TEST_CHECK_META_INFO_NAME (type);
OMNI_TEST_CHECK_META_INFO_NAME (scope);
OMNI_TEST_CHECK_META_INFO_NAME (function_prototype);
OMNI_TEST_CHECK_META_INFO_NAME (external_function);
OMNI_TEST_CHECK_META_INFO_NAME (function);
OMNI_TEST_CHECK_META_INFO_NAME (module);
OMNI_TEST_CHECK_META_INFO_NAME (parameter);
OMNI_TEST_CHECK_META_INFO_NAME (statement);
OMNI_TEST_CHECK_META_INFO_NAME (block);
OMNI_TEST_CHECK_META_INFO_NAME (expression);
OMNI_TEST_CHECK_META_INFO_NAME (modifying_expression);
OMNI_TEST_CHECK_META_INFO_NAME (function_call_expression);
OMNI_TEST_CHECK_META_INFO_NAME (variable_assignment_expression);
OMNI_TEST_CHECK_META_INFO_NAME (pure_expression);
OMNI_TEST_CHECK_META_INFO_NAME (binary_operator_expression);
OMNI_TEST_CHECK_META_INFO_NAME (cast_expression);
OMNI_TEST_CHECK_META_INFO_NAME (bitcast_expression);
OMNI_TEST_CHECK_META_INFO_NAME (literal_expression);
OMNI_TEST_CHECK_META_INFO_NAME (variable_declaration_expression);
OMNI_TEST_CHECK_META_INFO_NAME (variable_expression);
OMNI_TEST_CHECK_META_INFO_NAME (if_statement);
OMNI_TEST_CHECK_META_INFO_NAME (return_statement);
OMNI_TEST_CHECK_META_INFO_NAME (while_statement);
OMNI_TEST_CHECK_META_INFO_NAME (do_while_statement);
#undef OMNI_TEST_CHECK_META_INFO_NAME
BOOST_CHECK_EQUAL (omni::core::model::builtin_literal_expression<int>::getStaticMetaInfo ().getName (), "builtin_literal_expression");
}
BOOST_AUTO_TEST_SUITE_END ()
| 5,252 |
C++
| 38.201492 | 138 | 0.700876 |
daniel-kun/omni/source/omni/tests/core/model/test_modifying_expression.cpp
|
#include <omni/core/model/modifying_expression.hpp>
#include <omni/core/model/function_call_expression.hpp>
#include <omni/core/model/variable_assignment_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (modifyingExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = modifying_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "modifying_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 2u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& function_call_expression::getStaticMetaInfo (),
& variable_assignment_expression::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 898 |
C++
| 31.107142 | 78 | 0.722717 |
daniel-kun/omni/source/omni/tests/core/model/test_scope.cpp
|
#include <omni/core/model/scope.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/function_prototype.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/parameter.hpp>
#include <omni/core/model/statement.hpp>
#include <omni/core/context.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_SUITE (scopeTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core;
using namespace omni::core::model;
meta_info & meta = scope::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "scope");
BOOST_CHECK_EQUAL (meta.getParent (), & entity::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 4u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& function_prototype::getStaticMetaInfo (),
& module::getStaticMetaInfo (),
& parameter::getStaticMetaInfo (),
& statement::getStaticMetaInfo (),
}));
}
BOOST_AUTO_TEST_SUITE_END ()
| 1,013 |
C++
| 28.823529 | 74 | 0.692991 |
daniel-kun/omni/source/omni/tests/core/model/test_function_prototype.cpp
|
#include <omni/core/context.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/function_prototype.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/external_function.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (funcionPrototypeTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = function_prototype::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "function_prototype");
BOOST_CHECK_EQUAL (meta.getParent (), & scope::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 2u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& function::getStaticMetaInfo (),
& external_function::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 898 |
C++
| 27.999999 | 73 | 0.709354 |
daniel-kun/omni/source/omni/tests/core/model/test_binary_operator_expression.cpp
|
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/binary_operator_expression.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <omni/tests/test_file_manager.hpp>
#include <boost/test/unit_test.hpp>
#include <sstream>
#include <limits>
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
namespace omni {
namespace tests {
class test_binary_operator_expression_fixture {
public:
test_binary_operator_expression_fixture () :
_testCounter (0u),
_context (),
_module (_context, "test")
{
}
protected:
std::size_t _testCounter;
omni::core::context _context;
omni::core::model::module _module;
};
template <typename T>
T test (std::size_t & testCounter,
omni::core::model::module & m,
omni::core::model::binary_operator_expression::binary_operation operation,
std::shared_ptr <omni::core::model::builtin_literal_expression <T>> left,
std::shared_ptr <omni::core::model::builtin_literal_expression <T>> right)
{
using namespace omni::core;
std::shared_ptr <model::block> body (new model::block ());
body->appendStatement (
std::shared_ptr <model::statement> (
new model::return_statement (
std::shared_ptr <model::expression> (new model::binary_operator_expression (* m.getContext (), operation, left, right)))));
std::stringstream funcName;
funcName << "binaryOperatorExpressionTest" << ++ testCounter;
std::string testFuncName = funcName.str ();
std::shared_ptr <model::function> func (new model::function (testFuncName, left->getType (), body));
m.addFunction (func);
omni::tests::test_file_manager testFileManager;
T result = omni::tests::runFunction <T> (func, testFileManager, testFuncName);
return result;
}
/**
We are using a macro here because the BOOST_CHECK_EQUAL will print out the original expressions for LEFT and RIGHT instead of just the results.
This offers a better orientation when a BOOST_CHECK_EQUAL failes.
**/
#define TEST_BINOP(TESTCOUNTER, MODULE, OPERATION, OPERATOR, LEFT, RIGHT) { \
auto result = test (TESTCOUNTER,\
MODULE,\
OPERATION,\
std::make_shared <omni::core::model::builtin_literal_expression <decltype(LEFT)>> (* MODULE.getContext (), LEFT),\
std::make_shared <omni::core::model::builtin_literal_expression <decltype(RIGHT)>> (* MODULE.getContext (), RIGHT));\
BOOST_CHECK_EQUAL (result, static_cast <decltype (LEFT)> (LEFT OPERATOR RIGHT));\
if (result != static_cast <decltype (LEFT)> (LEFT OPERATOR RIGHT)) { \
std::stringstream fileName; \
fileName << "binaryOperatorExpressionTest" << TESTCOUNTER << ".ll"; \
omni::tests::test_file_manager testFileManager; \
MODULE.emitAssemblyFile(testFileManager.getTestFileName (fileName.str (), false).string ()); \
} \
}
/////////// PLUS //////////
#define TEST_PLUS(TESTCOUNTER, MODULE, LEFT, RIGHT) TEST_BINOP(TESTCOUNTER, MODULE, omni::core::model::binary_operator_expression::binary_operation::binary_plus_operation, +, LEFT, RIGHT)
template <typename T>
void testNumericLimitsPlus (std::size_t & testCounter, omni::core::model::module & mod)
{
TEST_BINOP (testCounter, mod, omni::core::model::binary_operator_expression::binary_operation::binary_plus_operation, +, 0, 0);
TEST_BINOP (testCounter, mod, omni::core::model::binary_operator_expression::binary_operation::binary_plus_operation, +, std::numeric_limits <T>::min (), std::numeric_limits <T>::min ());
TEST_BINOP (testCounter, mod, omni::core::model::binary_operator_expression::binary_operation::binary_plus_operation, +, std::numeric_limits <T>::max (), std::numeric_limits <T>::max ());
TEST_BINOP (testCounter, mod, omni::core::model::binary_operator_expression::binary_operation::binary_plus_operation, +, std::numeric_limits <T>::max () / 2, std::numeric_limits <T>::max () / 2);
}
BOOST_FIXTURE_TEST_SUITE (binaryOperatorExpressionTest, test_binary_operator_expression_fixture)
BOOST_AUTO_TEST_CASE (plusSignedShortNumericLimits)
{
using namespace omni::core;
testNumericLimitsPlus <signed short> (_testCounter, _module);
}
BOOST_AUTO_TEST_CASE (plusSignedShort1)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 1, 1);
}
BOOST_AUTO_TEST_CASE (plusSignedShort2)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 256, 256);
}
BOOST_AUTO_TEST_CASE (plusSignedShort3)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, -1, -1);
}
BOOST_AUTO_TEST_CASE (plusSignedShort4)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, -256, -256);
}
BOOST_AUTO_TEST_CASE (plusUnsignedShortNumericLimits)
{
using namespace omni::core;
testNumericLimitsPlus <unsigned short> (_testCounter, _module);
}
BOOST_AUTO_TEST_CASE (plusUnsignedShort1)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 1, 1);
}
BOOST_AUTO_TEST_CASE (plusUnsignedShort2)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 256, 256);
}
BOOST_AUTO_TEST_CASE (plusUnsignedShort3)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 0, 1);
}
BOOST_AUTO_TEST_CASE (plusUnsignedShort4)
{
using namespace omni::core;
TEST_PLUS (_testCounter, _module, 0, -256);
}
BOOST_AUTO_TEST_CASE (plusSignedInt)
{
using namespace omni::core;
testNumericLimitsPlus <signed int> (_testCounter, _module);
TEST_PLUS (_testCounter, _module, 1, 1);
TEST_PLUS (_testCounter, _module, 256, 256);
TEST_PLUS (_testCounter, _module, -1, -1);
TEST_PLUS (_testCounter, _module, -256, -256);
}
BOOST_AUTO_TEST_CASE (plusUnsignedInt)
{
using namespace omni::core;
testNumericLimitsPlus <unsigned int> (_testCounter, _module);
TEST_PLUS (_testCounter, _module, 1u, 1u);
TEST_PLUS (_testCounter, _module, 256u, 256u);
TEST_PLUS (_testCounter, _module, (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u), 1u);
TEST_PLUS (_testCounter, _module, (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u), (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u));
}
/////////// MINUS //////////
#define TEST_MINUS(TESTCOUNTER, MODULE, LEFT, RIGHT) TEST_BINOP(TESTCOUNTER, MODULE, omni::core::model::binary_operator_expression::binary_operation::binary_minus_operation, -, LEFT, RIGHT)
template <typename T>
void testNumericLimitsMinus (std::size_t & testCounter, omni::core::model::module & m)
{
TEST_BINOP (testCounter, m, omni::core::model::binary_operator_expression::binary_operation::binary_minus_operation, -, 0, 0);
TEST_BINOP (testCounter, m, omni::core::model::binary_operator_expression::binary_operation::binary_minus_operation, -, std::numeric_limits <T>::min (), std::numeric_limits <T>::min ());
TEST_BINOP (testCounter, m, omni::core::model::binary_operator_expression::binary_operation::binary_minus_operation, -, std::numeric_limits <T>::max (), std::numeric_limits <T>::max ());
TEST_BINOP (testCounter, m, omni::core::model::binary_operator_expression::binary_operation::binary_minus_operation, -, std::numeric_limits <T>::max () / 2, std::numeric_limits <T>::max () / 2);
}
BOOST_AUTO_TEST_CASE (minusSignedShortNumericLimits)
{
using namespace omni::core;
testNumericLimitsMinus <signed short> (_testCounter, _module);
}
BOOST_AUTO_TEST_CASE (minusSignedShort1)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 1, 1);
}
BOOST_AUTO_TEST_CASE (minusSignedShort2)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 256, 256);
}
BOOST_AUTO_TEST_CASE (minusSignedShort3)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, -1, -1);
}
BOOST_AUTO_TEST_CASE (minusSignedShort4)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, -256, -256);
}
BOOST_AUTO_TEST_CASE (minusUnsignedShortNumericLimits)
{
using namespace omni::core;
testNumericLimitsMinus <unsigned short> (_testCounter, _module);
}
BOOST_AUTO_TEST_CASE (minusUnsignedShort1)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 1, 1);
}
BOOST_AUTO_TEST_CASE (minusUnsignedShort2)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 256, 256);
}
BOOST_AUTO_TEST_CASE (minusUnsignedShort3)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 0, 1);
}
BOOST_AUTO_TEST_CASE (minusUnsignedShort4)
{
using namespace omni::core;
TEST_MINUS (_testCounter, _module, 0, -256);
}
BOOST_AUTO_TEST_CASE (minusSignedInt)
{
using namespace omni::core;
testNumericLimitsMinus <signed int> (_testCounter, _module);
TEST_MINUS (_testCounter, _module, 1, 1);
TEST_MINUS (_testCounter, _module, 256, 256);
TEST_MINUS (_testCounter, _module, -1, -1);
TEST_MINUS (_testCounter, _module, -256, -256);
}
BOOST_AUTO_TEST_CASE (minusUnsignedInt)
{
using namespace omni::core;
testNumericLimitsMinus <unsigned int> (_testCounter, _module);
TEST_MINUS (_testCounter, _module, 1u, 1u);
TEST_MINUS (_testCounter, _module, 256u, 256u);
TEST_MINUS (_testCounter, _module, (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u), 1u);
TEST_MINUS (_testCounter, _module, (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u), (static_cast <unsigned int> (std::numeric_limits <signed int>::max ()) + 1u));
}
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = binary_operator_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "binary_operator_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & pure_expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
}
}
| 10,204 |
C++
| 34.557491 | 199 | 0.679929 |
daniel-kun/omni/source/omni/tests/core/model/test_variable_expression.cpp
|
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (variableExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = variable_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "variable_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & pure_expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 551 |
C++
| 28.05263 | 83 | 0.720508 |
daniel-kun/omni/source/omni/tests/core/model/test_variable_declaration_expression.cpp
|
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (variableDeclarationExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = variable_declaration_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "variable_declaration_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & pure_expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ();
| 598 |
C++
| 30.526314 | 83 | 0.737458 |
daniel-kun/omni/source/omni/tests/core/model/test_external_function.cpp
|
#include <omni/core/model/external_function.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/type.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/parameter.hpp>
#include <omni/core/model/function_call_expression.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (externalFunctionTests)
BOOST_AUTO_TEST_CASE (ctor)
{
using namespace omni::core;
context c;
model::module mod (c, "test");
#ifdef WIN32
std::string putcharLib = "LIBCMT.LIB";
#else
std::string putcharLib;
#endif
std::shared_ptr <model::external_function> function_putchar (new model::external_function (putcharLib, "putchar", model::type::sharedBasicType (c, model::type_class::t_signedInt)));
std::shared_ptr <model::parameter> param1 (new model::parameter (model::type::sharedBasicType (c, model::type_class::t_signedInt), std::string ()));
function_putchar->appendParameter (param1);
std::shared_ptr <model::function_call_expression> functionCallExpression (new model::function_call_expression (function_putchar));
std::shared_ptr <model::builtin_literal_expression <signed int>> param1Value (new model::builtin_literal_expression <signed int> (c, 'O'));
auto param1Type = param1Value->getType ();
auto putcharParam1Type = function_putchar->getParameters () [0]->getType ();
std::shared_ptr <model::literal_expression> param1Expression (param1Value);
functionCallExpression->appendParameter (param1Expression);
std::shared_ptr <model::block> body (new model::block ());
std::shared_ptr <model::return_statement> returnStatement (new model::return_statement (functionCallExpression));
body->appendStatement (returnStatement);
std::shared_ptr <model::function> funcCaller (new model::function ("putcharCaller", model::type::sharedBasicType (c, model::type_class::t_signedInt), body));
mod.addFunction (function_putchar);
mod.addFunction (funcCaller);
omni::tests::test_file_manager testFileManager;
std::string functionName;
omni::tests::runFunction <int> (funcCaller, testFileManager, "externalFunctionTestsCtor");
}
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = external_function::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "external_function");
BOOST_CHECK_EQUAL (meta.getParent (), & function_prototype::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_SUITE_END ()
| 2,715 |
C++
| 42.11111 | 185 | 0.730018 |
daniel-kun/omni/source/omni/tests/core/model/test_block.cpp
|
#include <omni/core/model/block.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/meta_info.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <functional>
#include <algorithm>
namespace {
typedef std::function <void (omni::core::model::block &,
std::shared_ptr <omni::core::model::variable_declaration_expression>,
std::shared_ptr <omni::core::model::expression>)> buildModuleBody;
/**
Builds a valid or an invalid module.
@param shouldBeValid True, if buildModule should build a valid module. False, if it should build an invalid module.
**/
void buildModule (bool shouldBeValid, buildModuleBody builder)
{
using namespace omni::core;
context c;
model::module m (c, "test");
auto t = c.sharedBasicType (model::type_class::t_signedInt);
auto variableDeclaration = std::make_shared <model::variable_declaration_expression> (t);
auto variableExpression = std::make_shared <model::variable_expression> (variableDeclaration);
auto body = std::make_shared <model::block> ();
builder (* body, variableDeclaration, variableExpression);
body->appendStatement (std::make_shared <model::return_statement> (variableExpression));
auto func = m.createFunction ("test", t, body);
std::string errorInfo;
bool isValid = m.verify (errorInfo);
BOOST_CHECK_EQUAL (isValid, shouldBeValid);
if (shouldBeValid) {
BOOST_CHECK_EQUAL (errorInfo.length (), 0u);
} else {
BOOST_CHECK_NE (errorInfo.length (), 0u);
}
}
}
BOOST_AUTO_TEST_SUITE (blockTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = block::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "block");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_CASE (appendStatement)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (decl);
b.appendStatement (expr);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.appendStatement (decl);
});
}
BOOST_AUTO_TEST_CASE (prependStatement)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.prependStatement (decl);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (decl);
b.prependStatement (expr);
});
}
BOOST_AUTO_TEST_CASE (insertStatementAfter)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.prependStatement (decl);
b.insertStatementAfter (b.findStatement (decl), expr);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.prependStatement (expr);
b.insertStatementAfter (b.findStatement (expr), decl);
});
}
BOOST_AUTO_TEST_CASE (insertStatementBefore)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.prependStatement (expr);
b.insertStatementBefore (b.findStatement (expr), decl);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.prependStatement (decl);
b.insertStatementBefore (b.findStatement (decl), expr);
});
}
BOOST_AUTO_TEST_CASE (removeStatementFromPosition)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.appendStatement (decl);
b.appendStatement (std::make_shared <omni::core::model::variable_expression> (decl));
// Remove the first expression that uses the variable before it's declaration:
auto it = b.findStatement (expr);
BOOST_CHECK (it != b.statementsEnd ());
b.removeStatement (it);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.appendStatement (decl);
auto expression = std::make_shared <omni::core::model::variable_expression> (decl);
b.appendStatement (expression);
// Remove the last expression, so that the expression that uses the variable before it's declaration stays:
auto it = b.findStatement (expression);
BOOST_CHECK (it != b.statementsEnd ());
b.removeStatement (it);
});
}
BOOST_AUTO_TEST_CASE (removeStatement)
{
buildModule (true,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.appendStatement (decl);
b.appendStatement (std::make_shared <omni::core::model::variable_expression> (decl));
// Remove the first expression that uses the variable before it's declaration:
b.removeStatement (expr);
});
buildModule (false,
[] (omni::core::model::block & b,
std::shared_ptr <omni::core::model::variable_declaration_expression> decl,
std::shared_ptr <omni::core::model::expression> expr) -> void {
b.appendStatement (expr);
b.appendStatement (decl);
auto expression = std::make_shared <omni::core::model::variable_expression> (decl);
b.appendStatement (expression);
// Remove the last expression, so that the expression that uses the variable before it's declaration stays:
b.removeStatement (expression);
});
}
BOOST_AUTO_TEST_SUITE_END ()
| 7,744 |
C++
| 39.763158 | 115 | 0.608858 |
daniel-kun/omni/source/omni/tests/core/model/test_if_statement.cpp
|
#include <omni/core/model/if_statement.hpp>
#include <omni/core/context.hpp>
#include <omni/core/model/module.hpp>
#include <omni/core/model/builtin_literal_expression.hpp>
#include <omni/core/model/return_statement.hpp>
#include <omni/core/model/block.hpp>
#include <omni/core/model/function.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_file_manager.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <sstream>
BOOST_AUTO_TEST_SUITE (ifStatementTests)
BOOST_AUTO_TEST_CASE (ctor)
{
using namespace omni::core;
context c;
auto condition = std::make_shared <model::builtin_literal_expression <bool>> (c, true);
auto trueBlock = std::make_shared <model::block> ();
auto elseBlock = std::make_shared <model::block> ();
model::if_statement ifStatement (condition, trueBlock, elseBlock);
BOOST_CHECK (ifStatement.getCondition () == condition);
BOOST_CHECK (ifStatement.getTrueBlock () == trueBlock);
BOOST_CHECK (ifStatement.getElseBlock () == elseBlock);
model::if_statement ifStatement2 (condition, trueBlock, nullptr);
BOOST_CHECK (ifStatement2.getCondition () == condition);
BOOST_CHECK (ifStatement2.getTrueBlock () == trueBlock);
BOOST_CHECK (ifStatement2.getElseBlock () == nullptr);
}
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = if_statement::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "if_statement");
BOOST_CHECK_EQUAL (meta.getParent (), & statement::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 0u);
}
BOOST_AUTO_TEST_CASE (mixedTests)
{
using namespace omni::core;
context c;
model::module m (c, "test");
auto runDemo = [& c, & m] (bool cond) -> int
{
auto condition = std::make_shared <model::builtin_literal_expression <bool>> (c, cond);
auto trueBlock = std::make_shared <model::block> ();
trueBlock->appendStatement (std::make_shared <model::return_statement> (std::make_shared <model::builtin_literal_expression <int>> (c, 42)));
auto elseBlock = std::make_shared <model::block> ();
elseBlock->appendStatement (std::make_shared <model::return_statement> (std::make_shared <model::builtin_literal_expression <int>> (c, 128)));
auto ifStatement = std::make_shared <model::if_statement> (condition, trueBlock, elseBlock);
auto body = std::make_shared <model::block> ();
body->appendStatement (ifStatement);
std::stringstream str;
str << "test" << cond;
std::shared_ptr <model::function> func = m.createFunction (str.str (), c.sharedBasicType (model::type_class::t_signedInt), body);
omni::tests::test_file_manager testFileManager;
return omni::tests::runFunction <int> (func, testFileManager, "ifStatementMixedTests");
};
int result = runDemo (true);
BOOST_CHECK_EQUAL (result, 42);
BOOST_CHECK_NE (result, 128);
result = runDemo (false);
BOOST_CHECK_EQUAL (result, 128);
BOOST_CHECK_NE (result, 42);
}
BOOST_AUTO_TEST_SUITE_END ()
| 3,137 |
C++
| 35.488372 | 150 | 0.676761 |
daniel-kun/omni/source/omni/tests/core/model/test_pure_expression.cpp
|
#include <omni/core/model/pure_expression.hpp>
#include <omni/core/model/binary_operator_expression.hpp>
#include <omni/core/model/cast_expression.hpp>
#include <omni/core/model/literal_expression.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <omni/core/model/variable_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (pureExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = pure_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "pure_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 5u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& binary_operator_expression::getStaticMetaInfo (),
& cast_expression::getStaticMetaInfo (),
& literal_expression::getStaticMetaInfo (),
& variable_declaration_expression::getStaticMetaInfo (),
& variable_expression::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 1,186 |
C++
| 33.911764 | 78 | 0.719224 |
daniel-kun/omni/source/omni/tests/core/model/test_cast_expression.cpp
|
#include <omni/core/model/cast_expression.hpp>
#include <omni/core/model/bitcast_expression.hpp>
#include <omni/core/model/meta_info.hpp>
#include <omni/tests/test_utils.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (castExpressionTests)
BOOST_AUTO_TEST_CASE (metaInfo)
{
using namespace omni::core::model;
meta_info & meta = cast_expression::getStaticMetaInfo ();
BOOST_CHECK_EQUAL (meta.getName (), "cast_expression");
BOOST_CHECK_EQUAL (meta.getParent (), & pure_expression::getStaticMetaInfo ());
BOOST_CHECK_EQUAL (meta.getChildCount (), 1u);
BOOST_CHECK (omni::tests::checkMetaInfoChildren (meta, {
& bitcast_expression::getStaticMetaInfo ()
}));
}
BOOST_AUTO_TEST_SUITE_END ();
| 745 |
C++
| 27.692307 | 83 | 0.707383 |
daniel-kun/omni/source/omni/tests/core/tools/test_string.cpp
|
#include <omni/core/tools/string.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (stringTests)
BOOST_AUTO_TEST_CASE (startsWith)
{
using namespace omni::core::tools;
BOOST_CHECK (starts_with ("asdf", "a"));
BOOST_CHECK (starts_with ("asdf", "asdf"));
BOOST_CHECK (starts_with ("", ""));
BOOST_CHECK (starts_with ("asdf", ""));
BOOST_CHECK (! starts_with ("asdf", "s"));
BOOST_CHECK (! starts_with ("asdf", "asdfgh"));
BOOST_CHECK (! starts_with ("asdf", " a"));
BOOST_CHECK (! starts_with (" asdf", "a"));
}
BOOST_AUTO_TEST_CASE (isNumeric)
{
using namespace omni::core::tools;
BOOST_CHECK (is_numeric ("1"));
BOOST_CHECK (is_numeric ("1."));
BOOST_CHECK (is_numeric ("1,000"));
BOOST_CHECK (is_numeric ("1,000."));
BOOST_CHECK (is_numeric ("1,000.123"));
BOOST_CHECK (is_numeric ("1.123"));
BOOST_CHECK (is_numeric ("12345678901234567890"));
BOOST_CHECK (is_numeric ("12345678901234567890."));
BOOST_CHECK (is_numeric ("12345678901234567890.12345"));
BOOST_CHECK (! is_numeric (" 1"));
BOOST_CHECK (! is_numeric ("1 "));
BOOST_CHECK (! is_numeric ("a1"));
BOOST_CHECK (! is_numeric ("a 1"));
BOOST_CHECK (! is_numeric ("1a"));
BOOST_CHECK (! is_numeric ("1 a"));
// Checking of correct positions of thousands and decimal separator not yet implemented:
// BOOST_CHECK (! is_numeric ("1,"));
// BOOST_CHECK (! is_numeric ("1,12"));
// BOOST_CHECK (! is_numeric ("1,12"));
// BOOST_CHECK (! is_numeric ("1,123,123,45"));
}
BOOST_AUTO_TEST_SUITE_END ()
| 1,593 |
C++
| 31.530612 | 92 | 0.603264 |
daniel-kun/omni/source/omni/tests/core/input/test_utils_input.cpp
|
#include "test_utils_input.hpp"
#include <omni/core/input/syntax_element.hpp>
#include <omni/core/input/abstract_syntax_element.hpp>
#include <omni/core/input/concrete_syntax_element.hpp>
#include <omni/core/input/syntax_template_element.hpp>
#include <omni/core/input/fixed_template_element.hpp>
#include <omni/core/input/variable_template_element.hpp>
#include <omni/core/input/variable_template_provider.hpp>
namespace {
class test_variable_provider : public omni::core::input::variable_template_provider {
public:
test_variable_provider ()
{
_variables.push_back ("foo");
}
std::vector <std::string> provide (std::string input) override {
std::vector <std::string> result;
for (auto i : _variables) {
if (i.find (input) == 0u) {
result.push_back (i);
}
}
return result;
}
private:
std::vector <std::string> _variables;
} testVariableProvider;
}
/**
Returns an syntax_element that contains some demo content:
- if (<statement>) { <statement> }
- while (<statement>) { statement> }
- variable "foo"
- return <statement>
**/
std::shared_ptr <omni::core::input::syntax_element> omni::tests::makeTestSyntaxElement ()
{
using namespace omni::core;
auto statementElement = std::make_shared <input::abstract_syntax_element> ();
statementElement->setName ("root_statement");
auto ifSyntaxElement (std::make_shared <input::concrete_syntax_element> ());
ifSyntaxElement->setName ("if_statement");
auto a = std::make_shared <input::fixed_template_element> (* ifSyntaxElement, 0, "if");
auto b = std::make_shared <input::fixed_template_element> (* ifSyntaxElement, 1, " (");
auto c = std::make_shared <input::syntax_template_element> (* ifSyntaxElement, 2, statementElement);
auto d = std::make_shared <input::fixed_template_element> (* ifSyntaxElement, 3, ") {\n");
auto e = std::make_shared <input::syntax_template_element> (* ifSyntaxElement, 4, statementElement);
auto f = std::make_shared <input::fixed_template_element> (* ifSyntaxElement, 5, "}\n");
auto ifTemplates = std::vector <std::shared_ptr <input::template_element>> {
a, b, c, d, e, f,
};
ifSyntaxElement->setTemplates (ifTemplates);
auto returnSyntaxElement = std::make_shared <input::concrete_syntax_element> ();
returnSyntaxElement->setName ("return_statement");
auto returnTemplate1 = std::make_shared <input::fixed_template_element> (* returnSyntaxElement, 0, "return ");
auto returnTemplate2 = std::make_shared <input::syntax_template_element> (* returnSyntaxElement, 1, statementElement);
auto returnTemplate3 = std::make_shared <input::fixed_template_element> (* returnSyntaxElement, 2, "\n");
returnSyntaxElement->setTemplates (
std::vector <std::shared_ptr <input::template_element>> {
returnTemplate1,
returnTemplate2,
returnTemplate3,
});
auto whileSyntaxElement = std::make_shared <input::concrete_syntax_element> ();
whileSyntaxElement->setName ("while_statement");
auto whileTemplate1 = std::make_shared <input::fixed_template_element> (* whileSyntaxElement, 0, "while");
auto whileTemplate2 = std::make_shared <input::fixed_template_element> (* whileSyntaxElement, 1, " (");
auto whileTemplate3 = std::make_shared <input::syntax_template_element> (* whileSyntaxElement, 2, statementElement);
auto whileTemplate4 = std::make_shared <input::fixed_template_element> (* whileSyntaxElement, 3, ") {\n");
auto whileTemplate5 = std::make_shared <input::syntax_template_element> (* whileSyntaxElement, 4, statementElement);
auto whileTemplate6 = std::make_shared <input::fixed_template_element> (* whileSyntaxElement, 5, "}\n");
whileSyntaxElement->setTemplates (
std::vector <std::shared_ptr <input::template_element>> {
whileTemplate1,
whileTemplate2,
whileTemplate3,
whileTemplate4,
whileTemplate5,
whileTemplate6
});
auto variableSyntaxElement = std::make_shared <input::concrete_syntax_element> ();
variableSyntaxElement->setName ("variable_statement");
auto variableTemplate1 = std::make_shared <input::variable_template_element> (* variableSyntaxElement, 0, testVariableProvider);
variableSyntaxElement->setTemplates (
std::vector <std::shared_ptr <input::template_element>> {
variableTemplate1
});
statementElement->setPossibleSubstitutions (
std::vector <std::shared_ptr <input::syntax_element>> {
ifSyntaxElement,
returnSyntaxElement,
whileSyntaxElement,
variableSyntaxElement
});
return statementElement;
}
| 4,832 |
C++
| 42.936363 | 132 | 0.666184 |
daniel-kun/omni/source/omni/tests/core/input/test_utils_input.hpp
|
#ifndef OMNI_TESTS_CORE_INPUT_TEST_UTILS_INPUT_HPP
#define OMNI_TESTS_CORE_INPUT_TEST_UTILS_INPUT_HPP
#include <memory>
namespace omni {
namespace core {
namespace input {
class syntax_element;
} // namespace input
} // namespace core
} // namespace omni
namespace omni {
namespace tests {
std::shared_ptr <core::input::syntax_element> makeTestSyntaxElement ();
}
}
#endif // include guard
| 394 |
C++
| 17.809523 | 71 | 0.741117 |
daniel-kun/omni/source/omni/tests/core/input/test_input_manager.cpp
|
#include <omni/core/input/input_state.hpp>
#include "test_utils_input.hpp"
#include <omni/core/input/syntax_element.hpp>
#include <omni/core/input/template_element.hpp>
#include <omni/core/input/fixed_template_element.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/signals2.hpp>
#include <stack>
namespace {
std::tuple <std::string, std::string> runInputSimulation (omni::core::input::syntax_element & statementElement, std::vector <std::string> & simulatedInput)
{
using namespace omni::core;
std::string output;
std::string autoCompletion;
while (simulatedInput.size () > 0) {
std::string input = simulatedInput.front ();
simulatedInput.erase (simulatedInput.begin ());
std::vector <input::syntax_suggestion> suggestions = statementElement.suggest (input, 0u);
BOOST_CHECK_GT (suggestions.size (), 0u);
bool hasMoreInput = ! simulatedInput.empty ();
if (! suggestions.empty ()) {
input::syntax_suggestion selectedSuggestion = suggestions [0u];
output += selectedSuggestion.text;
if (selectedSuggestion.syntaxElement != nullptr) {
input::syntax_element & selectedSyntaxElem = * selectedSuggestion.syntaxElement;
for (std::size_t t = 1u; t < selectedSyntaxElem.templateElementCount (); ++t) {
std::shared_ptr <input::syntax_element> element = selectedSyntaxElem.templateElementAt (t)->dive ();
if (element != nullptr) {
if (hasMoreInput) {
auto inputResult = runInputSimulation (* element, simulatedInput);
output += std::get <0> (inputResult);
} else {
autoCompletion += "<" + element->getName () + ">";
}
} else {
std::shared_ptr <input::fixed_template_element> textTemplateElement = std::dynamic_pointer_cast <input::fixed_template_element> (selectedSyntaxElem.templateElementAt (t));
if (textTemplateElement != nullptr) {
if (hasMoreInput) {
output += textTemplateElement->getText ();
} else {
autoCompletion += textTemplateElement->getText ();
}
}
}
}
}
}
break;
}
return std::make_tuple (output, autoCompletion);
}
}
namespace omni {
namespace core {
namespace input {
class input_manager {
public:
typedef boost::signals2::signal <void (std::string output, std::string suggestion)> on_output_changed_signal;
input_manager ();
on_output_changed_signal onOutputChanged;
void accept ();
void input (std::string text);
void backspace ();
private:
std::shared_ptr <syntax_element> _rootSyntaxElement;
std::vector <std::string> _inputHistory;
std::stack <syntax_element> _syntaxStack;
}; // class input_manager
} // namepace input
} // namepace core
} // namepace omni
omni::core::input::input_manager::input_manager () :
_rootSyntaxElement (omni::tests::makeTestSyntaxElement ()),
_inputHistory (),
_syntaxStack ()
{
}
void omni::core::input::input_manager::accept ()
{
}
void omni::core::input::input_manager::input (std::string text)
{
_inputHistory.push_back (text);
std::tuple <std::string, std::string> result = runInputSimulation (*_rootSyntaxElement, _inputHistory);
onOutputChanged (std::get <0> (result), std::get <1> (result));
}
void omni::core::input::input_manager::backspace ()
{
}
#if 0
BOOST_AUTO_TEST_SUITE (inputManagerTests)
BOOST_AUTO_TEST_CASE (basic)
{
using namespace omni::core::input;
std::string result;
input_manager manager;
boost::signals2::connection connection = manager.onOutputChanged.connect ([&result] (std::string output, std::string suggestion) -> void {
result = output;
});
manager.input ("i");
manager.accept ();
manager.input ("fo");
manager.accept ();
manager.input ("w");
manager.accept ();
manager.input ("fo");
manager.accept ();
manager.input ("r");
manager.accept ();
manager.input ("f");
manager.accept ();
std::string desiredOutput = R"(if (foo) {
while (foo) {
return foo
}
}
)";
BOOST_CHECK_EQUAL (result, desiredOutput);
}
BOOST_AUTO_TEST_SUITE_END ()
#endif
| 4,531 |
C++
| 30.041096 | 195 | 0.598323 |
daniel-kun/omni/source/omni/tests/core/input/test_syntax_tree_parser_xml.cpp
|
#include <omni/core/input/syntax_tree_parser_xml.hpp>
#include <omni/core/input/syntax_element.hpp>
#include <boost/test/unit_test.hpp>
#include <fstream>
/*
BOOST_AUTO_TEST_SUITE (inputSyntaxTreeParserXmlTests)
BOOST_AUTO_TEST_CASE (basic)
{
using namespace omni::core::input;
std::ifstream str ("../resources/syntax.xml");
std::shared_ptr <syntax_element> statement = syntax_tree_parser_xml::parse (str);
BOOST_CHECK_EQUAL (statement->getName (), "statement");
}
BOOST_AUTO_TEST_SUITE_END ()
*/
| 523 |
C++
| 22.818181 | 85 | 0.705545 |
daniel-kun/omni/source/omni/tests/core/input/test_input_state.cpp
|
#include <omni/core/input/abstract_syntax_element.hpp>
#include <omni/core/input/template_element.hpp>
#include <omni/core/input/fixed_template_element.hpp>
#include "test_utils_input.hpp"
#include <boost/test/unit_test.hpp>
#include <tuple>
#include <vector>
#include <string>
#include <utility>
namespace {
std::string runInputSimulation (omni::core::input::syntax_element & statementElement, std::size_t templateIndex, std::vector <std::tuple <std::string, std::size_t>> & simulatedInput)
{
using namespace omni::core;
std::string output;
while (simulatedInput.size () > 0) {
std::tuple <std::string, std::size_t> input = simulatedInput.front ();
simulatedInput.erase (simulatedInput.begin ());
std::vector <input::syntax_suggestion> suggestions = statementElement.suggest (std::get <0> (input), templateIndex);
BOOST_CHECK_GT (suggestions.size (), 0u);
BOOST_CHECK_LT (std::get <1> (input), suggestions.size ());
if (! suggestions.empty () && std::get <1> (input) < suggestions.size ()) {
input::syntax_suggestion selectedSuggestion = suggestions [std::get <1> (input)];
output += selectedSuggestion.text;
if (selectedSuggestion.syntaxElement != nullptr) {
input::syntax_element & selectedSyntaxElem = * selectedSuggestion.syntaxElement;
for (std::size_t t = 1u; t < selectedSyntaxElem.templateElementCount (); ++t) {
std::shared_ptr <input::syntax_element> element = selectedSyntaxElem.templateElementAt (t)->dive ();
if (element != nullptr) {
output += runInputSimulation (* element, 0u, simulatedInput);
} else {
std::shared_ptr <input::fixed_template_element> textTemplateElement = std::dynamic_pointer_cast <input::fixed_template_element> (selectedSyntaxElem.templateElementAt (t));
if (textTemplateElement != nullptr) {
output += textTemplateElement->getText ();
}
}
}
}
}
break;
}
return output;
}
}
BOOST_AUTO_TEST_SUITE (inputStateTests)
BOOST_AUTO_TEST_CASE (basic)
{
using namespace omni::core;
std::shared_ptr <input::syntax_element> statementElement = omni::tests::makeTestSyntaxElement ();
// Simulates the input of "i<tab>fo<tab>r<tab>f<tab>"
// with the desired output of "if (foo) return foo"
// first: Text that has been typed
// second: Index of the suggestion that has been accepted
// third: Dive into the suggested element, or step to the next element on the same level?
std::vector <std::tuple <std::string, std::size_t>> simulatedInput {
std::make_tuple ("i", 0u), // "if (...)"
std::make_tuple ("fo", 0u), // "foo"
std::make_tuple ("w", 0u), // "while (...)"
std::make_tuple ("f", 0u), // "foo"
std::make_tuple ("r", 0u), // "return ..."
std::make_tuple ("f", 0u), // "foo"
};
std::string output = runInputSimulation (* statementElement, 0u, simulatedInput);
std::string desiredOutput = R"(if (foo) {
while (foo) {
return foo
}
}
)";
BOOST_CHECK_EQUAL (output, desiredOutput);
}
BOOST_AUTO_TEST_SUITE_END ()
| 3,354 |
C++
| 39.421686 | 195 | 0.603459 |
daniel-kun/omni/interface/omni/runtime/runtime.hpp
|
#ifndef OMNI_RUNTIME_RUNTIME_HPP
#define OMNI_RUNTIME_RUNTIME_HPP
#ifdef _MSC_VER
# ifdef omni_runtime_EXPORTS
# define OMNI_RUNTIME_API __declspec (dllexport)
# else
# define OMNI_RUNTIME_API __declspec (dllimport)
# endif
#else
# define OMNI_RUNTIME_API
#endif
#endif
| 293 |
C++
| 17.374999 | 54 | 0.699659 |
daniel-kun/omni/interface/omni/runtime/memory.hpp
|
#ifndef OMNI_RUNTIME_MEMORY_HPP
#define OMNI_RUNTIME_MEMORY_HPP
#include <omni/runtime/runtime.hpp>
#include <cstddef>
extern "C" {
typedef std::size_t reference_count_t;
void OMNI_RUNTIME_API * omni_runtime_memory_allocate (std::size_t sizeInBytes);
void OMNI_RUNTIME_API * omni_runtime_memory_add_reference (void * memory);
void OMNI_RUNTIME_API * omni_runtime_memory_remove_reference (void * memory);
}
#endif
| 420 |
C++
| 21.157894 | 79 | 0.75 |
daniel-kun/omni/interface/omni/ui/entity_toggle_widget.hpp
|
#ifndef OMNI_UI_ENTITY_TOGGLE_WIDGET_HPP
#define OMNI_UI_ENTITY_TOGGLE_WIDGET_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_base_widget.hpp>
#include <QAction>
#include <QStackedLayout>
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace ui {
class entity_widget_provider_base;
/**
**/
class OMNI_UI_API entity_toggle_widget : public entity_base_widget {
Q_OBJECT
public:
enum class Mode {
m_view,
m_edit
};
entity_toggle_widget (omni::core::context & context, entity_widget_provider_base & provider, QWidget * parent);
std::shared_ptr <omni::core::model::entity> getEntity () override;
void setEntity (std::shared_ptr <omni::core::model::entity> entity) override;
Mode currentViewMode ();
public slots:
Mode toggleViewMode ();
protected:
void focusInEvent (QFocusEvent * event) override;
void focusOutEvent (QFocusEvent * event) override;
void keyPressEvent (QKeyEvent * event) override;
private:
omni::core::context & _c;
entity_widget_provider_base & _provider;
QAction _toggleAction;
QStackedLayout _layout;
std::shared_ptr <omni::core::model::entity> _entity;
std::unique_ptr <omni::ui::entity_base_widget> _viewWidget;
std::unique_ptr <omni::ui::entity_base_widget> _editWidget;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 1,388 |
C++
| 22.542372 | 115 | 0.691643 |
daniel-kun/omni/interface/omni/ui/init.hpp
|
#ifndef OMNI_UI_INIT_HPP
#define OMNI_UI_INIT_HPP
#include <omni/ui/ui.hpp>
namespace omni {
namespace ui {
void OMNI_UI_API init ();
} // namespace ui
} // namespace omni
#endif // include guard
| 201 |
C++
| 12.466666 | 25 | 0.686567 |
daniel-kun/omni/interface/omni/ui/entity_widget_provider_base.hpp
|
#ifndef OMNI_UI_ENTITY_WIDGET_PROVIDER_BASE_HPP
#define OMNI_UI_ENTITY_WIDGET_PROVIDER_BASE_HPP
#include <omni/ui/ui.hpp>
#include <QWidget>
#include <QKeyEvent>
#include <memory>
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace ui {
class entity_base_widget;
/**
@brief Abstract interface to create edit- and view-widgets.
**/
class OMNI_UI_API entity_widget_provider_base {
public:
virtual std::unique_ptr <omni::ui::entity_base_widget> createViewWidget (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget * editWidget) = 0;
virtual std::unique_ptr <omni::ui::entity_base_widget> createEditWidget (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget & viewWidget) = 0;
virtual bool keyPressEvent (QKeyEvent * event) = 0;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 892 |
C++
| 24.514285 | 173 | 0.721973 |
daniel-kun/omni/interface/omni/ui/flowlayout.hpp
|
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include <QLayout>
#include <QRect>
#include <QWidgetItem>
#include <QStyle>
#include <omni/ui/ui.hpp>
class OMNI_UI_API FlowLayout : public QLayout
{
public:
FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item);
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const;
bool hasHeightForWidth() const;
int heightForWidth(int) const;
int count() const;
QLayoutItem *itemAt(int index) const;
QSize minimumSize() const;
void setGeometry(const QRect &rect);
QSize sizeHint() const;
QLayoutItem *takeAt(int index);
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
int m_hSpace;
int m_vSpace;
};
#endif
| 3,008 |
C++
| 36.148148 | 87 | 0.68883 |
daniel-kun/omni/interface/omni/ui/suggestion_text_edit.hpp
|
#ifndef OMNI_UI_SUGGESTION_TEXT_EDIT_HPP
#define OMNI_UI_SUGGESTION_TEXT_EDIT_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/suggestion_list_model.hpp>
#include <QLineEdit>
#include <QCompleter>
namespace omni {
namespace core {
namespace input {
class syntax_suggestion;
}
}
}
namespace omni {
namespace ui {
class OMNI_UI_API suggestion_text_edit : public QLineEdit {
Q_OBJECT
public:
explicit suggestion_text_edit (QWidget * parent = 0);
explicit suggestion_text_edit (QString const & text, QWidget * parent = 0);
Q_SIGNALS:
void suggestionsRequested (QString const & text, std::vector <omni::core::input::syntax_suggestion> & suggestions);
void suggestionAccepted (omni::core::input::syntax_suggestion const & suggestion);
private slots:
void showSuggestionsWhenTextChanged (QString const & text);
void acceptCompletion (QString const & text);
private:
suggestion_list_model _model;
QCompleter _completer;
};
}
}
#endif // include guard
| 993 |
C++
| 21.088888 | 123 | 0.726083 |
daniel-kun/omni/interface/omni/ui/blueprint.hpp
|
#ifndef OMNI_UI_BLUEPRINT_HPP
#define OMNI_UI_BLUEPRINT_HPP
#include <omni/ui/ui.hpp>
#include <QWidget>
namespace omni {
namespace ui {
class OMNI_UI_API blueprint : public QWidget {
Q_OBJECT
public:
blueprint (QWidget * parent);
protected:
void paintEvent (QPaintEvent * event) override;
};
}
}
#endif // include guard
| 341 |
C++
| 12.679999 | 51 | 0.70088 |
daniel-kun/omni/interface/omni/ui/entity_widget_provider.hpp
|
#ifndef OMNI_UI_ENTITY_WIDGET_PROVIDER_HPP
#define OMNI_UI_ENTITY_WIDGET_PROVIDER_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_widget_provider_base.hpp>
#include <QWidget>
#include <QKeyEvent>
#include <functional>
#include <string>
#include <memory>
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace ui {
class entity_base_widget;
/**
@brief Creates edit- and view-widgets for a specific type of entity.
**/
class OMNI_UI_API entity_widget_provider : public entity_widget_provider_base {
public:
static entity_widget_provider & getProvider (std::string entityType);
entity_widget_provider (
std::function <std::unique_ptr <omni::ui::entity_base_widget> (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget * editWidget)> viewCreator,
std::function <std::unique_ptr <omni::ui::entity_base_widget> (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget & viewWidget)> editCreator,
std::function <bool (QKeyEvent * event)> keyHandler);
std::unique_ptr <omni::ui::entity_base_widget> createViewWidget (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget * editWidget) override;
std::unique_ptr <omni::ui::entity_base_widget> createEditWidget (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget & viewWidget) override;
bool keyPressEvent (QKeyEvent * event) override;
private:
std::function <std::unique_ptr <omni::ui::entity_base_widget> (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget * editWidget)> _viewCreator;
std::function <std::unique_ptr <omni::ui::entity_base_widget> (QWidget * parent, omni::core::context & context, omni::ui::entity_base_widget & viewWidget)> _editCreator;
std::function <bool (QKeyEvent * event)> _keyHandler;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 1,944 |
C++
| 36.403845 | 176 | 0.715535 |
daniel-kun/omni/interface/omni/ui/suggestion_list_model.hpp
|
#ifndef OMNI_UI_SUGGESTION_LIST_MODEL_HPP
#define OMNI_UI_SUGGESTION_LIST_MODEL_HPP
#include <omni/ui/ui.hpp>
#include <omni/core/input/syntax_suggestion.hpp>
#include <QAbstractListModel>
namespace omni {
namespace ui {
class OMNI_UI_API suggestion_list_model : public QAbstractListModel {
Q_OBJECT
public:
void addSuggestion (omni::core::input::syntax_suggestion suggestion);
omni::core::input::syntax_suggestion getSuggestion (int row) const;
omni::core::input::syntax_suggestion getSuggestion (QString suggestionText) const;
void clear ();
int rowCount (QModelIndex const & parent) const override;
QVariant data (QModelIndex const & index, int role) const override;
private:
std::vector <omni::core::input::syntax_suggestion> _suggestions;
};
}
}
#endif // include guard
| 819 |
C++
| 22.428571 | 86 | 0.735043 |
daniel-kun/omni/interface/omni/ui/variable_declaration_expression_view.hpp
|
#ifndef OMNI_UI_VARIABLE_DECLARATION_EXPRESSION_VIEW_HPP
#define OMNI_UI_VARIABLE_DECLARATION_EXPRESSION_VIEW_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_base_widget.hpp>
#include <omni/ui/entity_toggle_widget.hpp>
#include <omni/ui/entity_widget_provider_base.hpp>
#include <omni/ui/entity_placeholder_widget.hpp>
#include <omni/core/model/variable_declaration_expression.hpp>
#include <QHBoxLayout>
#include <QLabel>
namespace omni {
namespace ui {
/**
@brief BRIEF
DOCS
**/
class OMNI_UI_API variable_declaration_expression_view : public entity_base_widget {
Q_OBJECT
public:
variable_declaration_expression_view (omni::core::context & context, omni::core::model::module & module, QWidget * parent);
std::shared_ptr <omni::core::model::entity> getEntity () override;
void setEntity (std::shared_ptr <omni::core::model::entity> entity) override;
void startEdit () override;
private:
void updateInitializationExpression (std::shared_ptr <omni::core::model::entity> initializationExpression);
QHBoxLayout _layout;
std::unique_ptr <entity_widget_provider_base> _nameWidgetProvider;
QLabel _varFixedText;
entity_toggle_widget _nameWidget;
QLabel _assignmentOperator;
entity_placeholder_widget _initializationExpression;
std::shared_ptr <omni::core::model::variable_declaration_expression> _variableDeclExpression;
boost::signals2::connection _initExpressionExpandedConnection;
};
}
}
#endif // include guard
| 1,483 |
C++
| 29.916666 | 127 | 0.75118 |
daniel-kun/omni/interface/omni/ui/entity_placeholder_widget.hpp
|
#ifndef OMNI_UI_ENTITY_PLACEHOLDER_WIDGET_HPP
#define OMNI_UI_ENTITY_PLACEHOLDER_WIDGET_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_base_widget.hpp>
#include <omni/core/model/meta_info.hpp>
#ifndef Q_MOC_RUN
#include <boost/signals2.hpp>
#endif
#include <QWidget>
#include <QMenu>
#include <QHBoxLayout>
#include <QLineEdit>
namespace omni {
namespace core {
class context;
namespace model {
class module;
}
}
}
namespace omni {
namespace ui {
/**
@brief entity_placeholder_widget is a placeholder for any entity_base_widget that displays an entity that implements the given entityType.
The entityType is usually a very generic type such as "expression" or "statement". If the entitType is "expression", the entity_placeholder_widget can choose literal_expressions,
variable_assignment_expressions, binary_operator_expressions, and so on. If the entitType is statement, the entity_placeholder_widget can choose blocks, if_statements,
while_statements, and so on.
TODO: Should the entity_placeholder_widget be permanent and have the chosen entity_base_widget as children, or should the entity_placeholder_widget be deleted after a type has been
chosen and replaced with the entity_base_widget for the given type?
**/
class OMNI_UI_API entity_placeholder_widget : public QWidget {
Q_OBJECT
public:
using on_entity_expanded_signal = boost::signals2::signal <void (std::shared_ptr <omni::core::model::entity>)>;
entity_placeholder_widget (omni::core::context & context, omni::core::model::module & module, QWidget * parent, omni::core::model::meta_info const & entityMeta);
on_entity_expanded_signal onEntityExpanded;
protected:
void contextMenuEvent (QContextMenuEvent * event) override;
private slots:
void switchToEntityType ();
void editorTextChanged (const QString & text);
private:
void populateMenu (omni::core::model::meta_info const & meta, QMenu & menu);
void createEditorViewFromMetaInfo (const omni::core::model::meta_info & metaInfo, std::shared_ptr <omni::core::model::entity> entity);
omni::core::context & _context;
omni::core::model::module & _module;
omni::core::model::meta_info const & _entityMeta;
QMenu _selectorPopup;
QHBoxLayout _layout;
QLineEdit _editor;
std::unique_ptr <entity_base_widget> _entityWidget;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 2,392 |
C++
| 31.337837 | 180 | 0.744147 |
daniel-kun/omni/interface/omni/ui/ui_meta_extension.hpp
|
#ifndef OMNI_UI_UI_META_EXTENSION_HPP
#define OMNI_UI_UI_META_EXTENSION_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_base_widget.hpp>
#include <omni/core/model/meta_info_extension.hpp>
#include <memory>
#include <functional>
namespace omni {
namespace core {
class context;
namespace model {
class module;
}
}
}
namespace omni {
namespace ui {
/**
@class ui_meta_extension ui_meta_extension.hpp omni/ui/ui_meta_extension.hpp
@brief Holds meta-information for the ui subsystem for every non-abstract omni entity.
**/
class OMNI_UI_API ui_meta_extension : public omni::core::model::meta_info_extension {
public:
using CreateViewWidgetFunction = std::function <std::unique_ptr <entity_base_widget> (omni::core::context & context,
omni::core::model::module & module,
QWidget * parent,
std::shared_ptr <omni::core::model::entity> entity)>;
ui_meta_extension (CreateViewWidgetFunction viewWidgetCreator);
std::unique_ptr <entity_base_widget> createViewWidget (omni::core::context & context,
omni::core::model::module & module,
QWidget * parent,
std::shared_ptr <omni::core::model::entity> entity) const;
private:
CreateViewWidgetFunction _viewWidgetCreator;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 1,846 |
C++
| 35.215686 | 143 | 0.502167 |
daniel-kun/omni/interface/omni/ui/entity_base_widget.hpp
|
#ifndef OMNI_UI_ENTIY_BASE_WIDGET_HPP
#define OMNI_UI_ENTIY_BASE_WIDGET_HPP
#include <omni/ui/ui.hpp>
#include <QWidget>
#include <memory>
namespace omni {
namespace core {
namespace model {
class entity;
}
}
}
namespace omni {
namespace ui {
/**
@brief entity_base_widget is a base class for widgets that display or edit all kinds of non-abstract entities.
Such entities can be omni::core::model::literal_expression s, variable_declaration_expression s, while_statement s and so on.
Compound entities (such as the if_statement, which is a combination of the if-syntax itself, an expression that is the condition and a statement that is the body) have themselves other
entity_base_widget as their children.
The entity that is displayed or edited by an entity_base_widget is access through the methods @see setEntity() and @see getEntity() and stored as a shared_ptr, so that it can be used in
other, unrelated circumstances, too.
**/
class OMNI_UI_API entity_base_widget : public QWidget {
Q_OBJECT
public:
entity_base_widget (QWidget * parent);
virtual std::shared_ptr <omni::core::model::entity> getEntity ();
virtual void setEntity (std::shared_ptr <omni::core::model::entity> entity);
virtual void startEdit ();
};
} // namespace ui
} // namespace omni
#endif // include guard
| 1,313 |
C++
| 27.565217 | 185 | 0.741051 |
daniel-kun/omni/interface/omni/ui/literal_expression_view.hpp
|
#ifndef OMNI_UI_LITERAL_EXPRESSION_VIEW_HPP
#define OMNI_UI_LITERAL_EXPRESSION_VIEW_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/entity_base_widget.hpp>
#include <QHBoxLayout>
#include <QLabel>
#ifndef Q_MOC_RUN
#include <boost/signals2.hpp>
#endif
#include <memory>
namespace omni {
namespace core {
namespace model {
class literal_expression;
}
}
}
namespace omni {
namespace ui {
/**
@brief Displays an omni::core::model::literal_expression.
It displays the value and the type of the literal_expression that is set via @see setEntity() or @see setLiteral(), with live update when changes are detected.
**/
class OMNI_UI_API literal_expression_view : public entity_base_widget {
Q_OBJECT
public:
literal_expression_view (QWidget * parent);
std::shared_ptr <omni::core::model::entity> getEntity () override;
void setEntity (std::shared_ptr <omni::core::model::entity> entity) override;
void setLiteral (std::shared_ptr <omni::core::model::literal_expression> literalExpression);
std::shared_ptr <omni::core::model::literal_expression> getLiteral ();
private:
void updateContent ();
QHBoxLayout _layout;
QLabel _valueLabel;
QLabel _typeLabel;
std::shared_ptr <omni::core::model::literal_expression> _literalExpression;
boost::signals2::scoped_connection _literalValueChangedConnection;
};
} // namespace ui
} // namespace omni
#endif // include guard
| 1,578 |
C++
| 27.196428 | 159 | 0.651458 |
daniel-kun/omni/interface/omni/ui/syntax_input.hpp
|
#ifndef OMNI_UI_SYNTAX_INPUT_HPP
#define OMNI_UI_SYNTAX_INPUT_HPP
#include <omni/ui/ui.hpp>
#include <omni/ui/flowlayout.hpp>
#include <omni/core/input/syntax_suggestion.hpp>
#include <QWidget>
namespace omni {
namespace core {
namespace input {
class syntax_element;
}
}
}
namespace omni {
namespace ui {
/**
syntax_input is an control that can populate an omni::core model from user input via an omni::core::input::syntax_element.
**/
class OMNI_UI_API syntax_input : public QWidget {
Q_OBJECT
public:
syntax_input (QWidget * parent, omni::core::input::syntax_element & syntaxElement);
protected:
private slots:
void provideSuggestions (QString const & text, std::vector <omni::core::input::syntax_suggestion> & suggestions);
void acceptSuggestion (omni::core::input::syntax_suggestion suggestion);
private:
void addRootTextEdit ();
void clearWidgets ();
omni::core::input::syntax_element & _syntaxElement;
FlowLayout _layout;
std::list <std::shared_ptr <QWidget>> _widgets;
};
}
}
#endif // include guard
| 1,058 |
C++
| 19.764705 | 122 | 0.713611 |
daniel-kun/omni/interface/omni/ui/generic_entity_editor.hpp
|
#ifndef OMNI_UI_GENERIC_ENTITY_EDITOR_HPP
#define OMNI_UI_GENERIC_ENTITY_EDITOR_HPP
#include <omni/ui/entity_base_widget.hpp>
#include <QStackedLayout>
#include <QLineEdit>
#include <memory>
#include <functional>
namespace omni {
namespace ui {
/**
@brief generic_entity_editor can be used directly or as a base class for simple entity editors that use a QLineEdit to edit the entity.
generic_entity_editor uses the entity's toString() method (with fullyQualified set to false) or the provided textToEntityConverter (@see setEntityToTextConverter())to form an editable text from the entity.
Converting a text to an entity is less generic, so it requires an text-to-entity-converter to be set via @see setTextToEntityConverter().
Auto-completion and other editing aids are yet to be implemented.
The generic_entity_editor has it's focus proxy set to a QLineEdit that is it's sole child widget, without margins or paddings. That way, generic_entity_editor behaves like it was a
QLineEdit itself.
**/
class OMNI_UI_API generic_entity_editor : public entity_base_widget {
Q_OBJECT
public:
generic_entity_editor (QWidget * parent, std::shared_ptr <omni::core::model::entity> entity = std::shared_ptr <omni::core::model::entity> ());
std::function <std::string (std::shared_ptr <omni::core::model::entity>)> getEntityToTextConverter () const;
void setEntityToTextConverter (std::function <std::string (std::shared_ptr <omni::core::model::entity>)> converter);
std::function <std::shared_ptr <omni::core::model::entity> (std::string text, std::shared_ptr <omni::core::model::entity> originatingEntity)> getTextToEntityConverter () const;
void setTextToEntityConverter (std::function <std::shared_ptr <omni::core::model::entity> (std::string text, std::shared_ptr <omni::core::model::entity> originatingEntity)> converter);
std::shared_ptr <omni::core::model::entity> getEntity () override;
void setEntity (std::shared_ptr <omni::core::model::entity> entity) override;
private:
std::function <std::string (std::shared_ptr <omni::core::model::entity>)> _entityToTextConverter;
std::function <std::shared_ptr <omni::core::model::entity> (std::string text, std::shared_ptr <omni::core::model::entity> originatingEntity)> _textToEntityConverter;
std::shared_ptr <omni::core::model::entity> _entity;
QStackedLayout _layout;
QLineEdit _edit;
};
}
}
#endif // include guard
| 2,426 |
C++
| 45.673076 | 205 | 0.740313 |
daniel-kun/omni/interface/omni/ui/tree_sort_filter_proxy_model.hpp
|
#ifndef OMNI_UI_TREE_SORT_FILTER_PROXY_MODEL_HPP
#define OMNI_UI_TREE_SORT_FILTER_PROXY_MODEL_HPP
#include <omni/ui/ui.hpp>
#include <QSortFilterProxyModel>
namespace omni {
namespace ui {
/**
@brief Provides pragmatic filter semantics for tree models. This means, that parent nodes are not
filtered as long as any of their child nodes matches the filter.
**/
class OMNI_UI_API tree_sort_filter_proxy_model : public QSortFilterProxyModel {
public:
QModelIndex firstMatchingIndex () const;
bool filterAcceptsRowExactly (int sourceRow, const QModelIndex & sourceParent) const;
protected:
bool filterAcceptsRow (int sourceRow, const QModelIndex & sourceParent) const;
private:
QModelIndex firstMatchingIndexImpl (const QModelIndex & parent) const;
};
}
}
#endif // include guard
| 800 |
C++
| 25.699999 | 98 | 0.76875 |
daniel-kun/omni/interface/omni/ui/ui.hpp
|
#ifndef OMNI_UI_UI_HPP
#define OMNI_UI_UI_HPP
#ifdef _MSC_VER
# ifdef omni_ui_EXPORTS
# define OMNI_UI_API __declspec (dllexport)
# else
# define OMNI_UI_API __declspec (dllimport)
# endif
#else
# define OMNI_UI_API
#endif
#endif
| 252 |
C++
| 15.866666 | 49 | 0.654762 |
daniel-kun/omni/interface/omni/core/statement_emit_result.hpp
|
#ifndef OMNI_CORE_STATEMENT_EMIT_RESULT_HPP
#define OMNI_CORE_STATEMENT_EMIT_RESULT_HPP
#include <omni/core/core.hpp>
#include <memory>
namespace llvm {
class BasicBlock;
class Value;
}
namespace omni {
namespace core {
/**
statement_emit_result is a small helper-class intended to carry the information that is returned from a call to
omni::core::statement::llmEmit().
**/
class OMNI_CORE_API statement_emit_result {
public:
statement_emit_result (llvm::BasicBlock * continueBlock, llvm::Value * value);
llvm::BasicBlock * getContinueBlock () const;
llvm::Value * getValue () const;
bool hasValue () const;
private:
llvm::BasicBlock * _continueBlock;
llvm::Value * _value;
};
}
}
#endif // include guard
| 801 |
C++
| 21.277777 | 115 | 0.657928 |
daniel-kun/omni/interface/omni/core/module_emit_options.hpp
|
#ifndef OMNI_CORE_MODULE_EMIT_OPTIONS_HPP
#define OMNI_CORE_MODULE_EMIT_OPTIONS_HPP
#include <omni/core/core.hpp>
#ifndef Q_MOC_RUN
#include <boost/filesystem/path.hpp>
#endif
#include <vector>
#include <set>
namespace omni {
namespace core {
/**
module_emit_options contains several options that the class context uses to emit assembly code (context::emitAssemblyFile), object files (context::emitObjectFile)
or shared library files (context::emitSharedLibraryFile).
Options include things like library and include search paths, linker options, options for llvm code generation, etc.
**/
class OMNI_CORE_API module_emit_options {
public:
module_emit_options ();
~ module_emit_options ();
void addLibrarySearchPath (boost::filesystem::path searchPath);
std::vector <boost::filesystem::path> getLibrarySearchPaths () const;
void addLibrary (std::string library);
std::set <std::string> getLibraries () const;
private:
std::vector <boost::filesystem::path> _librarySearchPaths;
std::set <std::string> _libraries;
};
} // namespace core
} // namespace omni
#endif
| 1,169 |
C++
| 28.999999 | 166 | 0.697177 |
daniel-kun/omni/interface/omni/core/core.hpp
|
#ifndef OMNI_CORE_CORE_HPP
#define OMNI_CORE_CORE_HPP
#ifdef _MSC_VER
# ifdef omni_core_EXPORTS
# define OMNI_CORE_API __declspec (dllexport)
# else
# define OMNI_CORE_API __declspec (dllimport)
# endif
#else
# define OMNI_CORE_API
#endif
// Check for 32 or 64 bit environment:
// Check windows
#if _WIN32 || _WIN64
# if _WIN64
# define ENVIRONMENT64
# else
# define ENVIRONMENT32
# endif
#endif
// Check GCC
#if __GNUC__
# if __x86_64__ || __ppc64__
# define ENVIRONMENT64
# else
# define ENVIRONMENT32
# endif
#endif
#endif
| 596 |
C++
| 16.558823 | 51 | 0.620805 |
daniel-kun/omni/interface/omni/core/parser.hpp
|
#ifndef OMNI_CORE_PARSER_HPP
#define OMNI_CORE_PARSER_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <omni/core/model/expression.hpp>
#include <memory>
#include <vector>
namespace omni {
namespace core {
namespace core {
class scope;
}
}
}
namespace omni {
namespace core {
/**
@class parser parser.hpp omni/core/parser.hpp
@brief The parser can parse text and create statements and expressions from it's content.
The parser is used to interpret input and create entities from it. The parser distinguishes between parsing statements and expressions.
**/
class OMNI_CORE_API parser {
public:
/**
@brief Contains the result of parsing a text as a statement or an expression. T may only be omni::core::model::statement or expression.
**/
template <typename T>
struct parser_result {
std::shared_ptr <T> entity; ///< The entity that the parsed text can represent.
bool exact; ///< True, if the parsed text matches exactly the entities textual representation. False, if it is only a partial match.
};
using StatementList = std::vector <parser_result <omni::core::model::statement>>;
using ExpressionList = std::vector <parser_result <omni::core::model::expression>>;
static StatementList parseStatement (omni::core::model::scope & scope, std::string const & text);
static StatementList parseIfStatement (omni::core::model::scope & scope, std::string const & text);
static ExpressionList parseExpression (omni::core::model::scope & scope, std::string const & text);
static ExpressionList parseVariableDeclaration (omni::core::model::scope & scope, std::string const & text);
static ExpressionList parseBuiltinLiteral (omni::core::model::scope & scope, std::string const & text);
};
} // namespace core
} // namespace omni
#endif // include guard
| 1,857 |
C++
| 33.407407 | 140 | 0.723748 |
daniel-kun/omni/interface/omni/core/logic_error.hpp
|
#ifndef OMNI_CORE_LOGIC_ERROR_HPP
#define OMNI_CORE_LOGIC_ERROR_HPP
#include <omni/core/core.hpp>
#include <stdexcept>
#include <string>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
class OMNI_CORE_API logic_error : public std::logic_error {
public:
logic_error (std::string const & fileName, std::string const & functionName, int lineNumber, std::string const & errorMessage);
};
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 535 |
C++
| 19.615384 | 135 | 0.708411 |
daniel-kun/omni/interface/omni/core/runtime.hpp
|
#ifndef OMNI_CORE_RUNTIME_HPP
#define OMNI_CORE_RUNTIME_HPP
#include <omni/core/core.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class external_function;
class module;
}
}
}
namespace omni {
namespace core {
/**
Manages the functions and structures provided by the omni runtime.
Use omni::core::module::getRuntime() to access it in a specific module.
TODO: This should be implemented by parsing the omni runtime headers using clang.
**/
class OMNI_CORE_API runtime {
public:
runtime (model::module & module);
std::shared_ptr <model::external_function> getMemoryAllocate ();
std::shared_ptr <model::external_function> getMemoryAddReference ();
std::shared_ptr <model::external_function> getMemoryRemoveReference ();
private:
model::module & _module;
std::shared_ptr <model::external_function> _memoryAllocate;
std::shared_ptr <model::external_function> _memoryAddReference;
std::shared_ptr <model::external_function> _memoryRemoveReference;
};
} // namespace core
} // namespace omni
#endif // include guard
| 1,155 |
C++
| 25.272727 | 85 | 0.684848 |
daniel-kun/omni/interface/omni/core/not_implemented_error.hpp
|
#ifndef OMNI_CORE_NOT_IMPLEMENTED_ERROR_HPP
#define OMNI_CORE_NOT_IMPLEMENTED_ERROR_HPP
#include <omni/core/core.hpp>
#include <omni/core/logic_error.hpp>
#include <string>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
class OMNI_CORE_API not_implemented_error : public omni::core::logic_error {
public:
not_implemented_error (std::string const & fileName, std::string const & functionName, int lineNumber);
};
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 564 |
C++
| 20.730768 | 111 | 0.719858 |
daniel-kun/omni/interface/omni/core/no_context_error.hpp
|
#ifndef OMNI_CORE_NO_CONTEXT_ERROR_HPP
#define OMNI_CORE_NO_CONTEXT_ERROR_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <stdexcept>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
/**
Is thrown when something was expected to be added to a context at this point (such as when compiling a function), but it was not yet added to a context.
**/
class OMNI_CORE_API no_context_error : public std::runtime_error {
public:
no_context_error (domain domain, std::string const & identifier);
};
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 677 |
C++
| 22.37931 | 156 | 0.703102 |
daniel-kun/omni/interface/omni/core/sandbox.hpp
|
#ifndef OMNI_TAKE2_SANDBOX_HPP
#define OMNI_TAKE2_SANDBOX_HPP
namespace omni {
namespace take2 {
void __declspec (dllexport) sandbox ();
} // namespace take2
} // namespace omni
#endif
| 190 |
C++
| 13.692307 | 40 | 0.721053 |
daniel-kun/omni/interface/omni/core/domain.hpp
|
#ifndef OMNI_CORE_DOMAIN_HPP
#define OMNI_CORE_DOMAIN_HPP
#include <omni/core/core.hpp>
#include <ostream>
namespace omni {
namespace core {
/**
Every object in the omni context that has an `id' resides in a specific domain to minimize potential id collision and
to easily see what kind of object is referenced by a specific id. When storing, showing or reading an id the domain should
always be accompanying the actual id - e.g. as a prefix.
**/
enum class domain {
invalid,
first,
binary_operator_expression = first,
bitcast_expression,
block,
do_while_statement,
expression,
external_function,
function,
function_call_expression,
if_statement,
builtin_literal_expression,
module,
parameter,
return_statement,
statement,
type,
variable_assignment_expression,
variable_declaration_expression,
variable_expression,
while_statement,
last = while_statement,
};
std::ostream OMNI_CORE_API & operator << (std::ostream & lhs, omni::core::domain rhs);
} // namespace core
} // namespace omni
#endif // include guard
| 1,224 |
C++
| 25.630434 | 126 | 0.637255 |
daniel-kun/omni/interface/omni/core/id.hpp
|
#ifndef OMNI_CORE_ID_HPP
#define OMNI_CORE_ID_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <string>
#include <ostream>
namespace omni {
namespace core {
/**
@class id id.hpp omni/core/model/id.hpp
@brief An id consists of a domain and a globally unique identifier that is used throughout omni to identify parts of the context such as variables, types,
functions, classes, enums, and even statements and expressions.
To minimize the potential clash of ids, the identifiers for entities in omni are split into "domains" (@see domain).
This means that only a pair of domain and id builds up a unique identifier of an entity. The id alone is not unique.
Usually objects of type id should be passed around as values instead of references or shared_ptr.
**/
class OMNI_CORE_API id {
public:
id ();
id (domain domain, std::string id);
bool operator<(id const & rhs) const;
bool operator==(id const & rhs) const;
bool isValid () const;
domain getDomain () const;
std::string getId () const;
private:
domain _domain;
std::string _id;
};
std::ostream OMNI_CORE_API & operator << (std::ostream & lhs, id const & rhs);
} // namespace core
} // namespace omni
#endif // include guard
| 1,337 |
C++
| 28.086956 | 158 | 0.666417 |
daniel-kun/omni/interface/omni/core/already_exists_error.hpp
|
#ifndef OMNI_CORE_ALREADY_EXISTS_ERROR_HPP
#define OMNI_CORE_ALREADY_EXISTS_ERROR_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <stdexcept>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
/**
Is thrown when something was expected to not exist, but it existed.
E.g. when adding a function to a class where a function with the same prototype already exists.
**/
class OMNI_CORE_API already_exists_error : public std::runtime_error {
public:
already_exists_error (domain domain, std::string const & identifier);
};
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 708 |
C++
| 22.633333 | 99 | 0.710452 |
daniel-kun/omni/interface/omni/core/context.hpp
|
#ifndef OMNI_CORE_CONTEXT_HPP
#define OMNI_CORE_CONTEXT_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <omni/core/module_emit_options.hpp>
#include <omni/core/id.hpp>
#include <omni/core/model/type_class.hpp>
#include <memory>
#include <string>
#include <map>
#include <utility>
namespace llvm {
class raw_ostream;
class LLVMContext;
}
namespace omni {
namespace core {
namespace model {
class function;
class function_prototype;
class type;
class block;
class entity;
class module;
}
}
}
namespace omni {
namespace core {
/**
The "context" is an instance of the omni compiler that store some global information about the architecture of the underlying targets
and a list of modules that are to be emitted when the whole context is emitted.
**/
class OMNI_CORE_API context {
public:
context ();
~ context();
std::shared_ptr <model::type> sharedBasicType (model::type_class typeClass, int indirectionLevel = 0) const;
void addModule (std::shared_ptr <model::module> module);
const llvm::LLVMContext & llvmContext () const;
llvm::LLVMContext & llvmContext ();
private:
std::unique_ptr <llvm::LLVMContext> _llvmContext;
std::map <std::pair <model::type_class, int>, std::shared_ptr <model::type>> _sharedBasicTypes;
std::vector <std::shared_ptr <model::module>> _modules;
};
} // namespace core
} // namespace omni
#endif // include guard
| 1,512 |
C++
| 23.403225 | 137 | 0.671958 |
daniel-kun/omni/interface/omni/core/invalid_argument_error.hpp
|
#ifndef OMNI_CORE_INVALID_ARGUMENT_ERROR_HPP
#define OMNI_CORE_INVALID_ARGUMENT_ERROR_HPP
#include <omni/core/core.hpp>
#include <stdexcept>
#include <string>
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4275)
#endif
namespace omni {
namespace core {
class OMNI_CORE_API invalid_argument_error : public std::invalid_argument {
public:
invalid_argument_error (std::string const & fileName, std::string const & functionName, int lineNumber, std::string argumentName, std::string const & errorMessage);
};
} // namespace core
} // namespace omni
#ifdef _MSC_VER
# pragma warning(pop)
#endif
#endif // include guard
| 665 |
C++
| 21.199999 | 172 | 0.717293 |
daniel-kun/omni/interface/omni/core/verification_failed_error.hpp
|
#ifndef OMNI_CORE_VERIFICATION_FAILED_ERROR_HPP
#define OMNI_CORE_VERIFICATION_FAILED_ERROR_HPP
#include <omni/core/core.hpp>
#include <stdexcept>
#include <string>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
/**
Is thrown when a module is tried to be emitted, but the verification failed.
**/
class OMNI_CORE_API verification_failed_error : public std::runtime_error {
public:
verification_failed_error (std::string moduleName, std::string verificationErrorInfo);
};
}
}
#pragma warning(pop)
#endif // include guard
| 599 |
C++
| 19.689654 | 94 | 0.717863 |
daniel-kun/omni/interface/omni/core/model/function.hpp
|
#ifndef OMNI_CORE_MODEL_FUNCTION_HPP
#define OMNI_CORE_MODEL_FUNCTION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/function_prototype.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class module;
/**
@class function function.hpp omni/core/model/function.hpp
@brief Defines a function implementation that can be called with a function_call_expression.
A function consists of a name that should be unique within a scope, a return-type, a number of parameters and a body.
For more information about the return-type and the parameters, see function_prototype.
A function can be exported. An exported function is visible from other modules than the one the function is defined in.
A function is not emitted to a binary if it has not been added to a module via scope::addFunction.
Currently, only top-level functions that are directly added to a module are supported.
Functions that are added to any other scope deeper within a module are not emitted.
**/
class OMNI_CORE_API function : public function_prototype {
public:
function (std::string const & name,
std::shared_ptr <type> returnType = std::shared_ptr <type> (),
std::shared_ptr <block> body = std::shared_ptr <block> (),
std::vector <std::shared_ptr <parameter>> parameters = std::vector <std::shared_ptr <parameter>> (),
bool isExported = false);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setExported (bool isExported);
bool isExported () const;
void setBody (std::shared_ptr <block> body);
const std::shared_ptr <block> getBody () const;
std::shared_ptr <block> getBody ();
llvm::Function * llvmFunction () override;
private:
llvm::Function * _llvmFunction;
bool _isExported;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,088 |
C++
| 34.406779 | 123 | 0.670019 |
daniel-kun/omni/interface/omni/core/model/meta_info_extension.hpp
|
#ifndef OMNI_CORE_MODEL_META_INFO_EXTENSION_HPP
#define OMNI_CORE_MODEL_META_INFO_EXTENSION_HPP
#include <omni/core/core.hpp>
namespace omni {
namespace core {
namespace model {
/**
@class meta_info_extension meta_info_extension.hpp omni/core/model/meta_info_extension.hpp
@brief This class is abstract. Base-class for custom meta-information properties that can be added to meta_info.
E.g. the UI subsystem uses this heavily to attach meta-information to entity types.
**/
class OMNI_CORE_API meta_info_extension {
public:
virtual ~ meta_info_extension () = 0;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 696 |
C++
| 25.807691 | 116 | 0.70977 |
daniel-kun/omni/interface/omni/core/model/pure_expression.hpp
|
#ifndef OMNI_CORE_PURE_EXPRESSION_HPP
#define OMNI_CORE_PURE_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/expression.hpp>
namespace omni {
namespace core {
namespace model {
/**
Abstract.
An pure_expression is an expression that does not modify it's operands and does not have side-effects.
A pure_expression does not have any special functionality or properties, it is just a kind of a class of expressions.
@see modifying_expression
**/
class OMNI_CORE_API pure_expression : public expression {
public:
pure_expression ();
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 790 |
C++
| 24.516128 | 121 | 0.697468 |
daniel-kun/omni/interface/omni/core/model/meta_info.hpp
|
#ifndef OMNI_CORE_MODEL_META_INFO_HPP
#define OMNI_CORE_MODEL_META_INFO_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/meta_info_extension.hpp>
#include <string>
#include <vector>
#include <memory>
#include <map>
namespace omni {
namespace core {
namespace model {
/**
@class meta_info meta_info.hpp omni/core/model/meta_info.hpp
@brief Provides meta-information about different entity types in the Omni Programming Language.
Meta-information include the name of the specific kind of entity, it's hierarchical parent type and it's decendant types.
E.g. modifying_expression's hierarchical parent is expression, and it's decendant (implementing) types are function_call_expression and variable_assignment_expression.
Additional meta_info_extensions can be registered under arbitrary names to attach any value to an entity type.
Other omni subsystems make use of these extensions. The extension properties' names start with "omni.", such as "omni.ui".
**/
class OMNI_CORE_API meta_info {
public:
meta_info (const std::string & name);
meta_info (const meta_info & parent, const std::string & name);
bool isAbstract () const;
const std::string & getName () const;
const meta_info * getParent () const;
const meta_info & getChildAt (std::size_t index) const;
std::size_t getChildCount () const;
const meta_info_extension * getExtension (const std::string & extensionName) const;
void setExtension (const std::string & extensionName, std::shared_ptr <meta_info_extension> extension);
private:
meta_info * _parent;
std::string _name;
std::vector <meta_info*> _children;
std::map <std::string, std::shared_ptr <meta_info_extension>> _extensions;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,918 |
C++
| 35.903845 | 171 | 0.689781 |
daniel-kun/omni/interface/omni/core/model/literal_expression.hpp
|
#ifndef OMNI_CORE_MODEL_LITERAL_EXPRESSION_HPP
#define OMNI_CORE_MODEL_LITERAL_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/pure_expression.hpp>
#ifndef Q_MOC_RUN
#include <boost/any.hpp>
#include <boost/signals2.hpp>
#endif
namespace omni {
namespace core {
class context;
}}
namespace omni {
namespace core {
namespace model {
/**
@class literal_expression literal_expression.hpp omni/core/model/literal_expression.hpp
@brief A literal_expression is an expression that returns a value that was already defined at compile time.
literal_expression is abstract. Use the subclass builtin_literal_expression to create a literal.
(class_literal_expression will be coming later, when classes are implemented.)
**/
class OMNI_CORE_API literal_expression : public pure_expression {
public:
typedef boost::signals2::signal <void (literal_expression & sender, boost::any oldValue, boost::any newValue)> ValueChangedSignal;
boost::signals2::connection connectValueChanged (ValueChangedSignal::slot_type handler);
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
virtual std::string toString (bool fullyQualified = true) const = 0;
static std::shared_ptr <literal_expression> fromString (omni::core::context & context, std::string const & text, literal_expression * originatingLiteral);
protected:
virtual void valueChanged (boost::any oldValue, boost::any newValue);
private:
ValueChangedSignal _valueChangedSignal;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,681 |
C++
| 30.148148 | 162 | 0.724569 |
daniel-kun/omni/interface/omni/core/model/type_mismatch_error.hpp
|
#ifndef OMNI_CORE_TYPE_MISMATCH_ERROR_HPP
#define OMNI_CORE_TYPE_MISMATCH_ERROR_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <stdexcept>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
namespace model {
class type;
/**
Is thrown when something expected two types to match exactly, but they did not match.
E.g. binary_operator_expression's ctor expects the types of the left and right hand side expressions to return the same type.
Same for variable assignments, etc.
**/
class OMNI_CORE_API type_mismatch_error : public std::runtime_error {
public:
type_mismatch_error (type & leftType, type & rightType);
};
} // namespace model
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 835 |
C++
| 23.588235 | 129 | 0.711377 |
daniel-kun/omni/interface/omni/core/model/scope.hpp
|
#ifndef OMNI_CORE_MODEL_SCOPE_HPP
#define OMNI_CORE_MODEL_SCOPE_HPP
#include <omni/core/core.hpp>
#include <omni/core/id.hpp>
#include <omni/core/model/entity.hpp>
#include <memory>
#include <map>
#include <vector>
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace core {
namespace model {
class type;
class function_prototype;
class function;
class block;
class module;
class parameter;
/**
@class scope scope.hpp omni/core/model/scope.hpp
@brief This class is abstract. A scope contains a list of top-level entities, which are accessible within this scope and it's children's scopes.
Top-level entities currently are functions, only.
**/
class OMNI_CORE_API scope : public entity {
public:
explicit scope ();
explicit scope (std::string name);
explicit scope (id scopeId, std::string name = std::string ());
~ scope () = 0;
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
std::shared_ptr <function> createFunction (
std::string const & name,
std::shared_ptr <type> returnType,
std::shared_ptr <block> body,
std::vector <std::shared_ptr <parameter>> parameters = std::vector <std::shared_ptr <parameter>> (),
bool isExported = false);
std::shared_ptr <function_prototype> findFunctionByName (std::string const & name);
void addFunction (std::shared_ptr <function_prototype> function);
bool removeFunction (std::shared_ptr <function_prototype> function);
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,727 |
C++
| 27.327868 | 148 | 0.649102 |
daniel-kun/omni/interface/omni/core/model/modifying_expression.hpp
|
#ifndef OMNI_CORE_MODIFYING_EXPRESSION_HPP
#define OMNI_CORE_MODIFYING_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/expression.hpp>
namespace omni {
namespace core {
namespace model {
/**
Abstract.
An modifying_expression is an expression that does modify at least one of it's operands or has side-effects.
A modifying_expression does not have any special functionality or properties, it is just a kind of a class of expressions.
@see pure_expression
**/
class OMNI_CORE_API modifying_expression : public expression {
public:
modifying_expression ();
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 819 |
C++
| 25.451612 | 126 | 0.703297 |
daniel-kun/omni/interface/omni/core/model/binary_operator_expression.hpp
|
#ifndef OMNI_CORE_BINARY_OPERATOR_EXPRESSION_HPP
#define OMNI_CORE_BINARY_OPERATOR_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/pure_expression.hpp>
#include <memory>
namespace llvm {
class Value;
class BasicBlock;
}
namespace omni {
namespace core {
namespace model {
class type;
/**
A binary_operator_expression is an expression that returns the result of a binary operator that is applied to it's two operands.
A binary operator is an operator that takes a left-hand-side and a right-hand-side operand.
Examples are:
1 + 5
5 - 1
9 * 2
8 / 4
5 mod 2
5 div 2
5 bit-and 2
3 bit-or 5
9 bit-xor 2
**/
class OMNI_CORE_API binary_operator_expression : public pure_expression {
public:
enum class binary_operation {
binary_lessthan_operation, /// a < b
binary_plus_operation, /// a + b
binary_minus_operation /// a - b
};
binary_operator_expression (context & context, binary_operation op, std::shared_ptr <expression> leftOperand, std::shared_ptr <expression> rightOperand);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setLeftOperand (std::shared_ptr <expression> leftOperand);
std::shared_ptr <expression> getLeftOperand () const;
void setRightOperand (std::shared_ptr <expression> rightOperand);
std::shared_ptr <expression> getRightOperand () const;
std::shared_ptr <type> getType () const override;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <type> _type;
binary_operation _operator;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,885 |
C++
| 26.735294 | 161 | 0.655172 |
daniel-kun/omni/interface/omni/core/model/expression.hpp
|
#ifndef OMNI_CORE_EXPRESSION_HPP
#define OMNI_CORE_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <memory>
namespace llvm {
class BasicBlock;
class Value;
}
namespace omni {
namespace core {
namespace model {
class type;
/**
An expression is a statement that returns or is a value. An expression can stand alone as a statement, or it can be part of other statements or expressions.
For example, the binary_operator_expression has one expression as the left hand side operand and
another expression as the right hand side operand. A function_call_expression receives expressions as it's parameters and is itself an expression.
**/
class OMNI_CORE_API expression : public statement {
public:
expression ();
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
virtual std::shared_ptr <type> getType () const = 0;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,067 |
C++
| 25.699999 | 160 | 0.701031 |
daniel-kun/omni/interface/omni/core/model/type_class.hpp
|
#ifndef OMNI_CORE_TYPE_CLASS_HPP
#define OMNI_CORE_TYPE_CLASS_HPP
#include <omni/core/core.hpp>
#include <ostream>
namespace omni {
namespace core {
namespace model {
enum class type_class {
t_void,
t_boolean,
t_unsignedByte,
t_signedByte,
t_unsignedShort,
t_signedShort,
t_unsignedInt,
t_signedInt,
t_unsignedLong,
t_signedLong,
t_unsignedLongLong,
t_signedLongLong,
t_char,
t_string,
t_class,
t_enum
};
std::ostream OMNI_CORE_API & operator << (std::ostream & lhs, const omni::core::model::type_class rhs);
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 740 |
C++
| 19.027027 | 107 | 0.593243 |
daniel-kun/omni/interface/omni/core/model/while_statement.hpp
|
#ifndef OMNI_CORE_WHILE_STATEMENT_HPP
#define OMNI_CORE_WHILE_STATEMENT_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class block;
class expression;
/**
An while_statement executes the body as long as condition is true.
**/
class OMNI_CORE_API while_statement : public statement {
public:
while_statement ();
while_statement (std::shared_ptr <expression> condition, std::shared_ptr <block> body);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
std::shared_ptr <expression> getCondition ();
const std::shared_ptr <expression> getCondition () const;
void setCondition (std::shared_ptr <expression> condition);
std::shared_ptr <block> getBody ();
const std::shared_ptr <block> getBody () const;
void setBody (std::shared_ptr <block> body);
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <expression> _condition;
std::shared_ptr <block> _body;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,316 |
C++
| 25.87755 | 95 | 0.656535 |
daniel-kun/omni/interface/omni/core/model/block.hpp
|
#ifndef OMNI_CORE_BLOCK_HPP
#define OMNI_CORE_BLOCK_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <vector>
#include <memory>
namespace llvm {
class LLVMContext;
class BasicBlock;
class Function;
}
namespace omni {
namespace core {
namespace model {
class statement;
/**
A block is a list of statements that is executed in a specific context. Examples are function bodies and bodies of an 'if', 'else', 'while' or 'for'-statement.
**/
class OMNI_CORE_API block : public statement {
public:
typedef std::vector <std::shared_ptr <statement>> statement_list;
block ();
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
const statement_list getStatements () const;
statement_list::iterator findStatement (std::shared_ptr <statement> statement);
statement_list::iterator statementsEnd ();
std::shared_ptr <statement> prependStatement (std::shared_ptr <statement> statement);
std::shared_ptr <statement> appendStatement (std::shared_ptr <statement> statement);
std::shared_ptr <statement> insertStatementAfter (statement_list::iterator position, std::shared_ptr <statement> statement);
std::shared_ptr <statement> insertStatementBefore (statement_list::iterator position, std::shared_ptr <statement> statement);
std::shared_ptr <statement> removeStatement (statement_list::iterator position);
std::shared_ptr <statement> removeStatement (std::shared_ptr <statement> statement);
llvm::BasicBlock * llvmEmitIntoExistingBlock (llvm::BasicBlock * llvmBasicBlock);
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::size_t _statementCount;
statement_list _statements;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,994 |
C++
| 32.813559 | 163 | 0.692578 |
daniel-kun/omni/interface/omni/core/model/variable_declaration_expression.hpp
|
#ifndef OMNI_CORE_VARIABLE_DECLARATION_EXPRESSION_HPP
#define OMNI_CORE_VARIABLE_DECLARATION_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/pure_expression.hpp>
namespace llvm {
class Value;
}
namespace omni {
namespace core {
namespace model {
class type;
class expression;
/**
@class variable_declaration_expression variable_declaration_expression.hpp omni/core/model/variable_declaration_expression.hpp
@brief A variable_declaration_expression is an expression that declares a variable and returns it's content.
A variable declaration always contains a name. The properties of the variable are either defined by a specified type for the variable or by an initialization expression.
If a type is specified, the variable is initialized with the type's default value - which means that the type needs to *have* a default value. This is guarantueed for all built-in types.
Classes may not have a default constructor and hence do not have a default value.
If an initialization expression is specified in a variable declaration, the variable's type is deduced from the expression's type and the value of the variable is initialized with the
return value of the expression.
As a variable declaration is an expression, it can be used wherever a value is needed. E.g. in the condition of an if-statement. The variable's scope is propagated across it's parent scope.
This means if a variable is declared in a block, it is known across the block and all it's children. If it is declared in an if-statement's condition, it is known in all the children of the
if-statement - this includes the true-block and the else-block.
**/
class OMNI_CORE_API variable_declaration_expression : public pure_expression {
public:
variable_declaration_expression ();
variable_declaration_expression (std::shared_ptr <type> type);
variable_declaration_expression (std::shared_ptr <expression> initializer);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
std::shared_ptr <type> getType () const override;
void setType (std::shared_ptr <type> type);
std::shared_ptr <expression> getInitializationExpression () const;
void setInitializationExpression (std::shared_ptr <expression> initializer);
llvm::Value * llvmPointerValue ();
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <type> _type;
llvm::Value * _llvmPointerValue; // internal
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,759 |
C++
| 42.124999 | 193 | 0.7278 |
daniel-kun/omni/interface/omni/core/model/bitcast_expression.hpp
|
#ifndef OMNI_CORE_BITCAST_EXPRESSION_HPP
#define OMNI_CORE_BITCAST_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/cast_expression.hpp>
namespace omni {
namespace core {
namespace model {
/**
A bitcast_expression casts one type to another, where both types have the same bit width.
The cast does not change any bits, but instead just reinterprets the given bits to be a value of the given target type.
bitcasts are dangerous and are usually only used internal in the compiler. Most likely, they will not surface in the omni language.
**/
class OMNI_CORE_API bitcast_expression : public cast_expression {
public:
bitcast_expression (std::shared_ptr <expression> sourceExpression, std::shared_ptr <type> targetType);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setSourceExpression (std::shared_ptr <expression> sourceExpression);
std::shared_ptr <expression> getSourceExpression () const;
std::shared_ptr <type> getType () const override;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <type> _targetType;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,377 |
C++
| 31.809523 | 135 | 0.702977 |
daniel-kun/omni/interface/omni/core/model/external_function.hpp
|
#ifndef OMNI_CORE_EXTERNAL_FUNCTION_HPP
#define OMNI_CORE_EXTERNAL_FUNCTION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/function_prototype.hpp>
namespace omni {
namespace core {
namespace model {
class module;
class type;
/**
@class external_function external_function.hpp omni/core/model/external_function.hpp
@brief Declares an external function that can be called with a function_call_expression.
An external function is defined in a different module than the function_call_expression is called in.
An external function consists of a name that should be unique within a scope, a return-type, a number of parameters and a library name
that it is defined in.
The library name of an external_function declaration will be added to the list of linked libraries at link-time.
Each library will only be added once - multiple external_function s that have the same libraryName will not lead to a library linked multiple times.
**/
class OMNI_CORE_API external_function : public function_prototype {
public:
external_function (std::string libraryName = std::string (),
std::string functionName = std::string (),
std::shared_ptr <type> returnType = std::shared_ptr <type> (),
std::vector <std::shared_ptr <parameter>> parameters = std::vector <std::shared_ptr <parameter>> (),
bool isDllImport = false);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setLibraryName (std::string libraryName);
std::string getLibraryName () const;
void setDllImport (bool isDllImport);
bool isDllImport () const;
void fillLibraries (std::set <std::string> & libraries) override;
llvm::Function * llvmFunction () override;
private:
llvm::Function * _llvmFunction;
std::string _libraryName;
bool _isDllImport;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,161 |
C++
| 36.929824 | 152 | 0.664044 |
daniel-kun/omni/interface/omni/core/model/statement.hpp
|
#ifndef OMNI_CORE_STATEMENT_HPP
#define OMNI_CORE_STATEMENT_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/scope.hpp>
#include <omni/core/statement_emit_result.hpp>
namespace llvm {
class BasicBlock;
class Value;
}
namespace omni {
namespace core {
namespace model {
/**
Abstract.
A statement can be anything that is being executed in a block.
There is a distinction between statements that return a result ("expressions") and all other statements that do not
return a result. Everything that returns a result derives from omni::core::expression, while anything else does directly
derive from omni::core::statement.
**/
class OMNI_CORE_API statement : public scope {
public:
statement ();
virtual ~ statement ();
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
virtual statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) = 0;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,078 |
C++
| 25.317073 | 124 | 0.691095 |
daniel-kun/omni/interface/omni/core/model/native_type_to_type_class.hpp
|
#ifndef OMNI_CORE_NATIVE_TYPE_TO_TYPE_CLASS_HPP
#define OMNI_CORE_NATIVE_TYPE_TO_TYPE_CLASS_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/type_class.hpp>
#include <string>
namespace omni {
namespace core {
namespace model {
/**
Allows templated conversion from C++ native types to the corresponding type_class.
Use it as this:
type_class t = native_type_to_type_class <t>::typeClass;
**/
template <typename T>
class native_type_to_type_class {
};
// void -> t_void
template <>
class native_type_to_type_class <void> {
public:
typedef void nativeType;
static const type_class typeClass = type_class::t_void;
};
// bool -> t_boolean
template <>
class native_type_to_type_class <bool> {
public:
typedef bool nativeType;
static const type_class typeClass = type_class::t_boolean;
};
// unsigned char -> t_unsignedByte
template <>
class native_type_to_type_class <unsigned char> {
public:
typedef unsigned char nativeType;
static const type_class typeClass = type_class::t_unsignedByte;
};
// signed char -> t_signedByte
template <>
class native_type_to_type_class <signed char> {
public:
typedef signed char nativeType;
static const type_class typeClass = type_class::t_signedByte;
};
// unsigned short -> t_unsignedShort
template <>
class native_type_to_type_class <unsigned short> {
public:
typedef unsigned short nativeType;
static const type_class typeClass = type_class::t_unsignedShort;
};
// signed short -> t_signedShort
template <>
class native_type_to_type_class <signed short> {
public:
typedef signed short nativeType;
static const type_class typeClass = type_class::t_signedShort;
};
// unsigned int -> t_unsignedInt
template <>
class native_type_to_type_class <unsigned int> {
public:
typedef unsigned int nativeType;
static const type_class typeClass = type_class::t_unsignedInt;
};
// signed int -> t_signedInt
template <>
class native_type_to_type_class <signed int> {
public:
typedef signed int nativeType;
static const type_class typeClass = type_class::t_signedInt;
};
// unsigned long -> t_unsignedLong
template <>
class native_type_to_type_class <unsigned long> {
public:
typedef unsigned long nativeType;
static const type_class typeClass = type_class::t_unsignedLong;
};
// signed long -> t_signedLong
template <>
class native_type_to_type_class <signed long> {
public:
typedef signed long nativeType;
static const type_class typeClass = type_class::t_signedLong;
};
// unsigned long long -> t_unsignedLongLong
template <>
class native_type_to_type_class <unsigned long long> {
public:
typedef unsigned long long nativeType;
static const type_class typeClass = type_class::t_unsignedLongLong;
};
// signed long long -> t_signedLongLong
template <>
class native_type_to_type_class <signed long long> {
public:
typedef signed long long nativeType;
static const type_class typeClass = type_class::t_signedLongLong;
};
// char -> t_char
template <>
class native_type_to_type_class <char> {
public:
typedef char nativeType;
static const type_class typeClass = type_class::t_char;
};
// std::string -> t_string
template <>
class native_type_to_type_class <std::string> {
public:
typedef std::string nativeType;
static const type_class typeClass = type_class::t_string;
};
}
}
}
#endif
| 3,377 |
C++
| 23.302158 | 86 | 0.711874 |
daniel-kun/omni/interface/omni/core/model/variable_assignment_expression.hpp
|
#ifndef OMNI_CORE_VARIABLE_ASSIGNMENT_EXPRESSION_HPP
#define OMNI_CORE_VARIABLE_ASSIGNMENT_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/modifying_expression.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class variable_declaration_expression;
/**
A variable_assignment_expression changes the value of a variable to the return value of any expression.
This variable_assignment_expression needs to be either used by another expression or statement to be executed.
It can be put into a block if the assignment of the variable should be the only affect.
Otherwise, it can be used as a parameter to a function call, as a left or right hand side operand of a binary_operator_expression, etc.
**/
class OMNI_CORE_API variable_assignment_expression : public modifying_expression {
public:
variable_assignment_expression (std::shared_ptr <variable_declaration_expression> variable, std::shared_ptr <expression> value);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setVariable (std::shared_ptr <variable_declaration_expression> variable);
std::shared_ptr <variable_declaration_expression> getVariable () const;
void setValue (std::shared_ptr <expression> value);
std::shared_ptr <expression> getValue () const;
std::shared_ptr <type> getType () const override;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
static statement_emit_result llvmEmitImpl (llvm::BasicBlock * llvmBasicBlock, variable_declaration_expression & variable, expression & value);
private:
std::shared_ptr <variable_declaration_expression> _variable;
llvm::Value * _llvmValue;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,950 |
C++
| 38.019999 | 150 | 0.721538 |
daniel-kun/omni/interface/omni/core/model/cast_expression.hpp
|
#ifndef OMNI_CORE_CAST_EXPRESSION_HPP
#define OMNI_CORE_CAST_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/pure_expression.hpp>
namespace omni {
namespace core {
namespace model {
/**
Abstract.
cast_expression is an abstract base class for different other, concrete casts.
Casts never change the item that is being casted, hence they are "pure".
**/
class OMNI_CORE_API cast_expression : public pure_expression {
public:
cast_expression ();
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 704 |
C++
| 22.499999 | 82 | 0.681818 |
daniel-kun/omni/interface/omni/core/model/function_prototype.hpp
|
#ifndef OMNI_CORE_MODEL_FUNCTION_PROTOTYPE_HPP
#define OMNI_CORE_MODEL_FUNCTION_PROTOTYPE_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/scope.hpp>
#include <memory>
#include <vector>
#include <string>
namespace llvm {
class FunctionType;
class Function;
class Module;
}
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace core {
namespace model {
class module;
class parameter;
class block;
class type;
/**
@class function_prototype function_prototype.hpp omni/core/model/function_prototype.hpp
@brief This class is abstract. A function_prototype defines the name, return type and parameters of a function and adds basic functionalities to read and modify these values.
function_prototype serves as a common divisor for function and external_function, since they share their main characteristics.
See @see omni::core::model::function and @see external_function for more details.
**/
class OMNI_CORE_API function_prototype : public scope {
public:
function_prototype (std::string const & name,
std::shared_ptr <type> returnType,
std::vector <std::shared_ptr <parameter>> parameters = std::vector <std::shared_ptr <parameter>> ());
virtual ~ function_prototype ();
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
void setReturnType (std::shared_ptr <type> returnType);
const std::shared_ptr <type> getReturnType () const;
std::shared_ptr <type> getReturnType ();
llvm::FunctionType * llvmFunctionType ();
virtual llvm::Function * llvmFunction () = 0;
void appendParameter (std::shared_ptr <parameter> parameter);
void setParameters (std::vector <std::shared_ptr <parameter>> parameters);
std::vector <std::shared_ptr <parameter>> getParameters ();
private:
std::shared_ptr <type> _returnType;
std::size_t _paramCount;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,142 |
C++
| 29.183098 | 178 | 0.668067 |
daniel-kun/omni/interface/omni/core/model/parameter.hpp
|
#ifndef OMNI_CORE_MODEL_PARAMETER_HPP
#define OMNI_CORE_MODEL_PARAMETER_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/scope.hpp>
namespace omni {
namespace core {
namespace model {
class type;
/**
@class parameter parameter.hpp omni/core/model/parameter.hpp
@brief Defines a parameter that can be passed to an external_function or a omni::core::model::function.
A parameter consists of a type and a name.
@see function_prototype::getParameters ().
**/
class OMNI_CORE_API parameter : public scope {
public:
parameter (std::shared_ptr <type> parameterType = std::shared_ptr <type> (), std::string name = std::string ());
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setType (std::shared_ptr <type> type);
const std::shared_ptr <type> getType () const;
std::shared_ptr <type> getType ();
private:
std::shared_ptr <type> _type;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,129 |
C++
| 24.681818 | 120 | 0.654562 |
daniel-kun/omni/interface/omni/core/model/entity.hpp
|
#ifndef OMNI_CORE_MODEL_ENTITY_HPP
#define OMNI_CORE_MODEL_ENTITY_HPP
#include <omni/core/core.hpp>
#include <omni/core/id.hpp>
#ifndef Q_MOC_RUN
#include <boost/signals2.hpp>
#endif
#include <string>
#include <memory>
#include <map>
#include <set>
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace core {
namespace model {
class scope;
class module;
class meta_info;
/**
@class entity entity.hpp omni/core/model/entity.hpp
@brief This class is abstract. Base class for all objects that are part of a context, such as any kinds of statements and expressions, like variable declarations, if-statements, etc.
The Omni Programming Language Model consists of a network of entities. The highest level entity in the model is the module. A module, in turn, mainly contains functions.
Functions contain a block that builds up it's body, which in turn contains a list of statements, such as variable declarations, etc.
See one of the many base-classes for further description of what they do.
**/
class OMNI_CORE_API entity {
public:
typedef boost::signals2::signal <void (entity & sender)> ChangedSignal;
/**
Used to store lists that map a component's name to an entity.
@see getComponents(omni::core::domain)
**/
typedef std::map <std::string, std::shared_ptr <entity>> name_to_entities_map;
/**
Used to store lists that map a component's domain to a list of entities.
@see getComponents()
**/
typedef std::map <domain, name_to_entities_map> domain_to_name_to_entities_map;
explicit entity ();
explicit entity (std::string const & name);
explicit entity (id entityId, std::string const & name);
virtual ~ entity () = 0;
static meta_info & getStaticMetaInfo ();
virtual meta_info & getMetaInfo () const = 0;
void setId (id newId);
id getId () const;
virtual domain getDomain () const = 0;
void setName (const std::string & name);
std::string getName () const;
void setParent (entity * parent);
entity * getParent ();
const entity * getParent () const;
virtual module * getModule ();
virtual const module * getModule () const;
virtual context * getContext ();
virtual const context * getContext () const;
virtual void setComponent (domain domain, std::string name, std::shared_ptr <entity> entity);
const domain_to_name_to_entities_map & getComponents () const;
domain_to_name_to_entities_map getComponents ();
const name_to_entities_map getComponents (domain domain) const;
name_to_entities_map getComponents (domain domain);
std::shared_ptr <entity> getComponent (domain domain, std::string name) const;
template <typename T>
std::shared_ptr <T> getComponentAs (domain domain, std::string name) const;
std::map <std::string, std::shared_ptr <entity>> getComponentsStartingWith (domain domain, std::string name) const;
template <typename T>
std::map <std::string, std::shared_ptr <T>> getComponentsStartingWithAs (domain domain, std::string name) const;
std::shared_ptr <entity> lookupComponentById (id id);
void clearComponents ();
void clearComponents (domain domain);
bool removeComponent (domain domain, std::string name);
bool removeComponent (domain domain, std::shared_ptr <entity> component);
boost::signals2::connection connectChanged (ChangedSignal::slot_type handler);
virtual void fillLibraries (std::set <std::string> & libraries);
protected:
virtual void changed ();
private:
void updateIds ();
entity * _parent;
std::string _name;
id _id;
domain_to_name_to_entities_map _components;
ChangedSignal _changedSignal;
};
} // namespace model
} // namespace core
} // namespace omni
/**
@brief Returns the component that is stored for the given domain with the given name, if it is of type `T'.
For an explanation of what a component is, @see getComponents()
Which domains and names are used to store the components depends on the actual entity, see the respective documentation of the actual entity's class.
Note that a component's name has nothing to do with an entity's name that can be retrieved by getName().
@param domain The domain that the component is stored in.
@param name The name that the component is stored as.
@return The component that is stored for the given domain with the given name. Returns nullptr if the component does not exist or can not by dynamic_cast'ed to `T'.
**/
template <typename T>
std::shared_ptr <T> omni::core::model::entity::getComponentAs (omni::core::domain domain, std::string name) const
{
return std::dynamic_pointer_cast <T> (getComponent (domain, name));
}
/**
@brief Returns a list of components for the given domain whose names start with the given prefix, if they are of type `T'.
For an explanation of what a component is, @see getComponents()
This function can be used when an entity contains a list of components with the same meaning, such as a function contains a list of parameters.
All parameters start with the same name, so a list of parameters can be retrieved by calling getComponentsStartingWith(omni::core::domain::parameter, "parameter").
@param domain The domain that the components are stored in.
@param prefix The prefix that the names of the components start with.
@return A list that maps the component's name to the stored entity. Only entities that can be dynamic_cast'ed to `T' are listed.
**/
template <typename T>
std::map <std::string, std::shared_ptr <T>> omni::core::model::entity::getComponentsStartingWithAs (omni::core::domain domain, std::string prefix) const
{
std::map <std::string, std::shared_ptr <T>> result;
for (auto i : getComponentsStartingWith (domain, prefix)) {
result [i.first] = std::dynamic_pointer_cast <T> (i.second);
}
return result;
}
#endif // include guard
| 6,147 |
C++
| 37.666666 | 186 | 0.68749 |
daniel-kun/omni/interface/omni/core/model/type.hpp
|
#ifndef OMNI_CORE_TYPE_HPP
#define OMNI_CORE_TYPE_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/entity.hpp>
#include <omni/core/model/type_class.hpp>
#ifndef Q_MOC_RUN
#include <boost/noncopyable.hpp>
#endif
namespace llvm {
class Type;
}
namespace omni {
namespace core {
namespace model {
/**
@class type type.hpp omni/core/model/type.hpp
@brief A type defines the properties of types that can be used for variables, function-parameters, function-return-values, etc.
<b>Important:</b> Always use type::sharedBasicType or context::sharedBasicType to get a type-object for any builtin-types.
The type_class differentiates between a few basic built-in types and user-defined types (classes).
(Currently, classes are not yet implemented for omni. Once they will be implemented, a new class class_type will be derived from
type that implements various functionality and properties that classes offer.)
A type is always strictly coupled with a context and, in contrast to most entities, can not exist without a context.
Builtin-types are not defined in any module, hence getModule () always returns nullptr.
Likely, builtin-classes do not have parents, hence getParent () always returns nullptr, too.
**/
class OMNI_CORE_API type : public entity, public boost::noncopyable {
public:
type (context & context, type_class typeClass, unsigned int indirectionLevel = 0);
virtual ~ type ();
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
std::string toString (bool fullyQualified = true);
static std::string toString (type_class typeClass, bool fullyQualified = true);
context * getContext () override;
const context * getContext () const override;
domain getDomain () const override;
module * getModule () override;
const module * getModule () const override;
void setComponent (domain domain, std::string name, std::shared_ptr <entity> entity) override;
type_class getTypeClass () const;
unsigned int getIndirectionLevel () const;
static std::shared_ptr <type> sharedBasicType(context & context, type_class typeClass, unsigned int indirectionLevel = 0);
llvm::Type * llvmType ();
private:
context & _context;
type_class _typeClass;
unsigned int _indirectionLevel;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,534 |
C++
| 32.355263 | 132 | 0.697316 |
daniel-kun/omni/interface/omni/core/model/do_while_statement.hpp
|
#ifndef OMNI_CORE_DO_WHILE_STATEMENT_HPP
#define OMNI_CORE_DO_WHILE_STATEMENT_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/while_statement.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class block;
class expression;
/**
An do_while_statement executes the body in a loop and exits the loop when the condition is false.
**/
class OMNI_CORE_API do_while_statement : public while_statement {
public:
do_while_statement ();
do_while_statement (std::shared_ptr <expression> condition, std::shared_ptr <block> body);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 947 |
C++
| 23.307692 | 101 | 0.676874 |
daniel-kun/omni/interface/omni/core/model/if_statement.hpp
|
#ifndef OMNI_CORE_IF_STATEMENT_HPP
#define OMNI_CORE_IF_STATEMENT_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class block;
class expression;
/**
An if_statement executes either the trueBlock or the elseBlock depending on a condition.
The conditon and the trueBlock are necessary, the elseBlock is optional.
**/
class OMNI_CORE_API if_statement : public statement {
public:
if_statement (std::shared_ptr <expression> condition, std::shared_ptr <block> trueBlock, std::shared_ptr <block> elseBlock);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
void setCondition (std::shared_ptr <expression> condition);
std::shared_ptr <expression> getCondition ();
const std::shared_ptr <expression> getCondition () const;
void setTrueBlock (std::shared_ptr <block> trueBlock);
std::shared_ptr <block> getTrueBlock ();
const std::shared_ptr <block> getTrueBlock () const;
void setElseBlock (std::shared_ptr <block> elseBlock);
std::shared_ptr <block> getElseBlock ();
const std::shared_ptr <block> getElseBlock () const;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,507 |
C++
| 29.77551 | 132 | 0.676841 |
daniel-kun/omni/interface/omni/core/model/variable_expression.hpp
|
#ifndef OMNI_CORE_VARIABLE_EXPRESSION_HPP
#define OMNI_CORE_VARIABLE_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/pure_expression.hpp>
#include <memory>
namespace omni {
namespace core {
namespace model {
class variable_declaration_expression;
/**
A `variable expression' is any mention of a variable that is used to take that variable's value.
E.g. in "int foo = x;", the "x" is a variable_expression.
To assign values to a variable, use the variable_assignment_expression.
**/
class OMNI_CORE_API variable_expression : public pure_expression {
public:
variable_expression (std::shared_ptr <variable_declaration_expression> variable);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
std::shared_ptr <type> getType () const override;
void setVariable (std::shared_ptr <variable_declaration_expression> variable);
const std::shared_ptr <variable_declaration_expression> getVariable () const ;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <variable_declaration_expression> _variable;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,350 |
C++
| 29.022222 | 100 | 0.698519 |
daniel-kun/omni/interface/omni/core/model/module.hpp
|
#ifndef OMNI_CORE_MODEL_MODULE_HPP
#define OMNI_CORE_MODEL_MODULE_HPP
#include <omni/core/core.hpp>
#include <omni/core/id.hpp>
#include <omni/core/module_emit_options.hpp>
#include <omni/core/model/scope.hpp>
#include <ostream>
#include <memory>
#include <map>
namespace llvm {
class raw_ostream;
class Module;
}
namespace omni {
namespace core {
class context;
}
}
namespace omni {
namespace core {
namespace model {
class function;
/**
A module contains code for a static library, a shared library or an executable.
See @domain for a list of possible parts of a module.
**/
class OMNI_CORE_API module : public scope {
public:
module (context & context, std::string name = std::string ());
module (context & context, id moduleId, std::string name = std::string ());
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
context * getContext () override;
const context * getContext () const override;
module * getModule () override;
const module * getModule () const override;
id createId (domain domain);
void setEntryPoint (std::shared_ptr <model::function> function);
void emitAssemblyFile (std::ostream & stream, const module_emit_options & options = module_emit_options ());
void emitAssemblyFile (llvm::raw_ostream & stream, const module_emit_options & options = module_emit_options ());
void emitAssemblyFile (std::string const & fileName, const module_emit_options & options = module_emit_options ());
void emitObjectFile (std::ostream & stream, const module_emit_options & options = module_emit_options ());
void emitObjectFile (llvm::raw_ostream & stream, const module_emit_options & options = module_emit_options ());
void emitObjectFile (std::string const & fileName, const module_emit_options & options = module_emit_options ());
void emitSharedLibraryFile (std::ostream & stream, const module_emit_options & options = module_emit_options ());
void emitSharedLibraryFile (llvm::raw_ostream & stream, const module_emit_options & options = module_emit_options ());
void emitSharedLibraryFile (std::string const & fileName, const module_emit_options & options = module_emit_options ());
bool verify (std::string & errorInfo);
llvm::Module & llvmModule ();
private:
std::shared_ptr <llvm::Module> _llvmModule;
context & _context;
std::shared_ptr <model::function> _entryPoint;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 2,716 |
C++
| 33.392405 | 128 | 0.668262 |
daniel-kun/omni/interface/omni/core/model/use_before_declaration_error.hpp
|
#ifndef OMNI_CORE_USE_BEFORE_DECLARATION_ERROR_HPP
#define OMNI_CORE_USE_BEFORE_DECLARATION_ERROR_HPP
#include <omni/core/core.hpp>
#include <omni/core/domain.hpp>
#include <stdexcept>
#pragma warning(push)
#pragma warning(disable:4275)
namespace omni {
namespace core {
namespace model {
/**
Is thrown when something was used, before it was declared.
E.g. when trying to take a value from a variable_declaration_expression, when that variable_declaration_statement was not executed (aka emitted) before.
**/
class OMNI_CORE_API use_before_declaration_error : public std::runtime_error {
public:
use_before_declaration_error (domain domain, std::string const & identifier);
};
} // namespace model
} // namespace core
} // namespace omni
#pragma warning(pop)
#endif // include guard
| 827 |
C++
| 24.874999 | 156 | 0.725514 |
daniel-kun/omni/interface/omni/core/model/return_statement.hpp
|
#ifndef OMNI_CORE_RETURN_STATEMENT_HPP
#define OMNI_CORE_RETURN_STATEMENT_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/statement.hpp>
#include <memory>
namespace llvm {
class BasicBlock;
}
namespace omni {
namespace core {
namespace model {
class expression;
class OMNI_CORE_API return_statement : public statement {
public:
return_statement ();
return_statement (std::shared_ptr <expression> expression);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
std::shared_ptr <expression> getExpression ();
const std::shared_ptr <expression> getExpression () const;
void setExpression (std::shared_ptr <expression> expression);
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 978 |
C++
| 22.878048 | 84 | 0.683027 |
daniel-kun/omni/interface/omni/core/model/builtin_literal_expression.hpp
|
#ifndef OMNI_CORE_MODEL_BUILTIN_LITERAL_EXPRESSION_HPP
#define OMNI_CORE_MODEL_BUILTIN_LITERAL_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/literal_expression.hpp>
#include <omni/core/model/native_type_to_type_class.hpp>
namespace omni {
namespace core {
namespace model {
/**
@class builtin_literal_expression builtin_literal_expression.hpp omni/core/model/builtin_literal_expression.hpp
@brief A builtin_literal_expression can be used to define literals of builtin numeric types (char, short, int, double, float).
To access the value of a literal e.g. as a function parameter or in an assignment or similar, instantiate a literal_expression
with this literal.
**/
template <typename T>
class OMNI_CORE_API builtin_literal_expression : public literal_expression {
public:
explicit builtin_literal_expression (context & context, T value);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
std::string toString (bool fullyQualified = true) const override;
domain getDomain () const override;
std::shared_ptr <type> getType () const override;
static const type_class typeClass = native_type_to_type_class <T>::typeClass;
void setValue (T value);
T getValue () const;
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <type> _type;
T _value;
};
} // namespace model
} // namespace core
} // namespace omni
#ifndef _MSC_VER
extern template class omni::core::model::builtin_literal_expression <bool>;
extern template class omni::core::model::builtin_literal_expression <char>;
extern template class omni::core::model::builtin_literal_expression <signed char>;
extern template class omni::core::model::builtin_literal_expression <unsigned char>;
extern template class omni::core::model::builtin_literal_expression <signed short>;
extern template class omni::core::model::builtin_literal_expression <unsigned short>;
extern template class omni::core::model::builtin_literal_expression <signed int>;
extern template class omni::core::model::builtin_literal_expression <unsigned int>;
extern template class omni::core::model::builtin_literal_expression <signed long>;
extern template class omni::core::model::builtin_literal_expression <unsigned long>;
extern template class omni::core::model::builtin_literal_expression <signed long long>;
extern template class omni::core::model::builtin_literal_expression <unsigned long long>;
#endif
#endif
| 2,604 |
C++
| 38.469696 | 130 | 0.735407 |
daniel-kun/omni/interface/omni/core/model/function_call_expression.hpp
|
#ifndef OMNI_CORE_FUNCTION_CALL_EXPRESSION_HPP
#define OMNI_CORE_FUNCTION_CALL_EXPRESSION_HPP
#include <omni/core/core.hpp>
#include <omni/core/model/modifying_expression.hpp>
#include <memory>
#include <vector>
namespace llvm {
class Value;
class BasicBlock;
}
namespace omni {
namespace core {
namespace model {
class function_prototype;
class expression;
class type;
/**
A void function call is a statement, not an expression, because it does not have a result.
**/
class OMNI_CORE_API function_call_expression : public modifying_expression {
public:
function_call_expression ();
function_call_expression (std::shared_ptr <function_prototype> func);
function_call_expression (std::shared_ptr <function_prototype> func, std::vector <std::shared_ptr <expression>> parameters);
static meta_info & getStaticMetaInfo ();
meta_info & getMetaInfo () const override;
domain getDomain () const override;
std::shared_ptr <type> getType () const override;
void setFunction (std::shared_ptr <function_prototype> func);
const std::shared_ptr <function_prototype> getFunction () const;
std::shared_ptr <function_prototype> getFunction ();
void appendParameter (std::shared_ptr <expression> parameter);
void setParameters (std::vector <std::shared_ptr <expression>> parameters);
std::vector <std::shared_ptr <expression>> getParameters ();
statement_emit_result llvmEmit (llvm::BasicBlock * llvmBasicBlock) override;
private:
std::shared_ptr <function_prototype> _function;
std::size_t _paramCount;
};
} // namespace model
} // namespace core
} // namespace omni
#endif // include guard
| 1,766 |
C++
| 28.949152 | 132 | 0.681767 |
daniel-kun/omni/interface/omni/core/tools/string.hpp
|
#ifndef OMNI_CORE_TOOLS_STRING_HPP
#define OMNI_CORE_TOOLS_STRING_HPP
#include <omni/core/core.hpp>
#include <string>
namespace omni {
namespace core {
namespace tools {
bool OMNI_CORE_API starts_with (std::string const & string, std::string const & startText);
bool OMNI_CORE_API is_numeric (std::string const & string);
} // namespace tools
} // namespace core
} // namespace omni
#endif // include guard
| 412 |
C++
| 20.736841 | 91 | 0.728155 |
daniel-kun/omni/interface/omni/core/input/input_state.hpp
|
#ifndef OMNI_CORE_INPUT_STATE_HPP
#define OMNI_CORE_INPUT_STATE_HPP
#include <omni/core/core.hpp>
#include <omni/core/input/syntax_suggestion.hpp>
namespace omni {
namespace core {
namespace input {
/**
**/
class OMNI_CORE_API input_state {
public:
};
} // namespace input
} // namespace core
} // namespace omni
#endif // include guard
| 342 |
C++
| 14.590908 | 48 | 0.71345 |
daniel-kun/omni/interface/omni/core/input/variable_template_provider.hpp
|
#ifndef OMNI_CORE_INPUT_VARIABLE_TEMPLATE_PROVIDER_HPP
#define OMNI_CORE_INPUT_VARIABLE_TEMPLATE_PROVIDER_HPP
#include <omni/core/core.hpp>
#include <string>
#include <vector>
namespace omni {
namespace core {
namespace input {
/**
**/
class OMNI_CORE_API variable_template_provider {
public:
virtual std::vector <std::string> provide (std::string input) = 0;
};
} // namespace input
} // namespace core
} // namespace omni
#endif // include guard
| 458 |
C++
| 17.359999 | 70 | 0.720524 |
daniel-kun/omni/interface/omni/core/input/template_variables.hpp
|
#ifndef OMNI_CORE_TEMPLATE_VARIABLES_HPP
#define OMNI_CORE_TEMPLATE_VARIABLES_HPP
namespace omni {
namespace core {
namespace input {
/**
**/
enum class template_variables {
/**
A variable's name can be inserted in this place. Used in variable_expression and variable_assignment_expression.
**/
variable,
/**
A function's name can be inserted in this place. Used in function_call_expression.
**/
function,
/**
A plus or a minus sign can be inserted in this place. Used in literal_expression for numeric literals.
**/
numeric_sign,
/**
An binary operator can be inserted in this place. Used in binary_operator_expression.
**/
binary_operator
};
} // namespace input
} // namespace core
} // namespace omni
#endif // include guard
| 797 |
C++
| 22.470588 | 116 | 0.681305 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.