]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.cpp
Use std::vector for static_names
[xonotic/gmqcc.git] / ast.cpp
diff --git a/ast.cpp b/ast.cpp
index efff1116d0d1f00afabeb97e1a925d4b9e6bafbc..85244f48d7caa2d4a9c23341eab95be287e851bd 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1181,9 +1181,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     self->ir_func = NULL;
     self->curblock = NULL;
 
-    self->breakblocks    = NULL;
-    self->continueblocks = NULL;
-
     vtype->hasvalue = true;
     vtype->constval.vfunc = self;
 
@@ -1191,8 +1188,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     self->argc             = NULL;
     self->fixedparams      = NULL;
     self->return_value     = NULL;
-
-    self->static_names     = NULL;
     self->static_count     = 0;
 
     return self;
@@ -1204,7 +1199,6 @@ cleanup:
 
 void ast_function_delete(ast_function *self)
 {
-    size_t i;
     if (self->name)
         mem_d((void*)self->name);
     if (self->vtype) {
@@ -1216,13 +1210,10 @@ void ast_function_delete(ast_function *self)
          */
         ast_unref(self->vtype);
     }
-    for (i = 0; i < vec_size(self->static_names); ++i)
-        mem_d(self->static_names[i]);
-    vec_free(self->static_names);
+    for (auto &it : self->static_names)
+        mem_d(it);
     for (auto &it : self->blocks)
         ast_delete(it);
-    vec_free(self->breakblocks);
-    vec_free(self->continueblocks);
     if (self->varargs)
         ast_delete(self->varargs);
     if (self->argc)
@@ -2895,11 +2886,11 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         /* enter */
         func->curblock = bbody;
 
-        vec_push(func->breakblocks,    bbreak);
+        func->breakblocks.push_back(bbreak);
         if (bcontinue)
-            vec_push(func->continueblocks, bcontinue);
+            func->continueblocks.push_back(bcontinue);
         else
-            vec_push(func->continueblocks, bbody);
+            func->continueblocks.push_back(bbody);
 
         /* generate */
         if (self->body) {
@@ -2909,8 +2900,8 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         }
 
         end_bbody = func->curblock;
-        vec_pop(func->breakblocks);
-        vec_pop(func->continueblocks);
+        func->breakblocks.pop_back();
+        func->continueblocks.pop_back();
     }
 
     /* post-loop-condition */
@@ -3047,9 +3038,9 @@ bool ast_breakcont_codegen(ast_breakcont *self, ast_function *func, bool lvalue,
     self->expression.outr = (ir_value*)1;
 
     if (self->is_continue)
-        target = func->continueblocks[vec_size(func->continueblocks)-1-self->levels];
+        target = func->continueblocks[func->continueblocks.size()-1-self->levels];
     else
-        target = func->breakblocks[vec_size(func->breakblocks)-1-self->levels];
+        target = func->breakblocks[func->breakblocks.size()-1-self->levels];
 
     if (!target) {
         compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
@@ -3113,7 +3104,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
         return false;
 
     /* setup the break block */
-    vec_push(func->breakblocks, bout);
+    func->breakblocks.push_back(bout);
 
     /* Now create all cases */
     for (auto &it : self->cases) {
@@ -3218,7 +3209,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     func->curblock = bout;
 
     /* restore the break block */
-    vec_pop(func->breakblocks);
+    func->breakblocks.pop_back();
 
     /* Move 'bout' to the end, it's nicer */
     vec_remove(func->ir_func->blocks, bout_id, 1);
@@ -3344,9 +3335,8 @@ bool ast_state_codegen(ast_state *self, ast_function *func, bool lvalue, ir_valu
 bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value **out)
 {
     ast_expression_codegen *cgen;
-    ir_value              **params;
-    ir_instr               *callinstr;
-    size_t i;
+    std::vector<ir_value*> params;
+    ir_instr *callinstr;
 
     ir_value *funval = NULL;
 
@@ -3367,17 +3357,15 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
     if (!funval)
         return false;
 
-    params = NULL;
-
     /* parameters */
     for (auto &it : self->params) {
         ir_value *param;
         cgen = it->codegen;
         if (!(*cgen)(it, func, false, &param))
-            goto error;
+            return false;
         if (!param)
-            goto error;
-        vec_push(params, param);
+            return false;
+        params.push_back(param);
     }
 
     /* varargs counter */
@@ -3398,20 +3386,15 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
                                      ast_function_label(func, "call"),
                                      funval, !!(self->func->flags & AST_FLAG_NORETURN));
     if (!callinstr)
-        goto error;
+        return false;
 
-    for (i = 0; i < vec_size(params); ++i) {
-        ir_call_param(callinstr, params[i]);
-    }
+    for (auto &it : params)
+        ir_call_param(callinstr, it);
 
     *out = ir_call_value(callinstr);
     self->expression.outr = *out;
 
     codegen_output_type(self, *out);
 
-    vec_free(params);
     return true;
-error:
-    vec_free(params);
-    return false;
 }