diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/boot/ast.h (renamed from include/elna/frontend/ast.h) | 55 | ||||
| -rw-r--r-- | include/elna/boot/dependency.h (renamed from include/elna/frontend/dependency.h) | 8 | ||||
| -rw-r--r-- | include/elna/boot/driver.h (renamed from include/elna/frontend/driver.h) | 4 | ||||
| -rw-r--r-- | include/elna/boot/result.h (renamed from include/elna/frontend/result.h) | 6 | ||||
| -rw-r--r-- | include/elna/boot/semantic.h (renamed from include/elna/frontend/semantic.h) | 14 | ||||
| -rw-r--r-- | include/elna/boot/symbol.h (renamed from include/elna/frontend/symbol.h) | 4 | ||||
| -rw-r--r-- | include/elna/gcc/elna-builtins.h | 10 | ||||
| -rw-r--r-- | include/elna/gcc/elna-diagnostic.h | 6 | ||||
| -rw-r--r-- | include/elna/gcc/elna-generic.h | 92 | ||||
| -rw-r--r-- | include/elna/gcc/elna-tree.h | 12 |
10 files changed, 99 insertions, 112 deletions
diff --git a/include/elna/frontend/ast.h b/include/elna/boot/ast.h index bbb8a36..7d94e84 100644 --- a/include/elna/frontend/ast.h +++ b/include/elna/boot/ast.h @@ -22,10 +22,10 @@ along with GCC; see the file COPYING3. If not see #include <string> #include <vector> #include <optional> -#include "elna/frontend/symbol.h" -#include "elna/frontend/result.h" +#include "elna/boot/symbol.h" +#include "elna/boot/result.h" -namespace elna::frontend +namespace elna::boot { enum class binary_operator { @@ -71,14 +71,14 @@ namespace elna::frontend class program; class binary_expression; class unary_expression; - class named_type_expression; + class type_expression; class array_type_expression; class pointer_type_expression; class record_type_expression; class union_type_expression; class procedure_type_expression; class enumeration_type_expression; - class variable_expression; + class named_expression; class array_access_expression; class field_access_expression; class dereference_expression; @@ -111,14 +111,14 @@ namespace elna::frontend virtual void visit(program *) = 0; virtual void visit(binary_expression *) = 0; virtual void visit(unary_expression *) = 0; - virtual void visit(named_type_expression *) = 0; + virtual void visit(type_expression *) = 0; virtual void visit(array_type_expression *) = 0; virtual void visit(pointer_type_expression *) = 0; virtual void visit(record_type_expression *) = 0; virtual void visit(union_type_expression *) = 0; virtual void visit(procedure_type_expression *) = 0; virtual void visit(enumeration_type_expression *) = 0; - virtual void visit(variable_expression *) = 0; + virtual void visit(named_expression *) = 0; virtual void visit(array_access_expression *) = 0; virtual void visit(field_access_expression *) = 0; virtual void visit(dereference_expression *) = 0; @@ -139,7 +139,7 @@ namespace elna::frontend [[noreturn]] void not_implemented(); public: - [[noreturn]] virtual void visit(named_type_expression *) override; + [[noreturn]] virtual void visit(type_expression *) override; [[noreturn]] virtual void visit(array_type_expression *) override; [[noreturn]] virtual void visit(pointer_type_expression *) override; [[noreturn]] virtual void visit(program *) override; @@ -165,7 +165,7 @@ namespace elna::frontend [[noreturn]] virtual void visit(traits_expression *) override; [[noreturn]] virtual void visit(binary_expression *) override; [[noreturn]] virtual void visit(unary_expression *) override; - [[noreturn]] virtual void visit(variable_expression *) override; + [[noreturn]] virtual void visit(named_expression *) override; [[noreturn]] virtual void visit(array_access_expression *) override; [[noreturn]] virtual void visit(field_access_expression *) override; [[noreturn]] virtual void visit(dereference_expression *) override; @@ -232,10 +232,10 @@ namespace elna::frontend /** * Some type expression. */ - class type_expression : public node + class type_expression : public virtual node { public: - virtual named_type_expression *is_named(); + virtual named_expression *is_named(); virtual array_type_expression *is_array(); virtual pointer_type_expression *is_pointer(); virtual record_type_expression *is_record(); @@ -243,21 +243,8 @@ namespace elna::frontend virtual procedure_type_expression *is_procedure(); virtual enumeration_type_expression *is_enumeration(); - protected: - type_expression(const struct position position); - }; - - /** - * Expression refering to a type by its name. - */ - class named_type_expression : public type_expression - { - public: - const std::string name; - - named_type_expression(const struct position position, const std::string& name); void accept(parser_visitor *visitor) override; - named_type_expression *is_named() override; + ~type_expression() = 0; }; class array_type_expression : public type_expression @@ -363,9 +350,6 @@ namespace elna::frontend { public: literal_expression *is_literal() override; - - protected: - literal_expression(); }; /** @@ -407,6 +391,7 @@ namespace elna::frontend { block(std::vector<constant_declaration*>&& constants, std::vector<variable_declaration *>&& variables, std::vector<statement *>&& body); + block(std::vector<constant_declaration*>&& constants, std::vector<variable_declaration *>&& variables); block(const block&) = delete; block(block&& that); @@ -553,7 +538,7 @@ namespace elna::frontend class designator_expression : public expression { public: - virtual variable_expression *is_variable(); + virtual named_expression *is_named(); virtual array_access_expression *is_array_access(); virtual field_access_expression *is_field_access(); virtual dereference_expression *is_dereference(); @@ -561,20 +546,20 @@ namespace elna::frontend designator_expression *is_designator() override; void accept(parser_visitor *visitor); ~designator_expression() = 0; - - protected: - designator_expression(); }; - class variable_expression : public designator_expression, public literal_expression + /** + * Expression refering to an entity by its name. + */ + class named_expression : public designator_expression, public type_expression { public: const std::string name; - variable_expression(const struct position position, const std::string& name); + named_expression(const struct position position, const std::string& name); void accept(parser_visitor *visitor) override; - variable_expression *is_variable() override; + named_expression *is_named() override; }; class array_access_expression : public designator_expression diff --git a/include/elna/frontend/dependency.h b/include/elna/boot/dependency.h index f1502d1..4ec4d44 100644 --- a/include/elna/frontend/dependency.h +++ b/include/elna/boot/dependency.h @@ -19,11 +19,11 @@ along with GCC; see the file COPYING3. If not see #include <filesystem> #include <fstream> -#include "elna/frontend/result.h" -#include "elna/frontend/ast.h" -#include "elna/frontend/symbol.h" +#include "elna/boot/result.h" +#include "elna/boot/ast.h" +#include "elna/boot/symbol.h" -namespace elna::frontend +namespace elna::boot { class dependency : public error_container { diff --git a/include/elna/frontend/driver.h b/include/elna/boot/driver.h index 66ef579..288aa0c 100644 --- a/include/elna/frontend/driver.h +++ b/include/elna/boot/driver.h @@ -18,10 +18,10 @@ along with GCC; see the file COPYING3. If not see #pragma once #include <optional> -#include "elna/frontend/ast.h" +#include "elna/boot/ast.h" #include "location.hh" -namespace elna::frontend +namespace elna::boot { position make_position(const yy::location& location); diff --git a/include/elna/frontend/result.h b/include/elna/boot/result.h index 7e5ed77..9fc1849 100644 --- a/include/elna/frontend/result.h +++ b/include/elna/boot/result.h @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #include <memory> #include <variant> -namespace elna::frontend +namespace elna::boot { /** * Position in the source text. @@ -118,7 +118,7 @@ namespace elna::frontend } template<> -struct std::hash<elna::frontend::identifier_definition> +struct std::hash<elna::boot::identifier_definition> { - std::size_t operator()(const elna::frontend::identifier_definition& key) const noexcept; + std::size_t operator()(const elna::boot::identifier_definition& key) const noexcept; }; diff --git a/include/elna/frontend/semantic.h b/include/elna/boot/semantic.h index 8a295e4..66eb0a7 100644 --- a/include/elna/frontend/semantic.h +++ b/include/elna/boot/semantic.h @@ -22,11 +22,11 @@ along with GCC; see the file COPYING3. If not see #include <memory> #include <deque> -#include "elna/frontend/ast.h" -#include "elna/frontend/result.h" -#include "elna/frontend/symbol.h" +#include "elna/boot/ast.h" +#include "elna/boot/result.h" +#include "elna/boot/symbol.h" -namespace elna::frontend +namespace elna::boot { class undeclared_error : public error { @@ -127,11 +127,13 @@ namespace elna::frontend procedure_type build_procedure(procedure_type_expression& type_expression); std::vector<type_field> build_composite_type(const std::vector<field_declaration>& fields); + std::shared_ptr<variable_info> register_variable(const std::string& name, + const bool is_extern, const struct position position); public: name_analysis_visitor(const char *path, symbol_bag bag); - void visit(named_type_expression *type_expression) override; + void visit(type_expression *) override; void visit(array_type_expression *type_expression) override; void visit(pointer_type_expression *type_expression) override; void visit(program *program) override; @@ -157,7 +159,7 @@ namespace elna::frontend void visit(traits_expression *trait) override; void visit(binary_expression *expression) override; void visit(unary_expression *expression) override; - void visit(variable_expression *) override; + void visit(named_expression *type_expression) override; void visit(array_access_expression *expression) override; void visit(field_access_expression *expression) override; void visit(dereference_expression *expression) override; diff --git a/include/elna/frontend/symbol.h b/include/elna/boot/symbol.h index ec912ef..5ef917e 100644 --- a/include/elna/frontend/symbol.h +++ b/include/elna/boot/symbol.h @@ -24,9 +24,9 @@ along with GCC; see the file COPYING3. If not see #include <vector> #include <forward_list> -#include "elna/frontend/result.h" +#include "elna/boot/result.h" -namespace elna::frontend +namespace elna::boot { class alias_type; class primitive_type; diff --git a/include/elna/gcc/elna-builtins.h b/include/elna/gcc/elna-builtins.h index 60baab7..0cdf519 100644 --- a/include/elna/gcc/elna-builtins.h +++ b/include/elna/gcc/elna-builtins.h @@ -30,12 +30,12 @@ namespace elna::gcc void init_ttree(); std::shared_ptr<symbol_table> builtin_symbol_table(); - void rewrite_symbol_table(std::shared_ptr<frontend::symbol_table> info_table, std::shared_ptr<symbol_table> symbols); - tree handle_symbol(const std::string& symbol_name, std::shared_ptr<frontend::alias_type> reference, + void rewrite_symbol_table(std::shared_ptr<boot::symbol_table> info_table, std::shared_ptr<symbol_table> symbols); + tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference, std::shared_ptr<symbol_table> symbols); - tree get_inner_alias(const frontend::type& type, std::shared_ptr<symbol_table> symbols); - void declare_procedure(const std::string& name, const frontend::procedure_info& info, + tree get_inner_alias(const boot::type& type, std::shared_ptr<symbol_table> symbols); + void declare_procedure(const std::string& name, const boot::procedure_info& info, std::shared_ptr<symbol_table> symbols); - tree declare_variable(const std::string& name, const frontend::variable_info& info, + tree declare_variable(const std::string& name, const boot::variable_info& info, std::shared_ptr<symbol_table> symbols); } diff --git a/include/elna/gcc/elna-diagnostic.h b/include/elna/gcc/elna-diagnostic.h index 83f768e..1eef65d 100644 --- a/include/elna/gcc/elna-diagnostic.h +++ b/include/elna/gcc/elna-diagnostic.h @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include <deque> #include <memory> -#include "elna/frontend/result.h" +#include "elna/boot/result.h" namespace elna::gcc { @@ -40,7 +40,7 @@ namespace elna::gcc ~linemap_guard(); }; - location_t get_location(const frontend::position *position); + location_t get_location(const boot::position *position); std::string print_type(tree type); - void report_errors(const std::deque<std::unique_ptr<frontend::error>>& errors); + void report_errors(const std::deque<std::unique_ptr<boot::error>>& errors); } diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h index 97cd512..7490e92 100644 --- a/include/elna/gcc/elna-generic.h +++ b/include/elna/gcc/elna-generic.h @@ -17,9 +17,9 @@ along with GCC; see the file COPYING3. If not see #pragma once -#include "elna/frontend/ast.h" -#include "elna/frontend/symbol.h" -#include "elna/frontend/semantic.h" +#include "elna/boot/ast.h" +#include "elna/boot/symbol.h" +#include "elna/boot/semantic.h" #include "elna/gcc/elna-tree.h" #include "config.h" @@ -33,65 +33,65 @@ along with GCC; see the file COPYING3. If not see namespace elna::gcc { - class generic_visitor final : public frontend::empty_visitor + class generic_visitor final : public boot::empty_visitor { tree current_expression{ NULL_TREE }; - elna::frontend::symbol_bag bag; + elna::boot::symbol_bag bag; std::shared_ptr<symbol_table> symbols; void enter_scope(); tree leave_scope(); - void make_if_branch(frontend::conditional_statements& branch, tree goto_endif); + void make_if_branch(boot::conditional_statements& branch, tree goto_endif); - tree build_arithmetic_operation(frontend::binary_expression *expression, + tree build_arithmetic_operation(boot::binary_expression *expression, tree_code operator_code, tree left, tree right); - tree build_comparison_operation(frontend::binary_expression *expression, + tree build_comparison_operation(boot::binary_expression *expression, tree_code operator_code, tree left, tree right); - tree build_bit_logic_operation(frontend::binary_expression *expression, tree left, tree right); - tree build_equality_operation(frontend::binary_expression *expression, tree left, tree right); + tree build_bit_logic_operation(boot::binary_expression *expression, tree left, tree right); + tree build_equality_operation(boot::binary_expression *expression, tree left, tree right); void build_procedure_call(location_t call_location, - tree procedure_address, const std::vector<frontend::expression *>& arguments); + tree procedure_address, const std::vector<boot::expression *>& arguments); void build_record_call(location_t call_location, - tree symbol, const std::vector<frontend::expression *>& arguments); - bool build_builtin_procedures(frontend::procedure_call *call); - void build_assert_builtin(location_t call_location, const std::vector<frontend::expression *>& arguments); + tree symbol, const std::vector<boot::expression *>& arguments); + bool build_builtin_procedures(boot::procedure_call *call); + void build_assert_builtin(location_t call_location, const std::vector<boot::expression *>& arguments); - bool expect_trait_type_only(frontend::traits_expression *trait); - bool expect_trait_for_integral_type(frontend::traits_expression *trait); - void visit_statements(const std::vector<frontend::statement *>& statements); + bool expect_trait_type_only(boot::traits_expression *trait); + bool expect_trait_for_integral_type(boot::traits_expression *trait); + void visit_statements(const std::vector<boot::statement *>& statements); bool assert_constant(location_t expression_location); public: - generic_visitor(std::shared_ptr<symbol_table> symbol_table, elna::frontend::symbol_bag bag); + generic_visitor(std::shared_ptr<symbol_table> symbol_table, elna::boot::symbol_bag bag); - void visit(frontend::program *program) override; - void visit(frontend::procedure_declaration *definition) override; - void visit(frontend::procedure_call *call) override; - void visit(frontend::cast_expression *expression) override; - void visit(frontend::traits_expression *trait) override; - void visit(frontend::literal<std::int32_t> *literal) override; - void visit(frontend::literal<std::uint32_t> *literal) override; - void visit(frontend::literal<double> *literal) override; - void visit(frontend::literal<bool> *boolean) override; - void visit(frontend::literal<unsigned char> *character) override; - void visit(frontend::literal<std::nullptr_t> *) override; - void visit(frontend::literal<std::string> *string) override; - void visit(frontend::binary_expression *expression) override; - void visit(frontend::unary_expression *expression) override; - void visit(frontend::constant_declaration *definition) override; - void visit(frontend::variable_declaration *declaration) override; - void visit(frontend::variable_expression *expression) override; - void visit(frontend::array_access_expression *expression) override; - void visit(frontend::field_access_expression *expression) override; - void visit(frontend::dereference_expression *expression) override; - void visit(frontend::unit *unit) override; - void visit(frontend::assign_statement *statement) override; - void visit(frontend::if_statement *statement) override; - void visit(frontend::import_declaration *) override; - void visit(frontend::while_statement *statement) override; - void visit(frontend::return_statement *statement) override; - void visit(frontend::defer_statement *statement) override; - void visit(frontend::case_statement *statement) override; + void visit(boot::program *program) override; + void visit(boot::procedure_declaration *definition) override; + void visit(boot::procedure_call *call) override; + void visit(boot::cast_expression *expression) override; + void visit(boot::traits_expression *trait) override; + void visit(boot::literal<std::int32_t> *literal) override; + void visit(boot::literal<std::uint32_t> *literal) override; + void visit(boot::literal<double> *literal) override; + void visit(boot::literal<bool> *boolean) override; + void visit(boot::literal<unsigned char> *character) override; + void visit(boot::literal<std::nullptr_t> *) override; + void visit(boot::literal<std::string> *string) override; + void visit(boot::binary_expression *expression) override; + void visit(boot::unary_expression *expression) override; + void visit(boot::constant_declaration *definition) override; + void visit(boot::variable_declaration *declaration) override; + void visit(boot::named_expression *expression) override; + void visit(boot::array_access_expression *expression) override; + void visit(boot::field_access_expression *expression) override; + void visit(boot::dereference_expression *expression) override; + void visit(boot::unit *unit) override; + void visit(boot::assign_statement *statement) override; + void visit(boot::if_statement *statement) override; + void visit(boot::import_declaration *) override; + void visit(boot::while_statement *statement) override; + void visit(boot::return_statement *statement) override; + void visit(boot::defer_statement *statement) override; + void visit(boot::case_statement *statement) override; }; } diff --git a/include/elna/gcc/elna-tree.h b/include/elna/gcc/elna-tree.h index 48dfeb5..f1402a7 100644 --- a/include/elna/gcc/elna-tree.h +++ b/include/elna/gcc/elna-tree.h @@ -27,13 +27,13 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "fold-const.h" -#include "elna/frontend/ast.h" -#include "elna/frontend/symbol.h" +#include "elna/boot/ast.h" +#include "elna/boot/symbol.h" #include "elna/gcc/elna1.h" namespace elna::gcc { - using symbol_table = frontend::symbol_map<tree, tree, NULL_TREE>; + using symbol_table = boot::symbol_map<tree, tree, NULL_TREE>; bool is_integral_type(tree type); bool is_numeric_type(tree type); @@ -74,11 +74,11 @@ namespace elna::gcc void defer(tree statement_tree); tree chain_defer(); - tree do_pointer_arithmetic(frontend::binary_operator binary_operator, + tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right, location_t expression_location); - tree build_binary_operation(bool condition, frontend::binary_expression *expression, + tree build_binary_operation(bool condition, boot::binary_expression *expression, tree_code operator_code, tree left, tree right, tree target_type); - tree build_arithmetic_operation(frontend::binary_expression *expression, + tree build_arithmetic_operation(boot::binary_expression *expression, tree_code operator_code, tree left, tree right); tree build_field(location_t location, tree record_type, const std::string name, tree type); tree find_field_by_name(location_t expression_location, tree type, const std::string& field_name); |
