1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
4 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
7 import org.simantics.scl.compiler.environment.Environment;
8 import org.simantics.scl.compiler.errors.Locations;
9 import org.simantics.scl.compiler.internal.codegen.references.IVal;
10 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
11 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
12 import org.simantics.scl.compiler.internal.interpreted.IExpression;
13 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
14 import org.simantics.scl.compiler.types.Type;
15 import org.simantics.scl.compiler.types.exceptions.MatchException;
17 import gnu.trove.map.hash.TObjectIntHashMap;
18 import gnu.trove.set.hash.THashSet;
19 import gnu.trove.set.hash.TIntHashSet;
21 public class ECHRRuleset extends Expression {
25 public ECHRRuleset(CHRRuleset ruleset, Expression in) {
26 this.ruleset = ruleset;
31 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
32 ruleset.collectRefs(allRefs, refs);
33 in.collectRefs(allRefs, refs);
36 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
37 ruleset.collectVars(allVars, vars);
38 in.collectVars(allVars, vars);
41 public void forVariables(VariableProcedure procedure) {
42 ruleset.forVariables(procedure);
43 in.forVariables(procedure);
46 protected void updateType() throws MatchException {
47 setType(in.getType());
50 public IVal toVal(Environment env, CodeWriter w) {
51 ruleset.generateCode(w);
52 return in.toVal(env, w);
55 public void collectFreeVariables(THashSet<Variable> vars) {
56 ruleset.collectFreeVariables(vars);
57 in.collectFreeVariables(vars);
60 public Expression resolve(TranslationContext context) {
62 context.pushCHRConstraintFrame();
63 ruleset.resolve(context);
64 in = in.resolve(context);
65 context.popCHRConstraintFrame(ruleset.constraints);
70 public void setLocationDeep(long loc) {
71 if(location == Locations.NO_LOCATION) {
73 ruleset.setLocationDeep(loc);
74 in.setLocationDeep(loc);
78 public Expression decorate(ExpressionDecorator decorator) {
79 in = in.decorate(decorator);
83 public void collectEffects(THashSet<Type> effects) {
84 ruleset.collectEffects(effects);
85 in.collectEffects(effects);
88 public void accept(ExpressionVisitor visitor) {
93 public Expression inferType(TypingContext context) {
94 ruleset.checkType(context);
95 in = in.inferType(context);
100 public Expression simplify(SimplificationContext context) {
101 ruleset.simplify(context);
102 ruleset.compile(context);
103 in = in.simplify(context);
108 public Expression accept(ExpressionTransformer transformer) {
109 return transformer.transform(this);
113 public IExpression toIExpression(ExpressionInterpretationContext context) {
114 throw new UnsupportedOperationException();