diff --git a/src/language/utils/SymbolTable.hpp b/src/language/utils/SymbolTable.hpp index 7321994564a8810b10e81d60503a55226abf0c56..5d81c68112a5022be3188412553962025010b323 100644 --- a/src/language/utils/SymbolTable.hpp +++ b/src/language/utils/SymbolTable.hpp @@ -285,14 +285,13 @@ class SymbolTable std::vector<Symbol> builtin_function_symbol_list; for (auto i_stored_symbol : m_symbol_list) { - if (use_position.byte < i_stored_symbol.attributes().position().byte) - continue; - // Symbol must be defined before the call - std::string_view stored_symbol_name = i_stored_symbol.name(); - if ((stored_symbol_name.size() > symbol.size()) and (stored_symbol_name[symbol.size()] == ':')) { - if (stored_symbol_name.substr(0, symbol.size()) == symbol) { - builtin_function_symbol_list.push_back(i_stored_symbol); + if (use_position.byte >= i_stored_symbol.attributes().position().byte) { + std::string_view stored_symbol_name = i_stored_symbol.name(); + if ((stored_symbol_name.size() > symbol.size()) and (stored_symbol_name[symbol.size()] == ':')) { + if (stored_symbol_name.substr(0, symbol.size()) == symbol) { + builtin_function_symbol_list.push_back(i_stored_symbol); + } } } } @@ -308,15 +307,14 @@ class SymbolTable has(const std::string& symbol, const TAO_PEGTL_NAMESPACE::position& use_position) { for (auto i_stored_symbol : m_symbol_list) { - if (use_position.byte < i_stored_symbol.attributes().position().byte) - continue; - // Symbol must be defined before the call - std::string_view stored_symbol_name = i_stored_symbol.name(); - if ((stored_symbol_name.size() == symbol.size()) or - (stored_symbol_name.size() > symbol.size() and (stored_symbol_name[symbol.size()] == ':'))) { - if (stored_symbol_name.substr(0, symbol.size()) == symbol) { - return true; + if (use_position.byte >= i_stored_symbol.attributes().position().byte) { + std::string_view stored_symbol_name = i_stored_symbol.name(); + if ((stored_symbol_name.size() == symbol.size()) or + (stored_symbol_name.size() > symbol.size() and (stored_symbol_name[symbol.size()] == ':'))) { + if (stored_symbol_name.substr(0, symbol.size()) == symbol) { + return true; + } } } } diff --git a/tests/test_SymbolTable.cpp b/tests/test_SymbolTable.cpp index 2be1a3d81a104e631894184eaf67f0d2d63d44d2..78cd4373b9901aa69a65bc8bceaa4a7e68c1ad0b 100644 --- a/tests/test_SymbolTable.cpp +++ b/tests/test_SymbolTable.cpp @@ -3,6 +3,7 @@ #include <language/utils/BuiltinFunctionEmbedder.hpp> #include <language/utils/SymbolTable.hpp> +#include <language/utils/TypeDescriptor.hpp> #include <pegtl/internal/iterator.hpp> @@ -186,6 +187,29 @@ TEST_CASE("SymbolTable", "[language]") value_output << symbol.attributes(); REQUIRE(value_output.str() == "function_id:2"); } + + { + const SymbolTable::Symbol symbol_decl{i_symbol_a->name(), i_symbol_a->attributes()}; + SymbolTable::Attributes attributes_b = attributes_a; + SymbolTable::Symbol symbol("foo", attributes_b); + + symbol = symbol_decl; + + std::stringstream value_output; + value_output << symbol.attributes(); + REQUIRE(value_output.str() == "function_id:2"); + } + + { + SymbolTable::Attributes attributes_b = attributes_a; + SymbolTable::Symbol symbol("foo", attributes_b); + + symbol = SymbolTable::Symbol{i_symbol_a->name(), i_symbol_a->attributes()}; + + std::stringstream value_output; + value_output << symbol.attributes(); + REQUIRE(value_output.str() == "function_id:2"); + } } SECTION("FunctionTable") @@ -220,4 +244,20 @@ TEST_CASE("SymbolTable", "[language]") REQUIRE(builtin_function_table.size() == 1); REQUIRE(const_builtin_function_table.size() == 1); } + + SECTION("TypeEmbedderTable") + { + std::shared_ptr root_st = std::make_shared<SymbolTable>(); + + auto& type_table = root_st->typeEmbedderTable(); + REQUIRE(type_table.size() == 0); + + const auto& const_type_table = static_cast<const SymbolTable&>(*root_st).typeEmbedderTable(); + REQUIRE(const_type_table.size() == 0); + + type_table.add(std::make_shared<TypeDescriptor>("a_type")); + + REQUIRE(type_table.size() == 1); + REQUIRE(const_type_table.size() == 1); + } }