]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
ast_value now has an initializer list array, still unused but it's there for later
authorWolfgang Bumiller <wry.git@bumiller.com>
Fri, 26 Apr 2013 08:45:13 +0000 (10:45 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Fri, 26 Apr 2013 08:47:55 +0000 (10:47 +0200)
ast.c
ast.h
parser.c

diff --git a/ast.c b/ast.c
index 3e5d304d1e53c6ba9666f56ddfd6aafdc4bc94c8..1e2836f8e2c39181b949d733e85503606b7e5703 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -317,8 +317,9 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
     self->cvq      = CV_NONE;
     self->hasvalue = false;
     self->isimm    = false;
-    self->uses    = 0;
+    self->uses     = 0;
     memset(&self->constval, 0, sizeof(self->constval));
+    self->initlist = NULL;
 
     self->ir_v           = NULL;
     self->ir_values      = NULL;
@@ -362,6 +363,20 @@ void ast_value_delete(ast_value* self)
     if (self->desc)
         mem_d(self->desc);
 
+    if (self->initlist) {
+        if (self->expression.next->expression.vtype == TYPE_STRING) {
+            /* strings are allocated, free them */
+            size_t i, len = vec_size(self->initlist);
+            /* in theory, len should be expression.count
+             * but let's not take any chances */
+            for (i = 0; i < len; ++i) {
+                if (self->initlist[i].vstring)
+                    mem_d(self->initlist[i].vstring);
+            }
+        }
+        vec_free(self->initlist);
+    }
+
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
diff --git a/ast.h b/ast.h
index bae07db39ec85c13481a10ecec947ece7f0c7ce8..98ad79228fee073da2a66cf4dbc581f4f4728b53 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -161,6 +161,15 @@ typedef struct
  * typedef float foo;
  * is like creating a 'float foo', foo serving as the type's name.
  */
+typedef union {
+    double        vfloat;
+    int           vint;
+    vector        vvec;
+    const char   *vstring;
+    int           ventity;
+    ast_function *vfunc;
+    ast_value    *vfield;
+} basic_value_t;
 struct ast_value_s
 {
     ast_expression_common expression;
@@ -179,15 +188,12 @@ struct ast_value_s
     bool isfield; /* this declares a field */
     bool isimm;   /* an immediate, not just const */
     bool hasvalue;
-    union {
-        double        vfloat;
-        int           vint;
-        vector        vvec;
-        const char   *vstring;
-        int           ventity;
-        ast_function *vfunc;
-        ast_value    *vfield;
-    } constval;
+    basic_value_t constval;
+    /* for TYPE_ARRAY we have an optional vector
+     * of constants when an initializer list
+     * was provided.
+     */
+    basic_value_t *initlist;
 
     /* usecount for the parser */
     size_t uses;
index 506f8d201fd812fccafce45c03930a29b5c178af..a09a54af75eb5b6b1ec645c4ec9e76e0bba40973 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5725,7 +5725,22 @@ skipvar:
                 break;
             }
         }
-        else if (parser->tok == '{' || parser->tok == '[')
+        else if (var->expression.vtype == TYPE_ARRAY && parser->tok == '{')
+        {
+            if (localblock) {
+                /* Note that fteqcc and most others don't even *have*
+                 * local arrays, so this is not a high priority.
+                 */
+                parseerror(parser, "TODO: initializers for local arrays");
+                break;
+            }
+            /*
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels);
+*/
+            parseerror(parser, "TODO: initializing global arrays is not supported yet!");
+            break;
+        }
+        else if (var->expression.vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
         {
             if (localblock) {
                 parseerror(parser, "cannot declare functions within functions");