From: Wolfgang (Blub) Bumiller Date: Sat, 18 Aug 2012 18:30:24 +0000 (+0200) Subject: ast_type_adopt - ast_entfield now adopts the full type of the field X-Git-Tag: 0.1-rc1~181 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=20635c5ae466c0b519647a4ec4e203b60d0e6e0a;p=xonotic%2Fgmqcc.git ast_type_adopt - ast_entfield now adopts the full type of the field --- diff --git a/ast.c b/ast.c index 3d8d45f..6598181 100644 --- a/ast.c +++ b/ast.c @@ -117,6 +117,28 @@ ast_value* ast_value_copy(const ast_value *self) return cp; } +#define ast_type_adopt(a, b) ast_type_adopt_impl((ast_expression*)(a), (ast_expression*)(b)) +static bool ast_type_adopt_impl(ast_expression *self, const ast_expression *other) +{ + size_t i; + const ast_expression_common *fromex; + ast_expression_common *selfex; + self->expression.vtype = other->expression.vtype; + if (other->expression.next) { + self->expression.next = (ast_expression*)ast_type_copy(ast_ctx(self), other->expression.next); + if (!self->expression.next) + return false; + } + fromex = &other->expression; + selfex = &self->expression; + for (i = 0; i < fromex->params_count; ++i) { + ast_value *v = ast_value_copy(fromex->params[i]); + if (!v || !ast_expression_common_params_add(selfex, v)) + return false; + } + return true; +} + static ast_expression* ast_shallow_type(lex_ctx ctx, int vtype) { ast_instantiate(ast_expression, ctx, ast_expression_delete_full); @@ -375,12 +397,14 @@ ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expressi ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen); - self->expression.vtype = outtype->expression.vtype; - self->expression.next = ast_type_copy(ctx, outtype->expression.next); - self->entity = entity; self->field = field; + if (!ast_type_adopt(self, outtype)) { + ast_entfield_delete(self); + return NULL; + } + return self; } diff --git a/data/vars.qc b/data/vars.qc index 7438a10..932df97 100644 --- a/data/vars.qc +++ b/data/vars.qc @@ -8,12 +8,23 @@ string(float) ftos = #2; entity() spawn = #3; void(entity) kill = #4; +.void(string x) printit; + float(vector different_name, vector b) dot; float(vector a, vector b) dot = { return a * b; }; +void(string x) myprintit = { + print3("-> ", x, "\n"); +}; + void() main = { + local entity pawn; print3("should be 1: ", ftos(dot('1 1 0', '1 0 0')), "\n"); + + pawn = spawn(); + pawn.printit = myprintit; + pawn.printit("Hello"); };