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

diff --git a/ast.cpp b/ast.cpp
index 6db9befa22d489980bc8b82b4d5fd1e1268c7cec..2a6657df426476bcda50c790f7ea718e517143cd 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1177,7 +1177,6 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
 
     self->vtype  = vtype;
     self->name   = name ? util_strdup(name) : NULL;
-    self->blocks = NULL;
 
     self->labelcount = 0;
     self->builtin = 0;
@@ -1223,9 +1222,8 @@ void ast_function_delete(ast_function *self)
     for (i = 0; i < vec_size(self->static_names); ++i)
         mem_d(self->static_names[i]);
     vec_free(self->static_names);
-    for (i = 0; i < vec_size(self->blocks); ++i)
-        ast_delete(self->blocks[i]);
-    vec_free(self->blocks);
+    for (auto &it : self->blocks)
+        ast_delete(it);
     vec_free(self->breakblocks);
     vec_free(self->continueblocks);
     if (self->varargs)
@@ -1785,8 +1783,6 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
     ast_expression         *ec;
     ast_expression_codegen *cgen;
 
-    size_t    i;
-
     (void)ir;
 
     irf = self->ir_func;
@@ -1825,7 +1821,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
             return false;
     }
 
-    if (!vec_size(self->blocks)) {
+    if (self->blocks.empty()) {
         compile_error(ast_ctx(self), "function `%s` has no body", self->name);
         return false;
     }
@@ -1860,9 +1856,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         }
     }
 
-    for (i = 0; i < vec_size(self->blocks); ++i) {
-        cgen = self->blocks[i]->expression.codegen;
-        if (!(*cgen)((ast_expression*)self->blocks[i], self, false, &dummy))
+    for (auto &it : self->blocks) {
+        cgen = it->expression.codegen;
+        if (!(*cgen)((ast_expression*)it, self, false, &dummy))
             return false;
     }
 
diff --git a/ast.h b/ast.h
index 3938f2a15404e7c63e3ef722bf2168dfec72f2bd..e5b331b73712176667c1418afe03c2c835173874 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -649,7 +649,7 @@ struct ast_function
      * here to use in ast_function_label.
      */
     char         labelbuf[64];
-    ast_block* *blocks;
+    std::vector<ast_block*> blocks;
     ast_value *varargs;
     ast_value *argc;
     ast_value *fixedparams;
index 0f292d0b2f33cab27b7745f88f74b93e033af499..649a553163f3719b423c2cbda377229296461ea7 100644 (file)
--- a/ftepp.cpp
+++ b/ftepp.cpp
@@ -1926,7 +1926,6 @@ void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
     lex_ctx_t ctx = { "__builtin__", 0, 0 };
     ctx.file = source;
     macro = ppmacro_new(ctx, name);
-    /*vec_push(ftepp->macros, macro);*/
     util_htset(ftepp->macros, name, macro);
 }
 
index 13c382a588c0c289fdf462bed69f2de9a15263a1..643301e94df226987d69144a736e7c57199acec7 100644 (file)
@@ -85,7 +85,7 @@ static ast_expression *intrin_isfinite(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, block);
+    func->blocks.push_back(block);
     intrin_reg(intrin, value, func);
 
     return (ast_expression*)value;;
@@ -130,7 +130,7 @@ static ast_expression *intrin_isinf(intrin_t *intrin) {
     );
 
     value->expression.params.push_back(x);
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
 
     intrin_reg(intrin, value, func);
 
@@ -175,7 +175,7 @@ static ast_expression *intrin_isnan(intrin_t *intrin) {
     );
 
     value->expression.params.push_back(arg1);
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
 
     intrin_reg(intrin, value, func);
 
@@ -205,7 +205,7 @@ static ast_expression *intrin_isnormal(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -241,7 +241,7 @@ static ast_expression *intrin_signbit(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -294,7 +294,7 @@ static ast_expression *intrin_acosh(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -347,7 +347,7 @@ static ast_expression *intrin_asinh(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -396,7 +396,7 @@ static ast_expression *intrin_atanh(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -509,8 +509,7 @@ static ast_expression *intrin_exp(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
-
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -540,8 +539,7 @@ static ast_expression *intrin_exp2(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
-
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -576,7 +574,7 @@ static ast_expression *intrin_expm1(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -1021,8 +1019,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
     );
 
     /* } */
-    vec_push(func->blocks, body);
-
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -1118,9 +1115,8 @@ static ast_expression *intrin_mod(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1158,10 +1154,8 @@ static ast_expression *intrin_fabs(intrin_t *intrin) {
 
     value->expression.params.push_back(arg1);
 
-    vec_push(func->blocks, body);
-
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1232,9 +1226,8 @@ static ast_expression *intrin_epsilon(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1273,9 +1266,8 @@ static ast_expression *intrin_nan(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, block);
+    func->blocks.push_back(block);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1321,9 +1313,8 @@ static ast_expression *intrin_inf(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, block);
+    func->blocks.push_back(block);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1866,9 +1857,8 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
         )
     );
 
-    vec_push(func->blocks, block);
+    func->blocks.push_back(block);
     intrin_reg(intrin, value, func);
-
     return (ast_expression*)value;
 }
 
@@ -1891,7 +1881,7 @@ static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, fl
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
@@ -1948,7 +1938,7 @@ static ast_expression *intrin_shift_variant(intrin_t *intrin, const char *name,
         )
     );
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     intrin_reg(intrin, value, func);
     return (ast_expression*)value;
 }
index c2d3eb37ad105a64b640b7d1f6402c2ccd851ccf..b2d423ee5c18a706267e682c0c7f2d31f77c9fe5 100644 (file)
@@ -4096,7 +4096,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
         goto enderrfn;
     }
 
-    vec_push(func->blocks, block);
+    func->blocks.push_back(block);
 
     parser->function = old;
     if (!parser_leaveblock(parser))
@@ -4356,7 +4356,7 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con
         return false;
     }
 
-    vec_push(func->blocks, body);
+    func->blocks.push_back(body);
     *out = fval;
 
     parser->accessors.push_back(fval);