Browse Source

fix export non-RECORD types (Issue #14)

Vladislav Folts 11 years ago
parent
commit
f1c1f515ca
3 changed files with 32 additions and 16 deletions
  1. 17 5
      src/context.js
  2. 0 9
      src/scope.js
  3. 15 2
      test/test_unit.js

+ 17 - 5
src/context.js

@@ -1625,15 +1625,27 @@ exports.TypeCast = ChainedContext.extend({
     }
     }
 });
 });
 
 
+function genExport(symbol){
+    if (symbol.isVariable())
+        return "function(){return " + symbol.id() + ";}";
+    if (symbol.isType()){
+        var type = symbol.info().type();
+        if (!(type instanceof Type.Record || type instanceof Type.Pointer))
+            return undefined;
+    }
+    return symbol.id();
+}
+
 function genExports(exports, gen){
 function genExports(exports, gen){
     var result = "";
     var result = "";
     for(var access in exports){
     for(var access in exports){
         var e = exports[access];
         var e = exports[access];
-        if (e.isVariable())
-            access = "function(){return " + access + ";}";
-        if (result.length)
-            result += ",\n";
-        result += "\t" + e.id() + ": " + access;
+        var code = genExport(e);
+        if (code){
+            if (result.length)
+                result += ",\n";
+            result += "\t" + e.id() + ": " + code;
+        }
     }
     }
     if (!result.length)
     if (!result.length)
         return;
         return;

+ 0 - 9
src/scope.js

@@ -106,15 +106,6 @@ var Module = Scope.extend({
         if (exported)
         if (exported)
             this.__exports[symbol.id()] = symbol;
             this.__exports[symbol.id()] = symbol;
     },
     },
-    resolve: function(symbol){
-        var id = symbol.id();
-        var exported = this.__exports[id];
-        if (exported)
-            // remove non-record types from generated exports
-            if (symbol.isType() && !(symbol.info().type() instanceof Type.Record))
-                delete this.__exports[id];
-        Scope.prototype.resolve.call(this, symbol);
-    },
     exports: function(){return this.__exports;}
     exports: function(){return this.__exports;}
 });
 });
 
 

+ 15 - 2
test/test_unit.js

@@ -136,11 +136,12 @@ function testWithGrammar(grammar, pass, fail){
 function testWithModule(src, pass, fail){
 function testWithModule(src, pass, fail){
     return testWithSetup(
     return testWithSetup(
         function(){
         function(){
-            var imported = oc.compileModule(new Stream(src));
+            var rtl = new RTL();
+            var imported = oc.compileModule(new Stream(src), rtl);
             var module = imported.symbol().info();
             var module = imported.symbol().info();
             return setup(function(s){
             return setup(function(s){
                 oc.compileModule(new Stream(s),
                 oc.compileModule(new Stream(s),
-                                 undefined,
+                                 rtl,
                                  function(){return module;});
                                  function(){return module;});
             });},
             });},
         pass,
         pass,
@@ -1212,6 +1213,18 @@ var testSuite = {
          ["MODULE m; IMPORT test; PROCEDURE p(VAR i: INTEGER); END p; BEGIN p(test.i); END m.",
          ["MODULE m; IMPORT test; PROCEDURE p(VAR i: INTEGER); END p; BEGIN p(test.i); END m.",
           "imported variable cannot be used as VAR parameter"]
           "imported variable cannot be used as VAR parameter"]
         )
         )
+    ),
+"import pointer type": testWithModule(
+    "MODULE test; TYPE TP* = POINTER TO RECORD END; END test.",
+    pass("MODULE m; IMPORT test; VAR p: test.TP; END m.")
+    ),
+"import array type": testWithModule(
+    "MODULE test; TYPE TA* = ARRAY 3 OF INTEGER; END test.",
+    pass("MODULE m; IMPORT test; VAR a: test.TA; END m.")
+    ),
+"import procedure type": testWithModule(
+    "MODULE test; TYPE TProc* = PROCEDURE; END test.",
+    pass("MODULE m; IMPORT test; VAR proc: test.TProc; END m.")
     )
     )
 };
 };