From: Wolfgang (Blub) Bumiller Date: Sat, 11 Aug 2012 20:14:16 +0000 (+0200) Subject: ast_member_new now fixed up for fields, ast_shallow_type added for creation of a... X-Git-Tag: 0.1-rc1~349^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=56c23dc11e18c1eee673e7db19c84bde89eb9c47;p=xonotic%2Fgmqcc.git ast_member_new now fixed up for fields, ast_shallow_type added for creation of a type-only ast_expression --- diff --git a/ast.c b/ast.c index d768409..e6d28a6 100644 --- a/ast.c +++ b/ast.c @@ -94,6 +94,15 @@ static ast_value* ast_value_copy(const ast_value *self) return cp; } +static ast_expression* ast_shallow_type(lex_ctx ctx, int vtype) +{ + ast_instantiate(ast_expression, ctx, ast_expression_delete_full); + self->expression.codegen = NULL; + self->expression.next = NULL; + self->expression.vtype = vtype; + return self; +} + static ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex) { size_t i; @@ -294,10 +303,22 @@ ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int fiel return NULL; } + if (owner->expression.vtype != TYPE_FLOAT && + owner->expression.vtype != TYPE_FIELD) { + printf("ast_member on an invalid owner of type %i\n", (int)owner->expression.vtype); + mem_d(self); + return NULL; + } + ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen); - self->expression.vtype = TYPE_FLOAT; - self->expression.next = NULL; + if (owner->expression.vtype == TYPE_VECTOR) { + self->expression.vtype = TYPE_FLOAT; + self->expression.next = NULL; + } else { + self->expression.vtype = TYPE_FIELD; + self->expression.next = ast_shallow_type(ctx, TYPE_FLOAT); + } self->owner = owner; self->field = field; @@ -958,8 +979,11 @@ bool ast_member_codegen(ast_member *self, ast_function *func, bool lvalue, ir_va if (!(*cgen)((ast_expression*)(self->owner), func, true, &vec)) return false; - if (vec->vtype != TYPE_VECTOR) + if (vec->vtype != TYPE_VECTOR && + !(vec->vtype == TYPE_FIELD && self->owner->expression.next->expression.vtype == TYPE_VECTOR)) + { return false; + } *out = ir_value_vector_member(vec, self->field);