mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-22 19:31:03 +00:00
Making logical 'and' and 'or' use NOT_ in -fcorrect-logic for both operands normally, but only for the first with -fperl-logic
This commit is contained in:
parent
d5cfe74d5d
commit
b85441d6af
1 changed files with 21 additions and 0 deletions
21
parser.c
21
parser.c
|
@ -838,8 +838,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (CanConstFold(exprs[0], exprs[1]))
|
if (CanConstFold(exprs[0], exprs[1]))
|
||||||
|
{
|
||||||
out = (ast_expression*)parser_const_float(parser,
|
out = (ast_expression*)parser_const_float(parser,
|
||||||
(generated_op == INSTR_OR ? (ConstF(0) || ConstF(1)) : (ConstF(0) && ConstF(1))));
|
(generated_op == INSTR_OR ? (ConstF(0) || ConstF(1)) : (ConstF(0) && ConstF(1))));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
|
if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
|
||||||
|
@ -848,6 +850,25 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
||||||
parseerror(parser, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
|
parseerror(parser, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (OPTS_FLAG(CORRECT_LOGIC)) {
|
||||||
|
/* non-floats need to be NOTed */
|
||||||
|
for (i = 0; i < 2; ++i) {
|
||||||
|
if (exprs[i]->expression.vtype != TYPE_FLOAT) {
|
||||||
|
if (type_not_instr[exprs[i]->expression.vtype] == AINSTR_END) {
|
||||||
|
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 -fcorrect-logic: %s and %s", ty1, ty2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
out = (ast_expression*)ast_unary_new(ctx, type_not_instr[exprs[i]->expression.vtype], exprs[i]);
|
||||||
|
if (!out)
|
||||||
|
break;
|
||||||
|
exprs[i] = out; out = NULL;
|
||||||
|
}
|
||||||
|
if (OPTS_FLAG(PERL_LOGIC))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
out = (ast_expression*)ast_binary_new(ctx, generated_op, exprs[0], exprs[1]);
|
out = (ast_expression*)ast_binary_new(ctx, generated_op, exprs[0], exprs[1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue