From: Wolfgang (Blub) Bumiller Date: Sat, 18 Aug 2012 15:42:38 +0000 (+0200) Subject: Don't re-add defs which had a prototype X-Git-Tag: 0.1-rc1~195 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0e3bc87c757c31e4b77010d8f64642aa8656dbf1;p=xonotic%2Fgmqcc.git Don't re-add defs which had a prototype --- diff --git a/parser.c b/parser.c index b193566..798f2dd 100644 --- a/parser.c +++ b/parser.c @@ -1740,10 +1740,14 @@ static bool parser_variable(parser_t *parser, ast_block *localblock) varentry_t varent; ast_expression *olddecl; + bool hadproto; + int basetype = parser_token(parser)->constval.t; while (true) { + hadproto = false; + if (!parser_next(parser)) { /* skip basetype or comma */ parseerror(parser, "expected variable declaration"); return false; @@ -1842,8 +1846,9 @@ static bool parser_variable(parser_t *parser, ast_block *localblock) } ast_function_delete(func); ast_value_delete(fval); - var = proto; - func = var->constval.vfunc; + fval = proto; + func = proto->constval.vfunc; + hadproto = true; } else { @@ -1857,66 +1862,68 @@ static bool parser_variable(parser_t *parser, ast_block *localblock) var = fval; } - varent.name = util_strdup(var->name); - varent.var = (ast_expression*)var; - if (var->expression.vtype == TYPE_VECTOR) - { - size_t len = strlen(varent.name); - varentry_t vx, vy, vz; - vx.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 0); - vy.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 1); - vz.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 2); - vx.name = (char*)mem_a(len+3); - vy.name = (char*)mem_a(len+3); - vz.name = (char*)mem_a(len+3); - memcpy(vx.name, varent.name, len); - memcpy(vy.name, varent.name, len); - memcpy(vz.name, varent.name, len); - vx.name[len] = vy.name[len] = vz.name[len] = '_'; - vx.name[len+1] = 'x'; - vy.name[len+1] = 'y'; - vz.name[len+1] = 'z'; - vx.name[len+2] = vy.name[len+2] = vz.name[len+2] = 0; - - if (!localblock) { - (void)!parser_t_globals_add(parser, varent); - (void)!parser_t_globals_add(parser, vx); - (void)!parser_t_globals_add(parser, vy); - (void)!parser_t_globals_add(parser, vz); - } else { - (void)!parser_t_locals_add(parser, varent); - (void)!parser_t_locals_add(parser, vx); - (void)!parser_t_locals_add(parser, vy); - (void)!parser_t_locals_add(parser, vz); - if (!ast_block_locals_add(localblock, var) || - !ast_block_collect(localblock, vx.var) || - !ast_block_collect(localblock, vy.var) || - !ast_block_collect(localblock, vz.var)) + if (!hadproto) { + varent.name = util_strdup(var->name); + varent.var = (ast_expression*)var; + if (var->expression.vtype == TYPE_VECTOR) + { + size_t len = strlen(varent.name); + varentry_t vx, vy, vz; + vx.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 0); + vy.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 1); + vz.var = (ast_expression*)ast_member_new(var->expression.node.context, (ast_expression*)var, 2); + vx.name = (char*)mem_a(len+3); + vy.name = (char*)mem_a(len+3); + vz.name = (char*)mem_a(len+3); + memcpy(vx.name, varent.name, len); + memcpy(vy.name, varent.name, len); + memcpy(vz.name, varent.name, len); + vx.name[len] = vy.name[len] = vz.name[len] = '_'; + vx.name[len+1] = 'x'; + vy.name[len+1] = 'y'; + vz.name[len+1] = 'z'; + vx.name[len+2] = vy.name[len+2] = vz.name[len+2] = 0; + + if (!localblock) { + (void)!parser_t_globals_add(parser, varent); + (void)!parser_t_globals_add(parser, vx); + (void)!parser_t_globals_add(parser, vy); + (void)!parser_t_globals_add(parser, vz); + } else { + (void)!parser_t_locals_add(parser, varent); + (void)!parser_t_locals_add(parser, vx); + (void)!parser_t_locals_add(parser, vy); + (void)!parser_t_locals_add(parser, vz); + if (!ast_block_locals_add(localblock, var) || + !ast_block_collect(localblock, vx.var) || + !ast_block_collect(localblock, vy.var) || + !ast_block_collect(localblock, vz.var)) + { + parser_pop_local(parser); + parser_pop_local(parser); + parser_pop_local(parser); + parser_pop_local(parser); + ast_value_delete(var); + return false; + } + } + } + else + { + if ( (!localblock && !parser_t_globals_add(parser, varent)) || + ( localblock && !parser_t_locals_add(parser, varent)) ) + { + ast_value_delete(var); + return false; + } + if (localblock && !ast_block_locals_add(localblock, var)) { - parser_pop_local(parser); - parser_pop_local(parser); - parser_pop_local(parser); parser_pop_local(parser); ast_value_delete(var); return false; } } } - else - { - if ( (!localblock && !parser_t_globals_add(parser, varent)) || - ( localblock && !parser_t_locals_add(parser, varent)) ) - { - ast_value_delete(var); - return false; - } - if (localblock && !ast_block_locals_add(localblock, var)) - { - parser_pop_local(parser); - ast_value_delete(var); - return false; - } - } if (!parser_next(parser)) { ast_value_delete(var);