diff --git a/src/language/ASTNodeDataTypeBuilder.cpp b/src/language/ASTNodeDataTypeBuilder.cpp index 7b249e79c58e0d36712d9d99c35bfed1be856e2e..0a6223c4f61124c79c35d6df990a09245f927ed2 100644 --- a/src/language/ASTNodeDataTypeBuilder.cpp +++ b/src/language/ASTNodeDataTypeBuilder.cpp @@ -49,7 +49,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) auto [i_symbol, found] = symbol_table->find(symbol, n.children[1]->begin()); Assert(found); - i_symbol->second.setDataType(data_type); + i_symbol->attributes().setDataType(data_type); n.m_data_type = data_type; } else if (n.is<language::let_declaration>()) { n.children[0]->m_data_type = ASTNodeDataType::function_t; @@ -71,7 +71,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) auto [i_symbol, found] = symbol_table->find(symbol, n.children[0]->begin()); Assert(found); - i_symbol->second.setDataType(n.children[0]->m_data_type); + i_symbol->attributes().setDataType(n.children[0]->m_data_type); } if (n.children[1]->children[0]->children.size() != n.children[2]->children[0]->children.size()) { @@ -107,7 +107,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) auto [i_symbol, found] = symbol_table->find(symbol, symbol_node.begin()); Assert(found); - i_symbol->second.setDataType(data_type); + i_symbol->attributes().setDataType(data_type); }; if (n.children[1]->children[0]->children.size() == 0) { @@ -124,7 +124,7 @@ ASTNodeDataTypeBuilder::_buildNodeDataTypes(ASTNode& n) auto [i_symbol, found] = symbol_table->find(n.string(), n.begin()); Assert(found); - n.m_data_type = i_symbol->second.dataType(); + n.m_data_type = i_symbol->attributes().dataType(); } } for (auto& child : n.children) { diff --git a/src/language/ASTSymbolInitializationChecker.cpp b/src/language/ASTSymbolInitializationChecker.cpp index 1c75f86a46a3dd868d582e2e421c4b2a6a5cc638..c111a95a7aaf3f5f82a85a9318d67fc0f3e9d362 100644 --- a/src/language/ASTSymbolInitializationChecker.cpp +++ b/src/language/ASTSymbolInitializationChecker.cpp @@ -13,7 +13,7 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) Assert(found, "unexpected error, should have been detected through declaration checking"); if (node.children.size() == 3) { this->_checkSymbolInitialization(*node.children[2]); - i_symbol->second.setIsInitialized(); + i_symbol->attributes().setIsInitialized(); } } else if (node.is<language::let_declaration>()) { const std::string& symbol = node.children[0]->string(); @@ -21,13 +21,13 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) Assert(found, "unexpected error, should have been detected through declaration checking"); if (node.children.size() == 3) { this->_checkSymbolInitialization(*node.children[2]); - i_symbol->second.setIsInitialized(); + i_symbol->attributes().setIsInitialized(); } } else if (node.is<language::function_definition>()) { const std::string& symbol = node.children[0]->string(); auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); - i_symbol->second.setIsInitialized(); + i_symbol->attributes().setIsInitialized(); this->_checkSymbolInitialization(*node.children[1]); } else if (node.is<language::eq_op>()) { // first checks for right hand side @@ -36,11 +36,11 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) const std::string& symbol = node.children[0]->string(); auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); - i_symbol->second.setIsInitialized(); + i_symbol->attributes().setIsInitialized(); } else if (node.is<language::name>()) { auto [i_symbol, found] = node.m_symbol_table->find(node.string(), node.begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); - if (not i_symbol->second.isInitialized()) { + if (not i_symbol->attributes().isInitialized()) { std::ostringstream error_message; error_message << "uninitialized symbol '" << rang::fg::red << node.string() << rang::fg::reset << '\''; throw parse_error(error_message.str(), std::vector{node.begin()}); diff --git a/src/language/ASTSymbolTableBuilder.cpp b/src/language/ASTSymbolTableBuilder.cpp index 3d0ad6942073f98366549cc6bc0e5ef70680be1d..441b8a24219b95580d8258072cd989cb4e710842 100644 --- a/src/language/ASTSymbolTableBuilder.cpp +++ b/src/language/ASTSymbolTableBuilder.cpp @@ -49,7 +49,7 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> throw parse_error(error_message.str(), std::vector{n.begin()}); } // Symbols will be initialized at call - i_symbol->second.setIsInitialized(); + i_symbol->attributes().setIsInitialized(); }; if (n.children[0]->is<language::name>()) { diff --git a/src/language/SymbolTable.hpp b/src/language/SymbolTable.hpp index 1e2d228724568b85840482c6eb8993ac64e81b8f..f955d45d3b656cbff9292916e5013daa0f209f32 100644 --- a/src/language/SymbolTable.hpp +++ b/src/language/SymbolTable.hpp @@ -1,6 +1,8 @@ #ifndef SYMBOL_TABLE_HPP #define SYMBOL_TABLE_HPP +#include <PugsMacros.hpp> + #include <ASTNodeDataType.hpp> #include <ASTNodeDataVariant.hpp> @@ -85,8 +87,47 @@ class SymbolTable Attributes(const Attributes&) = default; }; + class Symbol + { + private: + std::string m_name; + Attributes m_attributes; + + public: + PUGS_INLINE + const std::string& + name() const + { + return m_name; + } + + PUGS_INLINE + const Attributes& + attributes() const + { + return m_attributes; + } + + PUGS_INLINE + Attributes& + attributes() + { + return m_attributes; + } + + Symbol(const std::string& name, const Attributes& attributes) : m_name(name), m_attributes(attributes) {} + + Symbol& operator=(Symbol&&) = default; + Symbol& operator=(const Symbol&) = default; + + Symbol(const Symbol&) = default; + Symbol(Symbol&&) = default; + Symbol() = default; + ~Symbol() = default; + }; + private: - std::vector<std::pair<std::string, Attributes>> m_symbol_list; + std::vector<Symbol> m_symbol_list; std::shared_ptr<SymbolTable> m_parent_table; public: @@ -95,7 +136,7 @@ class SymbolTable { os << "-- Symbol table state -- parent : " << symbol_table.m_parent_table.get() << "\n"; for (auto i_symbol : symbol_table.m_symbol_list) { - os << ' ' << i_symbol.first << ": " << std::boolalpha << i_symbol.second << '\n'; + os << ' ' << i_symbol.name() << ": " << std::boolalpha << i_symbol.attributes() << '\n'; } os << "------------------------\n"; return os; @@ -107,13 +148,13 @@ class SymbolTable auto i_symbol = m_symbol_list.end(); for (auto i_stored_symbol = m_symbol_list.begin(); i_stored_symbol != m_symbol_list.end(); ++i_stored_symbol) { - if (i_stored_symbol->first == symbol) { + if (i_stored_symbol->name() == symbol) { i_symbol = i_stored_symbol; break; } } - if (i_symbol != m_symbol_list.end() and (use_position.byte >= i_symbol->second.position().byte)) { + if (i_symbol != m_symbol_list.end() and (use_position.byte >= i_symbol->attributes().position().byte)) { return std::make_pair(i_symbol, true); } else { if (m_parent_table) { @@ -125,15 +166,14 @@ class SymbolTable } auto - add(const std::string& symbol, const TAO_PEGTL_NAMESPACE::position& symbol_position) + add(const std::string& symbol_name, const TAO_PEGTL_NAMESPACE::position& symbol_position) { for (auto i_stored_symbol = m_symbol_list.begin(); i_stored_symbol != m_symbol_list.end(); ++i_stored_symbol) { - if (i_stored_symbol->first == symbol) { + if (i_stored_symbol->name() == symbol_name) { return std::make_pair(i_stored_symbol, false); } } - return std::make_pair(m_symbol_list.emplace(m_symbol_list.end(), - std::make_pair(symbol, Attributes(symbol_position))), + return std::make_pair(m_symbol_list.emplace(m_symbol_list.end(), Symbol{symbol_name, Attributes(symbol_position)}), true); } diff --git a/src/language/node_processor/AffectationProcessor.hpp b/src/language/node_processor/AffectationProcessor.hpp index ac0819697530782acc1ab2d65305b07962f577c9..50b1fd69caaf17c1a520f3eb8e653c1c660ac4bc 100644 --- a/src/language/node_processor/AffectationProcessor.hpp +++ b/src/language/node_processor/AffectationProcessor.hpp @@ -93,7 +93,7 @@ class AffectationProcessor final : public INodeProcessor const std::string& symbol = m_node.children[0]->string(); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.children[0]->begin()); Assert(found); - p_value = &i_symbol->second.value(); + p_value = &i_symbol->attributes().value(); } else { throw parse_error("invalid operands to affectation expression", std::vector{m_node.begin()}); } diff --git a/src/language/node_processor/AffectationToStringProcessor.hpp b/src/language/node_processor/AffectationToStringProcessor.hpp index 7bba4111b81ba9e1df7046b96468bceeb6810e31..7c22c095dddd310765d161a272310354601b275f 100644 --- a/src/language/node_processor/AffectationToStringProcessor.hpp +++ b/src/language/node_processor/AffectationToStringProcessor.hpp @@ -38,7 +38,7 @@ class AffectationToStringProcessor final : public INodeProcessor const std::string& symbol = m_node.children[0]->string(); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.children[0]->begin()); Assert(found); - p_value = &i_symbol->second.value(); + p_value = &i_symbol->attributes().value(); } }; diff --git a/src/language/node_processor/IncDecExpressionProcessor.hpp b/src/language/node_processor/IncDecExpressionProcessor.hpp index ca3c387c1f8d3050f901a8577148a8729f3be347..961adbddcc8e5dd4fff525a2e28c1f4fdea3334d 100644 --- a/src/language/node_processor/IncDecExpressionProcessor.hpp +++ b/src/language/node_processor/IncDecExpressionProcessor.hpp @@ -73,7 +73,7 @@ class IncDecExpressionProcessor final : public INodeProcessor const std::string& symbol = m_node.children[0]->string(); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.children[0]->begin()); Assert(found); - p_value = &i_symbol->second.value(); + p_value = &i_symbol->attributes().value(); } }; diff --git a/src/language/node_processor/NameProcessor.hpp b/src/language/node_processor/NameProcessor.hpp index f78ae71956b16f67aad287c613bb0d39282843a3..edb5d026cb2646d5bdb509955c460059e8b425cc 100644 --- a/src/language/node_processor/NameProcessor.hpp +++ b/src/language/node_processor/NameProcessor.hpp @@ -24,7 +24,7 @@ class NameProcessor final : public INodeProcessor const std::string& symbol = m_node.string(); auto [i_symbol, found] = m_node.m_symbol_table->find(symbol, m_node.begin()); Assert(found); - p_value = &(i_symbol->second.value()); + p_value = &(i_symbol->attributes().value()); } }; diff --git a/tests/test_ASTSymbolInitializationChecker.cpp b/tests/test_ASTSymbolInitializationChecker.cpp index a592dfe4fcba2463f86dbc94393a3f968dddf6a1..0c71c3a693c18ad0e8611c1502368fcf757db897 100644 --- a/tests/test_ASTSymbolInitializationChecker.cpp +++ b/tests/test_ASTSymbolInitializationChecker.cpp @@ -24,17 +24,17 @@ N p; position position{internal::iterator{"fixture"}, "fixture"}; position.byte = data.size(); // ensure that variables are declared at this point - auto [attribute_m, found_m] = ast->m_symbol_table->find("m", position); + auto [symbol_m, found_m] = ast->m_symbol_table->find("m", position); REQUIRE(found_m); - REQUIRE(attribute_m->second.isInitialized()); + REQUIRE(symbol_m->attributes().isInitialized()); - auto [attribute_n, found_n] = ast->m_symbol_table->find("n", position); + auto [symbol_n, found_n] = ast->m_symbol_table->find("n", position); REQUIRE(found_n); - REQUIRE(attribute_n->second.isInitialized()); + REQUIRE(symbol_n->attributes().isInitialized()); - auto [attribute_p, found_p] = ast->m_symbol_table->find("p", position); + auto [symbol_p, found_p] = ast->m_symbol_table->find("p", position); REQUIRE(found_p); - REQUIRE(not attribute_p->second.isInitialized()); + REQUIRE(not symbol_p->attributes().isInitialized()); } SECTION("Declaration plus affectation") @@ -56,17 +56,17 @@ m = n; position position{internal::iterator{"fixture"}, "fixture"}; position.byte = data.size(); // ensure that variables are declared at this point - auto [attribute_m, found_m] = ast->m_symbol_table->find("m", position); + auto [symbol_m, found_m] = ast->m_symbol_table->find("m", position); REQUIRE(found_m); - REQUIRE(attribute_m->second.isInitialized()); + REQUIRE(symbol_m->attributes().isInitialized()); - auto [attribute_n, found_n] = ast->m_symbol_table->find("n", position); + auto [symbol_n, found_n] = ast->m_symbol_table->find("n", position); REQUIRE(found_n); - REQUIRE(attribute_n->second.isInitialized()); + REQUIRE(symbol_n->attributes().isInitialized()); - auto [attribute_z, found_z] = ast->m_symbol_table->find("z", position); + auto [symbol_z, found_z] = ast->m_symbol_table->find("z", position); REQUIRE(found_z); - REQUIRE(not attribute_z->second.isInitialized()); + REQUIRE(not symbol_z->attributes().isInitialized()); } SECTION("used uninitialized") diff --git a/tests/test_AffectationProcessor.cpp b/tests/test_AffectationProcessor.cpp index 351a3af9ddd9bc0ac702ee5a8468436614e2f14f..2ce8f79be9fb0c5ff6c80aef8e3f11d26d399248 100644 --- a/tests/test_AffectationProcessor.cpp +++ b/tests/test_AffectationProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } #define CHECK_AFFECTATION_THROWS(data) \ diff --git a/tests/test_AffectationToStringProcessor.cpp b/tests/test_AffectationToStringProcessor.cpp index fb2ba582482b1fb0b7a9c68a0813e066947ad5ca..18831ae213724dd423528b417326655f21242cdf 100644 --- a/tests/test_AffectationToStringProcessor.cpp +++ b/tests/test_AffectationToStringProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("ASTAffectationToStringProcessor", "[language]") diff --git a/tests/test_BinaryExpressionProcessor_utils.hpp b/tests/test_BinaryExpressionProcessor_utils.hpp index ddd8ce2c8bff5aaa95c2281082e5acbb185b1f16..c6d7a8bd67b67935d636fec49810295272be1772 100644 --- a/tests/test_BinaryExpressionProcessor_utils.hpp +++ b/tests/test_BinaryExpressionProcessor_utils.hpp @@ -23,33 +23,33 @@ #include <sstream> -#define CHECK_BINARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_BINARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } #endif // TEST_BINARY_EXPRESSION_PROCESSOR_UTILS_HPP diff --git a/tests/test_ConcatExpressionProcessor.cpp b/tests/test_ConcatExpressionProcessor.cpp index 3b44302488398fd5f8fb038b8811b55c611a72a6..3baa9c59ff2c49480f0e8eefde4ca19b683c998f 100644 --- a/tests/test_ConcatExpressionProcessor.cpp +++ b/tests/test_ConcatExpressionProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_CONCAT_EXPRESSION_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_CONCAT_EXPRESSION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("ConcatExpressionProcessor", "[language]") diff --git a/tests/test_DoWhileProcessor.cpp b/tests/test_DoWhileProcessor.cpp index a04801163ba3f16c3054145049c2ba85060c2120..8cbc13823f9ab159ca41d02f14ba98865432ddbe 100644 --- a/tests/test_DoWhileProcessor.cpp +++ b/tests/test_DoWhileProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("DoWhileProcessor", "[language]") diff --git a/tests/test_ForProcessor.cpp b/tests/test_ForProcessor.cpp index bd833f7f540f40fdaa1e80d8691867b91b3463ec..9f0371d0697f01f5401b8be687e11988e7887b1a 100644 --- a/tests/test_ForProcessor.cpp +++ b/tests/test_ForProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_FOR_PROCESSOR_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_FOR_PROCESSOR_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("ForProcessor", "[language]") @@ -87,30 +87,4 @@ for(N l=0; l<10; ++l) { )"; CHECK_FOR_PROCESSOR_RESULT(data, "i", 42ul); } - - // SECTION("simple if(true)else") - // { - // std::string_view data = R"( - // N i = 0; - // if(true) { - // i = 1; - // } else { - // i = 2; - // } - // )"; - // CHECK_FOR_PROCESSOR_RESULT(data, "i", 1ul); - // } - - // SECTION("simple if(false)") - // { - // std::string_view data = R"( - // N i = 0; - // if(false) { - // i = 1; - // } else { - // i = 2; - // } - // )"; - // CHECK_FOR_PROCESSOR_RESULT(data, "i", 2ul); - // } } diff --git a/tests/test_IfProcessor.cpp b/tests/test_IfProcessor.cpp index a316f2d3158f9c192e2895585a4c976acbee22fb..5e6014b750cab1c305b0c91fb475aba868c89323 100644 --- a/tests/test_IfProcessor.cpp +++ b/tests/test_IfProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_IF_PROCESSOR_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_IF_PROCESSOR_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("IfProcessor", "[language]") diff --git a/tests/test_IncDecExpressionProcessor.cpp b/tests/test_IncDecExpressionProcessor.cpp index c25887322e1adf66d1fddd3745a753b16cf049a6..3cba4f9012fc9e50db061730ff58b9db8b94ede5 100644 --- a/tests/test_IncDecExpressionProcessor.cpp +++ b/tests/test_IncDecExpressionProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_INC_DEC_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_INC_DEC_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("IncDecExpressionProcessor", "[language]") diff --git a/tests/test_NameProcessor.cpp b/tests/test_NameProcessor.cpp index 73d7f7cae6e89f6b80bd09b96e05529d04944144..4152b3ae03189b62d1ecf4f93c8ac4ac498efbf9 100644 --- a/tests/test_NameProcessor.cpp +++ b/tests/test_NameProcessor.cpp @@ -51,12 +51,12 @@ n = 2; using namespace TAO_PEGTL_NAMESPACE; position use_position{internal::iterator{"fixture"}, "fixture"}; use_position.byte = 100; // after declarative position - auto symbol_n = symbol_table->find("n", use_position).first->second; + auto symbol_n = symbol_table->find("n", use_position).first->attributes(); auto value_n = std::get<long unsigned int>(symbol_n.value()); REQUIRE(value_n == 2); - auto symbol_m = symbol_table->find("m", use_position).first->second; + auto symbol_m = symbol_table->find("m", use_position).first->attributes(); auto value_m = std::get<long unsigned int>(symbol_m.value()); REQUIRE(value_m == 3); diff --git a/tests/test_SymbolTable.cpp b/tests/test_SymbolTable.cpp index aa15ef0c1f2e082585c15fed7aad8b2676d0c5e8..1bf8a63b8456c3be0c4ee90d616fe88e0ec2e15e 100644 --- a/tests/test_SymbolTable.cpp +++ b/tests/test_SymbolTable.cpp @@ -18,7 +18,7 @@ TEST_CASE("SymbolTable", "[language]") auto [i_symbol_a, created_a] = root_st->add("a", begin_position); REQUIRE(created_a); - REQUIRE(i_symbol_a->second.position().byte == 2); + REQUIRE(i_symbol_a->attributes().position().byte == 2); // Check that one cannot build another "a" in this table REQUIRE(not root_st->add("a", begin_position).second); @@ -47,7 +47,7 @@ TEST_CASE("SymbolTable", "[language]") SECTION("Attributes") { // undefined data - auto& attributes_a = i_search_a->second; + auto& attributes_a = i_search_a->attributes(); REQUIRE(attributes_a.dataType() == ASTNodeDataType::undefined_t); REQUIRE(not attributes_a.isInitialized()); @@ -121,8 +121,8 @@ TEST_CASE("SymbolTable", "[language]") REQUIRE(found_nested_a); // found the symbol created in nested symbol table - REQUIRE(&(i_search_nested_a->second) != &(i_root_symbol_a->second)); - REQUIRE(&(i_search_nested_a->second) == &(i_nested_symbol_a->second)); + REQUIRE(&(i_search_nested_a->attributes()) != &(i_root_symbol_a->attributes())); + REQUIRE(&(i_search_nested_a->attributes()) == &(i_nested_symbol_a->attributes())); auto [i_search_b, found_b] = nested_st->find("b", use_position); REQUIRE(not found_b); // "b" is not defined in any symbol table diff --git a/tests/test_UnaryExpressionProcessor.cpp b/tests/test_UnaryExpressionProcessor.cpp index f20c42e6d81391b79ce92ff5e2903da4dd0b2576..7947f3f60fcd0af1020245fd37ff0ed312f36c1b 100644 --- a/tests/test_UnaryExpressionProcessor.cpp +++ b/tests/test_UnaryExpressionProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_UNARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_UNARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("UnaryExpressionProcessor", "[language]") diff --git a/tests/test_WhileProcessor.cpp b/tests/test_WhileProcessor.cpp index 0b947150c069e10c01be52619c7047ef026986e3..9d58d96e0402eb7e93841ea1dd83f87673809c86 100644 --- a/tests/test_WhileProcessor.cpp +++ b/tests/test_WhileProcessor.cpp @@ -22,33 +22,33 @@ #include <sstream> -#define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - ASTNodeValueBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeDeclarationCleaner{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecUntilBreakOrContinue exec_policy; \ - ast->execute(exec_policy); \ - \ - auto symbol_table = ast->m_symbol_table; \ - \ - using namespace TAO_PEGTL_NAMESPACE; \ - position use_position{internal::iterator{"fixture"}, "fixture"}; \ - use_position.byte = 10000; \ - auto [symbol, found] = symbol_table->find(variable_name, use_position); \ - \ - auto attribute = symbol->second; \ - auto value = std::get<decltype(expected_value)>(attribute.value()); \ - \ - REQUIRE(value == expected_value); \ +#define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ + { \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeDeclarationCleaner{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecUntilBreakOrContinue exec_policy; \ + ast->execute(exec_policy); \ + \ + auto symbol_table = ast->m_symbol_table; \ + \ + using namespace TAO_PEGTL_NAMESPACE; \ + position use_position{internal::iterator{"fixture"}, "fixture"}; \ + use_position.byte = 10000; \ + auto [symbol, found] = symbol_table->find(variable_name, use_position); \ + \ + auto attributes = symbol->attributes(); \ + auto value = std::get<decltype(expected_value)>(attributes.value()); \ + \ + REQUIRE(value == expected_value); \ } TEST_CASE("WhileProcessor", "[language]")