diff --git a/src/language/ASTSymbolTableBuilder.cpp b/src/language/ASTSymbolTableBuilder.cpp index 205e5be56a6d1ac492c3b9127ab04e6929ee5d27..25cd81c708d323bc2281660a16a91801b06b63c6 100644 --- a/src/language/ASTSymbolTableBuilder.cpp +++ b/src/language/ASTSymbolTableBuilder.cpp @@ -19,7 +19,7 @@ ASTSymbolTableBuilder::buildSymbolTable(ASTNode& n, std::shared_ptr<SymbolTable> if (n.has_content()) { if (n.is<language::declaration>()) { const std::string& symbol = n.children[1]->string(); - auto [i_symbol, success] = symbol_table->add(symbol, n.children[1]->begin(), n.end()); + auto [i_symbol, success] = symbol_table->add(symbol, n.children[1]->begin()); if (not success) { std::ostringstream error_message; error_message << "symbol '" << rang::fg::red << symbol << rang::fg::reset << '\'' << " was already defined!"; diff --git a/src/language/SymbolTable.hpp b/src/language/SymbolTable.hpp index 570cc3ba7dcbcb3f4da09af5a88b8ee5a5187bbc..1e2d228724568b85840482c6eb8993ac64e81b8f 100644 --- a/src/language/SymbolTable.hpp +++ b/src/language/SymbolTable.hpp @@ -19,7 +19,6 @@ class SymbolTable ASTNodeDataVariant m_value; TAO_PEGTL_NAMESPACE::position m_position; - TAO_PEGTL_NAMESPACE::position m_end_of_declaration; public: auto& @@ -58,12 +57,6 @@ class SymbolTable return m_position; } - auto - endOfDeclaration() const - { - return m_end_of_declaration; - } - void setDataType(const ASTNodeDataType& data_type) { @@ -87,9 +80,7 @@ class SymbolTable return os; } - Attributes(const TAO_PEGTL_NAMESPACE::position& position, const TAO_PEGTL_NAMESPACE::position& end_of_declaration) - : m_position(position), m_end_of_declaration(end_of_declaration) - {} + Attributes(const TAO_PEGTL_NAMESPACE::position& position) : m_position(position) {} Attributes(const Attributes&) = default; }; @@ -122,8 +113,7 @@ class SymbolTable } } - if (i_symbol != m_symbol_list.end() and (use_position.byte > i_symbol->second.endOfDeclaration().byte or - use_position.byte == i_symbol->second.position().byte)) { + if (i_symbol != m_symbol_list.end() and (use_position.byte >= i_symbol->second.position().byte)) { return std::make_pair(i_symbol, true); } else { if (m_parent_table) { @@ -135,9 +125,7 @@ class SymbolTable } auto - add(const std::string& symbol, - const TAO_PEGTL_NAMESPACE::position& symbol_position, - const TAO_PEGTL_NAMESPACE::position& declaration_end) + add(const std::string& symbol, 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) { @@ -145,7 +133,7 @@ class SymbolTable } } return std::make_pair(m_symbol_list.emplace(m_symbol_list.end(), - std::make_pair(symbol, Attributes(symbol_position, declaration_end))), + std::make_pair(symbol, Attributes(symbol_position))), true); } diff --git a/tests/test_SymbolTable.cpp b/tests/test_SymbolTable.cpp index 087003104693dfdbaab00de1327c4c7c987c9197..c97706921882c4473b40d0a3a47f897a3d977b9d 100644 --- a/tests/test_SymbolTable.cpp +++ b/tests/test_SymbolTable.cpp @@ -13,13 +13,12 @@ TEST_CASE("SymbolTable", "[language]") using namespace TAO_PEGTL_NAMESPACE; position begin_position{internal::iterator{"fixture"}, "fixture"}; - position end_declaration{internal::iterator{"fixture"}, "fixture"}; - auto [i_symbol_a, created_a] = root_st->add("a", begin_position, end_declaration); + auto [i_symbol_a, created_a] = root_st->add("a", begin_position); REQUIRE(created_a); // Check that one cannot build another "a" in this table - REQUIRE(not root_st->add("a", begin_position, end_declaration).second); + REQUIRE(not root_st->add("a", begin_position).second); position use_position{internal::iterator{"fixture"}, "fixture"}; auto [i_search_a, found_a] = root_st->find("a", use_position); @@ -96,7 +95,7 @@ TEST_CASE("SymbolTable", "[language]") position begin_position{internal::iterator{"fixture"}, "fixture"}; position end_declaration{internal::iterator{"fixture"}, "fixture"}; - auto [i_root_symbol_a, created_root_a] = root_st->add("a", begin_position, end_declaration); + auto [i_root_symbol_a, created_root_a] = root_st->add("a", begin_position); REQUIRE(created_root_a); std::shared_ptr nested_st = std::make_shared<SymbolTable>(root_st); @@ -107,7 +106,7 @@ TEST_CASE("SymbolTable", "[language]") // symbol "a" is the one defined in root_st REQUIRE(i_root_symbol_a == i_search_a); - auto [i_nested_symbol_a, created_nested_a] = nested_st->add("a", begin_position, end_declaration); + auto [i_nested_symbol_a, created_nested_a] = nested_st->add("a", begin_position); REQUIRE(created_nested_a); auto [i_search_nested_a, found_nested_a] = nested_st->find("a", use_position);