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.types.TPred;
8 import org.simantics.scl.compiler.types.Type;
9 import org.simantics.scl.compiler.types.exceptions.MatchException;
11 import gnu.trove.map.hash.TObjectIntHashMap;
12 import gnu.trove.set.hash.THashSet;
13 import gnu.trove.set.hash.TIntHashSet;
15 public class EGetConstraint extends SimplifiableExpression {
19 public EGetConstraint(long loc, TPred constraint) {
21 this.constraint = constraint;
25 public void collectVars(TObjectIntHashMap<Variable> allVars,
28 evidence.collectVars(allVars, vars);
32 public Expression inferType(TypingContext context) {
33 Variable variable = new Variable("evidence");
34 variable.setType(constraint);
35 evidence = new EVariable(getLocation(), variable);
36 evidence.setType(variable.getType());
37 context.addConstraintDemand(evidence);
42 protected void updateType() throws MatchException {
47 public void collectFreeVariables(THashSet<Variable> vars) {
49 evidence.collectFreeVariables(vars);
53 public Expression simplify(SimplificationContext context) {
54 return evidence.simplify(context);
58 public Expression resolve(TranslationContext context) {
63 public void collectEffects(THashSet<Type> effects) {
67 public void setLocationDeep(long loc) {
68 if(location == Locations.NO_LOCATION) {
71 evidence.setLocationDeep(loc);
76 public void accept(ExpressionVisitor visitor) {
81 public Expression accept(ExpressionTransformer transformer) {
82 return transformer.transform(this);