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/TypeRefinementWithPreliminaryTypeAnalysis.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/TypeRefinementWithPreliminaryTypeAnalysis.xtend')
1 files changed, 105 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/TypeRefinementWithPreliminaryTypeAnalysis.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend new file mode 100644 index 00000000..be54d63c --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeRefinementWithPreliminaryTypeAnalysis.xtend | |||
@@ -0,0 +1,105 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
10 | import java.util.HashMap | ||
11 | |||
12 | class TypeRefinementWithPreliminaryTypeAnalysis extends TypeRefinementGenerator{ | ||
13 | public new(PatternGenerator base) { | ||
14 | super(base) | ||
15 | } | ||
16 | override requiresTypeAnalysis() { true } | ||
17 | |||
18 | |||
19 | override generateRefineObjectQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
20 | val possibleNewDynamicType = typeAnalysisResult.possibleNewDynamicTypes | ||
21 | val containment = p.containmentHierarchies.head | ||
22 | val inverseRelations = new HashMap | ||
23 | p.annotations.filter(InverseRelationAssertion).forEach[ | ||
24 | inverseRelations.put(it.inverseA,it.inverseB) | ||
25 | inverseRelations.put(it.inverseB,it.inverseA) | ||
26 | ] | ||
27 | return ''' | ||
28 | «FOR type:possibleNewDynamicType» | ||
29 | «IF(containment.typesOrderedInHierarchy.contains(type))» | ||
30 | «FOR containmentRelation : containment.containmentRelations.filter[canBeContainedByRelation(it,type)]» | ||
31 | «IF inverseRelations.containsKey(containmentRelation)» | ||
32 | pattern «this.patternName(containmentRelation,inverseRelations.get(containmentRelation),type)»( | ||
33 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
34 | relationInterpretation:PartialRelationInterpretation, inverseInterpretation:PartialRelationInterpretation, typeInterpretation:PartialTypeInterpratation, | ||
35 | container:DefinedElement) | ||
36 | { | ||
37 | find interpretation(problem,interpretation); | ||
38 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
39 | PartialTypeInterpratation.interpretationOf.name(typeInterpretation,"«type.name»"); | ||
40 | PartialInterpretation.partialrelationinterpretation(interpretation,relationInterpretation); | ||
41 | PartialRelationInterpretation.interpretationOf.name(relationInterpretation,"«containmentRelation.name»"); | ||
42 | PartialInterpretation.partialrelationinterpretation(interpretation,inverseInterpretation); | ||
43 | PartialRelationInterpretation.interpretationOf.name(inverseInterpretation,"«inverseRelations.get(containmentRelation).name»"); | ||
44 | «base.typeIndexer.referInstanceOf((containmentRelation.parameters.get(0) as ComplexTypeReference).referred,Modality.MUST,"container")» | ||
45 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
46 | «base.relationDeclarationIndexer.referRelation(containmentRelation as RelationDeclaration,"container","newObject",Modality.MAY)» | ||
47 | find mustExist(problem, interpretation, container); | ||
48 | neg find mustExist(problem, interpretation, newObject); | ||
49 | } | ||
50 | «ELSE» | ||
51 | pattern «this.patternName(containmentRelation,null,type)»( | ||
52 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
53 | relationInterpretation:PartialRelationInterpretation, typeInterpretation:PartialTypeInterpratation, | ||
54 | container:DefinedElement) | ||
55 | { | ||
56 | find interpretation(problem,interpretation); | ||
57 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
58 | PartialTypeInterpratation.interpretationOf.name(typeInterpretation,"«type.name»"); | ||
59 | PartialInterpretation.partialrelationinterpretation(interpretation,relationInterpretation); | ||
60 | PartialRelationInterpretation.interpretationOf.name(relationInterpretation,"«containmentRelation.name»"); | ||
61 | «base.typeIndexer.referInstanceOf((containmentRelation.parameters.get(0) as ComplexTypeReference).referred,Modality.MUST,"container")» | ||
62 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
63 | «base.relationDeclarationIndexer.referRelation(containmentRelation as RelationDeclaration,"container","newObject",Modality.MAY)» | ||
64 | find mustExist(problem, interpretation, container); | ||
65 | neg find mustExist(problem, interpretation, newObject); | ||
66 | } | ||
67 | «ENDIF» | ||
68 | «ENDFOR» | ||
69 | «ELSE» | ||
70 | pattern createObject_«base.canonizeName(type.name)»( | ||
71 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
72 | typeInterpretation:PartialTypeInterpratation) | ||
73 | { | ||
74 | find interpretation(problem,interpretation); | ||
75 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
76 | PartialTypeInterpratation.interpretationOf.name(type,"«type.name»"); | ||
77 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
78 | find mayExist(problem, interpretation, newObject); | ||
79 | neg find mustExist(problem, interpretation, newObject); | ||
80 | } | ||
81 | «ENDIF» | ||
82 | «ENDFOR» | ||
83 | ''' | ||
84 | } | ||
85 | |||
86 | override generateRefineTypeQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
87 | val newTypeRefinements = typeAnalysisResult.possibleNewTypeRefinements | ||
88 | return ''' | ||
89 | «FOR newTypeRefinement : newTypeRefinements» | ||
90 | pattern refineTypeTo_«base.canonizeName(newTypeRefinement.targetType.name)»(problem:LogicProblem, interpretation:PartialInterpretation, element: DefinedElement) { | ||
91 | find interpretation(problem,interpretation); | ||
92 | PartialInterpretation.newElements(interpretation,element); | ||
93 | «FOR inhibitorType : newTypeRefinement.inhibitorTypes» | ||
94 | neg «base.typeIndexer.referInstanceOf(inhibitorType,Modality.MUST,"element")» | ||
95 | «ENDFOR» | ||
96 | } | ||
97 | «ENDFOR» | ||
98 | ''' | ||
99 | } | ||
100 | |||
101 | override getRefineTypeQueryNames(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
102 | val newTypeRefinements = typeAnalysisResult.possibleNewTypeRefinements | ||
103 | newTypeRefinements.map[targetType].toInvertedMap['''refineTypeTo_«base.canonizeName(it.name)»'''] | ||
104 | } | ||
105 | } \ No newline at end of file | ||