]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
allowing inexing of array-fields
authorWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 12 Nov 2012 22:35:47 +0000 (23:35 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 12 Nov 2012 22:35:47 +0000 (23:35 +0100)
ast.c
parser.c

diff --git a/ast.c b/ast.c
index bfdcf621c80eb4a8d1c2a77bd8109589c15e4140..aa65da207af53f4e31e9b19e4e656cd4319ef422 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -588,6 +588,15 @@ ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_exp
         ast_array_index_delete(self);
         return NULL;
     }
+    if (array->expression.vtype == TYPE_FIELD && outtype->expression.vtype == TYPE_ARRAY) {
+        if (self->expression.vtype != TYPE_ARRAY) {
+            asterror(ast_ctx(self), "array_index node on type");
+            ast_array_index_delete(self);
+            return NULL;
+        }
+        self->array = outtype;
+        self->expression.vtype = TYPE_FIELD;
+    }
 
     return self;
 }
index b81d06c8fb9f8e573c4dd700222036738c3e8005..250a75a2fe55f72ed8c930afcfdafed233cf6700 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -464,7 +464,10 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
             break;
 
         case opid1('['):
-            if (exprs[0]->expression.vtype != TYPE_ARRAY) {
+            if (exprs[0]->expression.vtype != TYPE_ARRAY &&
+                !(exprs[0]->expression.vtype == TYPE_FIELD &&
+                  exprs[0]->expression.next->expression.vtype == TYPE_ARRAY))
+            {
                 ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                 parseerror(parser, "cannot index value of type %s", ty1);
                 return false;