Ver Fonte

type promotion in WHILE

Vladislav Folts há 11 anos atrás
pai
commit
29b953c608
3 ficheiros alterados com 37 adições e 24 exclusões
  1. BIN
      bin/compiled.zip
  2. 24 22
      src/eberon/eberon_context.js
  3. 13 2
      test/test_unit_eberon.js

BIN
bin/compiled.zip


+ 24 - 22
src/eberon/eberon_context.js

@@ -789,20 +789,6 @@ var Expression = Context.Expression.extend({
     }
 });
 
-var While = Context.While.extend({
-    init: function EberonContext$While(context){
-        Context.While.prototype.init.call(this, context);
-        var scope = EberonScope.makeOperator(
-            this.parent().currentScope(),
-            this.language().stdSymbols);
-        this.pushScope(scope);
-    },
-    endParse: function(){
-        this.popScope();
-        Context.While.prototype.endParse.call(this);
-    }
-});
-
 //var id = 0;
 
 var TypePromotionHandler = Class.extend({
@@ -864,6 +850,30 @@ var TypePromotionHandler = Class.extend({
     }
 });
 
+var While = Context.While.extend({
+    init: function EberonContext$While(context){
+        Context.While.prototype.init.call(this, context);
+
+        this.__typePromotion = new TypePromotionHandler();
+
+        var scope = EberonScope.makeOperator(
+            this.parent().currentScope(),
+            this.language().stdSymbols);
+        this.pushScope(scope);
+    },
+    handleMessage: function(msg){
+        if (this.__typePromotion.handleMessage(msg))
+            return;
+
+        return Context.While.prototype.handleMessage.call(this, msg);
+    },
+    endParse: function(){
+        this.popScope();
+        this.__typePromotion.reset();
+        Context.While.prototype.endParse.call(this);
+    }
+});
+
 var If = Context.If.extend({
     init: function EberonContext$If(context){
         Context.If.prototype.init.call(this, context);
@@ -873,14 +883,6 @@ var If = Context.If.extend({
         this.__newScope();
     },
     handleMessage: function(msg){
-        /*
-        if (msg instanceof TransferPromotedTypesMsg){
-            log("suppress transfer");
-            resetPromotedTypes(msg.types);
-            return;
-        }
-        */
-
         if (this.__typePromotion.handleMessage(msg))
             return;
 

+ 13 - 2
test/test_unit_eberon.js

@@ -480,7 +480,7 @@ exports.suite = {
              "~(b IS PDerived) OR b.flag = b.flag"
             )
         ),
-    "type promotion in condition": testWithContext(
+    "type promotion in IF": testWithContext(
         typePromotion.context,
         typePromotion.passConditions(
             "IF b IS PDerived THEN b.flag := FALSE; END;",
@@ -502,7 +502,7 @@ exports.suite = {
              // "invalid type test: 'Derived' is not an extension of 'Derived'"]
              )
         ),
-    "invert type promotion in condition": testWithContext(
+    "invert type promotion in IF": testWithContext(
         typePromotion.context,
         typePromotion.passConditions(
             "IF ~(b IS PDerived) THEN ELSE b.flag := FALSE; END;",
@@ -517,6 +517,17 @@ exports.suite = {
             "IF ~(b IS PDerived) & bVar THEN ELSE b.flag := FALSE; END; END p;",
             "IF ~(b IS PDerived) THEN ELSIF ~(b2 IS PDerived) THEN b2.flag := FALSE; END;"
             )
+        ),
+    "type promotion in WHILE": testWithContext(
+        typePromotion.context,
+        typePromotion.passConditions(
+            "WHILE (b IS PDerived) & b.flag DO END;",
+            "WHILE ~(b IS PDerived) OR b.flag DO END;",
+            "WHILE b IS PDerived DO b.flag := FALSE; END;"
+            ),
+        typePromotion.failConditions(
+            "WHILE b IS PDerived DO END; b.flag := FALSE;"
+            )
         )
     }
 };