]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Use std::vector for ast switch cases
authorDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 19:19:07 +0000 (14:19 -0500)
committerDale Weiler <weilercdale@gmail.com>
Thu, 15 Jan 2015 19:19:07 +0000 (14:19 -0500)
ast.cpp
ast.h
parser.cpp

diff --git a/ast.cpp b/ast.cpp
index 2a6657df426476bcda50c790f7ea718e517143cd..efff1116d0d1f00afabeb97e1a925d4b9e6bafbc 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -864,7 +864,6 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op)
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen);
 
     self->operand = op;
-    self->cases   = NULL;
 
     ast_propagate_effects(self, op);
 
@@ -873,15 +872,13 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op)
 
 void ast_switch_delete(ast_switch *self)
 {
-    size_t i;
     ast_unref(self->operand);
 
-    for (i = 0; i < vec_size(self->cases); ++i) {
-        if (self->cases[i].value)
-            ast_unref(self->cases[i].value);
-        ast_unref(self->cases[i].code);
+    for (auto &it : self->cases) {
+        if (it.value)
+            ast_unref(it.value);
+        ast_unref(it.code);
     }
-    vec_free(self->cases);
 
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
@@ -3078,7 +3075,6 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     ir_block *bout      = NULL;
     ir_block *bfall     = NULL;
     size_t    bout_id;
-    size_t    c;
 
     char      typestr[1024];
     uint16_t  cmpinstr;
@@ -3101,7 +3097,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     if (!(*cgen)((ast_expression*)(self->operand), func, false, &irop))
         return false;
 
-    if (!vec_size(self->cases))
+    if (self->cases.empty())
         return true;
 
     cmpinstr = type_eq_instr[irop->vtype];
@@ -3120,12 +3116,12 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     vec_push(func->breakblocks, bout);
 
     /* Now create all cases */
-    for (c = 0; c < vec_size(self->cases); ++c) {
+    for (auto &it : self->cases) {
         ir_value *cond, *val;
         ir_block *bcase, *bnot;
         size_t bnot_id;
 
-        ast_switch_case *swcase = &self->cases[c];
+        ast_switch_case *swcase = &it;
 
         if (swcase->value) {
             /* A regular case */
diff --git a/ast.h b/ast.h
index e5b331b73712176667c1418afe03c2c835173874..d101a21b05b0f5172e11218f330af4a935e531ac 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -522,7 +522,7 @@ struct ast_switch
 {
     ast_expression expression;
     ast_expression *operand;
-    ast_switch_case *cases;
+    std::vector<ast_switch_case> cases;
 };
 
 ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);
index b2d423ee5c18a706267e682c0c7f2d31f77c9fe5..86535fbf0f5d15179eca79fec9b06d06538a0598 100644 (file)
@@ -3142,7 +3142,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression *
             return false;
         }
         swcase.code = (ast_expression*)caseblock;
-        vec_push(switchnode->cases, swcase);
+        switchnode->cases.push_back(swcase);
         while (true) {
             ast_expression *expr;
             if (parser->tok == '}')