From: Hannu Niemistö Date: Tue, 20 Feb 2018 08:53:57 +0000 (+0200) Subject: (refs #7776) Fixed module export for javaImports X-Git-Tag: v1.43.0~136^2~585 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F1482%2F2;p=simantics%2Fplatform.git (refs #7776) Fixed module export for javaImports Change-Id: I50a5f635445d1b1d1df9dfc3ea0195f0859f86c0 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index ee21ef641..abdabf5ac 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -150,6 +150,8 @@ public class Elaboration { ArrayList dataTypes = new ArrayList(); THashMap classRefs = new THashMap(); THashMap branchPoints; + + THashMap exportMap = null; public Elaboration(CompilationContext compilationContext, CompilationTimer timer, EnvironmentFactory localEnvironmentFactory, String moduleName, ModuleHeader moduleHeader, ArrayList 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 exportMap = null; - if(moduleHeader != null && moduleHeader.export != null) { - exportMap = new THashMap(); - 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 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 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(); + 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."); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java index 0da48676a..1c674ae4d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java @@ -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 diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java index ac2e1a828..7b693aa62 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java @@ -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 index 000000000..3068516ab --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExportBug1.scl @@ -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