Add a symbol table with type info

This commit is contained in:
2025-03-09 00:53:13 +01:00
parent 868db6e0bf
commit f739194e06
9 changed files with 471 additions and 342 deletions

View File

@ -47,6 +47,7 @@ elna_OBJS = \
elna/lexer.o \
elna/parser.o \
elna/semantic.o \
elna/symbol.o \
elna/result.o \
$(END)

View File

@ -63,14 +63,16 @@ namespace gcc
return error_mark_node;
}
void do_semantic_analysis(std::shared_ptr<symbol_table> symbols, std::unique_ptr<boot::program>& ast)
void do_semantic_analysis(const char *path, std::unique_ptr<boot::program>& ast,
std::shared_ptr<symbol_table> symbols)
{
boot::declaration_visitor declaration_visitor;
auto info_table = boot::builtin_symbol_table();
boot::declaration_visitor declaration_visitor(path, info_table);
declaration_visitor.visit(ast.get());
for (auto unresolved : declaration_visitor.unresolved)
{
auto inner_alias = elna::gcc::get_inner_alias(symbols, boot::type(unresolved.second));
auto inner_alias = get_inner_alias(symbols, boot::type(unresolved.second));
symbols->enter(unresolved.first, inner_alias);
}
}

View File

@ -98,7 +98,7 @@ static void elna_parse_file(const char *filename)
symbol_table->enter("Float", elna_float_type_node);
symbol_table->enter("String", elna_string_type_node);
elna::gcc::do_semantic_analysis(symbol_table, driver.tree);
elna::gcc::do_semantic_analysis(filename, driver.tree, symbol_table);
elna::gcc::generic_visitor generic_visitor{ symbol_table };
generic_visitor.visit(driver.tree.get());