diff options
author | 2017-10-13 13:35:03 +0200 | |
---|---|---|
committer | 2017-10-13 13:35:03 +0200 | |
commit | fe2881fe9c09372ac4a5cc54e96b439d024dffd9 (patch) | |
tree | 3504ac660491293154ca2cb566a68ba8ce635c39 /Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend | |
parent | Refactoring of Alloy type mapping and interpretation. (diff) | |
download | VIATRA-Generator-fe2881fe9c09372ac4a5cc54e96b439d024dffd9.tar.gz VIATRA-Generator-fe2881fe9c09372ac4a5cc54e96b439d024dffd9.tar.zst VIATRA-Generator-fe2881fe9c09372ac4a5cc54e96b439d024dffd9.zip |
:lipstick:
Diffstat (limited to 'Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend')
-rw-r--r-- | Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend b/Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend new file mode 100644 index 00000000..934a863a --- /dev/null +++ b/Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/AlloyModelInterpretation_TypeInterpretation_FilteredTypes.xtend | |||
@@ -0,0 +1,72 @@ | |||
1 | package hu.bme.mit.inf.dlsreasoner.alloy.reasoner.builder | ||
2 | |||
3 | import edu.mit.csail.sdg.alloy4compiler.ast.ExprVar | ||
4 | import edu.mit.csail.sdg.alloy4compiler.ast.Sig | ||
5 | import edu.mit.csail.sdg.alloy4compiler.ast.Sig.Field | ||
6 | import edu.mit.csail.sdg.alloy4compiler.translator.A4Solution | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
10 | import java.util.ArrayList | ||
11 | import java.util.List | ||
12 | import java.util.Map | ||
13 | |||
14 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
15 | |||
16 | class AlloyModelInterpretation_TypeInterpretation_FilteredTypes implements AlloyModelInterpretation_TypeInterpretation{ | ||
17 | protected val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE | ||
18 | |||
19 | override resolveUnknownAtoms( | ||
20 | Iterable<ExprVar> objectAtoms, | ||
21 | A4Solution solution, | ||
22 | Logic2AlloyLanguageMapperTrace forwardTrace, | ||
23 | Map<String, Sig> name2AlloySig, | ||
24 | Map<String, Field> name2AlloyField, | ||
25 | Map<String,DefinedElement> expression2DefinedElement, | ||
26 | Map<TypeDeclaration, List<DefinedElement>> interpretationOfUndefinedType) | ||
27 | { | ||
28 | /*val Map<String,DefinedElement> expression2DefinedElement = new HashMap() | ||
29 | val Map<TypeDeclaration, List<DefinedElement>> interpretationOfUndefinedType = new HashMap;*/ | ||
30 | |||
31 | val typeTrace = forwardTrace.typeMapperTrace as Logic2AlloyLanguageMapper_TypeMapperTrace_FilteredTypes | ||
32 | |||
33 | // 1. Evaluate the defined elements | ||
34 | for(definedElementMappingEntry : typeTrace.definedElement2Declaration.entrySet) { | ||
35 | val name = definedElementMappingEntry.value.name | ||
36 | val matchingSig = '''this/«name»'''.toString.lookup(name2AlloySig) | ||
37 | val elementsOfSingletonSignature = solution.eval(matchingSig) | ||
38 | if(elementsOfSingletonSignature.size != 1) { | ||
39 | throw new IllegalArgumentException('''Defined element is unambigous: "«name»", possible values: «elementsOfSingletonSignature»!''') | ||
40 | } else { | ||
41 | val expressionOfDefinedElement = elementsOfSingletonSignature.head.atom(0)// as ExprVar | ||
42 | expression2DefinedElement.put(expressionOfDefinedElement, definedElementMappingEntry.key) | ||
43 | } | ||
44 | } | ||
45 | |||
46 | // 2. evaluate the signatures and create new elements if necessary | ||
47 | for(type2SingatureEntry : typeTrace.type2ALSType.entrySet) { | ||
48 | val type = type2SingatureEntry.key | ||
49 | if(type instanceof TypeDeclaration) { | ||
50 | val name = type2SingatureEntry.value.name | ||
51 | val matchingSig = '''this/«name»'''.toString.lookup(name2AlloySig) | ||
52 | val elementsOfSignature = solution.eval(matchingSig) | ||
53 | val elementList = new ArrayList(elementsOfSignature.size) | ||
54 | var newVariableIndex = 1; | ||
55 | for(elementOfSignature : elementsOfSignature) { | ||
56 | val expressionOfDefinedElement = elementOfSignature.atom(0) | ||
57 | if(expression2DefinedElement.containsKey(expressionOfDefinedElement)) { | ||
58 | elementList += expressionOfDefinedElement.lookup(expression2DefinedElement) | ||
59 | } else { | ||
60 | val newElementName = '''newObject «newVariableIndex.toString»''' | ||
61 | val newRepresentation = createDefinedElement => [ | ||
62 | it.name = newElementName | ||
63 | ] | ||
64 | elementList += newRepresentation | ||
65 | expression2DefinedElement.put(expressionOfDefinedElement,newRepresentation) | ||
66 | } | ||
67 | } | ||
68 | interpretationOfUndefinedType.put(type,elementList) | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } \ No newline at end of file | ||