Переглянути джерело

enhanced visibility of exectuion flow interpreter

Andreas Mülder 11 роки тому
батько
коміт
dffb4c8249

+ 1 - 1
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/AbstractExecutionFlowSimulationEngine.java

@@ -57,7 +57,7 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 		this.statechart = statechart;
 	}
 
-	protected final void runCycle() {
+	protected void runCycle() {
 		try {
 			interpreter.runCycle();
 		} catch (WrappedException ex) {

+ 10 - 23
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/DefaultExecutionFlowInterpreter.xtend

@@ -33,7 +33,6 @@ import org.yakindu.sct.model.sexec.Trace
 import org.yakindu.sct.model.sexec.UnscheduleTimeEvent
 import org.yakindu.sct.model.sexec.transformation.SexecExtensions
 import org.yakindu.sct.model.sgraph.RegularState
-import org.yakindu.sct.simulation.core.sruntime.EventDirection
 import org.yakindu.sct.simulation.core.sruntime.ExecutionContext
 
 /**
@@ -52,13 +51,14 @@ class DefaultExecutionFlowInterpreter implements IExecutionFlowInterpreter {
 	@Inject extension SexecExtensions
 	@Inject(optional=true)
 	ITraceStepInterpreter traceInterpreter
+	@Inject protected extension ExecutionContextExtensions
 
-	ExecutionFlow flow
-	ExecutionContext executionContext
-	ExecutionState[] activeStateConfiguration
-	Map<Integer, ExecutionState> historyStateConfiguration
-	List<Step> executionStack
-	int activeStateIndex
+	protected ExecutionFlow flow
+	protected ExecutionContext executionContext
+	protected ExecutionState[] activeStateConfiguration
+	protected Map<Integer, ExecutionState> historyStateConfiguration
+	protected List<Step> executionStack
+	protected int activeStateIndex
 
 	boolean suspended = false
 
@@ -88,29 +88,16 @@ class DefaultExecutionFlowInterpreter implements IExecutionFlowInterpreter {
 	}
 
 	override runCycle() {
-		raiseScheduledEvents()
+		executionContext.raiseScheduledEvents
 		activeStateIndex = 0
 		if(executionContext.executedElements.size > 0) executionContext.executedElements.clear
-		clearOutEvents()
+		executionContext.clearOutEvents
 		while (activeStateIndex < activeStateConfiguration.size) {
 			var state = activeStateConfiguration.get(activeStateIndex)
 			state?.reactSequence?.scheduleAndRun
 			activeStateIndex = activeStateIndex + 1
 		}
-		cleatLocalAndInEvents()
-	}
-
-	def cleatLocalAndInEvents() {
-		executionContext.allEvents.filter[direction == EventDirection.IN || direction == EventDirection.LOCAL].forEach[
-			if(raised) raised = false]
-	}
-
-	def raiseScheduledEvents() {
-		executionContext.allEvents.filter[scheduled].forEach[raised = true scheduled = false]
-	}
-
-	def clearOutEvents() {
-		executionContext.allEvents.filter[direction == EventDirection.OUT].forEach[if(raised) raised = false]
+		executionContext.clearLocalAndInEvents
 	}
 
 	override resume() {

+ 31 - 0
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/ExecutionContextExtensions.xtend

@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2014 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.core.sexec.interpreter
+
+import org.yakindu.sct.simulation.core.sruntime.EventDirection
+import org.yakindu.sct.simulation.core.sruntime.ExecutionContext
+
+class ExecutionContextExtensions {
+
+	def clearLocalAndInEvents(ExecutionContext executionContext) {
+		executionContext.allEvents.filter[direction == EventDirection.IN || direction == EventDirection.LOCAL].forEach[
+			if(raised) raised = false]
+	}
+
+	def raiseScheduledEvents(ExecutionContext executionContext) {
+		executionContext.allEvents.filter[scheduled].forEach[raised = true scheduled = false]
+	}
+
+	def clearOutEvents(ExecutionContext executionContext) {
+		executionContext.allEvents.filter[direction == EventDirection.OUT].forEach[if(raised) raised = false]
+	}
+
+}

+ 30 - 22
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/ExecutionContextHelper.xtend

@@ -1,8 +1,10 @@
 package org.yakindu.sct.simulation.core.sexec.interpreter
 
 import com.google.inject.Inject
+import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter
 import java.util.List
 import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.util.EcoreUtil
 import org.eclipse.xtext.naming.IQualifiedNameProvider
 import org.eclipse.xtext.util.SimpleAttributeResolver
 import org.yakindu.base.expressions.expressions.AssignmentExpression
@@ -18,22 +20,21 @@ import org.yakindu.sct.simulation.core.sruntime.ExecutionSlot
 import org.yakindu.sct.simulation.core.sruntime.ExecutionVariable
 
 class ExecutionContextHelper {
-	
+
 	@Inject
 	extension IQualifiedNameProvider nameProvider
-	
+
 	def dispatch ExecutionSlot resolveVariable(ExecutionContext context, ElementReferenceExpression e) {
 		if (e.reference instanceof VariableDefinition) {
 			return context.getVariable(e.reference.getFullyQualifiedName.toString)
-		} 
-		else null
+		} else
+			null
 	}
 
 	def dispatch ExecutionSlot resolveVariable(ExecutionContext context, FeatureCall e) {
 		if (e.feature instanceof VariableDefinition) {
 			return context.getVariable(e.feature.getFullyQualifiedName.toString)
-		}
-		else if (e.feature instanceof Property) {
+		} else if (e.feature instanceof Property) {
 			var current = e
 			val List<EObject> calls = newArrayList
 			calls.add(0, e.feature)
@@ -41,42 +42,49 @@ class ExecutionContextHelper {
 				current = current.owner as FeatureCall
 				calls.add(0, current.feature)
 			}
-			
+
+			//TODO:!!!!!FIXME
 			val varDef = (current.owner as ElementReferenceExpression).reference as VariableDefinition
-			val varDefFqn = varDef.getFullyQualifiedName.toString
-			
+			var varDefFqn = varDef.getFullyQualifiedName.toString
+			if (varDefFqn.equals("this")) {
+				var flow = EcoreUtil.getRootContainer(current)
+				var ContextElementAdapter adapter = EcoreUtil.getExistingAdapter(flow, typeof(ContextElementAdapter)) as ContextElementAdapter
+				varDefFqn = (adapter.element as VariableDefinition).fullyQualifiedName.toString
+			}
+
 			var featureSlot = context.getSlot(varDefFqn)
 			if (featureSlot == null) {
 				featureSlot = context.getVariable(varDef.getFullyQualifiedName.toString)
 				if (featureSlot == null)
 					return null // could not find starting slot for feature call
 			}
-			
+
 			// go through all calls and traverse execution context hierarchy accordingly
 			for (EObject feature : calls) {
-				
+
 				if (featureSlot instanceof CompositeSlot && feature instanceof Property) {
-					featureSlot = (featureSlot as CompositeSlot).slots.findFirst[slot | slot.name == feature.name]
+					featureSlot = (featureSlot as CompositeSlot).slots.findFirst[slot|slot.name == feature.name]
 				}
 				if (featureSlot instanceof ExecutionVariable && feature instanceof Operation) {
-//					TODO (featureSlot as ExecutionVariable).value
+					//					TODO (featureSlot as ExecutionVariable).value
 				}
 			}
-			
+
 			return featureSlot
-		}
-		else if (e.feature instanceof Operation) {
+		} else if (e.feature instanceof Operation) {
+
 			// for operation return the execution variable of the operation call's owner on which the operation is to be executed
 			return context.resolveVariable(e.owner)
-		}
-		else null
+		} else
+			null
 	}
-	
+
 	def dispatch ExecutionSlot resolveVariable(ExecutionContext context, AssignmentExpression e) {
 		return context.resolveVariable(e.varRef)
 	}
-	
+
 	def ExecutionEvent resolveEvent(ExecutionContext context, FeatureCall call) {
+
 		// TODO consider deeper nested calls as done in resolveVariable
 		var fqn = call.feature.fullyQualifiedName.toString
 		if (call.owner instanceof ElementReferenceExpression) {
@@ -88,8 +96,8 @@ class ExecutionContextHelper {
 		}
 		context.getEvent(fqn)
 	}
-	
+
 	def private name(EObject e) {
 		return SimpleAttributeResolver::NAME_RESOLVER.apply(e)
 	}
-}
+}