Fix alias resolution with type declarations

This commit is contained in:
Eugen Wissner 2025-03-28 10:40:14 +01:00
parent d359056354
commit 2826432765
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 12 additions and 17 deletions

View File

@ -41,14 +41,10 @@ namespace elna::gcc
{ {
if (auto reference = type.get<boot::primitive_type>()) if (auto reference = type.get<boot::primitive_type>())
{ {
auto looked_up = unresolved.find(reference->identifier); auto looked_up = symbols->lookup(reference->identifier);
if (looked_up == unresolved.cend()) if (looked_up != NULL_TREE)
{ {
return symbols->lookup(reference->identifier); return TREE_TYPE(looked_up);
}
else
{
return looked_up->second;
} }
} }
else if (auto reference = type.get<boot::record_type>()) else if (auto reference = type.get<boot::record_type>())
@ -73,22 +69,20 @@ namespace elna::gcc
} }
else if (auto reference = type.get<boot::alias_type>()) else if (auto reference = type.get<boot::alias_type>())
{ {
return handle_symbol(reference->name, reference->reference, symbols, unresolved); return handle_symbol(reference->name, reference, symbols, unresolved);
} }
return error_mark_node; return error_mark_node;
} }
tree handle_symbol(const std::string& symbol_name, const boot::type& type, tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference,
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved) std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved)
{ {
auto looked_up = symbols->lookup(symbol_name); auto looked_up = get_inner_alias(reference->reference, symbols, unresolved);
unresolved.insert({ symbol_name, looked_up });
if (looked_up == NULL_TREE)
{
looked_up = get_inner_alias(type, symbols, unresolved);
unresolved.insert({ symbol_name, looked_up });
}
return looked_up; return looked_up;
} }
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path, std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
@ -103,7 +97,7 @@ namespace elna::gcc
{ {
for (auto& [symbol_name, symbol_info] : declaration_visitor.unresolved) for (auto& [symbol_name, symbol_info] : declaration_visitor.unresolved)
{ {
handle_symbol(symbol_name, boot::type(symbol_info), symbols, unresolved); handle_symbol(symbol_name, symbol_info, symbols, unresolved);
} }
} }
return std::move(declaration_visitor.errors()); return std::move(declaration_visitor.errors());

View File

@ -35,9 +35,10 @@ namespace elna::gcc
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path, std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table, std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved); std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
tree handle_symbol(const std::string& symbol_name, const boot::type& type, tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference,
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved); std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
class generic_visitor final : public boot::parser_visitor class generic_visitor final : public boot::parser_visitor
{ {
tree current_expression{ NULL_TREE }; tree current_expression{ NULL_TREE };