aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/Alloy-Solver/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/src/hu/bme/mit/inf/dlsreasoner/alloy/reasoner/builder/Logic2AlloyLanguageMapper_ConstantMapper.xtend
blob: 401c2ec28ef47dab94fc94962bd08c636260ceb9 (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
package hu.bme.mit.inf.dlsreasoner.alloy.reasoner.builder

import hu.bme.mit.inf.dslreasoner.alloyLanguage.AlloyLanguageFactory
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ConstantDeclaration
import hu.bme.mit.inf.dslreasoner.alloyLanguage.ALSMultiplicity
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ConstantDefinition
import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*

class Logic2AlloyLanguageMapper_ConstantMapper {
	private val extension AlloyLanguageFactory factory = AlloyLanguageFactory.eINSTANCE
	private val Logic2AlloyLanguageMapper_Support support = new Logic2AlloyLanguageMapper_Support;
	val Logic2AlloyLanguageMapper base;
	public new(Logic2AlloyLanguageMapper base) {
		this.base = base
	}
	
	def protected dispatch transformConstant(ConstantDeclaration constant, Logic2AlloyLanguageMapperTrace trace) {
		if(!trace.constantDefinitions.containsKey(constant)) {
			val c = createALSFieldDeclaration=> [
				name = support.toID(constant.name)
				it.type = base.transformTypeReference(constant.type,trace)
				it.multiplicity = ALSMultiplicity.ONE
			]
			trace.logicLanguageBody.fields+= c
			trace.constantDeclaration2LanguageField.put(constant,c)
		}
	}
	
	def protected dispatch transformConstant(ConstantDefinition constant, Logic2AlloyLanguageMapperTrace trace) {
		val c = createALSFunctionDefinition=> [
			name = support.toID(constant.name)
			it.type = base.transformTypeReference(constant.type,trace)
			// the value is set later
		]
		trace.specification.functionDefinitions += c
		trace.constantDefinition2Function.put(constant,c)
	}
	
	def protected transformConstantDefinitionSpecification(ConstantDefinition constant, Logic2AlloyLanguageMapperTrace trace) {
		val definition = constant.lookup(trace.constantDefinition2Function)
		definition.value = base.transformTerm(constant.value, trace,emptyMap)
	}
}