Support one hardcoded import
This commit is contained in:
@@ -29,16 +29,14 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "stringpool.h"
|
||||
#include "diagnostic.h"
|
||||
#include "realmpfr.h"
|
||||
#include "stor-layout.h"
|
||||
#include "varasm.h"
|
||||
#include "fold-const.h"
|
||||
#include "langhooks.h"
|
||||
|
||||
namespace elna::gcc
|
||||
{
|
||||
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table,
|
||||
std::shared_ptr<boot::symbol_table> info_table)
|
||||
: symbols(symbol_table), info_table(info_table)
|
||||
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table, elna::boot::symbol_bag bag)
|
||||
: symbols(symbol_table), bag(bag)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -321,7 +319,7 @@ namespace elna::gcc
|
||||
DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>();
|
||||
|
||||
enter_scope();
|
||||
this->info_table = this->info_table->lookup(definition->identifier.identifier)->is_procedure()->symbols;
|
||||
this->bag.enter(this->bag.lookup(definition->identifier.identifier)->is_procedure()->symbols);
|
||||
|
||||
tree argument_chain = DECL_ARGUMENTS(fndecl);
|
||||
for (; argument_chain != NULL_TREE; argument_chain = TREE_CHAIN(argument_chain))
|
||||
@@ -339,7 +337,7 @@ namespace elna::gcc
|
||||
visit_statements(definition->body.value().body());
|
||||
|
||||
tree mapping = leave_scope();
|
||||
this->info_table = this->info_table->scope();
|
||||
this->bag.leave();
|
||||
|
||||
BLOCK_SUPERCONTEXT(BIND_EXPR_BLOCK(mapping)) = fndecl;
|
||||
DECL_INITIAL(fndecl) = BIND_EXPR_BLOCK(mapping);
|
||||
@@ -746,7 +744,7 @@ namespace elna::gcc
|
||||
void generic_visitor::visit(boot::variable_declaration *declaration)
|
||||
{
|
||||
this->current_expression = get_inner_alias(
|
||||
this->info_table->lookup(declaration->identifier.identifier)->is_variable()->symbol,
|
||||
this->bag.lookup(declaration->identifier.identifier)->is_variable()->symbol,
|
||||
this->symbols);
|
||||
|
||||
location_t declaration_location = get_location(&declaration->position());
|
||||
|
84
gcc/elna1.cc
84
gcc/elna1.cc
@@ -64,53 +64,65 @@ static bool elna_langhook_init(void)
|
||||
|
||||
static void elna_parse_file(const char *filename)
|
||||
{
|
||||
std::ifstream file{ filename, std::ios::in };
|
||||
|
||||
if (!file)
|
||||
{
|
||||
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);
|
||||
auto y = std::make_shared<elna::boot::symbol_table>(info_table);
|
||||
std::ifstream entry_point{ filename, std::ios::in };
|
||||
|
||||
if (!entry_point)
|
||||
{
|
||||
fatal_error(UNKNOWN_LOCATION, "Cannot open filename %s: %m", filename);
|
||||
}
|
||||
elna::boot::dependency outcome = elna::boot::read_sources(entry_point, filename);
|
||||
if (outcome.has_errors())
|
||||
{
|
||||
elna::gcc::report_errors(outcome.errors());
|
||||
}
|
||||
else
|
||||
elna::boot::dependency dependency;
|
||||
elna::boot::symbol_bag outcome_bag = elna::boot::symbol_bag{ std::move(outcome.unresolved), y };
|
||||
{
|
||||
for (const std::unique_ptr<elna::boot::program>& module_tree : outcome.modules)
|
||||
auto sub_path = "source/" + outcome.tree->imports.front()->segments.front() + ".elna";
|
||||
|
||||
auto x = std::make_shared<elna::boot::symbol_table>(info_table);
|
||||
std::ifstream entry_point{ sub_path, std::ios::in };
|
||||
|
||||
if (!entry_point)
|
||||
{
|
||||
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());
|
||||
}
|
||||
fatal_error(UNKNOWN_LOCATION, "Cannot open filename %s: %m", sub_path.c_str());
|
||||
}
|
||||
dependency = elna::boot::read_sources(entry_point, sub_path.c_str());
|
||||
if (dependency.has_errors())
|
||||
{
|
||||
elna::gcc::report_errors(dependency.errors());
|
||||
}
|
||||
elna::boot::symbol_bag dependency_bag = elna::boot::symbol_bag{ std::move(dependency.unresolved), x };
|
||||
|
||||
elna::boot::name_analysis_visitor name_analysis_visitor(sub_path.c_str(), dependency_bag);
|
||||
dependency.tree->accept(&name_analysis_visitor);
|
||||
|
||||
if (!name_analysis_visitor.errors().empty())
|
||||
{
|
||||
elna::gcc::report_errors(name_analysis_visitor.errors());
|
||||
}
|
||||
linemap_add(line_table, LC_ENTER, 0, sub_path.c_str(), 1);
|
||||
elna::gcc::rewrite_symbol_table(x, symbol_table);
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
|
||||
outcome_bag.add_import(dependency_bag);
|
||||
}
|
||||
elna::boot::name_analysis_visitor name_analysis_visitor(filename, outcome_bag);
|
||||
outcome.tree->accept(&name_analysis_visitor);
|
||||
|
||||
if (!name_analysis_visitor.errors().empty())
|
||||
{
|
||||
elna::gcc::report_errors(name_analysis_visitor.errors());
|
||||
}
|
||||
linemap_add(line_table, LC_ENTER, 0, filename, 1);
|
||||
elna::gcc::rewrite_symbol_table(y, symbol_table);
|
||||
|
||||
elna::gcc::generic_visitor generic_visitor{ symbol_table, outcome_bag };
|
||||
outcome.tree->accept(&generic_visitor);
|
||||
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user