]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
operator &~=
[xonotic/gmqcc.git] / parser.c
index 67d72023fda748f2967f097af249729132947e21..fb13d2b09c5037b9009b38adeb2b26dc70bd852c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1032,6 +1032,27 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                                                     (op->id == opid2('&','=') ? INSTR_BITAND : INSTR_BITOR),
                                                     exprs[0], exprs[1]);
             break;
+        case opid3('&','~','='):
+            /* This is like: a &= ~(b);
+             * But QC has no bitwise-not, so we implement it as
+             * a -= a & (b);
+             */
+            if (NotSameType(TYPE_FLOAT)) {
+                ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                ast_type_to_string(exprs[1], ty2, sizeof(ty2));
+                parseerror(parser, "invalid types used in expression: %s and %s",
+                           ty1, ty2);
+                return false;
+            }
+            if (ast_istype(exprs[0], ast_entfield))
+                assignop = type_storep_instr[exprs[0]->expression.vtype];
+            else
+                assignop = type_store_instr[exprs[0]->expression.vtype];
+            out = (ast_expression*)ast_binary_new(ctx, INSTR_BITAND, exprs[0], exprs[1]);
+            if (!out)
+                return false;
+            out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_SUB_F, exprs[0], out);
+            break;
     }
 #undef NotSameType