-fperl-logic now doesn't allow logic ops with operands of different types, but therefore uses the correct output type

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-12-18 16:56:22 +01:00
parent 9b9fbb6e3b
commit 2a61a65ce0
2 changed files with 15 additions and 2 deletions

9
ast.c
View file

@ -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;

View file

@ -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('?',':'):