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.exceptions.MatchException;
10 import gnu.trove.map.hash.TObjectIntHashMap;
11 import gnu.trove.set.hash.THashSet;
12 import gnu.trove.set.hash.TIntHashSet;
14 public class EGetConstraint extends SimplifiableExpression {
18 public EGetConstraint(long loc, TPred constraint) {
20 this.constraint = constraint;
24 public void collectVars(TObjectIntHashMap<Variable> allVars,
27 evidence.collectVars(allVars, vars);
31 public Expression inferType(TypingContext context) {
32 Variable variable = new Variable("evidence");
33 variable.setType(constraint);
34 evidence = new EVariable(getLocation(), variable);
35 evidence.setType(variable.getType());
36 context.addConstraintDemand(evidence);
41 protected void updateType() throws MatchException {
46 public void collectFreeVariables(THashSet<Variable> vars) {
48 evidence.collectFreeVariables(vars);
52 public Expression simplify(SimplificationContext context) {
53 return evidence.simplify(context);
57 public Expression resolve(TranslationContext context) {
62 public void setLocationDeep(long loc) {
63 if(location == Locations.NO_LOCATION) {
66 evidence.setLocationDeep(loc);
71 public void accept(ExpressionVisitor visitor) {
76 public Expression accept(ExpressionTransformer transformer) {
77 return transformer.transform(this);