#pragma once #include "basic_printers.hpp" #include "error_handling.hpp" #include "error_log.hpp" #include "expression_nodes.hpp" #include "name_tree.hpp" #include "statement_builders.hpp" #include "statement_nodes.hpp" #include "statement_printers.hpp" #include "tree_sitter_wrapper.hpp" #include "type_nodes.hpp" #include #include #include class SourcesManager { public: void add_file(const std::string &filename) { std::ifstream in; in.open(filename); std::stringstream source_stream; source_stream << in.rdbuf(); in.close(); std::string source = source_stream.str(); parser::ParseTree parse_tree(source); if (!parse_tree.is_properly_parsed()) { error_handling::handle_parsing_error( "There are some parsing errors in file", parse_tree.get_root()); } auto new_statements = builders::build_source_file( parse_tree.get_root(), expression_storage_, type_storage_, name_tree_); statements_.reserve(statements_.size() + new_statements.size()); for (auto &new_statement : new_statements) { statements_.push_back(std::move(new_statement)); } new_statements.clear(); } void print(std::ostream &out) { printers::Printer printer(out, 2, 80, true); printers::print(statements_, printer); } // nodes::ExpressionStorage *expressions() { return &expression_storage_; } const nodes::ExpressionStorage *expressions() const { return &expression_storage_; } // nodes::TypeStorage *types() { return &type_storage_; } const nodes::TypeStorage *types() const { return &type_storage_; } // names::NameTree *names() { return &name_tree_; } const names::NameTree *names() const { return &name_tree_; } // error_handling::ErrorLog *errors() { return &error_log_; } const error_handling::ErrorLog *errors() const { return &error_log_; } // size_t statements_size() const { return statements_.size(); } nodes::Statement *statement(size_t id) { return &statements_.at(id); } const nodes::Statement *statement(size_t id) const { return &statements_.at(id); } private: nodes::ExpressionStorage expression_storage_; nodes::TypeStorage type_storage_; names::NameTree name_tree_; error_handling::ErrorLog error_log_; std::vector statements_; };