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