diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/boot/dependency.h | 46 | ||||
| -rw-r--r-- | include/elna/boot/driver.h | 5 | ||||
| -rw-r--r-- | include/elna/boot/result.h | 7 | ||||
| -rw-r--r-- | include/elna/boot/semantic.h | 19 | ||||
| -rw-r--r-- | include/elna/gcc/elna-diagnostic.h | 11 | ||||
| -rw-r--r-- | include/elna/gcc/elna-generic.h | 6 |
6 files changed, 63 insertions, 31 deletions
diff --git a/include/elna/boot/dependency.h b/include/elna/boot/dependency.h index 4ec4d44..5f6eba5 100644 --- a/include/elna/boot/dependency.h +++ b/include/elna/boot/dependency.h @@ -33,23 +33,59 @@ namespace elna::boot std::unique_ptr<unit> tree; forward_table unresolved; - explicit dependency(const char *path); + dependency() = default; }; - dependency read_source(std::istream& entry_point, const char *entry_path); + dependency read_source(std::istream& entry_point); 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); + error_list analyze_semantics(std::unique_ptr<unit>& tree, symbol_bag bag); template<typename T> - struct dependency_state + class dependency_state { + std::unordered_map<std::filesystem::path, symbol_bag> cache; + + public: const std::shared_ptr<symbol_table> globals; T custom; - std::unordered_map<std::filesystem::path, symbol_bag> cache; + + using iterator = typename std::unordered_map<std::filesystem::path, symbol_bag>::iterator; + using const_iterator = typename std::unordered_map<std::filesystem::path, symbol_bag>::const_iterator; explicit dependency_state(T custom) : globals(builtin_symbol_table()), custom(custom) { } + + const_iterator find(const std::filesystem::path& key) + { + return cache.find(key); + } + + void insert(const std::filesystem::path& key, symbol_bag value) + { + cache.insert({ key, value }); + } + + iterator begin() + { + return this->cache.begin(); + } + + iterator end() + { + return this->cache.end(); + } + + const_iterator cbegin() const + { + return this->cache.cbegin(); + } + + const_iterator cend() const + { + return this->cache.cend(); + } + }; } diff --git a/include/elna/boot/driver.h b/include/elna/boot/driver.h index 288aa0c..cd29376 100644 --- a/include/elna/boot/driver.h +++ b/include/elna/boot/driver.h @@ -30,8 +30,7 @@ namespace elna::boot std::string message; public: - syntax_error(const std::string& message, - const char *input_file, const yy::location& location); + syntax_error(const std::string& message, const yy::location& location); virtual std::string what() const override; }; @@ -41,7 +40,7 @@ namespace elna::boot public: std::unique_ptr<unit> tree; - driver(const char *input_file); + driver() = default; }; constexpr char escape_invalid_char = '\xff'; diff --git a/include/elna/boot/result.h b/include/elna/boot/result.h index 9fc1849..3a84229 100644 --- a/include/elna/boot/result.h +++ b/include/elna/boot/result.h @@ -43,11 +43,10 @@ namespace elna::boot class error { protected: - error(const char *path, const struct position position); + error(const struct position position); public: const struct position position; - const char *path; virtual ~error() = default; @@ -68,11 +67,9 @@ namespace elna::boot protected: error_list m_errors; - error_container(const char *input_file); + error_container() = default; public: - const char *input_file; - error_list& errors(); template<typename T, typename... Args> diff --git a/include/elna/boot/semantic.h b/include/elna/boot/semantic.h index 7094ee9..97286f0 100644 --- a/include/elna/boot/semantic.h +++ b/include/elna/boot/semantic.h @@ -33,7 +33,7 @@ namespace elna::boot const std::string identifier; public: - undeclared_error(const std::string& identifier, const char *path, const struct position position); + undeclared_error(const std::string& identifier, const struct position position); std::string what() const override; }; @@ -43,7 +43,7 @@ namespace elna::boot const std::string identifier; public: - already_declared_error(const std::string& identifier, const char *path, const struct position position); + already_declared_error(const std::string& identifier, const struct position position); std::string what() const override; }; @@ -53,7 +53,7 @@ namespace elna::boot const std::string field_name; public: - field_duplication_error(const std::string& field_name, const char *path, const struct position position); + field_duplication_error(const std::string& field_name, const struct position position); std::string what() const override; }; @@ -63,8 +63,7 @@ namespace elna::boot const std::vector<std::string> cycle; public: - cyclic_declaration_error(const std::vector<std::string>& cycle, - const char *path, const struct position position); + cyclic_declaration_error(const std::vector<std::string>& cycle, const struct position position); std::string what() const override; }; @@ -74,7 +73,7 @@ namespace elna::boot const std::string identifier; public: - return_error(const std::string& identifier, const char *path, const struct position position); + return_error(const std::string& identifier, const struct position position); std::string what() const override; }; @@ -82,7 +81,7 @@ namespace elna::boot class variable_initializer_error : public error { public: - variable_initializer_error(const char *path, const struct position position); + variable_initializer_error(const struct position position); std::string what() const override; }; @@ -99,7 +98,7 @@ namespace elna::boot std::vector<std::string>& path); public: - explicit type_analysis_visitor(const char *path, symbol_bag bag); + explicit type_analysis_visitor(symbol_bag bag); void visit(program *program) override; @@ -132,7 +131,7 @@ namespace elna::boot const bool is_extern, const struct position position); public: - name_analysis_visitor(const char *path, symbol_bag bag); + name_analysis_visitor(symbol_bag bag); void visit(type_expression *) override; void visit(array_type_expression *type_expression) override; @@ -182,7 +181,7 @@ namespace elna::boot public: forward_table unresolved; - explicit declaration_visitor(const char *path); + explicit declaration_visitor(); void visit(program *program) override; void visit(import_declaration *) override; diff --git a/include/elna/gcc/elna-diagnostic.h b/include/elna/gcc/elna-diagnostic.h index 1eef65d..a8d4a69 100644 --- a/include/elna/gcc/elna-diagnostic.h +++ b/include/elna/gcc/elna-diagnostic.h @@ -17,16 +17,15 @@ along with GCC; see the file COPYING3. If not see #pragma once +#include <deque> +#include <memory> +#include <filesystem> + #include "config.h" #include "system.h" #include "coretypes.h" -#include "input.h" -#include "tree.h" #include "diagnostic.h" -#include <deque> -#include <memory> - #include "elna/boot/result.h" namespace elna::gcc @@ -34,6 +33,8 @@ namespace elna::gcc struct linemap_guard { explicit linemap_guard(const char *filename); + explicit linemap_guard(const std::filesystem::path filename); + linemap_guard(const linemap_guard&) = delete; linemap_guard(linemap_guard&&) = delete; diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h index 9e148e6..77fd792 100644 --- a/include/elna/gcc/elna-generic.h +++ b/include/elna/gcc/elna-generic.h @@ -17,6 +17,9 @@ along with GCC; see the file COPYING3. If not see #pragma once +#include <string> +#include <forward_list> + #include "elna/boot/ast.h" #include "elna/boot/symbol.h" #include "elna/boot/semantic.h" @@ -28,9 +31,6 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "tree-iterator.h" -#include <string> -#include <forward_list> - namespace elna::gcc { class generic_visitor final : public boot::empty_visitor |
