diff options
author | 2017-06-10 19:05:05 +0200 | |
---|---|---|
committer | 2017-06-10 19:05:05 +0200 | |
commit | 60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch) | |
tree | 5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend | |
parent | Initial commit, migrating from SVN (diff) | |
download | VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip |
Migrating Additional projects
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend new file mode 100644 index 00000000..3c49c323 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend | |||
@@ -0,0 +1,97 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
8 | import org.eclipse.emf.ecore.EClass | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeRefinementPrecondition | ||
10 | import java.util.Collections | ||
11 | |||
12 | class TypeIndexerWithPreliminaryTypeAnalysis implements TypeIndexer{ | ||
13 | val PatternGenerator base; | ||
14 | |||
15 | new(PatternGenerator base) { | ||
16 | this.base = base | ||
17 | } | ||
18 | override requiresTypeAnalysis() { true } | ||
19 | |||
20 | override getRequiredQueries() ''' | ||
21 | private pattern typeInterpretation(problem:LogicProblem, interpetation:PartialInterpretation, type:TypeDeclaration, typeInterpretation:PartialTypeInterpratation) { | ||
22 | find interpretation(problem,interpetation); | ||
23 | LogicProblem.types(problem,type); | ||
24 | PartialInterpretation.partialtypeinterpratation(interpetation,typeInterpretation); | ||
25 | PartialTypeInterpratation.interpretationOf(typeInterpretation,type); | ||
26 | } | ||
27 | |||
28 | private pattern directInstanceOf(problem:LogicProblem, interpetation:PartialInterpretation, element:DefinedElement, type:Type) { | ||
29 | find interpretation(problem,interpetation); | ||
30 | LogicProblem.types(problem,type); | ||
31 | TypeDefinition.elements(type,element); | ||
32 | } or { | ||
33 | find interpretation(problem,interpetation); | ||
34 | find typeInterpretation(problem,interpetation,type,typeInterpretation); | ||
35 | PartialTypeInterpratation.elements(typeInterpretation,element); | ||
36 | } | ||
37 | ''' | ||
38 | |||
39 | override generateInstanceOfQueries(LogicProblem problem, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
40 | val mayNewTypePreconditions = typeAnalysisResult.mayNewTypePreconditions | ||
41 | |||
42 | return ''' | ||
43 | «FOR type:problem.types» | ||
44 | «problem.generateMustInstenceOf(type)» | ||
45 | «problem.generateMayInstanceOf(type,mayNewTypePreconditions.get(type))» | ||
46 | «ENDFOR» | ||
47 | ''' | ||
48 | } | ||
49 | |||
50 | private def patternName(Type type, Modality modality) | ||
51 | '''«modality.toString.toLowerCase»InstanceOf«base.canonizeName(type.name)»''' | ||
52 | |||
53 | private def generateMustInstenceOf(LogicProblem problem, Type type) { | ||
54 | ''' | ||
55 | /** | ||
56 | * An element must be an instance of type "«type.name»". | ||
57 | */ | ||
58 | private pattern «patternName(type,Modality.MUST)»(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
59 | Type.name(type,"«type.name»"); | ||
60 | find directInstanceOf(problem,interpretation,element,type); | ||
61 | } | ||
62 | ''' | ||
63 | } | ||
64 | |||
65 | private def generateMayInstanceOf(LogicProblem problem, Type type, TypeRefinementPrecondition precondition) { | ||
66 | val inhibitorTypes = if(precondition!=null) { | ||
67 | precondition.inhibitorTypes | ||
68 | } else { | ||
69 | null | ||
70 | } | ||
71 | ''' | ||
72 | /** | ||
73 | * An element may be an instance of type "«type.name»". | ||
74 | */ | ||
75 | private pattern «patternName(type,Modality.MAY)»(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) | ||
76 | «IF inhibitorTypes != null»{ | ||
77 | find interpretation(problem,interpretation); | ||
78 | PartialInterpretation.newElements(interpretation,element); | ||
79 | «FOR inhibitorType : inhibitorTypes» | ||
80 | neg «referInstanceOf(inhibitorType,Modality.MUST,"element")» | ||
81 | «ENDFOR» | ||
82 | } or { | ||
83 | find interpretation(problem,interpretation); | ||
84 | PartialInterpretation.openWorldElementPrototype(interpetation,element); | ||
85 | } or | ||
86 | «ENDIF» | ||
87 | { «referInstanceOf(type,Modality.MUST,"element")» } | ||
88 | ''' | ||
89 | } | ||
90 | |||
91 | public override referInstanceOf(Type type, Modality modality, String variableName) { | ||
92 | '''find «patternName(type,modality)»(problem,interpretation,«variableName»);''' | ||
93 | } | ||
94 | public override referInstanceOf(EClass type, Modality modality, String variableName) { | ||
95 | '''find «modality.toString.toLowerCase»InstanceOf«base.canonizeName('''class «type.name»''')»(problem,interpretation,«variableName»);''' | ||
96 | } | ||
97 | } \ No newline at end of file | ||