]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
vararg accessor generation
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index f42a65493ed4e0f1ca3543d9965d19029d826352..0f5b05ca4a98383e22e61f4989c451ce94e353e5 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -348,6 +348,8 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
     self->getter = NULL;
     self->desc   = NULL;
 
+    self->argcounter = NULL;
+
     return self;
 }
 
@@ -355,6 +357,8 @@ void ast_value_delete(ast_value* self)
 {
     if (self->name)
         mem_d((void*)self->name);
+    if (self->argcounter)
+        mem_d((void*)self->argcounter);
     if (self->hasvalue) {
         switch (self->expression.vtype)
         {
@@ -1070,6 +1074,8 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
     vtype->hasvalue = true;
     vtype->constval.vfunc = self;
 
+    self->varargs = NULL;
+
     return self;
 }
 
@@ -1092,6 +1098,8 @@ void ast_function_delete(ast_function *self)
     vec_free(self->blocks);
     vec_free(self->breakblocks);
     vec_free(self->continueblocks);
+    if (self->varargs)
+        ast_delete(self->varargs);
     mem_d(self);
 }
 
@@ -1401,7 +1409,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
 
         func->flags |= IR_FLAG_HAS_ARRAYS;
 
-        if (param) {
+        if (param && !(self->expression.flags & AST_FLAG_IS_VARARG)) {
             compile_error(ast_ctx(self), "array-parameters are not supported");
             return false;
         }
@@ -1567,6 +1575,11 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         }
     }
 
+    if (self->varargs) {
+        if (!ast_local_codegen(self->varargs, self->ir_func, true))
+            return false;
+    }
+
     if (self->builtin) {
         irf->builtin = self->builtin;
         return true;