X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.cpp;h=d71c4715d7190ddd99915e544a497e358786ca89;hp=4768e6e5bb9db83be59b9415cb73733d66d829b9;hb=dedb3a49bdb619bf4fc303e0da6d4740fc9a4527;hpb=db9c37d18bcced1c3b0f1421044155b1d88f0b25 diff --git a/ast.cpp b/ast.cpp index 4768e6e..d71c471 100644 --- a/ast.cpp +++ b/ast.cpp @@ -67,12 +67,12 @@ static GMQCC_NORETURN void _ast_node_destroy(ast_node *self) } /* Initialize main ast node aprts */ -static void ast_node_init(ast_node *self, lex_ctx_t ctx, int nodetype) +static void ast_node_init(ast_node *self, lex_ctx_t ctx, int node_type) { self->context = ctx; - self->destroy = &_ast_node_destroy; - self->keep = false; - self->nodetype = nodetype; + self->destroy = &_ast_node_destroy; + self->keep_node = false; + self->node_type = node_type; self->side_effects = false; } @@ -104,7 +104,7 @@ static void ast_expression_delete(ast_expression *self) { if (self->next) ast_delete(self->next); - for (auto &it : self->params) + for (auto &it : self->type_params) ast_delete(it); if (self->varparam) ast_delete(self->varparam); @@ -120,17 +120,17 @@ ast_value* ast_value_copy(const ast_value *self) { const ast_expression *fromex; ast_expression *selfex; - ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype); + ast_value *cp = ast_value_new(self->expression.context, self->name, self->expression.vtype); if (self->expression.next) { - cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next); + cp->expression.next = ast_type_copy(self->expression.context, self->expression.next); } fromex = &self->expression; selfex = &cp->expression; selfex->count = fromex->count; selfex->flags = fromex->flags; - for (auto &it : fromex->params) { + for (auto &it : fromex->type_params) { ast_value *v = ast_value_copy(it); - selfex->params.push_back(v); + selfex->type_params.push_back(v); } return cp; } @@ -147,9 +147,9 @@ void ast_type_adopt_impl(ast_expression *self, const ast_expression *other) selfex = self; selfex->count = fromex->count; selfex->flags = fromex->flags; - for (auto &it : fromex->params) { + for (auto &it : fromex->type_params) { ast_value *v = ast_value_copy(it); - selfex->params.push_back(v); + selfex->type_params.push_back(v); } } @@ -189,9 +189,9 @@ ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex) selfex->count = fromex->count; selfex->flags = fromex->flags; - for (auto &it : fromex->params) { + for (auto &it : fromex->type_params) { ast_value *v = ast_value_copy(it); - selfex->params.push_back(v); + selfex->type_params.push_back(v); } return self; @@ -207,18 +207,18 @@ bool ast_compare_type(ast_expression *a, ast_expression *b) return false; if (!a->next != !b->next) return false; - if (a->params.size() != b->params.size()) + if (a->type_params.size() != b->type_params.size()) return false; if ((a->flags & AST_FLAG_TYPE_MASK) != (b->flags & AST_FLAG_TYPE_MASK) ) { return false; } - if (a->params.size()) { + if (a->type_params.size()) { size_t i; - for (i = 0; i < a->params.size(); ++i) { - if (!ast_compare_type((ast_expression*)a->params[i], - (ast_expression*)b->params[i])) + for (i = 0; i < a->type_params.size(); ++i) { + if (!ast_compare_type((ast_expression*)a->type_params[i], + (ast_expression*)b->type_params[i])) return false; } } @@ -267,19 +267,19 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi pos = ast_type_to_string_impl(e->next, buf, bufsize, pos); if (pos + 2 >= bufsize) goto full; - if (e->params.empty()) { + if (e->type_params.empty()) { buf[pos++] = '('; buf[pos++] = ')'; return pos; } buf[pos++] = '('; - pos = ast_type_to_string_impl((ast_expression*)(e->params[0]), buf, bufsize, pos); - for (i = 1; i < e->params.size(); ++i) { + pos = ast_type_to_string_impl((ast_expression*)(e->type_params[0]), buf, bufsize, pos); + for (i = 1; i < e->type_params.size(); ++i) { if (pos + 2 >= bufsize) goto full; buf[pos++] = ','; buf[pos++] = ' '; - pos = ast_type_to_string_impl((ast_expression*)(e->params[i]), buf, bufsize, pos); + pos = ast_type_to_string_impl((ast_expression*)(e->type_params[i]), buf, bufsize, pos); } if (pos + 1 >= bufsize) goto full; @@ -325,7 +325,7 @@ ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t) ast_instantiate(ast_value, ctx, ast_value_delete); ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_value_codegen); - self->expression.node.keep = true; /* keep */ + self->expression.keep_node = true; /* keep */ self->name = name ? util_strdup(name) : nullptr; self->expression.vtype = t; @@ -366,7 +366,7 @@ void ast_value_delete(ast_value* self) break; case TYPE_FUNCTION: /* unlink us from the function node */ - self->constval.vfunc->vtype = nullptr; + self->constval.vfunc->function_type = nullptr; break; /* NOTE: delete function? currently collected in * the parser structure @@ -394,7 +394,7 @@ void ast_value_delete(ast_value* self) void ast_value_params_add(ast_value *self, ast_value *p) { - self->expression.params.push_back(p); + self->expression.type_params.push_back(p); } bool ast_value_set_name(ast_value *self, const char *name) @@ -617,7 +617,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi } ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen); - self->expression.node.keep = true; /* keep */ + self->expression.keep_node = true; /* keep */ if (owner->vtype == TYPE_VECTOR) { self->expression.vtype = TYPE_FLOAT; @@ -642,7 +642,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi void ast_member_delete(ast_member *self) { - /* The owner is always an ast_value, which has .keep=true, + /* The owner is always an ast_value, which has .keep_node=true, * also: ast_members are usually deleted after the owner, thus * this will cause invalid access ast_unref(self->owner); @@ -1042,8 +1042,8 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) bool retval = true; const ast_expression *func = self->func; size_t count = self->params.size(); - if (count > func->params.size()) - count = func->params.size(); + if (count > func->type_params.size()) + count = func->type_params.size(); for (i = 0; i < count; ++i) { if (ast_istype(self->params[i], ast_argpipe)) { @@ -1052,13 +1052,13 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call"); return false; } - if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->params[i])) + if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->type_params[i])) retval = false; } - else if (!ast_compare_type(self->params[i], (ast_expression*)(func->params[i]))) + else if (!ast_compare_type(self->params[i], (ast_expression*)(func->type_params[i]))) { ast_type_to_string(self->params[i], tgot, sizeof(tgot)); - ast_type_to_string((ast_expression*)func->params[i], texp, sizeof(texp)); + ast_type_to_string((ast_expression*)func->type_params[i], texp, sizeof(texp)); compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s", (unsigned int)(i+1), texp, tgot); /* we don't immediately return */ @@ -1066,7 +1066,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) } } count = self->params.size(); - if (count > func->params.size() && func->varparam) { + if (count > func->type_params.size() && func->varparam) { for (; i < count; ++i) { if (ast_istype(self->params[i], ast_argpipe)) { /* warn about type safety instead */ @@ -1139,7 +1139,7 @@ bool ast_block_add_expr(ast_block *self, ast_expression *e) void ast_block_collect(ast_block *self, ast_expression *expr) { self->collect.push_back(expr); - expr->node.keep = true; + expr->keep_node = true; } void ast_block_delete(ast_block *self) @@ -1173,8 +1173,8 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype goto cleanup; } - self->vtype = vtype; - self->name = name ? util_strdup(name) : nullptr; + self->function_type = vtype; + self->name = name ? util_strdup(name) : nullptr; self->labelcount = 0; self->builtin = 0; @@ -1202,14 +1202,14 @@ void ast_function_delete(ast_function *self) { if (self->name) mem_d((void*)self->name); - if (self->vtype) { - /* ast_value_delete(self->vtype); */ - self->vtype->hasvalue = false; - self->vtype->constval.vfunc = nullptr; + if (self->function_type) { + /* ast_value_delete(self->function_type); */ + self->function_type->hasvalue = false; + self->function_type->constval.vfunc = nullptr; /* We use unref - if it was stored in a global table it is supposed * to be deleted from *there* */ - ast_unref(self->vtype); + ast_unref(self->function_type); } for (auto &it : self->static_names) mem_d(it); @@ -1781,8 +1781,8 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) } /* fill the parameter list */ - ec = &self->vtype->expression; - for (auto &it : ec->params) { + ec = &self->function_type->expression; + for (auto &it : ec->type_params) { if (it->expression.vtype == TYPE_FIELD) vec_push(irf->params, it->expression.next->vtype); else @@ -1854,8 +1854,8 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) /* TODO: check return types */ if (!self->curblock->final) { - if (!self->vtype->expression.next || - self->vtype->expression.next->vtype == TYPE_VOID) + if (!self->function_type->expression.next || + self->function_type->expression.next->vtype == TYPE_VOID) { return ir_block_create_return(self->curblock, ast_ctx(self), nullptr); }