]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
Merge "Trigger all drag start events from single place"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / Elaboration.java
index 799b0726819f3d6704f982ebfa0723e20fceb7e9..c59df828d93a852cf6c5b03d848f8cad9b3f3792 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,
@@ -190,7 +194,8 @@ public class Elaboration {
             compilationContext.environment = new EnvironmentOfModule(importedEnvironment, module);
         } catch (ImportFailureException e) {
             for(ImportFailure failure : e.failures)
-                errorLog.log(new CompilationError(failure.location, failure.toString(), ErrorSeverity.IMPORT_ERROR));
+                errorLog.log(new CompilationError(failure.location, failure.toString(),
+                        failure.reason == ImportFailure.MODULE_DOES_NOT_EXIST_REASON ? ErrorSeverity.ERROR : ErrorSeverity.IMPORT_ERROR));
             return;
         }
         for(ImportDeclaration importAst : importsAst)
@@ -711,6 +716,8 @@ public class Elaboration {
                         isPrivate = true;
                     }
             }
+            if(exportMap != null)
+                isPrivate = exportMap.remove(name) == null;
             
             Type type = createTypeTranslationContext().toType(javaMethod.type);
 
@@ -1077,7 +1084,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 +1221,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 +1244,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 +1264,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 +1275,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 +1363,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.");
+    }
 }