Prechádzať zdrojové kódy

INC/DEC work for non-const second argumnet (as in a new report 07/13).

Vladislav Folts 11 rokov pred
rodič
commit
86b986c14a
4 zmenil súbory, kde vykonal 14 pridanie a 7 odobranie
  1. 6 3
      src/procedure.js
  2. 2 0
      test/expected/inc_dec.js
  3. 2 0
      test/input/inc_dec.ob
  4. 4 4
      test/test_unit.js

+ 6 - 3
src/procedure.js

@@ -225,10 +225,13 @@ function incImpl(name, unary, op){
             return unary + x.code();
 
         var value = y.constValue();
+        var valueCode;
         if (value === undefined)
-            throw new Errors.Error("constant expected as second argument of " + name);
-        var comment = y.isTerm() ? "" : "/*" + y.code() + "*/";
-        var valueCode = value + comment;
+            valueCode = y.code();
+        else {
+            var comment = y.isTerm() ? "" : "/*" + y.code() + "*/";
+            valueCode = value + comment;
+        }
         return op(x.code(), valueCode);
     }
     var CallGenerator = TwoArgToOperatorProcCallGenerator.extend({

+ 2 - 0
test/expected/inc_dec.js

@@ -6,9 +6,11 @@ i += 2;
 i += 15/*3 * 5 | 0*/;
 i += 10/*ic*/;
 i += -2147483648/*2147483647 + 1 | 0*/;
+i += i + 1 | 0;
 --i;
 i -= 2;
 i -= 15/*3 * 5 | 0*/;
 i -= 10/*ic*/;
 i -= -2/*4294967295 * 2 | 0*/;
+i -= i * 2 | 0;
 }();

+ 2 - 0
test/input/inc_dec.ob

@@ -9,10 +9,12 @@ BEGIN
 	INC(i, 3 * 5);
 	INC(i, ic);
 	INC(i, 07FFFFFFFH + 1 );
+	INC(i, i + 1);
 
 	DEC(i);
 	DEC(i, 2);
 	DEC(i, 3 * 5);
 	DEC(i, ic);
 	DEC(i, 0FFFFFFFFH * 2);
+	DEC(i, i * 2);
 END m.

+ 4 - 4
test/test_unit.js

@@ -612,9 +612,9 @@ var testSuite = {
 "INC": testWithContext(
     context(Grammar.statement, "VAR i: INTEGER;"),
     pass("INC(i)",
-         "INC(i, 3)"),
+         "INC(i, 3)",
+         "INC(i, i)"),
     fail(["INC(i + i)", "expression cannot be used as VAR parameter"],
-         ["INC(i, i)", "constant expected as second argument of INC"],
          ["INC()", "at least 1 argument expected, got 0"],
          ["INC(i, 1, 2)", "at most 2 arguments expected, got 3"]
          )
@@ -622,9 +622,9 @@ var testSuite = {
 "DEC": testWithContext(
     context(Grammar.statement, "VAR i: INTEGER;"),
     pass("DEC(i)",
-         "DEC(i, 3)"),
+         "DEC(i, 3)",
+         "DEC(i, i)"),
     fail(["DEC(i + i)", "expression cannot be used as VAR parameter"],
-         ["DEC(i, i)", "constant expected as second argument of DEC"],
          ["DEC()", "at least 1 argument expected, got 0"],
          ["DEC(i, 1, 2)", "at most 2 arguments expected, got 3"]
          )