1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
5 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
6 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
8 import org.simantics.scl.compiler.environment.Environment;
9 import org.simantics.scl.compiler.errors.Locations;
10 import org.simantics.scl.compiler.internal.codegen.references.IVal;
11 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
12 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
13 import org.simantics.scl.compiler.internal.interpreted.IExpression;
14 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
15 import org.simantics.scl.compiler.types.Type;
16 import org.simantics.scl.compiler.types.exceptions.MatchException;
18 import gnu.trove.map.hash.TObjectIntHashMap;
19 import gnu.trove.set.hash.THashSet;
20 import gnu.trove.set.hash.TIntHashSet;
22 public class ECHRRulesetConstructor extends Expression {
25 public ECHRRulesetConstructor(CHRRuleset ruleset) {
26 this.ruleset = ruleset;
30 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
31 ruleset.collectRefs(allRefs, refs);
34 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
35 ruleset.collectVars(allVars, vars);
38 public void forVariables(VariableProcedure procedure) {
39 ruleset.forVariables(procedure);
42 protected void updateType() throws MatchException {
43 throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
46 public IVal toVal(Environment env, CodeWriter w) {
47 return ruleset.generateCode(w);
50 public void collectFreeVariables(THashSet<Variable> vars) {
51 ruleset.collectFreeVariables(vars);
54 public Expression resolve(TranslationContext context) {
56 context.pushCHRConstraintFrame();
57 ruleset.resolve(context);
58 context.popCHRConstraintFrame(ruleset.constraints);
63 public void setLocationDeep(long loc) {
64 if(location == Locations.NO_LOCATION) {
66 ruleset.setLocationDeep(loc);
70 public Expression decorate(ExpressionDecorator decorator) {
74 public void collectEffects(THashSet<Type> effects) {
75 ruleset.collectEffects(effects);
78 public void accept(ExpressionVisitor visitor) {
83 public Expression inferType(TypingContext context) {
84 ruleset.checkType(context);
89 public Expression simplify(SimplificationContext context) {
90 ruleset.simplify(context);
91 ruleset.compile(context);
96 public Expression accept(ExpressionTransformer transformer) {
97 return transformer.transform(this);
101 public IExpression toIExpression(ExpressionInterpretationContext context) {
102 throw new UnsupportedOperationException();