]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
-fperl-logic now doesn't allow logic ops with operands of different types, but theref...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 18 Dec 2012 15:56:22 +0000 (16:56 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 18 Dec 2012 15:56:22 +0000 (16:56 +0100)
ast.c
parser.c

diff --git a/ast.c b/ast.c
index 7c5d0b15f031546e7ce4a0bd78cda1e1c789fc9e..68a8eaccf0f6b7ef6c7303b56bbb2e70218aaba1 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -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;
index 4139770636084781a3a7eda7bf9b2f594ab7a8e7..e747626724394206a780bc040bd12b486e05985b 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -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('?',':'):