]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
NOT for entity, function and string - we're not constant-folding it for functions...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 14:24:47 +0000 (16:24 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 14:24:47 +0000 (16:24 +0200)
parser.c

index 121b39fc7faaa13ed656ea68badd329646647b52..4105ce75ce47daa91e0abc350bc1fc6a088d6640 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -481,6 +481,7 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
              (CanConstFold1(A) && CanConstFold1(B))
 #define ConstV(i) (asvalue[(i)]->constval.vvec)
 #define ConstF(i) (asvalue[(i)]->constval.vfloat)
+#define ConstS(i) (asvalue[(i)]->constval.vstring)
     switch (op->id)
     {
         default:
@@ -564,6 +565,19 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                     else
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[0]);
                     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:
                 parseerror(parser, "invalid types used in expression: cannot logically negate type %s",
                            type_name[exprs[0]->expression.vtype]);