Просмотр исходного кода

Some refactorings for better adapting logic in subclasses.

tomqc86@googlemail.com 12 лет назад
Родитель
Сommit
71252141d4

+ 8 - 8
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/DefaultExecutionContextInitializer.xtend

@@ -52,7 +52,7 @@ class DefaultExecutionContextInitializer implements IExecutionContextInitializer
 		flow.scopes.forEach[context.slots += transform]
 	}
 	
-	def dispatch create composite : new CompositeSlotImpl() transform(ImportScope scope) {
+	def dispatch ExecutionSlot create composite : new CompositeSlotImpl() transform(ImportScope scope) {
 		composite.name = "imports"
 		// retrieve namespaces from variable names and create corresponding composite slots
 		for (Declaration decl : scope.declarations.filter(ImportDeclaration).map[declaration]) {
@@ -85,29 +85,29 @@ class DefaultExecutionContextInitializer implements IExecutionContextInitializer
 		}
 	}
 
-	def dispatch create new CompositeSlotImpl() transform(InternalScope scope) {
+	def dispatch ExecutionSlot create new CompositeSlotImpl() transform(InternalScope scope) {
 		it.name = "internal"
 		scope.declarations.forEach[decl|it.slots += decl.transform]
 	}
 
-	def dispatch create new CompositeSlotImpl() transform(Scope scope) {
+	def dispatch ExecutionSlot create new CompositeSlotImpl() transform(Scope scope) {
 		it.name = "time events"
 		scope.declarations.forEach[decl|it.slots += decl.transform]
 	}
 
-	def dispatch create new CompositeSlotImpl() transform(InterfaceScope scope) {
+	def dispatch ExecutionSlot create new CompositeSlotImpl() transform(InterfaceScope scope) {
 		if(scope.name != null) it.name = scope.name else it.name = "default"
 		scope.declarations.forEach[decl|it.slots += decl.transform]
 	}
 
-	def dispatch create new ExecutionVariableImpl() transform(VariableDefinition variable) {
+	def dispatch ExecutionSlot create new ExecutionVariableImpl() transform(VariableDefinition variable) {
 		it.name = variable.fullyQualifiedName.lastSegment
 		it.fqName = variable.fullyQualifiedName.toString
 		it.type = variable.inferType.type
 		it.value = it.type.initialValue
 	}
 
-	def dispatch create new ExecutionEventImpl() transform(EventDefinition event) {
+	def dispatch ExecutionSlot create new ExecutionEventImpl() transform(EventDefinition event) {
 		it.name = event.fullyQualifiedName.lastSegment
 		it.fqName = event.fullyQualifiedName.toString
 		it.type = event.inferType.type
@@ -115,14 +115,14 @@ class DefaultExecutionContextInitializer implements IExecutionContextInitializer
 		it.direction = EventDirection.get(event.direction.value)
 	}
 
-	def dispatch create new ExecutionVariableImpl() transform(OperationDefinition op) {
+	def dispatch ExecutionSlot create new ExecutionVariableImpl() transform(OperationDefinition op) {
 		it.name = op.fullyQualifiedName.lastSegment
 		it.fqName = op.fullyQualifiedName.toString
 		it.type = new InferredType(if(op.type != null) op.type else voidType)
 		it.value = it.type.initialValue
 	}
 
-	def dispatch create new ExecutionEventImpl() transform(TimeEvent event) {
+	def dispatch ExecutionSlot create new ExecutionEventImpl() transform(TimeEvent event) {
 		it.name = event.fullyQualifiedName.lastSegment
 		it.fqName = event.fullyQualifiedName.toString
 		it.type = new InferredType(integerType)

+ 0 - 14
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/ExecutionContextHelper.xtend

@@ -72,20 +72,6 @@ class ExecutionContextHelper {
 		else null
 	}
 	
-	def private ExecutionSlot getSlot(CompositeSlot root, String name) {
-		for (ExecutionSlot slot : root.slots) {
-			if (slot.fqName == name) {
-				return slot
-			}
-			if (slot instanceof CompositeSlot) {
-				val foundSlot = (slot as CompositeSlot).getSlot(name)
-				if (foundSlot != null)
-					return foundSlot
-			}
-		}
-		return null
-	}
-
 	def dispatch ExecutionSlot resolveVariable(ExecutionContext context, AssignmentExpression e) {
 		return context.resolveVariable(e.varRef)
 	}

+ 13 - 9
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/StextStatementInterpreter.xtend

@@ -56,7 +56,7 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 	@Inject
 	extension IQualifiedNameProvider provider
 	@Inject
-	IOperationMockup operationDelegate
+	protected IOperationMockup operationDelegate
 	@Inject
 	extension ExecutionContextHelper helper
 
@@ -129,7 +129,7 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 			return eventRef.raised
 		}
 		// reference to an element with complex type is not reflected in an execution variable but in a composite slot
-		return fqn
+		return context.getSlot(fqn)
 	}
 
 	def dispatch Object execute(EventValueReferenceExpression expression) {
@@ -216,8 +216,12 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 		var result = statement.execute()
 		return evaluate(operator, result);
 	}
-
-	def dispatch Object execute(FeatureCall call) {
+
+	def dispatch Object execute(FeatureCall call) {
+		executeFeatureCall(call)
+	}
+	
+	def executeFeatureCall(FeatureCall call) {
 		if (call.operationCall) {
 			var parameter = call.args.map(it|execute)
 			if (operationDelegate.canExecute(call, parameter)) {
@@ -228,15 +232,15 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 		} else {
 			var variableRef = context.resolveVariable(call)
 			if (variableRef != null) {
-				return variableRef.getValue
-			}
+				return variableRef.getValue
+			}
 			var event = context.resolveEvent(call)
 			if (event != null)
 				return event.raised
 			println("No feature found for " + call.feature.fqn + " -> returning null")
-			return null;
-
-		}
+			return null;
+		}
+		
 	}
 
 	def String fqn(EObject obj) {