]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
multiple dots to start a field type, ie ..float for a fieldpointer field
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 16:37:54 +0000 (17:37 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 16:37:54 +0000 (17:37 +0100)
parser.c
tests/fieldparams.qc
tests/fieldparams.tmpl

index 83a5a48fb4788bd94ce4437ea43923e5aaebd55e..650de169a18b5a132d5bdc81c54ea5106b01a9b9 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3198,6 +3198,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
     const char *name = NULL;
     bool        isfield  = false;
     bool        wasarray = false;
+    size_t      morefields = 0;
 
     ctx = parser_ctx(parser);
 
@@ -3217,12 +3218,30 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va
         }
     }
 
+    /* Further dots are handled seperately because they won't be part of the
+     * basetype
+     */
+    while (parser->tok == '.') {
+        ++morefields;
+        if (!parser_next(parser)) {
+            parseerror(parser, "expected typename for field definition");
+            return NULL;
+        }
+    }
+
     /* generate the basic type value */
     if (cached_typedef) {
         var = ast_value_copy(cached_typedef);
         ast_value_set_name(var, "<type(from_def)>");
     } else
         var = ast_value_new(ctx, "<type>", parser_token(parser)->constval.t);
+
+    for (; morefields; --morefields) {
+        tmp = ast_value_new(ctx, "<.type>", TYPE_FIELD);
+        tmp->expression.next = (ast_expression*)var;
+        var = tmp;
+    }
+
     /* do not yet turn into a field - remember:
      * .void() foo; is a field too
      * .void()() foo; is a function
index 9ca71d6a9c351c85c2790d3407a4b35427e61d39..8e5cb031772457a30fd9f698ae6740b002b592b2 100644 (file)
@@ -3,6 +3,7 @@ entity() spawn = #3;
 
 .string a;
 .string b;
+..string ps;
 
 void(entity e, .string s) callout = {
     print(e.s, "\n");
@@ -14,4 +15,6 @@ void() main = {
     e.a = "foo";
     e.b = "bar";
     callout(e, b);
+    e.ps = a;
+    print(e.(e.ps), "\n");
 };
index 7d5217feb525fd9d722b8098be852aa8593b7fcd..5e1af6eaef94864685fa2af69fd0096863736b0c 100644 (file)
@@ -6,3 +6,4 @@ E: $null
 F: field paramaters fail
 S: field paramaters work
 M: bar
+M: foo