|
1 |
| -package hu.bme.mit.incquery.localsearch.cpp.generator.internal.runtime |
2 |
| - |
3 |
| -import hu.bme.mit.cpp.util.util.CppHelper |
4 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.internal.BaseGenerator |
5 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckInstanceOfStub |
6 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckMultiNavigationStub |
7 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckSingleNavigationStub |
8 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendInstanceOfStub |
9 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendMultiNavigationStub |
10 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendSingleNavigationStub |
11 |
| -import hu.bme.mit.incquery.localsearch.cpp.generator.model.SearchOperationStub |
12 |
| -import org.eclipse.emf.ecore.EClass |
13 |
| -import org.eclipse.emf.ecore.EClassifier |
14 |
| -import org.eclipse.emf.ecore.EStructuralFeature |
15 |
| -import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable |
16 |
| -import org.eclipse.xtend.lib.annotations.Accessors |
17 |
| - |
18 |
| -class RuntimeSearchOperationGenerator extends BaseGenerator { |
19 |
| - |
20 |
| - @Accessors(PUBLIC_GETTER) val SearchOperationStub operation; |
21 |
| - val MatchingFrameGenerator frameGenerator |
22 |
| - |
23 |
| - |
24 |
| - new(SearchOperationStub operation, MatchingFrameGenerator frameGenerator) { |
25 |
| - this.operation = operation |
26 |
| - this.frameGenerator = frameGenerator |
27 |
| - } |
28 |
| - |
29 |
| - override initialize() { |
30 |
| - } |
31 |
| - |
32 |
| - override compile() { |
33 |
| - operation.compileOperation |
34 |
| - } |
35 |
| - |
36 |
| - private dispatch def compileOperation(CheckInstanceOfStub operation) { |
37 |
| - return '''create_«CheckInstanceOfStub::NAME»(«operation.variable.toGetter», «operation.key.toTypeID»)''' |
38 |
| - } |
39 |
| - |
40 |
| - private dispatch def compileOperation(CheckSingleNavigationStub operation) { |
41 |
| - val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
42 |
| - return '''create_«CheckSingleNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toGetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
43 |
| - } |
44 |
| - |
45 |
| - private dispatch def compileOperation(CheckMultiNavigationStub operation) { |
46 |
| - val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
47 |
| - return '''create_«CheckMultiNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toGetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
48 |
| - } |
49 |
| - |
50 |
| - private dispatch def compileOperation(ExtendInstanceOfStub operation) { |
51 |
| - return '''create_«ExtendInstanceOfStub::NAME»(«operation.variable.toSetter», «operation.key.toTypeID», model)''' |
52 |
| - } |
53 |
| - |
54 |
| - private dispatch def compileOperation(ExtendSingleNavigationStub operation) { |
55 |
| - val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
56 |
| - return '''create_«ExtendSingleNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toSetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
57 |
| - } |
58 |
| - |
59 |
| - private dispatch def compileOperation(ExtendMultiNavigationStub operation) { |
60 |
| - val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
61 |
| - return '''create_«ExtendMultiNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toSetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
62 |
| - } |
63 |
| - |
64 |
| - private dispatch def compileOperation(SearchOperationStub operation) { |
65 |
| - return '''//NYI''' |
66 |
| - } |
67 |
| - |
68 |
| - private def toTypeID(EClassifier key) { |
69 |
| - '''«CppHelper::getTypeHelper(key).FQN»::type_id''' |
70 |
| - } |
71 |
| - |
72 |
| - private def toNavigator(EClass type, String name) { |
73 |
| - '''&«type.toCppName»::«name»''' |
74 |
| - } |
75 |
| - |
76 |
| - private def toGetter(PVariable variable) { |
77 |
| - '''&«frameGenerator.frameName»::«frameGenerator.getVariableName(variable)»''' |
78 |
| - } |
79 |
| - |
80 |
| - private def toSetter(PVariable variable) { |
81 |
| - '''&«frameGenerator.frameName»::«frameGenerator.getVariableName(variable)»''' |
82 |
| - } |
83 |
| - |
84 |
| - private def toCppName(EClassifier type) { |
85 |
| - CppHelper::getTypeHelper(type).FQN |
86 |
| - } |
87 |
| - |
88 |
| - private def toRelationName(EStructuralFeature key) { |
89 |
| - key.name |
90 |
| - } |
91 |
| -} |
| 1 | +package hu.bme.mit.incquery.localsearch.cpp.generator.internal.runtime |
| 2 | + |
| 3 | +import hu.bme.mit.cpp.util.util.CppHelper |
| 4 | +import hu.bme.mit.incquery.localsearch.cpp.generator.internal.BaseGenerator |
| 5 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckInstanceOfStub |
| 6 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckMultiNavigationStub |
| 7 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckSingleNavigationStub |
| 8 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendInstanceOfStub |
| 9 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendMultiNavigationStub |
| 10 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.ExtendSingleNavigationStub |
| 11 | +import org.eclipse.emf.ecore.EClass |
| 12 | +import org.eclipse.emf.ecore.EClassifier |
| 13 | +import org.eclipse.emf.ecore.EStructuralFeature |
| 14 | +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable |
| 15 | +import org.eclipse.xtend.lib.annotations.Accessors |
| 16 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.ISearchOperationStub |
| 17 | +import hu.bme.mit.incquery.localsearch.cpp.generator.model.CheckNACOperationStub |
| 18 | + |
| 19 | +class RuntimeSearchOperationGenerator extends BaseGenerator { |
| 20 | + |
| 21 | + val String queryName |
| 22 | + @Accessors(PUBLIC_GETTER) val ISearchOperationStub operation; |
| 23 | + val MatchingFrameGenerator frameGenerator |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + new(String queryName, ISearchOperationStub operation, MatchingFrameGenerator frameGenerator) { |
| 28 | + this.queryName = queryName |
| 29 | + this.operation = operation |
| 30 | + this.frameGenerator = frameGenerator |
| 31 | + } |
| 32 | + |
| 33 | + override initialize() { |
| 34 | + } |
| 35 | + |
| 36 | + override compile(StringBuilder setupCode) { |
| 37 | + operation.compileOperation(setupCode) |
| 38 | + } |
| 39 | + |
| 40 | + private dispatch def compileOperation(CheckInstanceOfStub operation, StringBuilder setupCode) { |
| 41 | + return '''create_«CheckInstanceOfStub::NAME»(«operation.variable.toGetter», «operation.key.toTypeID»)''' |
| 42 | + } |
| 43 | + |
| 44 | + private dispatch def compileOperation(CheckSingleNavigationStub operation, StringBuilder setupCode) { |
| 45 | + val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
| 46 | + return '''create_«CheckSingleNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toGetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
| 47 | + } |
| 48 | + |
| 49 | + private dispatch def compileOperation(CheckMultiNavigationStub operation, StringBuilder setupCode) { |
| 50 | + val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
| 51 | + return '''create_«CheckMultiNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toGetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
| 52 | + } |
| 53 | + |
| 54 | + private dispatch def compileOperation(CheckNACOperationStub operation, StringBuilder setupCode) { |
| 55 | + setupCode.append('''«operation.matcher» matcher_«operation.hashCode»(model, «queryName»QueryGroup::instance()->context())''') |
| 56 | + return '''create_«CheckNACOperationStub::NAME»<«frameGenerator.frameName»>(matcher_«operation.hashCode», «operation.bindings.join(", ")»)''' |
| 57 | + } |
| 58 | + |
| 59 | + private dispatch def compileOperation(ExtendInstanceOfStub operation, StringBuilder setupCode) { |
| 60 | + return '''create_«ExtendInstanceOfStub::NAME»(«operation.variable.toSetter», «operation.key.toTypeID», model)''' |
| 61 | + } |
| 62 | + |
| 63 | + private dispatch def compileOperation(ExtendSingleNavigationStub operation, StringBuilder setupCode) { |
| 64 | + val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
| 65 | + return '''create_«ExtendSingleNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toSetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
| 66 | + } |
| 67 | + |
| 68 | + private dispatch def compileOperation(ExtendMultiNavigationStub operation, StringBuilder setupCode) { |
| 69 | + val sourceType = operation.matchingFrame.getVariableStrictType(operation.source) as EClass |
| 70 | + return '''create_«ExtendMultiNavigationStub::NAME»(«operation.source.toGetter», «operation.target.toSetter», «sourceType.toNavigator(operation.key.toRelationName)»)''' |
| 71 | + } |
| 72 | + |
| 73 | + private dispatch def compileOperation(ISearchOperationStub operation, StringBuilder setupCode) { |
| 74 | + return '''//NYI''' |
| 75 | + } |
| 76 | + |
| 77 | + private def toTypeID(EClassifier key) { |
| 78 | + '''«CppHelper::getTypeHelper(key).FQN»::type_id''' |
| 79 | + } |
| 80 | + |
| 81 | + private def toNavigator(EClass type, String name) { |
| 82 | + '''&«type.toCppName»::«name»''' |
| 83 | + } |
| 84 | + |
| 85 | + private def toGetter(PVariable variable) { |
| 86 | + '''&«frameGenerator.frameName»::«frameGenerator.getVariableName(variable)»''' |
| 87 | + } |
| 88 | + |
| 89 | + private def toSetter(PVariable variable) { |
| 90 | + '''&«frameGenerator.frameName»::«frameGenerator.getVariableName(variable)»''' |
| 91 | + } |
| 92 | + |
| 93 | + private def toCppName(EClassifier type) { |
| 94 | + CppHelper::getTypeHelper(type).FQN |
| 95 | + } |
| 96 | + |
| 97 | + private def toRelationName(EStructuralFeature key) { |
| 98 | + key.name |
| 99 | + } |
| 100 | +} |
0 commit comments