X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ast.c;h=fc82940dcb0faf1d8063d6488454eaacdc13613a;hb=41881823b728fa73edac9df45f2239c83f5fa9ca;hp=40a53a3f3c7ed19a3a253e0496b79fb1ab2c030d;hpb=d148cfdcd5b668b6aa0110d59fe73bc46a17eee5;p=xonotic%2Fgmqcc.git diff --git a/ast.c b/ast.c index 40a53a3..fc82940 100644 --- a/ast.c +++ b/ast.c @@ -855,9 +855,12 @@ ast_call* ast_call_new(lex_ctx ctx, self->params = NULL; self->func = funcexpr; +/* self->expression.vtype = funcexpr->expression.next->expression.vtype; if (funcexpr->expression.next->expression.next) self->expression.next = ast_type_copy(ctx, funcexpr->expression.next->expression.next); +*/ + ast_type_adopt(self, funcexpr->expression.next); return self; } @@ -1075,6 +1078,17 @@ const char* ast_function_label(ast_function *self, const char *prefix) * But I can't imagine a pituation where the output is truly unnecessary. */ +void _ast_codegen_output_type(ast_expression_common *self, ir_value *out) +{ + if (out->vtype == TYPE_FIELD) + out->fieldtype = self->next->expression.vtype; + if (out->vtype == TYPE_FUNCTION) + out->outtype = self->next->expression.vtype; +} + +#define codegen_output_type(a,o) (_ast_codegen_output_type(&((a)->expression),(o))) +#define codegen_output_type_expr(a,o) (_ast_codegen_output_type(a,(o))) + bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out) { (void)func; @@ -1148,8 +1162,6 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name); return false; } - if (vtype == TYPE_FIELD) - v->fieldtype = elemtype->next->expression.vtype; v->context = ast_ctx(self); array->ir_v = self->ir_v = v; @@ -1167,8 +1179,6 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", name); return false; } - if (vtype == TYPE_FIELD) - array->ir_values[ai]->fieldtype = elemtype->next->expression.vtype; array->ir_values[ai]->context = ast_ctx(self); } mem_d(name); @@ -1201,8 +1211,6 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", self->name); return false; } - if (vtype == TYPE_FIELD) - v->fieldtype = elemtype->next->expression.vtype; v->context = ast_ctx(self); namelen = strlen(self->name); @@ -1219,8 +1227,6 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", name); return false; } - if (vtype == TYPE_FIELD) - self->ir_values[ai]->fieldtype = elemtype->next->expression.vtype; self->ir_values[ai]->context = ast_ctx(self); } mem_d(name); @@ -1235,8 +1241,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name); return false; } - if (self->expression.vtype == TYPE_FIELD) - v->fieldtype = self->expression.next->expression.vtype; + codegen_output_type(self, v); v->context = ast_ctx(self); } @@ -1332,8 +1337,6 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) compile_error(ast_ctx(self), "ir_function_create_local failed"); return false; } - if (vtype == TYPE_FIELD) - v->fieldtype = elemtype->next->expression.vtype; v->context = ast_ctx(self); namelen = strlen(self->name); @@ -1348,8 +1351,6 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", name); return false; } - if (vtype == TYPE_FIELD) - self->ir_values[ai]->fieldtype = elemtype->next->expression.vtype; self->ir_values[ai]->context = ast_ctx(self); } } @@ -1358,8 +1359,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) v = ir_function_create_local(func, self->name, self->expression.vtype, param); if (!v) return false; - if (self->expression.vtype == TYPE_FIELD) - v->fieldtype = self->expression.next->expression.vtype; + codegen_output_type(self, v); v->context = ast_ctx(self); } @@ -1971,6 +1971,7 @@ bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, i } else { *out = ir_block_create_load_from_ent(func->curblock, ast_ctx(self), ast_function_label(func, "efv"), ent, field, self->expression.vtype); + codegen_output_type(self, *out); } if (!*out) { compile_error(ast_ctx(self), "failed to create %s instruction (output type %s)", @@ -2854,6 +2855,8 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value *out = ir_call_value(callinstr); self->expression.outr = *out; + codegen_output_type(self, *out); + vec_free(params); return true; error: