X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=parser.c;h=15bb921fb30d9c67039cb1a710e1e7cd3b1b54a8;hp=e3b4d9abd12ba36b418a786d16089f9d477885ad;hb=90824c209329d73b9bdad86177348d18562891ab;hpb=35f9aef7295ed20c58aa812e106be921fa7e8acd diff --git a/parser.c b/parser.c index e3b4d9a..15bb921 100644 --- a/parser.c +++ b/parser.c @@ -287,10 +287,18 @@ static bool check_write_to(lex_ctx_t ctx, ast_expression *expr) if (ast_istype(expr, ast_value)) { ast_value *val = (ast_value*)expr; if (val->cvq == CV_CONST) { - if (val->name[0] == '#') + if (val->name[0] == '#') { compile_error(ctx, "invalid assignment to a literal constant"); - else + return false; + } + /* + * To work around quakeworld we must elide the error and make it + * a warning instead. + */ + if (OPTS_OPTION_U32(OPTION_STANDARD) != COMPILER_QCC) compile_error(ctx, "assignment to constant `%s`", val->name); + else + (void)!compile_warning(ctx, WARN_CONST_OVERWRITE, "assignment to constant `%s`", val->name); return false; } } @@ -457,24 +465,15 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) out = exprs[0]; break; case opid2('-','P'): - if (!(out = fold_op(parser->fold, op, exprs))) { - switch (exprs[0]->vtype) { - case TYPE_FLOAT: - out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_F, - (ast_expression*)parser->fold->imm_float[0], - exprs[0]); - break; - case TYPE_VECTOR: - out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_V, - (ast_expression*)parser->fold->imm_vector[0], - exprs[0]); - break; - default: - compile_error(ctx, "invalid types used in expression: cannot negate type %s", + if ((out = fold_op(parser->fold, op, exprs))) + break; + if (exprs[0]->vtype != TYPE_FLOAT && + exprs[0]->vtype != TYPE_VECTOR) { + compile_error(ctx, "invalid types used in unary expression: cannot negate type %s", type_name[exprs[0]->vtype]); - return false; - } + return false; } + out = (ast_expression*)ast_unary_new(ctx, (VINSTR_NEG_F-TYPE_FLOAT) + exprs[0]->vtype, exprs[0]); break; case opid2('!','P'): @@ -3291,7 +3290,13 @@ static bool parse_pragma_do(parser_t *parser) else { (void)!parsewarning(parser, WARN_UNKNOWN_PRAGMAS, "ignoring #pragma %s", parser_tokval(parser)); - return false; + + /* skip to eol */ + while (!parse_eol(parser)) { + parser_next(parser); + } + + return true; } return true; @@ -5294,7 +5299,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield return false; } - if (var->expression.vtype != find->vtype) { + if (!ast_compare_type((ast_expression*)var, find)) { char ty1[1024]; char ty2[1024];