From: Dale Weiler Date: Thu, 15 Jan 2015 04:45:00 +0000 (-0500) Subject: More std::vector migration X-Git-Tag: xonotic-v0.8.2~52 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4de08db0e7b73a832d638acc03c6936395fd2095;p=xonotic%2Fgmqcc.git More std::vector migration --- diff --git a/ast.cpp b/ast.cpp index 8b74467..57a7cc2 100644 --- a/ast.cpp +++ b/ast.cpp @@ -978,7 +978,6 @@ ast_call* ast_call_new(lex_ctx_t ctx, ast_side_effects(self) = true; - self->params = NULL; self->func = funcexpr; self->va_count = NULL; @@ -989,10 +988,8 @@ ast_call* ast_call_new(lex_ctx_t ctx, void ast_call_delete(ast_call *self) { - size_t i; - for (i = 0; i < vec_size(self->params); ++i) - ast_unref(self->params[i]); - vec_free(self->params); + for (auto &it : self->params) + ast_unref(it); if (self->func) ast_unref(self->func); @@ -1054,7 +1051,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) size_t i; bool retval = true; const ast_expression *func = self->func; - size_t count = vec_size(self->params); + size_t count = self->params.size(); if (count > func->params.size()) count = func->params.size(); @@ -1078,7 +1075,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type) retval = false; } } - count = vec_size(self->params); + count = self->params.size(); if (count > func->params.size() && func->varparam) { for (; i < count; ++i) { if (ast_istype(self->params[i], ast_argpipe)) { @@ -3389,13 +3386,10 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value params = NULL; /* parameters */ - for (i = 0; i < vec_size(self->params); ++i) - { + for (auto &it : self->params) { ir_value *param; - ast_expression *expr = self->params[i]; - - cgen = expr->codegen; - if (!(*cgen)(expr, func, false, ¶m)) + cgen = it->codegen; + if (!(*cgen)(it, func, false, ¶m)) goto error; if (!param) goto error; diff --git a/ast.h b/ast.h index 843bb8c..3486d65 100644 --- a/ast.h +++ b/ast.h @@ -586,7 +586,7 @@ struct ast_call { ast_expression expression; ast_expression *func; - ast_expression **params; + std::vector params; ast_expression *va_count; }; ast_call* ast_call_new(lex_ctx_t ctx, diff --git a/intrin.cpp b/intrin.cpp index d8dbdc0..228fd78 100644 --- a/intrin.cpp +++ b/intrin.cpp @@ -63,10 +63,10 @@ static ast_expression *intrin_isfinite(intrin_t *intrin) { value->expression.params.push_back(x); /* = isnan(x); */ - vec_push(callisnan->params, (ast_expression*)x); + callisnan->params.push_back((ast_expression*)x); /* = isinf(x); */ - vec_push(callisinf->params, (ast_expression*)x); + callisinf->params.push_back((ast_expression*)x); /* return (! || ); */ block->exprs.push_back( @@ -195,7 +195,7 @@ static ast_expression *intrin_isnormal(intrin_t *intrin) { ast_function *func = intrin_value(intrin, &value, "isnormal", TYPE_FLOAT); value->expression.params.push_back(x); - vec_push(callisfinite->params, (ast_expression*)x); + callisfinite->params.push_back((ast_expression*)x); /* return */ body->exprs.push_back( @@ -262,7 +262,7 @@ static ast_expression *intrin_acosh(intrin_t *intrin) { value->expression.params.push_back(x); /* = sqrt((x * x) - 1); */ - vec_push(callsqrt->params, + callsqrt->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_SUB_F, @@ -277,7 +277,7 @@ static ast_expression *intrin_acosh(intrin_t *intrin) { ); /* = log(x + ); */ - vec_push(calllog->params, + calllog->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_ADD_F, @@ -315,7 +315,7 @@ static ast_expression *intrin_asinh(intrin_t *intrin) { value->expression.params.push_back(x); /* = sqrt((x * x) + 1); */ - vec_push(callsqrt->params, + callsqrt->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_ADD_F, @@ -330,7 +330,7 @@ static ast_expression *intrin_asinh(intrin_t *intrin) { ); /* = log(x + ); */ - vec_push(calllog->params, + calllog->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_ADD_F, @@ -367,7 +367,7 @@ static ast_expression *intrin_atanh(intrin_t *intrin) { value->expression.params.push_back(x); /* = log((1 + x) / (1 - x)); */ - vec_push(calllog->params, + calllog->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_DIV_F, @@ -529,8 +529,8 @@ static ast_expression *intrin_exp2(intrin_t *intrin) { value->expression.params.push_back(arg1); - vec_push(callpow->params, (ast_expression*)intrin->fold->imm_float[3]); - vec_push(callpow->params, (ast_expression*)arg1); + callpow->params.push_back((ast_expression*)intrin->fold->imm_float[3]); + callpow->params.push_back((ast_expression*)arg1); /* return */ body->exprs.push_back( @@ -561,7 +561,7 @@ static ast_expression *intrin_expm1(intrin_t *intrin) { value->expression.params.push_back(x); /* = exp(x); */ - vec_push(callexp->params, (ast_expression*)x); + callexp->params.push_back((ast_expression*)x); /* return - 1; */ body->exprs.push_back( @@ -712,8 +712,8 @@ static ast_expression *intrin_pow(intrin_t *intrin) { ); /* = pow(base, -exp) */ - vec_push(callpow1->params, (ast_expression*)base); - vec_push(callpow1->params, + callpow1->params.push_back((ast_expression*)base); + callpow1->params.push_back( (ast_expression*)ast_unary_new( intrin_ctx(intrin), VINSTR_NEG_F, @@ -748,8 +748,8 @@ static ast_expression *intrin_pow(intrin_t *intrin) { ); /* = pow(base, exp / 2) */ - vec_push(callpow2->params, (ast_expression*)base); - vec_push(callpow2->params, + callpow2->params.push_back((ast_expression*)base); + callpow2->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_DIV_F, @@ -806,7 +806,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) { /* * = sqrt(base) */ - vec_push(callsqrt1->params, (ast_expression*)base); + callsqrt1->params.push_back((ast_expression*)base); /* * low = 0.0f; @@ -918,7 +918,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) { /* * = sqrt(square) */ - vec_push(callsqrt2->params, (ast_expression*)square); + callsqrt2->params.push_back((ast_expression*)square); /* * = { @@ -974,7 +974,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) { /* * = fabs(mid - exp) */ - vec_push(callfabs->params, + callfabs->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_SUB_F, @@ -1086,7 +1086,7 @@ static ast_expression *intrin_mod(intrin_t *intrin) { ); /* floor(sign * div) */ - vec_push(call->params, + call->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_MUL_F, @@ -1881,8 +1881,8 @@ static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, fl value->expression.params.push_back(arg1); - vec_push(callln->params, (ast_expression*)arg1); - vec_push(callln->params, (ast_expression*)fold_constgen_float(intrin->fold, base, false)); + callln->params.push_back((ast_expression*)arg1); + callln->params.push_back((ast_expression*)fold_constgen_float(intrin->fold, base, false)); body->exprs.push_back( (ast_expression*)ast_return_new( @@ -1927,12 +1927,11 @@ static ast_expression *intrin_shift_variant(intrin_t *intrin, const char *name, value->expression.params.push_back(b); /* = pow(2, b) */ - vec_push(callpow->params, (ast_expression*)intrin->fold->imm_float[3]); - vec_push(callpow->params, (ast_expression*)b); + callpow->params.push_back((ast_expression*)intrin->fold->imm_float[3]); + callpow->params.push_back((ast_expression*)b); /* = floor(a [instr] ) */ - vec_push( - callfloor->params, + callfloor->params.push_back( (ast_expression*)ast_binary_new( intrin_ctx(intrin), instr, diff --git a/parser.cpp b/parser.cpp index 7296611..ed84b61 100644 --- a/parser.cpp +++ b/parser.cpp @@ -594,8 +594,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (!mod) return false; /* can return null for missing floor */ call = ast_call_new(parser_ctx(parser), mod); - vec_push(call->params, exprs[0]); - vec_push(call->params, exprs[1]); + call->params.push_back(exprs[0]); + call->params.push_back(exprs[1]); out = (ast_expression*)call; } @@ -661,8 +661,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (!(out = fold_op(parser->fold, op, exprs))) { ast_expression *shift = intrin_func(parser->intrin, (op->id == opid2('<','<')) ? "__builtin_lshift" : "__builtin_rshift"); ast_call *call = ast_call_new(parser_ctx(parser), shift); - vec_push(call->params, exprs[0]); - vec_push(call->params, exprs[1]); + call->params.push_back(exprs[0]); + call->params.push_back(exprs[1]); out = (ast_expression*)call; } break; @@ -679,8 +679,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if(!(out = fold_op(parser->fold, op, exprs))) { ast_expression *shift = intrin_func(parser->intrin, (op->id == opid3('<','<','=')) ? "__builtin_lshift" : "__builtin_rshift"); ast_call *call = ast_call_new(parser_ctx(parser), shift); - vec_push(call->params, exprs[0]); - vec_push(call->params, exprs[1]); + call->params.push_back(exprs[0]); + call->params.push_back(exprs[1]); out = (ast_expression*)ast_store_new( parser_ctx(parser), INSTR_STORE_F, @@ -757,8 +757,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (!(out = fold_op(parser->fold, op, exprs))) { ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser->intrin, "pow")); - vec_push(gencall->params, exprs[0]); - vec_push(gencall->params, exprs[1]); + gencall->params.push_back(exprs[0]); + gencall->params.push_back(exprs[1]); out = (ast_expression*)gencall; } break; @@ -1265,7 +1265,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy) } for (i = 0; i < paramcount; ++i) - vec_push(call->params, sy->out[fid+1 + i].out); + call->params.push_back(sy->out[fid+1 + i].out); vec_shrinkby(sy->out, paramcount); (void)!ast_call_check_types(call, parser->function->vtype->expression.varparam); if (parser->max_param_count < paramcount)