1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
4 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
6 import org.simantics.scl.compiler.errors.Locations;
7 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
8 import org.simantics.scl.compiler.types.TPred;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.exceptions.MatchException;
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.THashSet;
14 import gnu.trove.set.hash.TIntHashSet;
16 public class EGetConstraint extends SimplifiableExpression {
20 public EGetConstraint(long loc, TPred constraint) {
22 this.constraint = constraint;
26 public void collectRefs(TObjectIntHashMap<Object> allRefs,
31 public void collectVars(TObjectIntHashMap<Variable> allVars,
34 evidence.collectVars(allVars, vars);
38 public Expression inferType(TypingContext context) {
39 Variable variable = new Variable("evidence");
40 variable.setType(constraint);
41 evidence = new EVariable(getLocation(), variable);
42 evidence.setType(variable.getType());
43 context.addConstraintDemand(evidence);
48 protected void updateType() throws MatchException {
53 public void collectFreeVariables(THashSet<Variable> vars) {
55 evidence.collectFreeVariables(vars);
59 public Expression simplify(SimplificationContext context) {
60 return evidence.simplify(context);
64 public Expression resolve(TranslationContext context) {
69 public Expression decorate(ExpressionDecorator decorator) {
70 return decorator.decorate(this);
74 public void collectEffects(THashSet<Type> effects) {
78 public void setLocationDeep(long loc) {
79 if(location == Locations.NO_LOCATION) {
82 evidence.setLocationDeep(loc);
87 public void accept(ExpressionVisitor visitor) {
92 public void forVariables(VariableProcedure procedure) {
93 evidence.forVariables(procedure);
97 public Expression accept(ExpressionTransformer transformer) {
98 return transformer.transform(this);