X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fcontexts%2FTypingContext.java;h=ac004eab692a062e0777c0ebd1d8c3dab3329087;hp=850f077db32d3ec9c8b81a2ebe5b4f6b32b30aa6;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=12d9af17384d960b75d58c3935d2b7b46d93e87b diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java index 850f077db..ac004eab6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java @@ -3,12 +3,10 @@ package org.simantics.scl.compiler.elaboration.contexts; import java.util.ArrayList; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; -import org.simantics.scl.compiler.common.names.Name; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.NoRepConstant; import org.simantics.scl.compiler.elaboration.expressions.EAmbiguous; import org.simantics.scl.compiler.elaboration.expressions.EApply; -import org.simantics.scl.compiler.elaboration.expressions.EConstant; -import org.simantics.scl.compiler.elaboration.expressions.EError; import org.simantics.scl.compiler.elaboration.expressions.ELiteral; import org.simantics.scl.compiler.elaboration.expressions.EPlaceholder; import org.simantics.scl.compiler.elaboration.expressions.EVariable; @@ -17,7 +15,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.ErrorLog; -import org.simantics.scl.compiler.errors.Locations; 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; @@ -42,9 +39,9 @@ import org.simantics.scl.compiler.types.util.TypeUnparsingContext; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; -public class TypingContext implements EnvironmentalContext { +public class TypingContext { - private ErrorLog errorLog; + private CompilationContext compilationContext; // Subsumption private ArrayList effectSubsumptions = new ArrayList(); @@ -71,11 +68,10 @@ public class TypingContext implements EnvironmentalContext { //TypeUnparsingContext tuc = new TypeUnparsingContext(); Environment environment; - THashMap constants = new THashMap(); - public TypingContext(ErrorLog errorLog, Environment environment) { - this.errorLog = errorLog; - this.environment = environment; + public TypingContext(CompilationContext compilationContext) { + this.compilationContext = compilationContext; + this.environment = compilationContext.environment; } /** @@ -94,7 +90,7 @@ public class TypingContext implements EnvironmentalContext { try { Types.unify(a, Types.NO_EFFECTS); } catch(UnificationException e) { - errorLog.log(loc, "No side-effects allowed here."); + compilationContext.errorLog.log(loc, "No side-effects allowed here."); return; } } @@ -336,7 +332,7 @@ public class TypingContext implements EnvironmentalContext { try { subsume(sub.loc, a, b); } catch (UnificationException e) { - errorLog.log(sub.loc, "Type " + a + " is not a subtype of " + b + "."); + compilationContext.errorLog.log(sub.loc, "Type " + a + " is not a subtype of " + b + "."); } nontrivialSubs = true; } @@ -361,7 +357,7 @@ public class TypingContext implements EnvironmentalContext { try { Types.unify(sub.a, sub.b); } catch (UnificationException e) { - errorLog.log(sub.loc, "Unification of types failed."); + compilationContext.errorLog.log(sub.loc, "Unification of types failed."); return false; } @@ -386,7 +382,7 @@ public class TypingContext implements EnvironmentalContext { if(type instanceof TMetaVar) return ((TMetaVar)type).getKind() == Kinds.EFFECT; else if(type instanceof TCon) - return environment.getTypeConstructor((TCon)type).kind == Kinds.EFFECT; + return environment.getTypeDescriptor((TCon)type).getKind() == Kinds.EFFECT; else if(type instanceof TVar) return ((TVar)type).getKind() == Kinds.EFFECT; else if(type instanceof TUnion) @@ -398,7 +394,7 @@ public class TypingContext implements EnvironmentalContext { public void solveSubsumptions(long globalLoc) { if(expandSubsumptions()) - new SubSolver(errorLog, effectSubsumptions, potentialSingletonEffects, globalLoc).solve(); + new SubSolver(compilationContext.errorLog, effectSubsumptions, potentialSingletonEffects, globalLoc).solve(); } public void declareEffect(long loc, Type effect) { @@ -415,7 +411,7 @@ public class TypingContext implements EnvironmentalContext { } public ErrorLog getErrorLog() { - return errorLog; + return compilationContext.errorLog; } public boolean isInPattern() { @@ -470,7 +466,7 @@ public class TypingContext implements EnvironmentalContext { public void typeError(long loc, Type requiredType, Type givenType) { TypeUnparsingContext tuc = new TypeUnparsingContext(); - errorLog.log(loc, "Expected <" + requiredType.toString(tuc) + "> got <" + givenType.toString(tuc) + ">."); + compilationContext.errorLog.log(loc, "Expected <" + requiredType.toString(tuc) + "> got <" + givenType.toString(tuc) + ">."); } public Expression solveConstraints(Environment environment, Expression expression) { @@ -486,33 +482,20 @@ public class TypingContext implements EnvironmentalContext { expression); for(Constraint c : red.unsolvedConstraints) - errorLog.log(c.getDemandLocation(), "There is no instance for <"+c.constraint+">."); + compilationContext.errorLog.log(c.getDemandLocation(), "There is no instance for <"+c.constraint+">."); } else expression = expression.decomposeMatching(); return expression; } - - public SCLValue getValue(Name name) { - if(constants.containsKey(name)) - return constants.get(name); - SCLValue value = environment.getValue(name); - if(value == null) - errorLog.log(Locations.NO_LOCATION, "Couldn't find " + name + "."); - constants.put(name, value); - return value; - } - - public Expression getConstant(Name name, Type ... typeParameters) { - SCLValue value = getValue(name); - if(value == null) - return new EError(Locations.NO_LOCATION); - return new EConstant(value, typeParameters); - } public Environment getEnvironment() { - return environment; + return compilationContext.environment; + } + + public CompilationContext getCompilationContext() { + return compilationContext; } }