1 package org.simantics.scl.compiler.internal.elaboration.transformations;
3 import gnu.trove.procedure.TObjectObjectProcedure;
5 import java.util.ArrayList;
7 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
8 import org.simantics.scl.compiler.elaboration.query.QMapping;
9 import org.simantics.scl.compiler.elaboration.query.Query;
10 import org.simantics.scl.compiler.elaboration.relations.LocalRelation;
11 import org.simantics.scl.compiler.elaboration.rules.SectionName;
12 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
14 public class DecomposedRule {
15 final TransformationRule rule;
16 final ArrayList<Query> sourceQueries = new ArrayList<Query>();
17 final ArrayList<QMapping> sourceMappings = new ArrayList<QMapping>();
18 final ArrayList<Query> targetQueries = new ArrayList<Query>();
19 final ArrayList<QMapping> targetMappings = new ArrayList<QMapping>();
21 LocalRelation ruleMatchingRelation;
23 private DecomposedRule(TransformationRule rule) {
27 public static DecomposedRule decompose(final TypingContext context, TransformationRule rule, final boolean forwardDirection) {
28 final DecomposedRule result = new DecomposedRule(rule);
29 rule.forEachSection(new TObjectObjectProcedure<SectionName, Query[]>() {
31 public boolean execute(SectionName sectionName, Query[] queries) {
32 switch(forwardDirection ? sectionName.forwardRole : sectionName.backwardRole) {
34 for(Query query : queries) {
35 if(query instanceof QMapping) {
36 QMapping mapping = (QMapping)query;
37 result.sourceMappings.add(mapping);
40 result.sourceQueries.add(query.copy(context));
44 case ENFORCE_FIRST_TIME: // Because this is one-shot, these two are equivalent
45 for(Query query : queries) {
46 if(query instanceof QMapping) {
47 QMapping mapping = (QMapping)query;
48 result.targetMappings.add(mapping);
51 result.targetQueries.add(query.copy(context));