]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java
(refs #7498) Bugfixing implementation of skeleton refs
[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 public class ECHRRulesetConstructor extends Expression {
17     public CHRRuleset ruleset;
18     
19     public ECHRRulesetConstructor(CHRRuleset ruleset) {
20         this.ruleset = ruleset;
21     }
22
23     @Override
24     protected void updateType() throws MatchException {
25         throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
26     }
27
28     @Override
29     public IVal toVal(CompilationContext context, CodeWriter w) {
30         return ruleset.generateCode(w);
31     }
32
33     @Override
34     public Expression resolve(TranslationContext context) {
35         context.pushFrame();
36         context.pushCHRConstraintFrame();
37         ruleset.resolve(context);
38         context.popCHRConstraintFrame(ruleset.constraints);
39         context.popFrame();
40         return this;
41     }
42     @Override
43     public void setLocationDeep(long loc) {
44         if(location == Locations.NO_LOCATION) {
45             this.location = loc;
46             ruleset.setLocationDeep(loc);
47         }
48     }
49     @Override
50     public void accept(ExpressionVisitor visitor) {
51         visitor.visit(this);
52     }
53     
54     @Override
55     public Expression inferType(TypingContext context) {
56         ruleset.checkType(context);
57         return this;
58     }
59     
60     @Override
61     public Expression simplify(SimplificationContext context) {
62         ruleset.simplify(context);
63         ruleset.compile(context);
64         return this;
65     }
66     
67     @Override
68     public Expression accept(ExpressionTransformer transformer) {
69         return transformer.transform(this);
70     }
71     
72     @Override
73     public IExpression toIExpression(ExpressionInterpretationContext context) {
74         throw new UnsupportedOperationException();
75     }
76
77 }