diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java | 198 |
1 files changed, 0 insertions, 198 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java deleted file mode 100644 index 7fd86f3c..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, Zoltan Ujhelyi, IncQuery Labs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.planner.compiler; | ||
10 | |||
11 | import java.util.Map; | ||
12 | |||
13 | import org.eclipse.emf.ecore.EReference; | ||
14 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
15 | import tools.refinery.viatra.runtime.emf.EMFQueryRuntimeContext; | ||
16 | import tools.refinery.viatra.runtime.emf.types.EClassTransitiveInstancesKey; | ||
17 | import tools.refinery.viatra.runtime.emf.types.EClassUnscopedTransitiveInstancesKey; | ||
18 | import tools.refinery.viatra.runtime.emf.types.EDataTypeInSlotsKey; | ||
19 | import tools.refinery.viatra.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfClassCheck; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfDataTypeCheck; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfJavaClassCheck; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.check.StructuralFeatureCheck; | ||
24 | import tools.refinery.viatra.runtime.localsearch.operations.check.nobase.ScopeCheck; | ||
25 | import tools.refinery.viatra.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureSource; | ||
26 | import tools.refinery.viatra.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureTarget; | ||
27 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverContainers; | ||
28 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverEClassInstances; | ||
29 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverEDatatypeInstances; | ||
30 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
31 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
32 | import tools.refinery.viatra.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
33 | import tools.refinery.viatra.runtime.matchers.planning.QueryProcessingException; | ||
34 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
35 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
36 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
38 | |||
39 | /** | ||
40 | * Operation compiler implementation that uses EMF-specific operations. | ||
41 | * | ||
42 | * @author Zoltan Ujhelyi | ||
43 | * @since 1.7 | ||
44 | * | ||
45 | */ | ||
46 | public class EMFOperationCompiler extends AbstractOperationCompiler { | ||
47 | |||
48 | private boolean baseIndexAvailable; | ||
49 | |||
50 | private final EMFQueryRuntimeContext runtimeContext; | ||
51 | |||
52 | public EMFOperationCompiler(IQueryRuntimeContext runtimeContext) { | ||
53 | this(runtimeContext, false); | ||
54 | } | ||
55 | |||
56 | public EMFOperationCompiler(IQueryRuntimeContext runtimeContext, boolean baseIndexAvailable) { | ||
57 | super(runtimeContext); | ||
58 | this.runtimeContext = (EMFQueryRuntimeContext) runtimeContext; | ||
59 | this.baseIndexAvailable = baseIndexAvailable; | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | protected void createCheck(TypeFilterConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
64 | final IInputKey inputKey = typeConstraint.getInputKey(); | ||
65 | if (inputKey instanceof JavaTransitiveInstancesKey) { | ||
66 | doCreateInstanceofJavaTypeCheck((JavaTransitiveInstancesKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
67 | } else if (inputKey instanceof EDataTypeInSlotsKey) { // TODO probably only occurs as TypeConstraint | ||
68 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
69 | } else if (inputKey instanceof EClassUnscopedTransitiveInstancesKey) { | ||
70 | doCreateInstanceofUnscopedClassCheck((EClassUnscopedTransitiveInstancesKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
71 | } else { | ||
72 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
73 | throw new QueryProcessingException(msg, null, msg, null); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | protected void createCheck(TypeConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
79 | final IInputKey inputKey = typeConstraint.getSupplierKey(); | ||
80 | if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
81 | doCreateInstanceofClassCheck((EClassTransitiveInstancesKey)inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
82 | } else if (inputKey instanceof EStructuralFeatureInstancesKey) { | ||
83 | int sourcePosition = variableMapping.get(typeConstraint.getVariablesTuple().get(0)); | ||
84 | int targetPosition = variableMapping.get(typeConstraint.getVariablesTuple().get(1)); | ||
85 | operations.add(new StructuralFeatureCheck(sourcePosition, targetPosition, | ||
86 | ((EStructuralFeatureInstancesKey) inputKey).getEmfKey())); | ||
87 | } else if (inputKey instanceof EDataTypeInSlotsKey) { | ||
88 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
89 | } else { | ||
90 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
91 | throw new QueryProcessingException(msg, null, msg, null); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | protected void createUnaryTypeCheck(IInputKey inputKey, int position) { | ||
97 | if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
98 | doCreateInstanceofClassCheck((EClassTransitiveInstancesKey)inputKey, position); | ||
99 | } else if (inputKey instanceof EClassUnscopedTransitiveInstancesKey) { | ||
100 | doCreateInstanceofUnscopedClassCheck((EClassUnscopedTransitiveInstancesKey)inputKey, position); | ||
101 | } else if (inputKey instanceof EDataTypeInSlotsKey) { | ||
102 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, position); | ||
103 | } else if (inputKey instanceof JavaTransitiveInstancesKey) { | ||
104 | doCreateInstanceofJavaTypeCheck((JavaTransitiveInstancesKey) inputKey, position); | ||
105 | } else { | ||
106 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
107 | throw new QueryProcessingException(msg, null, msg, null); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | private void doCreateInstanceofClassCheck(EClassTransitiveInstancesKey inputKey, int position) { | ||
112 | operations.add(new InstanceOfClassCheck(position, inputKey.getEmfKey())); | ||
113 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
114 | } | ||
115 | |||
116 | private void doCreateInstanceofUnscopedClassCheck(EClassUnscopedTransitiveInstancesKey inputKey, int position) { | ||
117 | operations.add(new InstanceOfClassCheck(position, inputKey.getEmfKey())); | ||
118 | } | ||
119 | |||
120 | private void doCreateInstanceofDatatypeCheck(EDataTypeInSlotsKey inputKey, int position) { | ||
121 | operations.add(new InstanceOfDataTypeCheck(position, inputKey.getEmfKey())); | ||
122 | } | ||
123 | private void doCreateInstanceofJavaTypeCheck(JavaTransitiveInstancesKey inputKey, int position) { | ||
124 | operations.add(new InstanceOfJavaClassCheck(position, inputKey.getInstanceClass())); | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public void createExtend(TypeConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
129 | final IInputKey inputKey = typeConstraint.getSupplierKey(); | ||
130 | if (inputKey instanceof EDataTypeInSlotsKey) { | ||
131 | if(baseIndexAvailable){ | ||
132 | operations.add(new IterateOverEDatatypeInstances(variableMapping.get(typeConstraint.getVariableInTuple(0)), ((EDataTypeInSlotsKey) inputKey).getEmfKey())); | ||
133 | } else { | ||
134 | int position = variableMapping.get(typeConstraint.getVariableInTuple(0)); | ||
135 | operations | ||
136 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEDatatypeInstances(position, | ||
137 | ((EDataTypeInSlotsKey) inputKey).getEmfKey(), runtimeContext.getEmfScope())); | ||
138 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
139 | } | ||
140 | } else if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
141 | if(baseIndexAvailable){ | ||
142 | operations.add(new IterateOverEClassInstances(variableMapping.get(typeConstraint.getVariableInTuple(0)), | ||
143 | ((EClassTransitiveInstancesKey) inputKey).getEmfKey())); | ||
144 | } else { | ||
145 | int position = variableMapping.get(typeConstraint.getVariableInTuple(0)); | ||
146 | operations | ||
147 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEClassInstances( | ||
148 | position, | ||
149 | ((EClassTransitiveInstancesKey) inputKey).getEmfKey(), runtimeContext.getEmfScope())); | ||
150 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
151 | } | ||
152 | } else if (inputKey instanceof EStructuralFeatureInstancesKey) { | ||
153 | final EStructuralFeature feature = ((EStructuralFeatureInstancesKey) inputKey).getEmfKey(); | ||
154 | |||
155 | int sourcePosition = variableMapping.get(typeConstraint.getVariablesTuple().get(0)); | ||
156 | int targetPosition = variableMapping.get(typeConstraint.getVariablesTuple().get(1)); | ||
157 | |||
158 | boolean fromBound = variableBindings.get(typeConstraint).contains(sourcePosition); | ||
159 | boolean toBound = variableBindings.get(typeConstraint).contains(targetPosition); | ||
160 | |||
161 | if (fromBound && !toBound) { | ||
162 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
163 | operations.add(new ScopeCheck(targetPosition, runtimeContext.getEmfScope())); | ||
164 | } else if(!fromBound && toBound){ | ||
165 | if (feature instanceof EReference && ((EReference)feature).isContainment()) { | ||
166 | // The iterate is also used to traverse a single container (third parameter) | ||
167 | operations.add(new IterateOverContainers(sourcePosition, targetPosition, false)); | ||
168 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
169 | } else if(baseIndexAvailable){ | ||
170 | TupleMask mask = TupleMask.fromSelectedIndices(variableMapping.size(), new int[] {targetPosition}); | ||
171 | operations.add(new ExtendToEStructuralFeatureSource(sourcePosition, targetPosition, feature, mask)); | ||
172 | } else { | ||
173 | operations.add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.ExtendToEStructuralFeatureSource( | ||
174 | sourcePosition, targetPosition, feature)); | ||
175 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
176 | } | ||
177 | } else { | ||
178 | // TODO Elaborate solution based on the navigability of edges | ||
179 | // As of now a static solution is implemented | ||
180 | if (baseIndexAvailable) { | ||
181 | operations.add(new IterateOverEClassInstances(sourcePosition, feature.getEContainingClass())); | ||
182 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
183 | } else { | ||
184 | operations | ||
185 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEClassInstances( | ||
186 | sourcePosition, feature.getEContainingClass(), runtimeContext.getEmfScope())); | ||
187 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
188 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
189 | operations.add(new ScopeCheck(targetPosition, runtimeContext.getEmfScope())); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | } else { | ||
194 | throw new IllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE + inputKey); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | } | ||