From: Wolfgang (Blub) Bumiller Date: Tue, 18 Dec 2012 15:56:22 +0000 (+0100) Subject: -fperl-logic now doesn't allow logic ops with operands of different types, but theref... X-Git-Tag: 0.1.9~47 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2a61a65ce0a63955efd896ed0259006bd2bd65a3;p=xonotic%2Fgmqcc.git -fperl-logic now doesn't allow logic ops with operands of different types, but therefore uses the correct output type --- diff --git a/ast.c b/ast.c index 7c5d0b1..68a8eac 100644 --- a/ast.c +++ b/ast.c @@ -397,8 +397,13 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op, if (op >= INSTR_EQ_F && op <= INSTR_GT) self->expression.vtype = TYPE_FLOAT; - else if (op == INSTR_AND || op == INSTR_OR || - op == INSTR_BITAND || op == INSTR_BITOR) + else if (op == INSTR_AND || op == INSTR_OR) { + if (OPTS_FLAG(PERL_LOGIC)) + ast_type_adopt(self, right); + else + self->expression.vtype = TYPE_FLOAT; + } + else if (op == INSTR_BITAND || op == INSTR_BITOR) self->expression.vtype = TYPE_FLOAT; else if (op == INSTR_MUL_VF || op == INSTR_MUL_FV) self->expression.vtype = TYPE_VECTOR; diff --git a/parser.c b/parser.c index 4139770..e747626 100644 --- a/parser.c +++ b/parser.c @@ -841,7 +841,15 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) out = (ast_expression*)parser_const_float(parser, (generated_op == INSTR_OR ? (ConstF(0) || ConstF(1)) : (ConstF(0) && ConstF(1)))); else + { + if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) { + ast_type_to_string(exprs[0], ty1, sizeof(ty1)); + ast_type_to_string(exprs[1], ty2, sizeof(ty2)); + parseerror(parser, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2); + return false; + } out = (ast_expression*)ast_binary_new(ctx, generated_op, exprs[0], exprs[1]); + } break; case opid2('?',':'):