Support one hardcoded import

This commit is contained in:
2025-07-10 00:43:17 +02:00
parent 181b19eefe
commit f02b2c49e5
14 changed files with 210 additions and 111 deletions

View File

@ -17,25 +17,39 @@ along with GCC; see the file COPYING3. If not see
#pragma once
#include <filesystem>
#include <fstream>
#include "elna/boot/result.h"
#include "elna/boot/ast.h"
namespace elna::boot
{
class dependency_graph
class source_path_error : public error
{
const std::string message;
public:
source_path_error(const std::string& message, const char *path);
std::string what() const override;
};
class dependency
{
error_list m_errors;
public:
std::vector<std::unique_ptr<program>> modules;
std::unique_ptr<unit> tree;
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
symbol_bag bag;
bool has_errors() const;
const error_list& errors() const;
dependency_graph();
explicit dependency_graph(error_list&& errors);
dependency();
explicit dependency(error_list&& errors);
};
dependency_graph read_sources(std::istream& entry_point, const char *entry_path);
dependency read_sources(const char *entry_path, std::shared_ptr<symbol_table> info_table,
std::shared_ptr<symbol_table> imports = nullptr);
}

View File

@ -39,7 +39,7 @@ namespace elna::boot
class driver : public error_container
{
public:
std::unique_ptr<program> tree;
std::unique_ptr<unit> tree;
driver(const char *input_file);
};

View File

@ -77,8 +77,7 @@ namespace elna::boot
type current_type;
constant_info::variant current_literal;
std::shared_ptr<symbol_table> symbols;
std::unordered_map<std::string, std::shared_ptr<alias_type>> unresolved;
symbol_bag bag;
procedure_type build_procedure(procedure_type_expression& type_expression);
std::vector<type_field> build_composite_type(const std::vector<field_declaration>& fields);
@ -87,8 +86,7 @@ namespace elna::boot
std::vector<std::string>& path);
public:
explicit name_analysis_visitor(const char *path, std::shared_ptr<symbol_table> symbols,
std::unordered_map<std::string, std::shared_ptr<alias_type>>&& unresolved);
name_analysis_visitor(const char *path, symbol_bag bag);
void visit(named_type_expression *type_expression) override;
void visit(array_type_expression *type_expression) override;

View File

@ -281,6 +281,7 @@ namespace elna::boot
};
using symbol_table = symbol_map<std::shared_ptr<info>, std::nullptr_t, nullptr>;
using forward_table = std::unordered_map<std::string, std::shared_ptr<alias_type>>;
class type_info : public info
{
@ -299,7 +300,7 @@ namespace elna::boot
std::shared_ptr<symbol_table> symbols;
procedure_info(const procedure_type symbol, const std::vector<std::string> names,
std::shared_ptr<symbol_table> parent_table = nullptr);
std::shared_ptr<symbol_table> scope = nullptr);
std::shared_ptr<procedure_info> is_procedure() override;
};
@ -325,4 +326,24 @@ namespace elna::boot
};
std::shared_ptr<symbol_table> builtin_symbol_table();
class symbol_bag
{
std::shared_ptr<symbol_table> symbols;
std::shared_ptr<symbol_table> imports;
public:
forward_table unresolved;
symbol_bag();
symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> symbols);
std::shared_ptr<info> lookup(const std::string& name);
bool enter(const std::string& name, std::shared_ptr<info> entry);
std::shared_ptr<symbol_table> enter();
void enter(std::shared_ptr<symbol_table> child);
void leave();
void add_import(std::shared_ptr<symbol_table> table);
};
}

View File

@ -36,8 +36,8 @@ namespace elna::gcc
class generic_visitor final : public boot::parser_visitor
{
tree current_expression{ NULL_TREE };
elna::boot::symbol_bag bag;
std::shared_ptr<symbol_table> symbols;
std::shared_ptr<boot::symbol_table> info_table;
void enter_scope();
tree leave_scope();
@ -63,7 +63,7 @@ namespace elna::gcc
bool assert_constant(location_t expression_location);
public:
generic_visitor(std::shared_ptr<symbol_table> symbol_table, std::shared_ptr<boot::symbol_table> info_table);
generic_visitor(std::shared_ptr<symbol_table> symbol_table, elna::boot::symbol_bag bag);
void visit(boot::program *program) override;
void visit(boot::procedure_declaration *definition) override;