Selaa lähdekoodia

fix type promotion for WHILE

Vladislav Folts 11 vuotta sitten
vanhempi
commit
f3d6032c20
3 muutettua tiedostoa jossa 28 lisäystä ja 21 poistoa
  1. BIN
      bin/compiled.zip
  2. 25 20
      src/eberon/eberon_context.js
  3. 3 1
      test/test_unit_eberon.js

BIN
bin/compiled.zip


+ 25 - 20
src/eberon/eberon_context.js

@@ -854,39 +854,53 @@ var OperatorScopes = Class.extend({
     init: function EberonContext$OperatorScopes(context){
         this.__context = context;
         this.__scope = undefined;
-        this.next();
+
+        this.__typePromotion = new TypePromotionHandler();
+        this.__typePromotions = [this.__typePromotion];
+
+        this.alternate();
     },
-    next: function(){
+    handleMessage: function(msg){
+        return this.__typePromotion.handleMessage(msg);
+    },
+    alternate: function(){
         if (this.__scope)
             this.__context.popScope();
         this.__scope = EberonScope.makeOperator(
             this.__context.parent().currentScope(),
             this.__context.language().stdSymbols);
         this.__context.pushScope(this.__scope);
+
+        this.__typePromotion.invert();
+        this.__typePromotion = new TypePromotionHandler();
+        this.__typePromotions.push(this.__typePromotion);
     },
-    reset: function(){this.__context.popScope();}
+    reset: function(){
+        this.__context.popScope();
+
+        for(var i = 0; i < this.__typePromotions.length; ++i){
+            this.__typePromotions[i].reset();
+        }
+    }
 });
 
 var While = Context.While.extend({
     init: function EberonContext$While(context){
         Context.While.prototype.init.call(this, context);
-
-        this.__typePromotion = new TypePromotionHandler();
         this.__scopes = new OperatorScopes(this);
     },
     handleLiteral: function(s){
         Context.While.prototype.handleLiteral.call(this, s);
         if (s == "ELSIF")
-            this.__scopes.next();
+            this.__scopes.alternate();
     },
     handleMessage: function(msg){
-        if (this.__typePromotion.handleMessage(msg))
+        if (this.__scopes.handleMessage(msg))
             return;
 
         return Context.While.prototype.handleMessage.call(this, msg);
     },
     endParse: function(){
-        this.__typePromotion.reset();
         this.__scopes.reset();
         Context.While.prototype.endParse.call(this);
     }
@@ -895,29 +909,20 @@ var While = Context.While.extend({
 var If = Context.If.extend({
     init: function EberonContext$If(context){
         Context.If.prototype.init.call(this, context);
-        this.__typePromotion = new TypePromotionHandler();
-        this.__typePromotions = [this.__typePromotion];
         this.__scopes = new OperatorScopes(this);
     },
     handleMessage: function(msg){
-        if (this.__typePromotion.handleMessage(msg))
+        if (this.__scopes.handleMessage(msg))
             return;
 
         return Context.If.prototype.handleMessage.call(this, msg);
     },
     handleLiteral: function(s){
         Context.If.prototype.handleLiteral.call(this, s);
-        if (s == "ELSIF" || s == "ELSE"){
-            this.__typePromotion.invert();
-            this.__typePromotion = new TypePromotionHandler();
-            this.__typePromotions.push(this.__typePromotion);
-            this.__scopes.next();
-        }
+        if (s == "ELSIF" || s == "ELSE")
+            this.__scopes.alternate();
     },
     endParse: function(){
-        for(var i = 0; i < this.__typePromotions.length; ++i){
-            this.__typePromotions[i].reset();
-        }
         this.__scopes.reset();
         Context.If.prototype.endParse.call(this);
     }

+ 3 - 1
test/test_unit_eberon.js

@@ -524,7 +524,9 @@ exports.suite = {
         temporaryValues.passStatements(
             "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;"
+            "WHILE b IS PDerived DO b.flag := FALSE; END;",
+            "WHILE ~(b IS PDerived) DO ELSIF b.flag DO END;",
+            "WHILE ~(b IS PDerived) DO ELSIF bVar DO b.flag := FALSE; END;"
             ),
         temporaryValues.failStatements(
             "WHILE b IS PDerived DO END; b.flag := FALSE;"