]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EPreCHRRulesetConstructor.java
(refs #7250) CHR rules modularization (first working version)
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EPreCHRRulesetConstructor.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
4 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
5 import org.simantics.scl.compiler.errors.Locations;
6 import org.simantics.scl.compiler.internal.parsing.declarations.DRulesetAst;
7
8 public class EPreCHRRulesetConstructor extends ASTExpression {
9     DRulesetAst rulesetAst;
10     
11     public EPreCHRRulesetConstructor(DRulesetAst rulesetAst) {
12         this.rulesetAst = rulesetAst;
13         this.location = rulesetAst.location;
14     }
15
16     @Override
17     public Expression resolve(TranslationContext context) {
18         CHRRuleset ruleset = rulesetAst.block.extractCHRRules(context);
19         ruleset.setLocationDeep(rulesetAst.location);
20         ruleset.setRulesetType(rulesetAst.type, rulesetAst.className);
21         ruleset.extensible = true;
22         context.getCompilationContext().module.addRuleset(rulesetAst.name, ruleset);
23         ECHRRulesetConstructor result = new ECHRRulesetConstructor(ruleset);
24         result.resolve(context);
25         result.setType(rulesetAst.type);
26         return result;
27     }
28
29     @Override
30     public void setLocationDeep(long loc) {
31         if(location == Locations.NO_LOCATION) {
32             rulesetAst.block.setLocationDeep(loc);
33             location = loc;
34         }
35     }
36
37     @Override
38     public Expression accept(ExpressionTransformer transformer) {
39         return this;
40     }
41 }