Explorar o código

type promotion in progress

Vladislav Folts %!s(int64=11) %!d(string=hai) anos
pai
achega
ded7cd3de0
Modificáronse 2 ficheiros con 15 adicións e 6 borrados
  1. 4 3
      src/eberon/eberon_context.js
  2. 11 3
      test/test_unit_eberon.js

+ 4 - 3
src/eberon/eberon_context.js

@@ -579,19 +579,20 @@ var ProcOrMethodDecl = Context.ProcDecl.extend({
 var Term = Context.Term.extend({
     init: function EberonContext$Term(context){
         Context.Term.prototype.init.call(this, context);
+        this.__promotedTypes = [];
     },
     handleMessage: function(msg){
         if (msg instanceof PromoteTypeMsg){
             var promoted = msg.info;
             promoted.promoteType(msg.type);
-            this.__promoted = promoted;
+            this.__promotedTypes.push(promoted);
             return undefined;
         }
         return Context.Term.prototype.handleMessage.call(this, msg);
     },
     endParse: function(){
-        if (this.__promoted)
-            this.__promoted.resetPromotion();
+        for(var i = 0; i < this.__promotedTypes.length; ++i)
+            this.__promotedTypes[i].resetPromotion();
         return Context.Term.prototype.endParse.call(this);
     }
 });

+ 11 - 3
test/test_unit_eberon.js

@@ -396,11 +396,19 @@ exports.suite = {
                 "TYPE Base = RECORD END;"
                 + "Derived = RECORD (Base) flag: BOOLEAN END;"
                 + "PDerived = POINTER TO Derived;"
-                + "VAR pBase: POINTER TO Base;"
+                + "VAR pBase: POINTER TO Base; bVar: BOOLEAN;"
                ),
-        pass("PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) & b.flag); END p;"),
+        pass("PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) & b.flag); END p;",
+             "PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) & bVar & b.flag); END p;",
+             "PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) & (bVar OR b.flag)); END p;",
+             "PROCEDURE p(); BEGIN b1 <- pBase; b2 <- pBase; ASSERT((b1 IS PDerived) & (b2 IS PDerived) & b1.flag & b2.flag); END p;"),
         fail(["PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) OR b.flag); END p;",
-              "type 'Base' has no 'flag' field"])
+              "type 'Base' has no 'flag' field"],
+             ["PROCEDURE p(); BEGIN b <- pBase; ASSERT((b IS PDerived) OR bVar & b.flag); END p;",
+              "type 'Base' has no 'flag' field"],
+             ["PROCEDURE p(); BEGIN b1 <- pBase; b2 <- pBase; ASSERT(((b1 IS PDerived) & (b2 IS PDerived) OR bVar) & b1.flag); END p;",
+              "type 'Base' has no 'flag' field"]
+              )
         )
     }
 };