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