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 collectRefs(TObjectIntHashMap<Object> allRefs,
30 public void collectVars(TObjectIntHashMap<Variable> allVars,
33 evidence.collectVars(allVars, vars);
37 public Expression inferType(TypingContext context) {
38 Variable variable = new Variable("evidence");
39 variable.setType(constraint);
40 evidence = new EVariable(getLocation(), variable);
41 evidence.setType(variable.getType());
42 context.addConstraintDemand(evidence);
47 protected void updateType() throws MatchException {
52 public void collectFreeVariables(THashSet<Variable> vars) {
54 evidence.collectFreeVariables(vars);
58 public Expression simplify(SimplificationContext context) {
59 return evidence.simplify(context);
63 public Expression resolve(TranslationContext context) {
68 public void collectEffects(THashSet<Type> effects) {
72 public void setLocationDeep(long loc) {
73 if(location == Locations.NO_LOCATION) {
76 evidence.setLocationDeep(loc);
81 public void accept(ExpressionVisitor visitor) {
86 public void forVariables(VariableProcedure procedure) {
87 evidence.forVariables(procedure);
91 public Expression accept(ExpressionTransformer transformer) {
92 return transformer.transform(this);