mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-21 02:40:56 +00:00
nil in ternary, and fix ternary to honor -fcorrect-logic/-ftrue/false-empty-strings
This commit is contained in:
parent
2cf4b4e56d
commit
a170154927
2 changed files with 6 additions and 3 deletions
5
ast.c
5
ast.c
|
@ -696,6 +696,7 @@ void ast_ifthen_delete(ast_ifthen *self)
|
|||
|
||||
ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
|
||||
{
|
||||
ast_expression *exprtype = ontrue;
|
||||
ast_instantiate(ast_ternary, ctx, ast_ternary_delete);
|
||||
/* This time NEITHER must be NULL */
|
||||
if (!ontrue || !onfalse) {
|
||||
|
@ -711,7 +712,9 @@ ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression *
|
|||
ast_propagate_effects(self, ontrue);
|
||||
ast_propagate_effects(self, onfalse);
|
||||
|
||||
if (!ast_type_adopt(self, ontrue)) {
|
||||
if (ontrue->expression.vtype == TYPE_NIL)
|
||||
exprtype = onfalse;
|
||||
if (!ast_type_adopt(self, exprtype)) {
|
||||
ast_ternary_delete(self);
|
||||
return NULL;
|
||||
}
|
||||
|
|
4
parser.c
4
parser.c
|
@ -983,14 +983,14 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
|||
return false;
|
||||
}
|
||||
vec_pop(parser->pot);
|
||||
if (exprs[1]->expression.vtype != exprs[2]->expression.vtype) {
|
||||
if (!ast_compare_type(exprs[1], exprs[2])) {
|
||||
ast_type_to_string(exprs[1], ty1, sizeof(ty1));
|
||||
ast_type_to_string(exprs[2], ty2, sizeof(ty2));
|
||||
parseerror(parser, "operands of ternary expression must have the same type, got %s and %s", ty1, ty2);
|
||||
return false;
|
||||
}
|
||||
if (CanConstFold1(exprs[0]))
|
||||
out = (ConstF(0) ? exprs[1] : exprs[2]);
|
||||
out = (immediate_is_true(ctx, asvalue[0]) ? exprs[1] : exprs[2]);
|
||||
else
|
||||
out = (ast_expression*)ast_ternary_new(ctx, exprs[0], exprs[1], exprs[2]);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue