]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7776) Fixed module export for javaImports 82/1482/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 20 Feb 2018 08:53:57 +0000 (10:53 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 20 Feb 2018 09:08:01 +0000 (11:08 +0200)
Change-Id: I50a5f635445d1b1d1df9dfc3ea0195f0859f86c0

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java
tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExportBug1.scl [new file with mode: 0644]

index ee21ef641a645ea5eae7096f62ece738fa6957fb..abdabf5ac7e3cc55b0fb875e71dfc038d1a1f9b5 100644 (file)
@@ -150,6 +150,8 @@ public class Elaboration {
     ArrayList<StandardTypeConstructor> dataTypes = new ArrayList<StandardTypeConstructor>();
     THashMap<String, ClassRef> classRefs = new THashMap<String, ClassRef>();
     THashMap<String, BranchPoint[]> branchPoints; 
+
+    THashMap<String, EVar> exportMap = null;
     
     public Elaboration(CompilationContext compilationContext, CompilationTimer timer, EnvironmentFactory localEnvironmentFactory,
             String moduleName, ModuleHeader moduleHeader, ArrayList<ImportDeclaration> importsAst,
@@ -713,6 +715,8 @@ public class Elaboration {
                         isPrivate = true;
                     }
             }
+            if(exportMap != null)
+                isPrivate = exportMap.remove(name) == null;
             
             Type type = createTypeTranslationContext().toType(javaMethod.type);
 
@@ -1216,14 +1220,6 @@ public class Elaboration {
                     typeMap.put(name.name, valueTypeAst);
             }
         
-        THashMap<String, EVar> exportMap = null;
-        if(moduleHeader != null && moduleHeader.export != null) {
-            exportMap = new THashMap<String, EVar>();
-            for(EVar export : moduleHeader.export)
-                if(exportMap.put(export.name, export) != null)
-                    errorLog.log(export.location, "The symbol " + export.name + " is exported multiple times.");
-        }
-        
         for(String name : valueDefinitionsAst.getValueNames()) {
             ArrayList<DValueAst> defs = valueDefinitionsAst.getDefinition(name);
             if(defs.size() != 1 || !(defs.get(0).value instanceof EPreCHRRulesetConstructor))
@@ -1267,9 +1263,6 @@ public class Elaboration {
                 throw e;
             }
         }
-        if(exportMap != null)
-            for(EVar export : exportMap.values())
-                errorLog.log(export.location, "The symbol " + export.name + " is not defined in the module.");
         for(String name : relationDefinitionsAst.getRelationNames()) {
             ArrayList<DRelationAst> definitions = relationDefinitionsAst.getDefinition(name);
             if(definitions.size() > 1) {
@@ -1373,4 +1366,19 @@ public class Elaboration {
     public void collectDebugInfo() {
         module.moduleDebugInfo = compilationContext.moduleDebugInfo = new ModuleDebugInfo();
     }
+
+    public void prepareExports() {
+        if(moduleHeader != null && moduleHeader.export != null) {
+            exportMap = new THashMap<String, EVar>();
+            for(EVar export : moduleHeader.export)
+                if(exportMap.put(export.name, export) != null)
+                    errorLog.log(export.location, "The symbol " + export.name + " is exported multiple times.");
+        }
+    }
+    
+    public void checkExports() {
+        if(exportMap != null)
+            for(EVar export : exportMap.values())
+                    errorLog.log(export.location, "The symbol " + export.name + " is not defined in the module.");
+    }
 }
index 0da48676ad0088cda95db8c4a5a53ae5942be191..1c674ae4d573126570d8307b9bbf0fc6ff9ba31f 100644 (file)
@@ -86,6 +86,8 @@ public class SCLCompiler {
                 elaboration.collectDebugInfo();
             // Elaboration
             if(hasErrors()) return;
+            elaboration.prepareExports();
+            if(hasErrors()) return;
             elaboration.addTypesToEnvironment(
                     declarations.dataTypesAst,
                     declarations.typeAliasesAst,
@@ -114,6 +116,7 @@ public class SCLCompiler {
             elaboration.addValueDefinitionsToEnvironment(declarations.typeAnnotationsAst);
             elaboration.processRules(declarations.rulesAst);
             elaboration.addSupplementedTypeAnnotationsToEnvironment();
+            elaboration.checkExports();
             if(SCLCompilerConfiguration.ENABLE_TIMING) phaseFinished("Elaboration");
             
             // Type checking
index ac2e1a8289866e1b0a528718b4dfadaab6e45670..7b693aa62212a6bf42bfb776d646c19ea748bbd3 100644 (file)
@@ -71,6 +71,7 @@ public class ModuleRegressionTests extends TestBase {
     @Test public void Equality() { test(); }
     @Test public void ExistentialData() { test(); }
     @Test public void ExistentialData2() { test(); }
+    @Test public void ExportBug1() { test(); }
     @Test public void ExpressionParsing() { test(); }
     @Test public void FaultyRecursion() { test(); }
     @Test public void Fibonacci() { test(); }
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExportBug1.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExportBug1.scl
new file mode 100644 (file)
index 0000000..3068516
--- /dev/null
@@ -0,0 +1,20 @@
+// module Trig
+module {
+    export = [sin]
+}
+
+importJava "java.lang.Math" where
+    sin :: Double -> Double
+    cos :: Double -> Double
+--
+import "Trig"
+
+main = sin 0.0
+--
+0.0
+--
+import "Trig"
+
+main = cos 0.0
+--
+3:8-3:11: Couldn't resolve cos.
\ No newline at end of file