From 7fa60c7f3e3a98026b4657afec5f6c02ed958657 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Tue, 20 Feb 2018 10:53:57 +0200 Subject: [PATCH] (refs #7776) Fixed module export for javaImports Change-Id: I50a5f635445d1b1d1df9dfc3ea0195f0859f86c0 --- .../scl/compiler/compilation/Elaboration.java | 30 ++++++++++++------- .../scl/compiler/compilation/SCLCompiler.java | 3 ++ .../compiler/tests/ModuleRegressionTests.java | 1 + .../scl/compiler/tests/scl/ExportBug1.scl | 20 +++++++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExportBug1.scl 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 -- 2.43.2