diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/frontend/dependency.h | 55 | ||||
| -rw-r--r-- | include/elna/frontend/semantic.h | 190 |
2 files changed, 0 insertions, 245 deletions
diff --git a/include/elna/frontend/dependency.h b/include/elna/frontend/dependency.h deleted file mode 100644 index f1502d1..0000000 --- a/include/elna/frontend/dependency.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Dependency graph analysis. - Copyright (C) 2025 Free Software Foundation, Inc. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING3. If not see -<http://www.gnu.org/licenses/>. */ - -#pragma once - -#include <filesystem> -#include <fstream> -#include "elna/frontend/result.h" -#include "elna/frontend/ast.h" -#include "elna/frontend/symbol.h" - -namespace elna::frontend -{ - class dependency : public error_container - { - error_list m_errors; - - public: - std::unique_ptr<unit> tree; - forward_table unresolved; - - explicit dependency(const char *path); - }; - - dependency read_source(std::istream& entry_point, const char *entry_path); - std::filesystem::path build_path(const std::vector<std::string>& segments); - error_list analyze_semantics(const char *path, std::unique_ptr<unit>& tree, symbol_bag bag); - - template<typename T> - struct dependency_state - { - const std::shared_ptr<symbol_table> globals; - T custom; - std::unordered_map<std::filesystem::path, symbol_bag> cache; - - explicit dependency_state(T custom) - : globals(builtin_symbol_table()), custom(custom) - { - } - }; -} diff --git a/include/elna/frontend/semantic.h b/include/elna/frontend/semantic.h deleted file mode 100644 index 8a295e4..0000000 --- a/include/elna/frontend/semantic.h +++ /dev/null @@ -1,190 +0,0 @@ -/* Name analysis. - Copyright (C) 2025 Free Software Foundation, Inc. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING3. If not see -<http://www.gnu.org/licenses/>. */ - -#pragma once - -#include <string> -#include <unordered_map> -#include <memory> -#include <deque> - -#include "elna/frontend/ast.h" -#include "elna/frontend/result.h" -#include "elna/frontend/symbol.h" - -namespace elna::frontend -{ - class undeclared_error : public error - { - const std::string identifier; - - public: - undeclared_error(const std::string& identifier, const char *path, const struct position position); - - std::string what() const override; - }; - - class already_declared_error : public error - { - const std::string identifier; - - public: - already_declared_error(const std::string& identifier, const char *path, const struct position position); - - std::string what() const override; - }; - - class field_duplication_error : public error - { - const std::string field_name; - - public: - field_duplication_error(const std::string& field_name, const char *path, const struct position position); - - std::string what() const override; - }; - - class cyclic_declaration_error : public error - { - const std::vector<std::string> cycle; - - public: - cyclic_declaration_error(const std::vector<std::string>& cycle, - const char *path, const struct position position); - - std::string what() const override; - }; - - class return_error : public error - { - const std::string identifier; - - public: - return_error(const std::string& identifier, const char *path, const struct position position); - - std::string what() const override; - }; - - class variable_initializer_error : public error - { - public: - variable_initializer_error(const char *path, const struct position position); - - std::string what() const override; - }; - - /** - * Checks types. - */ - class type_analysis_visitor final : public empty_visitor, public error_container - { - bool returns; - symbol_bag bag; - - bool check_unresolved_symbol(std::shared_ptr<alias_type> alias, - std::vector<std::string>& path); - - public: - explicit type_analysis_visitor(const char *path, symbol_bag bag); - - void visit(program *program) override; - - void visit(procedure_declaration *definition) override; - void visit(assign_statement *) override; - void visit(if_statement *) override; - void visit(while_statement *) override; - void visit(return_statement *) override; - void visit(defer_statement *) override; - void visit(case_statement *) override; - void visit(procedure_call *) override; - void visit(unit *unit) override; - void visit(type_declaration *definition) override; - }; - - /** - * Performs name analysis. - */ - class name_analysis_visitor final : public parser_visitor, public error_container - { - type current_type; - constant_info::variant current_literal; - - 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); - - public: - 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; - void visit(pointer_type_expression *type_expression) override; - void visit(program *program) override; - void visit(type_declaration *definition) override; - void visit(record_type_expression *type_expression) override; - void visit(union_type_expression *type_expression) override; - void visit(procedure_type_expression *type_expression) override; - void visit(enumeration_type_expression *type_expression) override; - - void visit(variable_declaration *declaration) override; - void visit(constant_declaration *definition) override; - void visit(procedure_declaration *definition) override; - void visit(assign_statement *statement) override; - void visit(if_statement *statement) override; - void visit(import_declaration *) override; - void visit(while_statement *statement) override; - void visit(return_statement *statement) override; - void visit(defer_statement *statement) override; - void visit(case_statement *statement) override; - void visit(procedure_call *call) override; - void visit(unit *unit) override; - void visit(cast_expression *expression) override; - 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(array_access_expression *expression) override; - void visit(field_access_expression *expression) override; - void visit(dereference_expression *expression) override; - void visit(literal<std::int32_t> *literal) override; - void visit(literal<std::uint32_t> *literal) override; - void visit(literal<double> *literal) override; - void visit(literal<bool> *literal) override; - void visit(literal<unsigned char> *literal) override; - void visit(literal<std::nullptr_t> *literal) override; - void visit(literal<std::string> *literal) override; - }; - - /** - * Collects global declarations without resolving any symbols. - */ - class declaration_visitor final : public empty_visitor, public error_container - { - public: - forward_table unresolved; - - explicit declaration_visitor(const char *path); - - void visit(program *program) override; - void visit(import_declaration *) override; - void visit(unit *unit) override; - void visit(type_declaration *definition) override; - void visit(variable_declaration *declaration) override; - void visit(procedure_declaration *definition) override; - }; -} |
