]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_member_new now fixed up for fields, ast_shallow_type added for creation of a...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 11 Aug 2012 20:14:16 +0000 (22:14 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 11 Aug 2012 20:14:16 +0000 (22:14 +0200)
ast.c

diff --git a/ast.c b/ast.c
index d7684090887af261cb8869c0c23caa5a3374d8a3..e6d28a61d19a4dcc32672c794a52f62657a4e49c 100644 (file)
--- 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);