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