]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
(refs #7776) Fixed module export for javaImports
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / Elaboration.java
index 799b0726819f3d6704f982ebfa0723e20fceb7e9..abdabf5ac7e3cc55b0fb875e71dfc038d1a1f9b5 100644 (file)
@@ -106,8 +106,10 @@ import org.simantics.scl.compiler.module.ConcreteModule;
 import org.simantics.scl.compiler.module.ImportDeclaration;
 import org.simantics.scl.compiler.module.InvalidModulePathException;
 import org.simantics.scl.compiler.module.ModuleUtils;
+import org.simantics.scl.compiler.module.debug.ModuleDebugInfo;
 import org.simantics.scl.compiler.module.repository.ImportFailure;
 import org.simantics.scl.compiler.module.repository.ImportFailureException;
+import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
 import org.simantics.scl.compiler.types.TCon;
 import org.simantics.scl.compiler.types.TForAll;
 import org.simantics.scl.compiler.types.TFun;
@@ -148,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,
@@ -711,6 +715,8 @@ public class Elaboration {
                         isPrivate = true;
                     }
             }
+            if(exportMap != null)
+                isPrivate = exportMap.remove(name) == null;
             
             Type type = createTypeTranslationContext().toType(javaMethod.type);
 
@@ -1077,7 +1083,7 @@ public class Elaboration {
         
         final THashMap<SectionName, Query[]> sections = new THashMap<SectionName, Query[]>();
 
-        final TranslationContext context = createTranslationContext();
+        final TranslationContext context = createTranslationContext(ruleName);
         if(length > 0) {
             THashMap<String, Variable> variables = context.getVariables();
             for(TransformationRule extendsRule : extendsRules) {
@@ -1214,21 +1220,13 @@ 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))
                 continue;
             try {
                 SCLValue value = module.getValue(name);
-                TranslationContext context = createTranslationContext();
+                TranslationContext context = createTranslationContext(name);
                 Expression expression = context.translateCases2(defs);
                 value.setExpression(expression);
                 
@@ -1245,7 +1243,7 @@ public class Elaboration {
                 continue;
             try {
                 SCLValue value = module.getValue(name);
-                TranslationContext context = createTranslationContext();
+                TranslationContext context = createTranslationContext(name);
                 Expression expression = context.translateCases2(defs);
                 value.setExpression(expression);
                 
@@ -1265,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) {
@@ -1279,13 +1274,13 @@ public class Elaboration {
             DRelationAst definition = definitions.get(0);
             ConcreteRelation relation = (ConcreteRelation)module.getRelation(name);
             relation.location = definition.location;
-            TranslationContext context = createTranslationContext();
+            TranslationContext context = createTranslationContext(name);
             definition.translateTo(context, relation);
         }
     }
     
-    private TranslationContext createTranslationContext() {
-        return new TranslationContext(compilationContext, null);
+    private TranslationContext createTranslationContext(String definitionName) {
+        return new TranslationContext(compilationContext, null, definitionName);
     }
     
     private void handleAnnotation(SCLValue value, ArrayList<DValueAst> defs, DAnnotationAst annotation) {
@@ -1367,4 +1362,23 @@ public class Elaboration {
             branchPoints.put(valueName, injector.getAndClearBranchPoints());
         }
     }
+
+    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.");
+    }
 }