]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
I added it for a reason, because I was smart. I forgot about it because of life :(
[xonotic/gmqcc.git] / parser.c
index 2f8867414984c8b7524cd13b99cc395f9c780d6b..7ba3782e3b8d8d445b5667a28b5ddf94fc0b9497 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1041,26 +1041,29 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
              * whole process ends up becoming:
              * (LHS | RHS) & (-1 - (LHS & RHS))
              */
-            #define TRY_TYPE(I)                                     \
-                if (exprs[0]->vtype != TYPE_FLOAT) {                \
-                    ast_type_to_string(exprs[0], ty1, sizeof(ty1)); \
-                    compile_error (                                 \
-                        ast_ctx(exprs[(I)]),                        \
-                        "invalid type for bit-xor in %s: %s",       \
-                        ty1,                                        \
-                        ((I) == 0)                                  \
-                            ? "left-hand-side of expression"        \
-                            : "right-hand-side of expression"       \
-                    );                                              \
-                    return false;                                   \
-                }
-            TRY_TYPE(0)
-            TRY_TYPE(1)
-            #undef TRY_TYPE
+            if (NotSameType(TYPE_FLOAT)) {
+                compile_error(ctx, "invalid types used in expression: cannot perform bit operations between types %s and %s",
+                              type_name[exprs[0]->vtype],
+                              type_name[exprs[1]->vtype]);
+                return false;
+            }
 
             if(CanConstFold(exprs[0], exprs[1])) {
                 out = (ast_expression*)parser_const_float(parser, (float)((qcint)(ConstF(0)) ^ ((qcint)(ConstF(1)))));
             } else {
+                ast_binary *expr = ast_binary_new(
+                    ctx,
+                    INSTR_SUB_F,
+                    (ast_expression*)parser_const_float_neg1(parser),
+                    (ast_expression*)ast_binary_new(
+                        ctx,
+                        INSTR_BITAND,
+                        exprs[0],
+                        exprs[1]
+                    )
+                );
+                expr->refs = AST_REF_NONE;
+                
                 out = (ast_expression*)
                     ast_binary_new(
                         ctx,
@@ -1071,17 +1074,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                             exprs[0],
                             exprs[1]
                         ),
-                        (ast_expression*)ast_binary_new(
-                            ctx,
-                            INSTR_SUB_F,
-                            (ast_expression*)parser_const_float_neg1(parser),
-                            (ast_expression*)ast_binary_new(
-                                ctx,
-                                INSTR_BITAND,
-                                exprs[0],
-                                exprs[1]
-                            )
-                        )
+                        (ast_expression*)expr
                     );
             }
             break;
@@ -1211,7 +1204,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             } else {
                 ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
 
-                eq->refs = (ast_binary_ref)false; /* references nothing */
+                eq->refs = AST_REF_NONE;
 
                     /* if (lt) { */
                 out = (ast_expression*)ast_ternary_new(ctx,