1
1
package hu.bme.mit.incquery.localsearch.cpp.generator.planner
2
2
3
- import com.google.common.base.CaseFormat
3
+ import com.google.common.base.Optional
4
+ import com.google.common.collect.Maps
4
5
import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckInstanceOfStub
5
6
import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckMultiNavigationStub
6
7
import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckSingleNavigationStub
@@ -9,8 +10,10 @@ import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendMultiNavigation
9
10
import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendSingleNavigationStub
10
11
import hu.bme.mit.incquery.localsearch.cpp.generator.model.MatchingFrameStub
11
12
import hu.bme.mit.incquery.localsearch.cpp.generator.model.PatternBodyStub
13
+ import hu.bme.mit.incquery.localsearch.cpp.generator.model.SearchOperationStub
14
+ import hu.bme.mit.incquery.localsearch.cpp.generator.model.TypeInfo
15
+ import hu.bme.mit.incquery.localsearch.cpp.generator.model.VariableInfo
12
16
import hu.bme.mit.incquery.localsearch.cpp.generator.planner.util.CompilerHelper
13
- import hu.bme.mit.incquery.localsearch.cpp.generator.planner.util.CompilerHelper.TypeMap
14
17
import java.util.Map
15
18
import java.util.Set
16
19
import org.eclipse.emf.ecore.EReference
@@ -34,61 +37,47 @@ class POperationCompiler {
34
37
35
38
var Map<PVariable , Integer > variableMapping
36
39
var Map<PConstraint , Set<Integer > > variableBindings
37
- var Map<PVariable , TypeMap > typeMapping
40
+ var Map<PVariable , TypeInfo > typeMapping
38
41
39
42
var MatchingFrameStub matchingFrame
40
- var PatternBodyStub patternBodyStub
41
43
42
44
43
- def void compile (SubPlan plan , PBody pBody , Set<PVariable > boundVariables , PatternBodyStub bodyStub ) {
45
+ def compile (SubPlan plan , PBody pBody , Set<PVariable > boundVariables ) {
44
46
variableMapping = CompilerHelper :: createVariableMapping(plan)
45
47
typeMapping = CompilerHelper :: createTypeMapping(plan)
46
48
variableBindings = CompilerHelper :: cacheVariableBindings(plan, variableMapping, boundVariables. map[variableMapping. get(it )]. toSet)
47
49
48
- matchingFrame = getMatchingFrame(plan, pBody)
49
- bodyStub. matchingFrame = matchingFrame
50
+ matchingFrame = getMatchingFrame(pBody)
50
51
51
- patternBodyStub = bodyStub
52
-
53
- CompilerHelper :: createOperationsList(plan). forEach [
54
- compile(variableMapping)
55
- ]
56
- return
52
+ val searchOperations = CompilerHelper :: createOperationsList(plan)
53
+ . map[compile]
54
+ . flatten
55
+ . toList
56
+ return new PatternBodyStub (pBody, matchingFrame, searchOperations)
57
57
}
58
58
59
- private def getMatchingFrame (SubPlan plan , PBody pBody ) {
59
+ private def getMatchingFrame (PBody pBody ) {
60
60
if (frameMap. containsKey(pBody)) {
61
61
frameMap. get(pBody)
62
62
} else {
63
- val tmpMatchingFrame = new MatchingFrameStub
64
- frameMap. put(pBody, tmpMatchingFrame)
65
-
66
-
67
- typeMapping. forEach [
68
- tmpMatchingFrame. addVariable($0 , $1 , variableMapping. get($0 ))
69
- ]
70
-
71
- plan. body. pattern. parameters. map[plan. body. getVariableByNameChecked(it . name)]. forEach [
72
- tmpMatchingFrame. setVariableKey(it )
73
- ]
74
-
75
- plan. body. pattern. parameters. forEach[
76
- tmpMatchingFrame. mapParameterToVariable(it , plan. body. getVariableByNameChecked(it . name))
77
- ]
78
-
79
- tmpMatchingFrame
63
+ val variableToParameterMap = Maps :: uniqueIndex(pBody. pattern. parameters) [pBody. getVariableByNameChecked(it . name)]
64
+ // don't pass this to anything else or evaluate it! (Lazy evaluation!!)
65
+ val variableInfos = pBody. allVariables. map[
66
+ new VariableInfo (Optional :: fromNullable(variableToParameterMap. get(it )), it , typeMapping. get(it ), variableMapping. get(it ))
67
+ ]. toList
68
+ new MatchingFrameStub (variableInfos)
80
69
}
81
70
}
82
71
83
- def compile (POperation pOperation , Map< PVariable , Integer > var iableMapping ) {
72
+ def compile (POperation pOperation ) {
84
73
switch (pOperation) {
85
74
PApply : {
86
75
val pConstraint = pOperation. getPConstraint
87
76
88
77
if (pConstraint. allBound)
89
- createCheck(pConstraint, variableMapping )
78
+ return createCheck(pConstraint)
90
79
else
91
- createExtend(pConstraint, variableMapping )
80
+ return createExtend(pConstraint)
92
81
93
82
}
94
83
PStart : {
@@ -98,15 +87,17 @@ class POperationCompiler {
98
87
default: { // TODO: throw an error
99
88
}
100
89
}
90
+ return #[]
101
91
}
102
92
103
- def dispatch void createCheck (TypeConstraint constraint , Map<PVariable , Integer > var iableMapping ) {
93
+ def dispatch createCheck (TypeConstraint constraint ) {
94
+ val operations = < SearchOperationStub > newArrayList
104
95
val inputKey = constraint. supplierKey
105
96
106
97
switch (inputKey) {
107
98
EClassTransitiveInstancesKey : {
108
99
val variable = constraint. getVariableInTuple(0 )
109
- patternBodyStub . addSearchOperation( new CheckInstanceOfStub (matchingFrame, variable, inputKey. wrappedKey) )
100
+ operations + = new CheckInstanceOfStub (matchingFrame, variable, inputKey. wrappedKey)
110
101
}
111
102
EStructuralFeatureInstancesKey : {
112
103
val src = constraint. getVariableInTuple(0 )
@@ -116,26 +107,31 @@ class POperationCompiler {
116
107
117
108
switch (relationType) {
118
109
case relationType. isOneToOne:
119
- patternBodyStub . addSearchOperation( new CheckSingleNavigationStub (matchingFrame, src, trg, inputKey. wrappedKey) )
110
+ operations + = new CheckSingleNavigationStub (matchingFrame, src, trg, inputKey. wrappedKey)
120
111
case relationType. isOneToMany:
121
- patternBodyStub . addSearchOperation( new CheckMultiNavigationStub (matchingFrame, src, trg, inputKey. wrappedKey) )
112
+ operations + = new CheckMultiNavigationStub (matchingFrame, src, trg, inputKey. wrappedKey)
122
113
}
123
114
}
124
115
}
116
+
117
+ return operations
125
118
}
126
119
127
120
// def dispatch createCheck(CheckPConstraint constraint, Map<PVariable, Integer> variableMapping, String patternName) {
128
121
// pattern.addSearchOperation(new CheckExpressionStub(matchingFrame, constraint.affectedVariables, constraint.expression))
129
122
// }
130
123
131
- def dispatch void createCheck (ExportedParameter constraint , Map< PVariable , Integer > var iableMapping ) {
124
+ def dispatch createCheck (ExportedParameter constraint ) {
132
125
// nop
126
+ #[]
133
127
}
134
128
135
- def dispatch void createCheck (PConstraint constraint , Map<PVariable , Integer > var iableMapping ) {
129
+ def dispatch createCheck (PConstraint constraint ) {
130
+ #[]
136
131
}
137
132
138
- def dispatch void createExtend (TypeConstraint constraint , Map<PVariable , Integer > var iableMapping ) {
133
+ def dispatch createExtend (TypeConstraint constraint ) {
134
+ val operations = < SearchOperationStub > newArrayList
139
135
val inputKey = constraint. supplierKey
140
136
141
137
// TODO : this is wasteful
@@ -147,7 +143,7 @@ class POperationCompiler {
147
143
switch (inputKey) {
148
144
EClassTransitiveInstancesKey : {
149
145
val variable = constraint. getVariableInTuple(0 )
150
- patternBodyStub . addSearchOperation( new ExtendInstanceOfStub (matchingFrame, variable, inputKey. wrappedKey) )
146
+ operations + = new ExtendInstanceOfStub (matchingFrame, variable, inputKey. wrappedKey)
151
147
}
152
148
EStructuralFeatureInstancesKey : {
153
149
var src = constraint. getVariableInTuple(0 )
@@ -163,25 +159,28 @@ class POperationCompiler {
163
159
trg = tmp
164
160
key = (key as EReference ). EOpposite
165
161
} else if (! fromBound && ! toBound) {
166
- patternBodyStub . addSearchOperation( new ExtendInstanceOfStub (matchingFrame, src, inputKey.wrappedKey. EContainingClass ) )
162
+ operations + = new ExtendInstanceOfStub (matchingFrame, src, inputKey.wrappedKey. EContainingClass )
167
163
}
168
164
169
165
switch (key) {
170
166
case key. isOneToOne:
171
- patternBodyStub . addSearchOperation( new ExtendSingleNavigationStub (matchingFrame, src, trg, key) )
167
+ operations + = new ExtendSingleNavigationStub (matchingFrame, src, trg, key)
172
168
case key. isOneToMany:
173
- patternBodyStub . addSearchOperation( new ExtendMultiNavigationStub (matchingFrame, src, trg, key) )
169
+ operations + = new ExtendMultiNavigationStub (matchingFrame, src, trg, key)
174
170
}
175
171
}
176
172
}
173
+ return operations
177
174
}
178
175
179
- def dispatch void createExtend (ExportedParameter constraint , Map< PVariable , Integer > var iableMapping ) {
176
+ def dispatch createExtend (ExportedParameter constraint ) {
180
177
// nop
178
+ #[]
181
179
}
182
180
183
- def dispatch void createExtend (PConstraint constraint , Map< PVariable , Integer > var iableMapping ) {
181
+ def dispatch createExtend (PConstraint constraint ) {
184
182
println(" Constraint type not yet implemented: " + constraint)
183
+ #[]
185
184
}
186
185
187
186
private def allBound (PConstraint pConstraint ) {
0 commit comments