]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/SCLCompiler.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / SCLCompiler.java
index b5bd4ef312c997038e5856164d2ef34dfbe69cb7..27583ea53b30e25df56ff6e3b73caf7cf1901b65 100644 (file)
@@ -18,8 +18,8 @@ import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
 import org.simantics.scl.compiler.top.StandardModuleInitializer;
 
 public class SCLCompiler {
-    ErrorLog errorLog = new ErrorLog();
-    DeclarationClassification declarations = new DeclarationClassification(errorLog);
+    CompilationContext compilationContext = new CompilationContext();
+    DeclarationClassification declarations = new DeclarationClassification(compilationContext);
     
     // publishable results
     Map<String, byte[]> classes;
@@ -42,9 +42,9 @@ public class SCLCompiler {
             for(DeclarationAst declaration : (ArrayList<DeclarationAst>)parser.parseModule())
                 declarations.handle(declaration);
         } catch(SCLSyntaxErrorException e) {
-            errorLog.log(e.location, e.getMessage());
+            compilationContext.errorLog.log(e.location, e.getMessage());
         } catch(Exception e) {
-            errorLog.log(e);
+            compilationContext.errorLog.log(e);
         } finally {
             try {
                 sourceReader.close();
@@ -55,13 +55,17 @@ public class SCLCompiler {
         if(SCLCompilerConfiguration.ENABLE_TIMING) phaseFinished("Parsing");
     }
     
+    private boolean hasErrors() {
+        return !compilationContext.errorLog.isEmpty();
+    }
+    
     public void compile(
             EnvironmentFactory localEnvironmentFactory,
             String moduleName,
             JavaReferenceValidator<?, ?, ?, ?> javaReferenceValidator) {
         try {
-            if(!errorLog.isEmpty()) return;
-            Elaboration elaboration = new Elaboration(errorLog,
+            if(hasErrors()) return;
+            Elaboration elaboration = new Elaboration(compilationContext,
                     timer,
                     localEnvironmentFactory,
                     moduleName,
@@ -72,24 +76,24 @@ public class SCLCompiler {
             if(options.computeCoverage)
                 elaboration.addCoverageBranchPoints();
             // Elaboration
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.addTypesToEnvironment(
                     declarations.dataTypesAst,
                     declarations.typeAliasesAst,
                     declarations.effectsAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processTypeAliases(declarations.typeAliasesAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processDataTypes(declarations.dataTypesAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processTypeClasses(declarations.typeClassesAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processDerivingInstances(declarations.derivingInstancesAst, declarations.instancesAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processInstances(declarations.instancesAst);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.processJavaMethods(declarations.javaMethodDeclarations);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             elaboration.addDataTypesToEnvironment();
             elaboration.addTypeClassesToEnvironment();
             elaboration.preprocessValueDefinitions(declarations.typeAnnotationsAst);
@@ -101,9 +105,9 @@ public class SCLCompiler {
             if(SCLCompilerConfiguration.ENABLE_TIMING) phaseFinished("Elaboration");
             
             // Type checking
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             //new TypeChecking(errorLog, elaboration.environment, elaboration.module).typeCheck();
-            new TypeChecking(errorLog, elaboration.environment, elaboration.module).typeCheck();
+            new TypeChecking(compilationContext, elaboration.module).typeCheck();
             
             if(SCLCompilerConfiguration.ENABLE_TIMING) phaseFinished("Type checking");
             
@@ -125,36 +129,33 @@ public class SCLCompiler {
             this.declarations = null;
             
             // Code generation
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             CodeGeneration codeGeneration = new CodeGeneration(
-                    errorLog,
-                    elaboration.environment,
-                    elaboration.namingPolicy,
-                    elaboration.javaTypeTranslator,
+                    compilationContext,
                     elaboration.javaReferenceValidator,
                     elaboration.module);
             codeGeneration.simplifyValues();
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.convertToSSA();
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.optimizeSSA();
             
             if(SCLCompilerConfiguration.ENABLE_TIMING) phaseFinished("SSA conversion and optimization");
             
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.generateCode();
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.generateDataTypes(elaboration.dataTypes);
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.generateTypeClasses();
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
             codeGeneration.generateTypeClassInstances();
-            if(!errorLog.isEmpty()) return;
+            if(hasErrors()) return;
 
             classes = codeGeneration.classes;
             module =  codeGeneration.module;
             moduleInitializer = StandardModuleInitializer.create(
-                    codeGeneration.namingPolicy.getModuleClassName(),
+                    compilationContext.namingPolicy.getModuleClassName(),
                     codeGeneration.externalConstants);
             
             module.setClasses(classes);
@@ -166,12 +167,12 @@ public class SCLCompiler {
                 reportTiming(moduleName);
             }
         } catch(Exception e) {
-            errorLog.log(e);
+            compilationContext.errorLog.log(e);
         }
     }
 
     public ErrorLog getErrorLog() {
-        return errorLog;
+        return compilationContext.errorLog;
     }
     
     public Map<String, byte[]> getClasses() {