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.TIntHashSet;
13 public class EGetConstraint extends SimplifiableExpression {
15 public EVariable evidence;
17 public EGetConstraint(long loc, TPred constraint) {
19 this.constraint = constraint;
23 public void collectVars(TObjectIntHashMap<Variable> allVars,
26 evidence.collectVars(allVars, vars);
30 public Expression inferType(TypingContext context) {
31 Variable variable = new Variable("evidence");
32 variable.setType(constraint);
33 evidence = new EVariable(getLocation(), variable);
34 evidence.setType(variable.getType());
35 context.addConstraintDemand(evidence);
40 protected void updateType() throws MatchException {
45 public Expression simplify(SimplificationContext context) {
46 return evidence.simplify(context);
50 public Expression resolve(TranslationContext context) {
55 public void setLocationDeep(long loc) {
56 if(location == Locations.NO_LOCATION) {
59 evidence.setLocationDeep(loc);
64 public void accept(ExpressionVisitor visitor) {
69 public Expression accept(ExpressionTransformer transformer) {
70 return transformer.transform(this);