]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Use std::vector for static_names
authorDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 20:15:35 +0000 (15:15 -0500)
committerDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 20:15:35 +0000 (15:15 -0500)
ast.cpp
ast.h
parser.cpp

diff --git a/ast.cpp b/ast.cpp
index 55e444054ea445513b5901768edb056f1f55b5d4..85244f48d7caa2d4a9c23341eab95be287e851bd 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1188,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;
@@ -1201,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) {
@@ -1213,9 +1210,8 @@ 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);
     if (self->varargs)
@@ -3339,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;
 
@@ -3362,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 */
@@ -3393,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;
 }
diff --git a/ast.h b/ast.h
index 647fd1b6b41ede7e4f4a67b7a632fa4ae6e72582..162704783ff7163d92c97c090db84d6f45cfc446 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -631,7 +631,7 @@ struct ast_function
     int builtin;
 
     /* list of used-up names for statics without the count suffix */
-    char **static_names;
+    std::vector<char*> static_names;
     /* number of static variables, by convention this includes the
      * ones without the count-suffix - remember this when dealing
      * with savegames. uint instead of size_t as %zu in printf is
index ac14a4d619dba6c2c85c25e97f4aa8a54ae7fb23..fd7bad95c4be8deb7468228ff489a7a70f111fe8 100644 (file)
@@ -5435,7 +5435,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                      * counter value.
                      * The counter is incremented either way.
                      */
-                    sn_size = vec_size(parser->function->static_names);
+                    sn_size = parser->function->static_names.size();
                     for (sn = 0; sn != sn_size; ++sn) {
                         if (strcmp(parser->function->static_names[sn], var->name) == 0)
                             break;
@@ -5447,7 +5447,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         mem_d(num);
                     }
                     else
-                        vec_push(parser->function->static_names, util_strdup(var->name));
+                        parser->function->static_names.push_back(util_strdup(var->name));
                     parser->function->static_count++;
                     ast_value_set_name(var, defname);