Support one hardcoded import
This commit is contained in:
73
gcc/elna1.cc
73
gcc/elna1.cc
@ -62,63 +62,62 @@ static bool elna_langhook_init(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void elna_parse_file(const char *filename)
|
||||
using dependency_state = elna::boot::dependency_state<std::shared_ptr<elna::gcc::symbol_table>>;
|
||||
|
||||
static elna::boot::dependency elna_parse_file(dependency_state& state, const char *filename)
|
||||
{
|
||||
std::ifstream file{ filename, std::ios::in };
|
||||
auto module_table = std::make_shared<elna::boot::symbol_table>(state.globals);
|
||||
std::ifstream entry_point{ filename, std::ios::in };
|
||||
|
||||
if (!file)
|
||||
if (!entry_point)
|
||||
{
|
||||
fatal_error(UNKNOWN_LOCATION, "cannot open filename %s: %m", filename);
|
||||
fatal_error(UNKNOWN_LOCATION, "Cannot open filename %s: %m", filename);
|
||||
}
|
||||
elna::boot::dependency_graph outcome = elna::boot::read_sources(file, filename);
|
||||
|
||||
std::shared_ptr<elna::boot::symbol_table> info_table = elna::boot::builtin_symbol_table();
|
||||
std::shared_ptr<elna::gcc::symbol_table> symbol_table = elna::gcc::builtin_symbol_table();
|
||||
|
||||
linemap_add(line_table, LC_ENTER, 0, filename, 1);
|
||||
elna::boot::dependency outcome = elna::boot::read_sources(entry_point, filename);
|
||||
|
||||
if (outcome.has_errors())
|
||||
{
|
||||
elna::gcc::report_errors(outcome.errors());
|
||||
}
|
||||
else
|
||||
elna::boot::symbol_bag outcome_bag = elna::boot::symbol_bag{ std::move(outcome.unresolved), module_table };
|
||||
|
||||
for (const auto& sub_tree : outcome.tree->imports)
|
||||
{
|
||||
for (const std::unique_ptr<elna::boot::program>& module_tree : outcome.modules)
|
||||
std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments);
|
||||
|
||||
if (state.cache.find(sub_path) == state.cache.end())
|
||||
{
|
||||
elna::boot::declaration_visitor declaration_visitor(filename);
|
||||
declaration_visitor.visit(module_tree.get());
|
||||
|
||||
if (declaration_visitor.errors().empty())
|
||||
{
|
||||
elna::boot::name_analysis_visitor name_analysis_visitor(filename, info_table,
|
||||
std::move(declaration_visitor.unresolved));
|
||||
name_analysis_visitor.visit(module_tree.get());
|
||||
|
||||
if (name_analysis_visitor.errors().empty())
|
||||
{
|
||||
elna::gcc::rewrite_symbol_table(info_table, symbol_table);
|
||||
|
||||
elna::gcc::generic_visitor generic_visitor{ symbol_table, info_table };
|
||||
generic_visitor.visit(module_tree.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
elna::gcc::report_errors(name_analysis_visitor.errors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
elna::gcc::report_errors(declaration_visitor.errors());
|
||||
}
|
||||
elna_parse_file(state, state.allocate_path(sub_path));
|
||||
}
|
||||
outcome_bag.add_import(state.cache.find(sub_path)->second);
|
||||
}
|
||||
elna::boot::name_analysis_visitor name_analysis_visitor(filename, outcome_bag);
|
||||
outcome.tree->accept(&name_analysis_visitor);
|
||||
|
||||
if (name_analysis_visitor.has_errors())
|
||||
{
|
||||
elna::gcc::report_errors(name_analysis_visitor.errors());
|
||||
}
|
||||
state.cache.insert({ filename, outcome_bag });
|
||||
elna::gcc::rewrite_symbol_table(module_table, state.custom);
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
|
||||
return outcome;
|
||||
}
|
||||
|
||||
static void elna_langhook_parse_file(void)
|
||||
{
|
||||
dependency_state state{ elna::gcc::builtin_symbol_table() };
|
||||
|
||||
for (unsigned int i = 0; i < num_in_fnames; i++)
|
||||
{
|
||||
elna_parse_file(in_fnames[i]);
|
||||
elna::boot::dependency outcome = elna_parse_file(state, in_fnames[i]);
|
||||
|
||||
linemap_add(line_table, LC_ENTER, 0, in_fnames[i], 1);
|
||||
elna::gcc::generic_visitor generic_visitor{ state.custom, state.cache.find(in_fnames[i])->second };
|
||||
outcome.tree->accept(&generic_visitor);
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user