NOT for entity, function and string - we're not constant-folding it for functions and entities right now

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-16 16:24:47 +02:00
parent 31a8cd80c8
commit 54dcbc22bf

View file

@ -481,6 +481,7 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
(CanConstFold1(A) && CanConstFold1(B)) (CanConstFold1(A) && CanConstFold1(B))
#define ConstV(i) (asvalue[(i)]->constval.vvec) #define ConstV(i) (asvalue[(i)]->constval.vvec)
#define ConstF(i) (asvalue[(i)]->constval.vfloat) #define ConstF(i) (asvalue[(i)]->constval.vfloat)
#define ConstS(i) (asvalue[(i)]->constval.vstring)
switch (op->id) switch (op->id)
{ {
default: default:
@ -564,6 +565,19 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
else else
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[0]); out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[0]);
break; break;
case TYPE_STRING:
if (CanConstFold1(exprs[0]))
out = (ast_expression*)parser_const_float(parser, !ConstS(0) || !*ConstS(0));
else
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_S, exprs[0]);
break;
/* we don't constant-fold NOT for these types */
case TYPE_ENTITY:
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_ENT, exprs[0]);
break;
case TYPE_FUNCTION:
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_FNC, exprs[0]);
break;
default: default:
parseerror(parser, "invalid types used in expression: cannot logically negate type %s", parseerror(parser, "invalid types used in expression: cannot logically negate type %s",
type_name[exprs[0]->expression.vtype]); type_name[exprs[0]->expression.vtype]);