]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_value_copy should copy the expression substructure as well - exposing ast_value_c...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 15:16:20 +0000 (17:16 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 15:16:20 +0000 (17:16 +0200)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index bca493e606285cf59b8e15ffc56dfe4c861645ab..52023ff27004b5c26863861fb9e46948b7c0107a 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -92,8 +92,11 @@ static void ast_expression_delete_full(ast_expression *self)
 MEM_VEC_FUNCTIONS(ast_expression_common, ast_value*, params)
 
 static ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex);
-static ast_value* ast_value_copy(const ast_value *self)
+ast_value* ast_value_copy(const ast_value *self)
 {
+    size_t i;
+    const ast_expression_common *fromex;
+    ast_expression_common *selfex;
     ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype);
     if (self->expression.next) {
         cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next);
@@ -102,6 +105,15 @@ static ast_value* ast_value_copy(const ast_value *self)
             return NULL;
         }
     }
+    fromex   = &self->expression;
+    selfex = &cp->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)) {
+            ast_value_delete(cp);
+            return NULL;
+        }
+    }
     return cp;
 }
 
diff --git a/ast.h b/ast.h
index 9951216438bb43fdabc6643f994869d1e263e52c..d118adbf6566668e59837d6deda1118ad7728528 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -149,6 +149,7 @@ struct ast_value_s
 };
 
 ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype);
+ast_value* ast_value_copy(const ast_value *self);
 /* This will NOT delete an underlying ast_function */
 void ast_value_delete(ast_value*);
 
index a084e2f05ca32130bdc6b70808cb7562225e7f88..b193566f77e0ee5dbc27256794668b6c23692197 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2042,6 +2042,7 @@ static bool parser_do(parser_t *parser)
     else if (parser->tok == '.')
     {
         ast_value *var;
+        ast_value *typevar;
         ast_value *fld;
         ast_expression *oldex;
         bool       isfunc = false;
@@ -2065,11 +2066,12 @@ static bool parser_do(parser_t *parser)
         }
 
         /* parse the field type fully */
-        var = parser_parse_type(parser, basetype, &isfunc);
+        typevar = var = parser_parse_type(parser, basetype, &isfunc);
         if (!var)
             return false;
 
         while (true) {
+            var = ast_value_copy(typevar);
             /* now the field name */
             if (parser->tok != TOKEN_IDENT) {
                 parseerror(parser, "expected field name");
@@ -2179,6 +2181,7 @@ nextfield:
                 return false;
             }
         }
+        ast_delete(typevar);
 
         /* skip the semicolon */
         if (!parser_next(parser))