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.exceptions.MatchException;
16 import gnu.trove.map.hash.TObjectIntHashMap;
17 import gnu.trove.set.hash.THashSet;
18 import gnu.trove.set.hash.TIntHashSet;
20 public class ECHRRulesetConstructor extends Expression {
23 public ECHRRulesetConstructor(CHRRuleset ruleset) {
24 this.ruleset = ruleset;
28 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
29 ruleset.collectVars(allVars, vars);
33 protected void updateType() throws MatchException {
34 throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
38 public IVal toVal(CompilationContext context, CodeWriter w) {
39 return ruleset.generateCode(w);
43 public void collectFreeVariables(THashSet<Variable> vars) {
44 ruleset.collectFreeVariables(vars);
48 public Expression resolve(TranslationContext context) {
50 context.pushCHRConstraintFrame();
51 ruleset.resolve(context);
52 context.popCHRConstraintFrame(ruleset.constraints);
57 public void setLocationDeep(long loc) {
58 if(location == Locations.NO_LOCATION) {
60 ruleset.setLocationDeep(loc);
64 public void accept(ExpressionVisitor visitor) {
69 public Expression inferType(TypingContext context) {
70 ruleset.checkType(context);
75 public Expression simplify(SimplificationContext context) {
76 ruleset.simplify(context);
77 ruleset.compile(context);
82 public Expression accept(ExpressionTransformer transformer) {
83 return transformer.transform(this);
87 public IExpression toIExpression(ExpressionInterpretationContext context) {
88 throw new UnsupportedOperationException();