]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Prefix ++,--
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 23 Nov 2012 10:52:03 +0000 (11:52 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 23 Nov 2012 10:52:03 +0000 (11:52 +0100)
parser.c

index 8098110980495ed7d8313a45c74f1b54c569c832..54577ea1b817860016bce55e18fd17fba207e9ff 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -413,7 +413,7 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
     ast_expression *exprs[3];
     ast_block      *blocks[3];
     ast_value      *asvalue[3];
-    size_t i, assignop;
+    size_t i, assignop, addop;
     qcint  generated_op = 0;
 
     char ty1[1024];
@@ -878,6 +878,28 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
             }
             out = (ast_expression*)ast_store_new(ctx, assignop, exprs[0], exprs[1]);
             break;
+        case opid3('+','+','P'):
+        case opid3('-','-','P'):
+            /* prefix ++ */
+            if (exprs[0]->expression.vtype != TYPE_FLOAT) {
+                ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                parseerror(parser, "invalid type for prefix increment: %s", ty1);
+                return false;
+            }
+            if (op->id == opid3('+','+','P'))
+                addop = INSTR_ADD_F;
+            else
+                addop = INSTR_SUB_F;
+            if (ast_istype(exprs[0], ast_entfield)) {
+                out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop,
+                                                        exprs[0],
+                                                        (ast_expression*)parser_const_float(parser, 1));
+            } else {
+                out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop,
+                                                        exprs[0],
+                                                        (ast_expression*)parser_const_float(parser, 1));
+            }
+            break;
         case opid2('+','='):
         case opid2('-','='):
             if (exprs[0]->expression.vtype != exprs[1]->expression.vtype ||