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.TIntHashSet;
19 public class ECHRRulesetConstructor extends Expression {
20 public CHRRuleset ruleset;
22 public ECHRRulesetConstructor(CHRRuleset ruleset) {
23 this.ruleset = ruleset;
27 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
28 ruleset.collectVars(allVars, vars);
32 protected void updateType() throws MatchException {
33 throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
37 public IVal toVal(CompilationContext context, CodeWriter w) {
38 return ruleset.generateCode(w);
42 public Expression resolve(TranslationContext context) {
44 context.pushCHRConstraintFrame();
45 ruleset.resolve(context);
46 context.popCHRConstraintFrame(ruleset.constraints);
51 public void setLocationDeep(long loc) {
52 if(location == Locations.NO_LOCATION) {
54 ruleset.setLocationDeep(loc);
58 public void accept(ExpressionVisitor visitor) {
63 public Expression inferType(TypingContext context) {
64 ruleset.checkType(context);
69 public Expression simplify(SimplificationContext context) {
70 ruleset.simplify(context);
71 ruleset.compile(context);
76 public Expression accept(ExpressionTransformer transformer) {
77 return transformer.transform(this);
81 public IExpression toIExpression(ExpressionInterpretationContext context) {
82 throw new UnsupportedOperationException();