]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java
(refs #7375) Replaced ExpressionDecorator by ExpressionTransformer
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ECHRRulesetConstructor.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
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;
16
17 import gnu.trove.map.hash.TObjectIntHashMap;
18 import gnu.trove.set.hash.THashSet;
19 import gnu.trove.set.hash.TIntHashSet;
20
21 public class ECHRRulesetConstructor extends Expression {
22     CHRRuleset ruleset;
23     
24     public ECHRRulesetConstructor(CHRRuleset ruleset) {
25         this.ruleset = ruleset;
26     }
27     
28     @Override
29     public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
30         ruleset.collectRefs(allRefs, refs);
31     }
32     @Override
33     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
34         ruleset.collectVars(allVars, vars);
35     }
36     @Override
37     public void forVariables(VariableProcedure procedure) {
38         ruleset.forVariables(procedure);
39     }
40     @Override
41     protected void updateType() throws MatchException {
42         throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
43     }
44     @Override
45     public IVal toVal(CompilationContext context, CodeWriter w) {
46         return ruleset.generateCode(w);
47     }
48     @Override
49     public void collectFreeVariables(THashSet<Variable> vars) {
50         ruleset.collectFreeVariables(vars);
51     }
52     @Override
53     public Expression resolve(TranslationContext context) {
54         context.pushFrame();
55         context.pushCHRConstraintFrame();
56         ruleset.resolve(context);
57         context.popCHRConstraintFrame(ruleset.constraints);
58         context.popFrame();
59         return this;
60     }
61     @Override
62     public void setLocationDeep(long loc) {
63         if(location == Locations.NO_LOCATION) {
64             this.location = loc;
65             ruleset.setLocationDeep(loc);
66         }
67     }
68     @Override
69     public void collectEffects(THashSet<Type> effects) {
70         ruleset.collectEffects(effects);
71     }
72     @Override
73     public void accept(ExpressionVisitor visitor) {
74         visitor.visit(this);
75     }
76     
77     @Override
78     public Expression inferType(TypingContext context) {
79         ruleset.checkType(context);
80         return this;
81     }
82     
83     @Override
84     public Expression simplify(SimplificationContext context) {
85         ruleset.simplify(context);
86         ruleset.compile(context);
87         return this;
88     }
89     
90     @Override
91     public Expression accept(ExpressionTransformer transformer) {
92         return transformer.transform(this);
93     }
94     
95     @Override
96     public IExpression toIExpression(ExpressionInterpretationContext context) {
97         throw new UnsupportedOperationException();
98     }
99
100 }