]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / TypeChecking.java
index 554a360811b69b2312151b9c4f8fe503d131c790..667c089c3e24fe58561a674622f053a0ed6d9662 100644 (file)
@@ -25,7 +25,6 @@ import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
 import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
 import org.simantics.scl.compiler.environment.Environment;
-import org.simantics.scl.compiler.errors.ErrorLog;
 import org.simantics.scl.compiler.internal.elaboration.constraints.Constraint;
 import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintEnvironment;
 import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintSolver;
@@ -45,17 +44,16 @@ import gnu.trove.set.hash.THashSet;
 import gnu.trove.set.hash.TIntHashSet;
 
 public class TypeChecking {
-    final ErrorLog errorLog;
+    final CompilationContext compilationContext;
     final Environment environment;
     final ConcreteModule module;
     
     ConstraintEnvironment ce;
     TypeCheckingScheduler scheduler;
     
-    public TypeChecking(ErrorLog errorLog, Environment environment,
-            ConcreteModule module) {
-        this.errorLog = errorLog;
-        this.environment = environment;
+    public TypeChecking(CompilationContext compilationContext, ConcreteModule module) {
+        this.compilationContext = compilationContext;
+        this.environment = compilationContext.environment;
         this.module = module;
     }
     
@@ -100,7 +98,7 @@ public class TypeChecking {
                             expression = expression.checkType(context, value.getType());
                             context.popEffectUpperBound();
                             for(EAmbiguous overloaded : context.overloadedExpressions)
-                                overloaded.assertResolved(errorLog);
+                                overloaded.assertResolved(compilationContext.errorLog);
                             value.setExpression(expression);
                             
                             ArrayList<EVariable> constraintDemand = context.getConstraintDemand();
@@ -129,7 +127,7 @@ public class TypeChecking {
                                 
                                 for(Constraint c : red.unsolvedConstraints)
                                     if(c.constraint.isGround())
-                                        errorLog.log(c.getDemandLocation(), "There is no instance for <"+c.constraint+">.");
+                                        compilationContext.errorLog.log(c.getDemandLocation(), "There is no instance for <"+c.constraint+">.");
                                 
                                 ArrayList<Variable> fe = new ArrayList<Variable>(red.unsolvedConstraints.size());
                                 for(Constraint c : red.unsolvedConstraints)
@@ -212,12 +210,12 @@ public class TypeChecking {
                                 ArrayList<TPred> givenConstraints = new ArrayList<TPred>();
                                 type = Types.removePred(type, givenConstraints);
 
-                                TypingContext context = new TypingContext(errorLog, environment);
+                                TypingContext context = new TypingContext(compilationContext);
                                 context.pushEffectUpperBound(expression.location, Types.PROC);
                                 expression = expression.checkType(context, type);
                                 context.popEffectUpperBound();
                                 for(EAmbiguous overloaded : context.overloadedExpressions)
-                                    overloaded.assertResolved(errorLog);
+                                    overloaded.assertResolved(compilationContext.errorLog);
                                 expression.getType().addPolarity(Polarity.POSITIVE);
                                 context.solveSubsumptions(expression.getLocation());
                                 ArrayList<EVariable> demands = context.getConstraintDemand();
@@ -226,10 +224,10 @@ public class TypeChecking {
                                             ConstraintSolver.solve(ce, givenConstraints, demands, true);    
                                     givenConstraints.clear();
                                     for(Constraint c :  red.unsolvedConstraints) {
-                                        errorLog.log(c.getDemandLocation(), 
+                                        compilationContext.errorLog.log(c.getDemandLocation(), 
                                                 "Constraint <"+c.constraint+"> is not given and cannot be derived.");
                                     }
-                                    if(errorLog.isEmpty()) { // To prevent exceptions
+                                    if(compilationContext.errorLog.isEmpty()) { // To prevent exceptions
                                         expression = ExpressionAugmentation.augmentSolved(
                                                 red.solvedConstraints,
                                                 expression);
@@ -239,13 +237,13 @@ public class TypeChecking {
                                     }
                                 }
                                 else {
-                                    if(errorLog.isEmpty()) // To prevent exceptions
+                                    if(compilationContext.errorLog.isEmpty()) // To prevent exceptions
                                         expression = expression.decomposeMatching();
                                 }
                                 expression = expression.closure(vars.toArray(new TVar[vars.size()]));
                                 value.setExpression(expression);
                             } catch(Exception e) {
-                                errorLog.log(expression.location, e);
+                                compilationContext.errorLog.log(expression.location, e);
                             }
                         }
                     });
@@ -336,7 +334,7 @@ public class TypeChecking {
     
     public void typeCheck() {
         ce = new ConstraintEnvironment(environment);
-        scheduler = new TypeCheckingScheduler(errorLog, environment);
+        scheduler = new TypeCheckingScheduler(compilationContext);
         
         typeCheckValues();
         typeCheckRelations();
@@ -424,7 +422,7 @@ public class TypeChecking {
                     for(MappingRelation mappingRelation : module.getMappingRelations())
                         for(Type parameterType : mappingRelation.parameterTypes)
                             if(!parameterType.isGround()) {
-                                errorLog.log(mappingRelation.location, "Parameter types of the mapping relation are not completely determined.");
+                                compilationContext.errorLog.log(mappingRelation.location, "Parameter types of the mapping relation are not completely determined.");
                                 break;
                             }
                 }