aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/TypeIndexerWithPreliminaryTypeAnalysis.xtend
blob: 0393b80384f768213c11c3c5f47f8d0da186a262 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns

import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult

class TypeIndexerWithPreliminaryTypeAnalysis extends TypeIndexer {
	new(PatternGenerator base) {
		super(base)
	}

	override requiresTypeAnalysis() { true }

	protected override generateMayInstanceOf(LogicProblem problem, Type type, TypeAnalysisResult typeAnalysisResult) {
		val precondition = typeAnalysisResult?.mayNewTypePreconditions?.get(type)
		val inhibitorTypes = precondition?.inhibitorTypes
		'''
			private pattern scopeDisallowsNew«base.canonizeName(type.name)»(problem:LogicProblem, interpretation:PartialInterpretation) {
				find interpretation(problem,interpretation);
				PartialInterpretation.scopes(interpretation,scope);
				Scope.targetTypeInterpretation(scope,typeInterpretation);
				Scope.maxNewElements(scope,0);
				PartialComplexTypeInterpretation.interpretationOf(typeInterpretation,type);
				Type.name(type,"«type.name»");
			}
			
			/**
			 * An element may be an instance of type "«type.name»".
			 */
			private pattern «patternName(type,Modality.MAY)»(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement)
			«IF inhibitorTypes !== null»
				{
					find interpretation(problem,interpretation);
					PartialInterpretation.newElements(interpretation,element);
					«FOR inhibitorType : inhibitorTypes»
						neg «referInstanceOf(inhibitorType,Modality.MUST,"element")»
					«ENDFOR»
					neg find scopeDisallowsNew«base.canonizeName(type.name)»(problem, interpretation);
					neg find isPrimitive(element);
				} or {
					find interpretation(problem,interpretation);
					PartialInterpretation.openWorldElements(interpretation,element);
					«FOR inhibitorType : inhibitorTypes»
						neg «referInstanceOf(inhibitorType,Modality.MUST,"element")»
					«ENDFOR»
					neg find scopeDisallowsNew«base.canonizeName(type.name)»(problem, interpretation);
					neg find isPrimitive(element);
				} or
			«ENDIF»
			{ «referInstanceOf(type,Modality.MUST,"element")» }
		'''
	}
}