Create a generic type for types with an error list
This commit is contained in:
@ -133,5 +133,15 @@ namespace gcc
|
||||
}
|
||||
gcc_unreachable();
|
||||
}
|
||||
|
||||
void report_errors(const std::deque<std::unique_ptr<boot::error>>& errors)
|
||||
{
|
||||
for (const auto& error : errors)
|
||||
{
|
||||
auto gcc_location = elna::gcc::get_location(&error->position);
|
||||
|
||||
error_at(gcc_location, error->what().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,18 +63,23 @@ namespace gcc
|
||||
return error_mark_node;
|
||||
}
|
||||
|
||||
void do_semantic_analysis(const char *path, std::unique_ptr<boot::program>& ast,
|
||||
std::shared_ptr<symbol_table> symbols)
|
||||
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
||||
std::unique_ptr<boot::program>& ast, std::shared_ptr<symbol_table> symbols)
|
||||
{
|
||||
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)
|
||||
|
||||
if (declaration_visitor.errors().empty())
|
||||
{
|
||||
auto inner_alias = get_inner_alias(symbols, boot::type(unresolved.second));
|
||||
symbols->enter(unresolved.first, inner_alias);
|
||||
for (auto unresolved : declaration_visitor.unresolved)
|
||||
{
|
||||
auto inner_alias = get_inner_alias(symbols, boot::type(unresolved.second));
|
||||
symbols->enter(unresolved.first, inner_alias);
|
||||
}
|
||||
}
|
||||
return std::move(declaration_visitor.errors());
|
||||
}
|
||||
|
||||
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table)
|
||||
|
20
gcc/elna1.cc
20
gcc/elna1.cc
@ -79,12 +79,7 @@ static void elna_parse_file(const char *filename)
|
||||
linemap_add(line_table, LC_ENTER, 0, filename, 1);
|
||||
if (parser())
|
||||
{
|
||||
for (const auto& error : driver.errors())
|
||||
{
|
||||
auto gcc_location = elna::gcc::get_location(&error->position);
|
||||
|
||||
error_at(gcc_location, error->what().c_str());
|
||||
}
|
||||
elna::gcc::report_errors(driver.errors());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,10 +93,17 @@ 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(filename, driver.tree, symbol_table);
|
||||
elna::gcc::generic_visitor generic_visitor{ symbol_table };
|
||||
auto semantic_errors = elna::gcc::do_semantic_analysis(filename, driver.tree, symbol_table);
|
||||
|
||||
generic_visitor.visit(driver.tree.get());
|
||||
if (semantic_errors.empty())
|
||||
{
|
||||
elna::gcc::generic_visitor generic_visitor{ symbol_table };
|
||||
generic_visitor.visit(driver.tree.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
elna::gcc::report_errors(semantic_errors);
|
||||
}
|
||||
}
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user