Fixing shadows in parser.c - moving generate_checksum over the static parser global

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-22 20:46:33 +01:00
parent b771695e0d
commit 07d5686a47

158
parser.c
View file

@ -167,7 +167,7 @@ static ast_value* parser_const_float(parser_t *parser, double d)
size_t i;
ast_value *out;
for (i = 0; i < vec_size(parser->imm_float); ++i) {
if (parser->imm_float[i]->constval.vfloat == d)
if ((double)(parser->imm_float[i]->constval.vfloat) == d)
return parser->imm_float[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_FLOAT);
@ -1826,7 +1826,7 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
/* case list! */
while (parser->tok != '}') {
ast_block *block;
ast_block *caseblock;
if (parser->tok != TOKEN_KEYWORD) {
ast_delete(switchnode);
@ -1869,13 +1869,13 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
parseerror(parser, "expected statements or case");
return false;
}
block = ast_block_new(parser_ctx(parser));
if (!block) {
caseblock = ast_block_new(parser_ctx(parser));
if (!caseblock) {
if (swcase.value) ast_unref(swcase.value);
ast_delete(switchnode);
return false;
}
swcase.code = (ast_expression*)block;
swcase.code = (ast_expression*)caseblock;
vec_push(switchnode->cases, swcase);
while (true) {
ast_expression *expr;
@ -1888,13 +1888,13 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
break;
}
}
if (!parse_statement(parser, block, &expr, true)) {
if (!parse_statement(parser, caseblock, &expr, true)) {
ast_delete(switchnode);
return false;
}
if (!expr)
continue;
vec_push(block->exprs, expr);
vec_push(caseblock->exprs, expr);
}
}
@ -3581,6 +3581,78 @@ static bool parser_global_statement(parser_t *parser)
return true;
}
static uint16_t progdefs_crc_sum(uint16_t old, const char *str)
{
return util_crc16(old, str, strlen(str));
}
static void progdefs_crc_file(const char *str)
{
/* write to progdefs.h here */
}
static uint16_t progdefs_crc_both(uint16_t old, const char *str)
{
old = progdefs_crc_sum(old, str);
progdefs_crc_file(str);
return old;
}
static void generate_checksum(parser_t *parser)
{
uint16_t crc = 0xFFFF;
size_t i;
crc = progdefs_crc_both(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{");
crc = progdefs_crc_sum(crc, "\tint\tpad[28];\n");
/*
progdefs_crc_file("\tint\tpad;\n");
progdefs_crc_file("\tint\tofs_return[3];\n");
progdefs_crc_file("\tint\tofs_parm0[3];\n");
progdefs_crc_file("\tint\tofs_parm1[3];\n");
progdefs_crc_file("\tint\tofs_parm2[3];\n");
progdefs_crc_file("\tint\tofs_parm3[3];\n");
progdefs_crc_file("\tint\tofs_parm4[3];\n");
progdefs_crc_file("\tint\tofs_parm5[3];\n");
progdefs_crc_file("\tint\tofs_parm6[3];\n");
progdefs_crc_file("\tint\tofs_parm7[3];\n");
*/
for (i = 0; i < parser->crc_globals; ++i) {
if (!ast_istype(parser->globals[i].var, ast_value))
continue;
switch (parser->globals[i].var->expression.vtype) {
case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
crc = progdefs_crc_both(crc, "\tint\t");
break;
}
crc = progdefs_crc_both(crc, parser->globals[i].name);
crc = progdefs_crc_both(crc, ";\n");
}
crc = progdefs_crc_both(crc, "} globalvars_t;\n\ntypedef struct\n{\n");
for (i = 0; i < parser->crc_fields; ++i) {
if (!ast_istype(parser->fields[i].var, ast_value))
continue;
switch (parser->fields[i].var->expression.next->expression.vtype) {
case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
crc = progdefs_crc_both(crc, "\tint\t");
break;
}
crc = progdefs_crc_both(crc, parser->fields[i].name);
crc = progdefs_crc_both(crc, ";\n");
}
crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
code_crc = crc;
}
static parser_t *parser;
bool parser_init()
@ -3708,78 +3780,6 @@ void parser_cleanup()
mem_d(parser);
}
static uint16_t progdefs_crc_sum(uint16_t old, const char *str)
{
return util_crc16(old, str, strlen(str));
}
static void progdefs_crc_file(const char *str)
{
/* write to progdefs.h here */
}
static uint16_t progdefs_crc_both(uint16_t old, const char *str)
{
old = progdefs_crc_sum(old, str);
progdefs_crc_file(str);
return old;
}
static void generate_checksum(parser_t *parser)
{
uint16_t crc = 0xFFFF;
size_t i;
crc = progdefs_crc_both(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{");
crc = progdefs_crc_sum(crc, "\tint\tpad[28];\n");
/*
progdefs_crc_file("\tint\tpad;\n");
progdefs_crc_file("\tint\tofs_return[3];\n");
progdefs_crc_file("\tint\tofs_parm0[3];\n");
progdefs_crc_file("\tint\tofs_parm1[3];\n");
progdefs_crc_file("\tint\tofs_parm2[3];\n");
progdefs_crc_file("\tint\tofs_parm3[3];\n");
progdefs_crc_file("\tint\tofs_parm4[3];\n");
progdefs_crc_file("\tint\tofs_parm5[3];\n");
progdefs_crc_file("\tint\tofs_parm6[3];\n");
progdefs_crc_file("\tint\tofs_parm7[3];\n");
*/
for (i = 0; i < parser->crc_globals; ++i) {
if (!ast_istype(parser->globals[i].var, ast_value))
continue;
switch (parser->globals[i].var->expression.vtype) {
case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
crc = progdefs_crc_both(crc, "\tint\t");
break;
}
crc = progdefs_crc_both(crc, parser->globals[i].name);
crc = progdefs_crc_both(crc, ";\n");
}
crc = progdefs_crc_both(crc, "} globalvars_t;\n\ntypedef struct\n{\n");
for (i = 0; i < parser->crc_fields; ++i) {
if (!ast_istype(parser->fields[i].var, ast_value))
continue;
switch (parser->fields[i].var->expression.next->expression.vtype) {
case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
crc = progdefs_crc_both(crc, "\tint\t");
break;
}
crc = progdefs_crc_both(crc, parser->fields[i].name);
crc = progdefs_crc_both(crc, ";\n");
}
crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
code_crc = crc;
}
bool parser_finish(const char *output)
{
size_t i;