]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java
(refs #7278, refs #7279) Small fixes to InternalCompilerExceptions
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ECHRRuleset.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import org.simantics.scl.compiler.compilation.CompilationContext;
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.errors.Locations;
9 import org.simantics.scl.compiler.internal.codegen.references.IVal;
10 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
11 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
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 ECHRRuleset extends Expression {
22     CHRRuleset ruleset;
23     Expression in;
24     
25     public ECHRRuleset(CHRRuleset ruleset, Expression in) {
26         this.ruleset = ruleset;
27         this.in = in;
28     }
29     
30     @Override
31     public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
32         ruleset.collectRefs(allRefs, refs);
33         in.collectRefs(allRefs, refs);
34     }
35     @Override
36     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
37         ruleset.collectVars(allVars, vars);
38         in.collectVars(allVars, vars);
39     }
40     @Override
41     public void forVariables(VariableProcedure procedure) {
42         ruleset.forVariables(procedure);
43         in.forVariables(procedure);
44     }
45     @Override
46     protected void updateType() throws MatchException {
47         setType(in.getType());
48     }
49     @Override
50     public IVal toVal(CompilationContext context, CodeWriter w) {
51         ruleset.generateCode(w);
52         return in.toVal(context, w);
53     }
54     @Override
55     public void collectFreeVariables(THashSet<Variable> vars) {
56         ruleset.collectFreeVariables(vars);
57         in.collectFreeVariables(vars);
58     }
59     @Override
60     public Expression resolve(TranslationContext context) {
61         context.pushFrame();
62         context.pushCHRConstraintFrame();
63         ruleset.resolve(context);
64         in = in.resolve(context);
65         context.popCHRConstraintFrame(ruleset.constraints);
66         context.popFrame();
67         return this;
68     }
69     @Override
70     public void setLocationDeep(long loc) {
71         if(location == Locations.NO_LOCATION) {
72             this.location = loc;
73             ruleset.setLocationDeep(loc);
74             in.setLocationDeep(loc);
75         }
76     }
77     @Override
78     public Expression decorate(ExpressionDecorator decorator) {
79         in = in.decorate(decorator);
80         return this;
81     }
82     @Override
83     public void collectEffects(THashSet<Type> effects) {
84         ruleset.collectEffects(effects);
85         in.collectEffects(effects);
86     }
87     @Override
88     public void accept(ExpressionVisitor visitor) {
89         visitor.visit(this);
90     }
91     
92     @Override
93     public Expression inferType(TypingContext context) {
94         ruleset.checkType(context);
95         in = in.inferType(context);
96         return this;
97     }
98     
99     @Override
100     public Expression simplify(SimplificationContext context) {
101         ruleset.simplify(context);
102         ruleset.compile(context);
103         in = in.simplify(context);
104         return this;
105     }
106     
107     @Override
108     public Expression accept(ExpressionTransformer transformer) {
109         return transformer.transform(this);
110     }
111     
112     @Override
113     public IExpression toIExpression(ExpressionInterpretationContext context) {
114         throw new UnsupportedOperationException();
115     }
116
117 }