aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/oldTypes
blob: f5f5a9b6a70f6bbf90e8d2ebbee76c9c6ee304f8 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*def dispatch boolean hasDeclaredElement(TypeDefinition type) { return false; }
	def dispatch boolean hasDeclaredElement(TypeDeclaration type) {
		if(type.isAbstract) {
			type.subtypes.exists[it.hasDeclaredElement]
		} else return true;
	}
	
	def dispatch List<TypeDefinition> allEnumSubtypes(TypeDefinition type) { return #[type] }
	def dispatch List<TypeDefinition> allEnumSubtypes(TypeDeclaration type) {
		return type.subtypes.map[it.allEnumSubtypes].flatten.toList
	}
	
	def protected transformTypes(List<Type> types, Logic2AlloyLanguageMapperTrace trace) {
		val Map<TypeDeclaration,ALSSignatureDeclaration> signatureTrace = new HashMap;
		
		// Creating the root type
		val objectType = createALSSignatureDeclaration => [ name=#["util","object"].toID it.abstract = true ]
		trace.objectSupperClass = objectType
		trace.specification.typeDeclarations += objectType
		
		// Creating the images of the types
		for(type : types) {
			if(type instanceof TypeDefinition) {
				if(type.elements.empty) {
					trace.type2ALSType.put(type,#[]);
				} else {
					val e = createALSEnumDeclaration => [
						it.name = type.name.toID
						it.literal += type.elements.map[transformDefinedElement(trace)]
					]
					trace.type2ALSType.put(type,#[e])
					trace.specification.typeDeclarations += e
				}
			}
			else if(type instanceof TypeDeclaration) {
				if(hasDeclaredElement(type)) {
					val s = createALSSignatureDeclaration => [
						name=type.name.toID
						it.abstract = type.isIsAbstract
					]
					trace.type2ALSType.put(type,new LinkedList=>[add(s)])
					signatureTrace.put(type, s)
					trace.specification.typeDeclarations += s
				}
				else {
					signatureTrace.put(type, null)
					trace.type2ALSType.put(type,new LinkedList);// empty
				}
			}
			else throw new IllegalArgumentException('''Unknown type «type.class.name»''')
		}
		
		
		for(type: types.filter(TypeDeclaration)) {
			// Adding inheritance
			val s = type.lookup(signatureTrace)
			if(s!=null) {
				for(supertype : type.supertypes) {
					s.supertype += (supertype as TypeDeclaration).lookup(signatureTrace)
				}
				if(type.supertypes.empty) {
					s.supertype += objectType
				}
			}
			// Adding enum subtypes
			type.lookup(trace.type2ALSType)+=type.allEnumSubtypes.map[it.lookup(trace.type2ALSType)].flatten
		}
	}
	
	def protected transformDefinedElement(DefinedElement element, Logic2AlloyLanguageMapperTrace trace) {
		val result = createALSEnumLiteral => [name = element.name.toID]
		trace.definedElement2EnumProperty.put(element,result)
		return result
	}*/