]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
All code is now C89/C90 compat
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 81eef29f0ec8f8999daa87ba9e0fed0ed0d64fa3..aede5aa2688fd7166d420a0521d3f66ec48cbac1 100644 (file)
--- a/ast.c
+++ b/ast.c
 #include "gmqcc.h"
 #include "ast.h"
 
-#define ast_instantiate(T, ctx, destroyfn)                    \
-    T *self = (T*)mem_a(sizeof(T));                           \
-    ast_node_init((ast_node*)self, ctx);                      \
-    ( (ast_node*)self )->node.destroy = (ast_node_delete*)destroyfn;
+#define ast_instantiate(T, ctx, destroyfn)                          \
+    T* self = (T*)mem_a(sizeof(T));                                 \
+    ast_node_init((ast_node*)self, ctx);                            \
+    ( (ast_node*)self )->node.destroy = (ast_node_delete*)destroyfn
 
 /* It must not be possible to get here. */
 static void _ast_node_destroy(ast_node *self)
@@ -180,6 +180,8 @@ void ast_block_delete(ast_block *self)
 
 ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
 {
+    ast_instantiate(ast_function, ctx, ast_function_delete);
+    
     if (!vtype)
         return NULL;
     if (vtype->isconst)
@@ -187,8 +189,6 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
     if (vtype->vtype != TYPE_FUNCTION)
         return NULL;
 
-    ast_instantiate(ast_function, ctx, ast_function_delete);
-
     self->vtype = vtype;
     self->name = name ? util_strdup(name) : NULL;
     MEM_VECTOR_INIT(self, blocks);
@@ -241,6 +241,7 @@ bool ast_value_codegen(ast_value *self, ast_function *func, ir_value **out)
 
 bool ast_global_codegen(ast_value *self, ir_builder *ir)
 {
+    ir_value *v = NULL;
     if (self->isconst && self->vtype == TYPE_FUNCTION)
     {
         ir_function *func = ir_builder_create_function(ir, self->name);
@@ -252,7 +253,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir)
         return true;
     }
 
-    ir_value *v = ir_builder_create_global(ir, self->name, self->vtype);
+    v = ir_builder_create_global(ir, self->name, self->vtype);
     if (!v)
         return false;