1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.compilation.CompilationContext;
5 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
6 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
8 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
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.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 ECHRRulesetConstructor extends Expression {
24 public ECHRRulesetConstructor(CHRRuleset ruleset) {
25 this.ruleset = ruleset;
29 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
30 ruleset.collectRefs(allRefs, refs);
33 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
34 ruleset.collectVars(allVars, vars);
37 protected void updateType() throws MatchException {
38 throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
41 public IVal toVal(CompilationContext context, CodeWriter w) {
42 return ruleset.generateCode(w);
45 public void collectFreeVariables(THashSet<Variable> vars) {
46 ruleset.collectFreeVariables(vars);
49 public Expression resolve(TranslationContext context) {
51 context.pushCHRConstraintFrame();
52 ruleset.resolve(context);
53 context.popCHRConstraintFrame(ruleset.constraints);
58 public void setLocationDeep(long loc) {
59 if(location == Locations.NO_LOCATION) {
61 ruleset.setLocationDeep(loc);
65 public void collectEffects(THashSet<Type> effects) {
66 ruleset.collectEffects(effects);
69 public void accept(ExpressionVisitor visitor) {
74 public Expression inferType(TypingContext context) {
75 ruleset.checkType(context);
80 public Expression simplify(SimplificationContext context) {
81 ruleset.simplify(context);
82 ruleset.compile(context);
87 public Expression accept(ExpressionTransformer transformer) {
88 return transformer.transform(this);
92 public IExpression toIExpression(ExpressionInterpretationContext context) {
93 throw new UnsupportedOperationException();