From 282643276597a0dba8f27770eeb587e5bcdec9ca Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 28 Mar 2025 10:40:14 +0100 Subject: [PATCH] Fix alias resolution with type declarations --- gcc/elna-generic.cc | 26 ++++++++++---------------- include/elna/gcc/elna-generic.h | 3 ++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/gcc/elna-generic.cc b/gcc/elna-generic.cc index 278b24e..e5ddc54 100644 --- a/gcc/elna-generic.cc +++ b/gcc/elna-generic.cc @@ -41,14 +41,10 @@ namespace elna::gcc { if (auto reference = type.get()) { - auto looked_up = unresolved.find(reference->identifier); - if (looked_up == unresolved.cend()) + auto looked_up = symbols->lookup(reference->identifier); + if (looked_up != NULL_TREE) { - return symbols->lookup(reference->identifier); - } - else - { - return looked_up->second; + return TREE_TYPE(looked_up); } } else if (auto reference = type.get()) @@ -73,22 +69,20 @@ namespace elna::gcc } else if (auto reference = type.get()) { - return handle_symbol(reference->name, reference->reference, symbols, unresolved); + return handle_symbol(reference->name, reference, symbols, unresolved); } 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 reference, std::shared_ptr symbols, std::unordered_map& 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; + } std::deque> do_semantic_analysis(const char *path, @@ -103,7 +97,7 @@ namespace elna::gcc { 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()); diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h index 95ee7d7..14b9b0f 100644 --- a/include/elna/gcc/elna-generic.h +++ b/include/elna/gcc/elna-generic.h @@ -35,9 +35,10 @@ namespace elna::gcc std::deque> do_semantic_analysis(const char *path, std::unique_ptr& ast, std::shared_ptr info_table, std::shared_ptr symbols, std::unordered_map& unresolved); - tree handle_symbol(const std::string& symbol_name, const boot::type& type, + tree handle_symbol(const std::string& symbol_name, std::shared_ptr reference, std::shared_ptr symbols, std::unordered_map& unresolved); + class generic_visitor final : public boot::parser_visitor { tree current_expression{ NULL_TREE };