fix: random bugs

This commit is contained in:
TopchetoEU 2023-01-26 18:47:20 +02:00
parent fafd2ad864
commit 99cae2ee78
No known key found for this signature in database
GPG Key ID: 5ED5FFB2A3F5DB21
7 changed files with 14 additions and 90 deletions

View File

@ -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<located_t<std::string>> 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;
}
}

View File

@ -33,8 +33,6 @@ namespace ppc::tree::constr {
}
#endif
};
struct exp_t: public named_t {
};
template <class ParserT, class GlobT = glob_t>
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<token_t> &tokens):
messages(messages), tokens(tokens) { }
ast_ctx_t(msg_stack_t &messages, std::vector<token_t> &tokens);
};
bool parse_identifier(ast_ctx_t &ctx, size_t &res_i, located_t<std::string> &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;

View File

@ -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 };
}

View File

@ -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<std::string> deps {};
if (name.length() == 0) {

View File

@ -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) {

View File

@ -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);

View File

@ -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)));