From 99cae2ee78b9ad684fa723330095323d7051f1bb Mon Sep 17 00:00:00 2001 From: topchetoeu <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 26 Jan 2023 18:47:20 +0200 Subject: [PATCH] fix: random bugs --- include/lang/common.hh | 8 +++-- include/treeifier/constr.hh | 11 ++---- src/lang/module.cc | 70 ------------------------------------ src/lsproj.cc | 1 - src/main/main.cc | 7 ++-- src/treeifier/constr.cc | 2 +- src/treeifier/constr/glob.cc | 5 ++- 7 files changed, 14 insertions(+), 90 deletions(-) delete mode 100644 src/lang/module.cc diff --git a/include/lang/common.hh b/include/lang/common.hh index 0f3ec89..c81a5c5 100644 --- a/include/lang/common.hh +++ b/include/lang/common.hh @@ -63,10 +63,10 @@ namespace ppc::lang { bool operator>=(const loc_nmsp_t &other) const { return compare(other) >= 0; } nmsp_t strip_location() const; + std::string to_string() const; operator nmsp_t() { return strip_location(); } operator std::string() const { return to_string(); } - std::string to_string() const; loc_nmsp_t() { } loc_nmsp_t(std::initializer_list> segments): base(segments.begin(), segments.end()) { } @@ -76,11 +76,13 @@ namespace ppc::lang { bool resolve_name(const SetT &defs, const nmsp_t &src, const nmsp_t &target) { if (src == target) return true; - for (auto &it : defs) { - nmsp_t val = (nmsp_t)it; + for (const auto &it : defs) { + nmsp_t val = (const nmsp_t&)(it); val.insert(val.end(), src.begin(), src.end()); if (val == target) return true; } + + return false; } } \ No newline at end of file diff --git a/include/treeifier/constr.hh b/include/treeifier/constr.hh index 2278ccb..5a8d2fa 100644 --- a/include/treeifier/constr.hh +++ b/include/treeifier/constr.hh @@ -33,8 +33,6 @@ namespace ppc::tree::constr { } #endif }; - struct exp_t: public named_t { - }; template class parser_t { @@ -51,18 +49,13 @@ namespace ppc::tree::constr { loc_nmsp_t nmsp; ast_ctx_t &operator=(const ast_ctx_t &other) = delete; - ast_ctx_t(msg_stack_t &messages, std::vector &tokens): - messages(messages), tokens(tokens) { } + ast_ctx_t(msg_stack_t &messages, std::vector &tokens); }; bool parse_identifier(ast_ctx_t &ctx, size_t &res_i, located_t &out); bool parse_nmsp(ast_ctx_t &ctx, size_t &res_i, loc_nmsp_t &out); - bool parse_nmsp_id(ast_ctx_t &ctx, size_t &res_i, nmsp_t nmsp); + bool parse_nmsp_id(ast_ctx_t &ctx, size_t &res_i, glob_t glob, nmsp_t nmsp); - class exp_parser_t { - public: - bool operator()(ast_ctx_t &ctx, glob_t &out) const; - }; class glob_parser_t { public: bool operator()(ast_ctx_t &ctx, glob_t &out) const; diff --git a/src/lang/module.cc b/src/lang/module.cc deleted file mode 100644 index 123f3c8..0000000 --- a/src/lang/module.cc +++ /dev/null @@ -1,70 +0,0 @@ -#include "lang/module.hh" - -using namespace std::string_literals; -using namespace ppc::lang; - -definition_t::definition_t(function_t val) { - this->kind = FUNCTION; - this->val.func = new auto(val); -} -definition_t::definition_t(struct_t val) { - this->kind = STRUCT; - this->val.str = new auto(val); -} -definition_t::definition_t(field_t val) { - this->kind = FIELD; - this->val.field = new auto(val); -} -definition_t::definition_t(const definition_t &val) { - this->kind = val.kind; - switch (val.kind) { - case STRUCT: - this->val.str = new auto(*val.val.str); - break; - case FUNCTION: - this->val.func = new auto(*val.val.func); - break; - case FIELD: - this->val.field = new auto(*val.val.field); - break; - } -} - -definition_t::~definition_t() { - switch (this->kind) { - case FUNCTION: - delete this->val.func; - break; - case FIELD: - delete this->val.field; - break; - case STRUCT: - delete this->val.str; - break; - } -} - - -function_t &definition_t::get_func() { - if (!this->is_func()) throw "Definition is not a function."s; - return *this->val.func; -} -struct_t &definition_t::get_struct() { - if (!this->is_struct()) throw "Definition is not a struct."s; - return *this->val.str; -} -field_t &definition_t::get_field() { - if (!this->is_field()) throw "Definition is not a field."s; - return *this->val.field; -} - - -statement_t statement_t::call(const nmsp_t &func) { - return { CALL, { .call = new auto(func) } }; -} -statement_t statement_t::stack(int64_t stack) { - return { STACK, { .stack = stack } }; -} -statement_t statement_t::ret() { - return { RETURN }; -} diff --git a/src/lsproj.cc b/src/lsproj.cc index f1d3dc7..7579810 100644 --- a/src/lsproj.cc +++ b/src/lsproj.cc @@ -51,7 +51,6 @@ std::string read_str(std::istream &f, const std::string &skip_chars, const std:: project_t read_project(std::istream &f) { int end_ch; std::string name = read_str(f, " \v\t\r\n", "\n", end_ch); - std::size_t cap = 16, n = 0; std::vector deps {}; if (name.length() == 0) { diff --git a/src/main/main.cc b/src/main/main.cc index a920688..aa491e2 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -18,7 +18,6 @@ #include "./opions.hh" #include "treeifier/constr.hh" -#include "treeifier/constr/glob.hh" #include "treeifier/lexer.hh" #include "treeifier/tokenizer.hh" #include "utils/json.hh" @@ -163,9 +162,11 @@ int main(int argc, const char *argv[]) { std::ifstream f { file, std::ios_base::in }; if (!f.is_open()) throw message_t::error("The file doesn't exist.", { file }); auto tokens = token_t::parse_many(msg_stack, lex::token_t::parse_file(msg_stack, file, f)); - auto ast = ast_ctx_t::parse(constr::glob_parser_t(), msg_stack, tokens); + glob_t glob; + auto ctx = ast_ctx_t(msg_stack, tokens); + glob_parser_t()(ctx, glob); #ifdef PROFILE_debug - ast.print(); + glob.print(); #endif } catch (const messages::message_t &msg) { diff --git a/src/treeifier/constr.cc b/src/treeifier/constr.cc index bb5af9e..ce7ff52 100644 --- a/src/treeifier/constr.cc +++ b/src/treeifier/constr.cc @@ -40,7 +40,7 @@ bool ppc::tree::constr::parse_nmsp(ast_ctx_t &ctx, size_t &res_i, loc_nmsp_t &ou bool ppc::tree::constr::parse_nmsp_id(ast_ctx_t &ctx, size_t &res_i, glob_t glob, nmsp_t nmsp) { helper_t h(ctx, res_i); - nmsp_t src; + loc_nmsp_t src; if (!h.parse(parse_nmsp, src)) return false; if (resolve_name(glob.imports, src, nmsp)) return h.submit(false); diff --git a/src/treeifier/constr/glob.cc b/src/treeifier/constr/glob.cc index 5dfead8..d150cf2 100644 --- a/src/treeifier/constr/glob.cc +++ b/src/treeifier/constr/glob.cc @@ -1,6 +1,5 @@ -#include "treeifier/constr/glob.hh" +#include "treeifier/constr.hh" #include "treeifier/constr/helper.hh" -#include "treeifier/constr/nmsp.hh" using namespace ppc::tree::constr; @@ -26,7 +25,7 @@ bool ppc::tree::constr::glob_parser_t::operator()(ast_ctx_t &ctx, glob_t &out) c loc_nmsp_t res; h.advance("Expected a namespace"); - h.force_parse(nmsp_parser_t(), "Expected a namespace.", res); + h.force_parse(parse_nmsp, "Expected a namespace.", res); if (!h.curr().is_operator(operator_t::SEMICOLON)) { ctx.messages.push(message_t::error("Expected a semicolon.", h.loc(1)));