]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Got rid of all the memleaks. We can now merge with master.
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 6e14bbc2184c8d8e7805495773b997c17d8aba0f..b2b7064d8d43d6a47cfec1831b16c07ed4b6fec5 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -826,14 +826,17 @@ void ast_switch_delete(ast_switch *self)
     mem_d(self);
 }
 
-ast_label* ast_label_new(lex_ctx ctx, const char *name)
+ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined)
 {
     ast_instantiate(ast_label, ctx, ast_label_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen);
 
-    self->name    = util_strdup(name);
-    self->irblock = NULL;
-    self->gotos   = NULL;
+    self->expression.vtype = TYPE_NOEXPR;
+
+    self->name      = util_strdup(name);
+    self->irblock   = NULL;
+    self->gotos     = NULL;
+    self->undefined = undefined;
 
     return self;
 }
@@ -2868,6 +2871,11 @@ bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_valu
     size_t i;
     ir_value *dummy;
 
+    if (self->undefined) {
+        compile_error(ast_ctx(self), "internal error: ast_label never defined");
+        return false;
+    }
+
     *out = NULL;
     if (lvalue) {
         compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");