Browse Source

Initial simulation engine and ui integration

Andreas Mülder 14 years ago
parent
commit
7a6291418c
40 changed files with 1824 additions and 1138 deletions
  1. 6 3
      plugins/org.yakindu.sct.core.simulation/META-INF/MANIFEST.MF
  2. 2 0
      plugins/org.yakindu.sct.core.simulation/plugin.xml
  3. 102 0
      plugins/org.yakindu.sct.core.simulation/schema/org.yakindu.sct.simulation.core.sgraph.executionbuilder.exsd
  4. 102 0
      plugins/org.yakindu.sct.core.simulation/schema/org.yakindu.sct.simulation.core.sgraph.executionlistener.exsd
  5. 13 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISGraphExecutionBuilder.java
  6. 19 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISGraphExecutionFacade.java
  7. 15 8
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartListener.java
  8. 44 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISimulationSessionListener.java
  9. 165 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/SGraphSimulationSession.java
  10. 42 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/SGraphSimulationSessionRegistry.java
  11. 8 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/IDebugConstants.java
  12. 53 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugElement.java
  13. 130 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugTarget.java
  14. 124 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugThread.java
  15. 53 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/extensions/Extensions.java
  16. 8 0
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/extensions/IExtensionPoints.java
  17. 50 2
      plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/launch/StatechartLaunchConfigurationDelegate.java
  18. 4 3
      plugins/org.yakindu.sct.simulation.runtime/META-INF/MANIFEST.MF
  19. 2 1
      plugins/org.yakindu.sct.simulation.runtime/build.properties
  20. 12 0
      plugins/org.yakindu.sct.simulation.runtime/plugin.xml
  21. 32 50
      plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/AbstractStatechart.java
  22. 5 5
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/ActionStatement.java
  23. 62 59
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/RTStatechart.java
  24. 0 12
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/ISGraphExtensionBuilder.java
  25. 24 40
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/SGraphBuilder.java
  26. 1 1
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assign.java
  27. 9 5
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Function.java
  28. 1 1
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ProcedureCall.java
  29. 1 1
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Scope.java
  30. 1 1
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Statement.java
  31. 1 1
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Raise.java
  32. 2 2
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/StatementSequence.java
  33. 0 520
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/ExpressionBuilder.java
  34. 400 421
      plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/STextBuilder.java
  35. 3 1
      plugins/org.yakindu.sct.ui.simulation/META-INF/MANIFEST.MF
  36. 20 0
      plugins/org.yakindu.sct.ui.simulation/plugin.xml
  37. 83 0
      plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/editor/HighlightingExecutionListener.java
  38. 1 1
      plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/launch/StatechartLaunchShortcut.java
  39. 128 0
      plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/view/EventView.java
  40. 96 0
      plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/view/EventViewUpdater.java

+ 6 - 3
plugins/org.yakindu.sct.core.simulation/META-INF/MANIFEST.MF

@@ -1,12 +1,15 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Simulation
-Bundle-SymbolicName: org.yakindu.sct.core.simulation;singleton:=true
+Bundle-SymbolicName: org.yakindu.sct.simulation.core;singleton:=true
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.yakindu.sct.core.simulation.Activator
 Bundle-Vendor: YAKINDU
 Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.debug.core;bundle-version="3.7.0"
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.emf.ecore;bundle-version="2.7.0",
+ org.yakindu.sct.model.sgraph;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ActivationPolicy: lazy
-Export-Package: org.yakindu.sct.core.simulation.launch
+Export-Package: org.yakindu.sct.core.simulation,
+ org.yakindu.sct.core.simulation.launch

+ 2 - 0
plugins/org.yakindu.sct.core.simulation/plugin.xml

@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
+   <extension-point id="org.yakindu.sct.simulation.core.sgraph.executionbuilder" name="SGraphExecutionBuilder" schema="schema/org.yakindu.sct.simulation.core.sgraph.executionbuilder.exsd"/>
+   <extension-point id="org.yakindu.sct.simulation.core.sgraph.sessionlistener" name="SgraphSessionListener" schema="schema/org.yakindu.sct.simulation.core.sgraph.executionlistener.exsd"/>
 
 <extension point="org.eclipse.debug.core.launchConfigurationTypes">
     <launchConfigurationType

+ 102 - 0
plugins/org.yakindu.sct.core.simulation/schema/org.yakindu.sct.simulation.core.sgraph.executionbuilder.exsd

@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.core.simulation" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.core.simulation" id="org.yakindu.sct.simulation.core.sgraph.executionbuilder" name="SGraphExecutionBuilder"/>
+      </appinfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="SGraphExecutionBuilder"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="SGraphExecutionBuilder">
+      <complexType>
+         <attribute name="class" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.core.simulation.builder.ISGraphExecutionBuilder"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>

+ 102 - 0
plugins/org.yakindu.sct.core.simulation/schema/org.yakindu.sct.simulation.core.sgraph.executionlistener.exsd

@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.simulation.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.simulation.core" id="org.yakindu.sct.simulation.core.sgraph.executionlistener" name="SgraphExecutionListener"/>
+      </appinfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="ISimulationSessionListener"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="ISimulationSessionListener">
+      <complexType>
+         <attribute name="class" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.core.simulation.builder.ISimulationSessionListener"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>

+ 13 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISGraphExecutionBuilder.java

@@ -0,0 +1,13 @@
+package org.yakindu.sct.core.simulation;
+
+import org.yakindu.sct.model.sgraph.Statechart;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public interface ISGraphExecutionBuilder {
+
+	public ISGraphExecutionFacade build(Statechart statechart);
+}

+ 19 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISGraphExecutionFacade.java

@@ -0,0 +1,19 @@
+package org.yakindu.sct.core.simulation;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public interface ISGraphExecutionFacade {
+
+	public void enter();
+
+	public void runCycle();
+	
+	public void raise(String eventName);
+
+	public void addExecutionListener(ISGraphExecutionListener listener);
+
+	public void removeExecutionListener(ISGraphExecutionListener listener);
+}

+ 15 - 8
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/StatechartListener.java

@@ -8,15 +8,22 @@
  * Contributors:
  *     committers of YAKINDU - initial API and implementation
  */
-package org.yakindu.sct.simulation.runtime.sgraph;
+package org.yakindu.sct.core.simulation;
 
-import org.yakindu.sct.simulation.runtime.sgraph.RTState;
-import org.yakindu.sct.simulation.runtime.sgraph.RTTransition;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
 
-public interface StatechartListener {
-	
-	void stateEntered(RTState state);
-	void stateLeft(RTState state);
-	void transitionFired(RTTransition trans);
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public interface ISGraphExecutionListener {
 
+	void stateEntered(Vertex vertex);
+
+	void stateLeft(Vertex vertex);
+
+	void transitionFired(Transition transition);
+	
 }

+ 44 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/ISimulationSessionListener.java

@@ -0,0 +1,44 @@
+package org.yakindu.sct.core.simulation;
+
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public interface ISimulationSessionListener extends ISGraphExecutionListener {
+
+	public static enum SimulationState {
+		STARTED, RUNNING, SINGLESTEP, PAUSED, TERMINATED
+	}
+
+	public void simulationStateChanged(SimulationState oldState,
+			SimulationState newState);
+
+	/**
+	 * Empty implementation
+	 * 
+	 */
+	public static class ISimulationSessionListenerAdapter implements
+			ISimulationSessionListener {
+
+		@Override
+		public void stateEntered(Vertex vertex) {
+		}
+
+		@Override
+		public void stateLeft(Vertex vertex) {
+		}
+
+		@Override
+		public void transitionFired(Transition transition) {
+		}
+
+		@Override
+		public void simulationStateChanged(SimulationState oldState,
+				SimulationState newState) {
+		}
+	}
+}

+ 165 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/SGraphSimulationSession.java

@@ -0,0 +1,165 @@
+package org.yakindu.sct.core.simulation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.yakindu.sct.core.simulation.ISimulationSessionListener.SimulationState;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+/**
+ * 
+ * @author muelder
+ * 
+ */
+public class SGraphSimulationSession implements Runnable,
+		ISGraphExecutionListener {
+
+	private List<ISimulationSessionListener> listeners;
+
+	private BlockingQueue<Runnable> taskQueue;
+
+	private SimulationState currentState;
+	private final ISGraphExecutionFacade facade;
+
+	private Timer timer;
+
+	public SGraphSimulationSession(ISGraphExecutionFacade facade) {
+		this.facade = facade;
+		facade.addExecutionListener(this);
+		listeners = new ArrayList<ISimulationSessionListener>();
+		taskQueue = new LinkedBlockingQueue<Runnable>();
+		timer = new Timer();
+	}
+
+	public void start() {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				changeSimulationState(SimulationState.STARTED);
+				facade.enter();
+				changeSimulationState(SimulationState.RUNNING);
+				scheduleCycle();
+			}
+		});
+	}
+
+	public void singleStep() {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				changeSimulationState(SimulationState.SINGLESTEP);
+			}
+		});
+	}
+
+	public void resume() {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				changeSimulationState(SimulationState.RUNNING);
+				scheduleCycle();
+			}
+		});
+	}
+
+	public void suspend() {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				changeSimulationState(SimulationState.PAUSED);
+			}
+		});
+	}
+
+	public void terminate() {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				changeSimulationState(SimulationState.TERMINATED);
+			}
+		});
+	}
+
+	public void raiseEvent(final String eventName) {
+		taskQueue.add(new Runnable() {
+			@Override
+			public void run() {
+				facade.raise(eventName);
+			}
+		});
+	}
+
+	public void setVariableValue(String variableName, Object value) {
+
+	}
+
+	protected void scheduleCycle() {
+		if (currentState == SimulationState.RUNNING) {
+			timer.schedule(new TimerTask() {
+				@Override
+				public void run() {
+					taskQueue.add(new Runnable() {
+						@Override
+						public void run() {
+							facade.runCycle();
+						}
+					});
+					scheduleCycle();
+				}
+			}, 100);
+
+		}
+	}
+
+	@Override
+	public void run() {
+		while (!(currentState == SimulationState.TERMINATED)) {
+			try {
+				Runnable task = taskQueue.take();
+				task.run();
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	protected void changeSimulationState(SimulationState newState) {
+		for (ISimulationSessionListener listener : listeners) {
+			listener.simulationStateChanged(this.currentState, newState);
+		}
+		this.currentState = newState;
+	}
+
+	@Override
+	public void stateEntered(Vertex vertex) {
+		for (ISimulationSessionListener listener : listeners) {
+			listener.stateEntered(vertex);
+		}
+	}
+
+	@Override
+	public void stateLeft(Vertex vertex) {
+		for (ISimulationSessionListener listener : listeners) {
+			listener.stateLeft(vertex);
+		}
+
+	}
+
+	@Override
+	public void transitionFired(Transition transition) {
+		for (ISimulationSessionListener listener : listeners) {
+			listener.transitionFired(transition);
+		}
+
+	}
+
+	public List<ISimulationSessionListener> getListeners() {
+		return listeners;
+	}
+
+}

+ 42 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/SGraphSimulationSessionRegistry.java

@@ -0,0 +1,42 @@
+package org.yakindu.sct.core.simulation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.yakindu.sct.core.simulation.extensions.Extensions;
+import org.yakindu.sct.core.simulation.extensions.IExtensionPoints;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class SGraphSimulationSessionRegistry implements IExtensionPoints {
+
+	public static final SGraphSimulationSessionRegistry INSTANCE = new SGraphSimulationSessionRegistry();
+
+	private List<SGraphSimulationSession> sessions;
+
+	private SGraphSimulationSessionRegistry() {
+		sessions = new ArrayList<SGraphSimulationSession>();
+	}
+
+	public void registerSimulationSession(SGraphSimulationSession session) {
+		session.getListeners().addAll(getListeners());
+		sessions.add(session);
+
+	}
+
+	protected List<ISimulationSessionListener> getListeners() {
+		Extensions<ISimulationSessionListener> extensions = new Extensions<ISimulationSessionListener>(
+				SESSION_LISTENER);
+		return extensions.getExtensions();
+	}
+
+	public SGraphSimulationSession getActiveSession() {
+		if (sessions.isEmpty())
+			return null;
+		return sessions.get(0);
+	}
+
+}

+ 8 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/IDebugConstants.java

@@ -0,0 +1,8 @@
+package org.yakindu.sct.core.simulation.debugmodel;
+
+public interface IDebugConstants {
+
+	public static final String ID_DEBUG_MODEL = "sct_debug";
+	public static final String DEBUG_TARGET = "YAKINDU Statechart Simulation";
+	public static final String DEBUG_THREAD = "Thread[1]";
+}

+ 53 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugElement.java

@@ -0,0 +1,53 @@
+package org.yakindu.sct.core.simulation.debugmodel;
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IDebugElement;
+import org.eclipse.debug.core.model.IDebugTarget;
+
+public abstract class SCTDebugElement extends PlatformObject implements
+		IDebugElement {
+
+	protected IDebugTarget target;
+
+	public SCTDebugElement(IDebugTarget target) {
+		this.target = target;
+	}
+
+	public String getModelIdentifier() {
+		return IDebugConstants.ID_DEBUG_MODEL;
+	}
+
+	public IDebugTarget getDebugTarget() {
+		return target;
+	}
+
+
+	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+		if (adapter == IDebugElement.class) {
+			return this;
+		}
+		return super.getAdapter(adapter);
+	}
+
+	protected void fireEvent(DebugEvent event) {
+		DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event });
+	}
+
+	protected void fireCreationEvent() {
+		fireEvent(new DebugEvent(this, DebugEvent.CREATE));
+	}
+
+	public void fireResumeEvent(int detail) {
+		fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
+	}
+
+	public void fireSuspendEvent(int detail) {
+		fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
+	}
+
+	protected void fireTerminateEvent() {
+		fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
+	}
+}

+ 130 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugTarget.java

@@ -0,0 +1,130 @@
+package org.yakindu.sct.core.simulation.debugmodel;
+
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IThread;
+import org.yakindu.sct.core.simulation.ISGraphExecutionFacade;
+/**
+ * 
+ * @author andreas muelder
+ *
+ */
+public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget {
+
+	private IProcess process;
+
+	private ILaunch launch;
+
+	private SCTDebugThread thread;
+
+	public SCTDebugTarget(ILaunch launch, ISGraphExecutionFacade facade)
+			throws CoreException {
+		super(null);
+		this.launch = launch;
+		thread = new SCTDebugThread(this, facade);
+		DebugPlugin.getDefault().getBreakpointManager()
+				.addBreakpointListener(this);
+	}
+
+	public IProcess getProcess() {
+		return process;
+	}
+
+	public IThread[] getThreads() throws DebugException {
+		return new IThread[] { thread };
+	}
+
+	public boolean hasThreads() throws DebugException {
+		return true;
+	}
+
+	public String getName() throws DebugException {
+		return IDebugConstants.DEBUG_TARGET;
+	}
+
+	public boolean supportsBreakpoint(IBreakpoint breakpoint) {
+		return false;
+	}
+
+	public boolean canTerminate() {
+		return thread.canTerminate();
+	}
+
+	public boolean isTerminated() {
+		return thread.isTerminated();
+	}
+
+	public void terminate() throws DebugException {
+		thread.terminate();
+	}
+
+	public boolean canResume() {
+		return thread.canResume();
+	}
+
+	public boolean canSuspend() {
+		return thread.canSuspend();
+	}
+
+	public boolean isSuspended() {
+		return thread.isSuspended();
+	}
+
+	public void resume() throws DebugException {
+		thread.resume();
+	}
+
+	public void suspend() throws DebugException {
+		thread.suspend();
+	}
+
+	@Override
+	public void breakpointAdded(IBreakpoint breakpoint) {
+	}
+
+	@Override
+	public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
+	}
+
+	@Override
+	public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
+	}
+
+	@Override
+	public boolean canDisconnect() {
+		return false;
+	}
+
+	@Override
+	public void disconnect() throws DebugException {
+
+	}
+
+	@Override
+	public boolean isDisconnected() {
+		return false;
+	}
+
+	@Override
+	public boolean supportsStorageRetrieval() {
+		return false;
+	}
+
+	@Override
+	public IMemoryBlock getMemoryBlock(long startAddress, long length)
+			throws DebugException {
+		return null;
+	}
+
+	@Override
+	public ILaunch getLaunch() {
+		return launch;
+	}
+}

+ 124 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/debugmodel/SCTDebugThread.java

@@ -0,0 +1,124 @@
+package org.yakindu.sct.core.simulation.debugmodel;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+import org.yakindu.sct.core.simulation.ISGraphExecutionFacade;
+import org.yakindu.sct.core.simulation.SGraphSimulationSession;
+import org.yakindu.sct.core.simulation.SGraphSimulationSessionRegistry;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class SCTDebugThread extends SCTDebugElement implements IThread {
+
+	private boolean stepping = false;
+	private boolean terminated;
+	private boolean suspended;
+	private Thread thread;
+	private SGraphSimulationSession session;
+
+	public SCTDebugThread(SCTDebugTarget target, ISGraphExecutionFacade facade) {
+		super(target);
+		session = new SGraphSimulationSession(facade);
+		SGraphSimulationSessionRegistry.INSTANCE.registerSimulationSession(session);
+		thread = new Thread(session);
+		thread.start();
+		session.start();
+	}
+
+	public IStackFrame[] getStackFrames() throws DebugException {
+		return null;
+	}
+
+	public boolean hasStackFrames() throws DebugException {
+		return false;
+	}
+
+	public int getPriority() throws DebugException {
+		return 0;
+	}
+
+	public String getName() throws DebugException {
+		return IDebugConstants.DEBUG_THREAD;
+	}
+
+	public IBreakpoint[] getBreakpoints() {
+		return null;
+	}
+
+	public boolean canResume() {
+		return suspended;
+	}
+
+	public boolean canSuspend() {
+		return !suspended && !terminated;
+	}
+
+	public boolean isSuspended() {
+		return suspended;
+	}
+
+	public void resume() throws DebugException {
+		session.resume();
+		suspended = false;
+	}
+
+	public void suspend() throws DebugException {
+		session.suspend();
+		suspended = true;
+	}
+
+	public boolean canStepInto() {
+		return false;
+	}
+
+	public boolean canStepOver() {
+		return isSuspended();
+	}
+
+	public boolean canStepReturn() {
+		return false;
+	}
+
+	public boolean isStepping() {
+		return stepping;
+	}
+
+	public void stepInto() throws DebugException {
+	}
+
+	public void stepOver() throws DebugException {
+		session.singleStep();
+	}
+
+	public void stepReturn() throws DebugException {
+	}
+
+	public boolean canTerminate() {
+		return !terminated;
+	}
+
+	public boolean isTerminated() {
+		return terminated;
+	}
+
+	public void terminate() throws DebugException {
+		session.terminate();
+		terminated = true;
+	}
+
+	@Override
+	public IStackFrame getTopStackFrame() throws DebugException {
+		return null;
+	}
+
+	@Override
+	public ILaunch getLaunch() {
+		return getDebugTarget().getLaunch();
+	}
+}

+ 53 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/extensions/Extensions.java

@@ -0,0 +1,53 @@
+package org.yakindu.sct.core.simulation.extensions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class Extensions<T> {
+
+	private String extensionPointId;
+
+	public Extensions(String extensionPointId) {
+		this.extensionPointId = extensionPointId;
+	}
+
+	public T getFirstExtension() {
+		return getExtensions().get(0);
+	}
+
+	public List<T> getExtensions() {
+		List<T> extensions = loadRegisteredProvider();
+		if (extensions.size() == 0)
+			throw new IllegalStateException(
+					"No extensions registered for extension point"
+							+ extensionPointId);
+		return extensions;
+	}
+
+	public List<T> loadRegisteredProvider() {
+		List<T> providers = new ArrayList<T>();
+		IConfigurationElement[] configurationElements = Platform
+				.getExtensionRegistry().getConfigurationElementsFor(
+						extensionPointId);
+		for (IConfigurationElement configurationElement : configurationElements) {
+			try {
+				@SuppressWarnings("unchecked")
+				T provider = (T) configurationElement
+						.createExecutableExtension("class");
+				providers.add(provider);
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+		}
+		return providers;
+	}
+}

+ 8 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/extensions/IExtensionPoints.java

@@ -0,0 +1,8 @@
+package org.yakindu.sct.core.simulation.extensions;
+
+public interface IExtensionPoints {
+
+	public static final String EXECUTION_BUILDER = "org.yakindu.sct.simulation.core.sgraph.executionbuilder";
+	public static final String SESSION_LISTENER = "org.yakindu.sct.simulation.core.sgraph.sessionlistener";
+
+}

+ 50 - 2
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/launch/StatechartLaunchConfigurationDelegate.java

@@ -10,11 +10,29 @@
  */
 package org.yakindu.sct.core.simulation.launch;
 
+import java.io.IOException;
+import java.util.Collections;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Factory;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.yakindu.sct.core.simulation.ISGraphExecutionBuilder;
+import org.yakindu.sct.core.simulation.ISGraphExecutionFacade;
+import org.yakindu.sct.core.simulation.debugmodel.SCTDebugTarget;
+import org.yakindu.sct.core.simulation.extensions.Extensions;
+import org.yakindu.sct.core.simulation.extensions.IExtensionPoints;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.model.sgraph.Statechart;
 
 /**
  * 
@@ -22,14 +40,44 @@ import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
  * 
  */
 public class StatechartLaunchConfigurationDelegate implements
-		ILaunchConfigurationDelegate {
+		ILaunchConfigurationDelegate, IExtensionPoints {
 
 	public void launch(ILaunchConfiguration configuration, String mode,
 			ILaunch launch, IProgressMonitor monitor) throws CoreException {
 		String filename = configuration.getAttribute(
 				IStatechartLaunchParameters.FILE_NAME, "");
 
-		System.out.println("Launching simulation for file " + filename);
+		Resource resource = loadResource(filename);
+		Statechart statechart = (Statechart) EcoreUtil.getObjectByType(
+				resource.getContents(), SGraphPackage.Literals.STATECHART);
+		ISGraphExecutionBuilder builder = getBuilder();
+		ISGraphExecutionFacade executionFacade = builder.build(statechart);
+		IDebugTarget target = new SCTDebugTarget(launch, executionFacade);
+		launch.addDebugTarget(target);
+	}
+
+	protected ISGraphExecutionBuilder getBuilder() {
+		Extensions<ISGraphExecutionBuilder> extensions = new Extensions<ISGraphExecutionBuilder>(
+				EXECUTION_BUILDER);
+		return extensions.getFirstExtension();
+	}
+
+
+	/**
+	 * Loads and returns the Resource for a given filename
+	 */
+	protected Resource loadResource(String filename) {
+		URI uri = URI.createFileURI(filename);
+		Factory factory = ResourceFactoryRegistryImpl.INSTANCE.getFactory(uri);
+		Resource resource = factory.createResource(uri);
+		ResourceSet resourceSet = new ResourceSetImpl();
+		resourceSet.getResources().add(resource);
+		try {
+			resource.load(Collections.EMPTY_MAP);
+			return resource;
+		} catch (IOException e) {
+			throw new IllegalStateException("Error loading resource", e);
+		}
 	}
 
 }

+ 4 - 3
plugins/org.yakindu.sct.simulation.runtime/META-INF/MANIFEST.MF

@@ -1,14 +1,15 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: YAKINDU SCT Runtime
-Bundle-SymbolicName: org.yakindu.sct.simulation.runtime
+Bundle-SymbolicName: org.yakindu.sct.simulation.runtime;singleton:=true
 Bundle-Version: 1.1.0.qualifier
 Bundle-Vendor: YAKINDU.org
 Require-Bundle: org.yakindu.sct.model.sgraph;bundle-version="1.0.0",
  org.eclipse.xtext;bundle-version="2.0.0",
- org.eclipse.emf.mwe.core;bundle-version="1.1.0",
  org.yakindu.sct.model.stext;bundle-version="1.0.0",
- org.yakindu.sct.model.stext.ui;bundle-version="1.0.0"
+ org.yakindu.sct.model.stext.ui;bundle-version="1.0.0",
+ org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.yakindu.sct.simulation.core;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: org.yakindu.sct.simulation.runtime,

+ 2 - 1
plugins/org.yakindu.sct.simulation.runtime/build.properties

@@ -3,6 +3,7 @@ source.. = src/,\
 output.. = bin/
 customBuildCallbacks = customBuildCallbacks.xml
 bin.includes = META-INF/,\
-               .
+               .,\
+               plugin.xml
 src.includes = src/,\
                src-gen/

+ 12 - 0
plugins/org.yakindu.sct.simulation.runtime/plugin.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.yakindu.sct.simulation.core.sgraph.executionbuilder">
+      <SGraphExecutionBuilder
+            class="org.yakindu.sct.simulation.runtime.stext.builder.STextBuilder"
+            clazz="org.yakindu.sct.simulation.runtime.stext.builder.STextBuilder">
+      </SGraphExecutionBuilder>
+   </extension>
+
+</plugin>

+ 32 - 50
plugins/org.yakindu.sct.simulation.runtime/src-gen/org/yakindu/sct/simulation/runtime/sgraph/AbstractStatechart.java

@@ -10,9 +10,36 @@ public abstract class AbstractStatechart {
 
 	protected Set<RTEvent> raisedEvents = new HashSet<RTEvent>();
 
-	// ------------------------------------------------------------------------
-	// (EXTERNAL) EVENT-INTERFACE IMPLEMENTATION
-	// ------------------------------------------------------------------------
+	private String id;
+
+	// the nested regions of this state, sorted by priority
+
+	private List<RTRegion> regions = new ArrayList<RTRegion>();
+
+	private List<RTTransition> transitions = new ArrayList<RTTransition>();
+
+	// used to request time events from environment
+	protected RTTimingService timingService = null;
+
+	protected AbstractStatechart(String id) {
+		this.id = id;
+		this.timingService = new RTDefaultTimingService(this);
+	}
+
+	protected AbstractStatechart(String id, RTTimingService timingService) {
+		this.id = id;
+		this.timingService = timingService;
+	}
+
+	public List<RTRegion> getRegions() {
+		return regions;
+	}
+
+	protected List<RTTransition> getTransitions() {
+
+		return transitions;
+
+	}
 
 	public void setEvent(RTEvent event) {
 
@@ -22,10 +49,6 @@ public abstract class AbstractStatechart {
 
 	}
 
-	// ------------------------------------------------------------------------
-	// (INTERNAL) TIMING-SERVICE-INTERFACE IMPLEMENTATION
-	// ------------------------------------------------------------------------
-
 	protected void requestTimeEvent(RTTimeEvent event) {
 		timingService.requestTimeEvent(event);
 	}
@@ -34,9 +57,6 @@ public abstract class AbstractStatechart {
 		timingService.cancelTimeEvent(event);
 	}
 
-	// ------------------------------------------------------------------------
-	// (EXTERNAL) EXECUTION-INTERFACE IMPLEMENTATION
-	// ------------------------------------------------------------------------
 
 	public void enter() {
 
@@ -68,50 +88,12 @@ public abstract class AbstractStatechart {
 
 	}
 
-	// ------------------------------------------------------------------------
-	// INITIALIZATION CODE
-	// ------------------------------------------------------------------------
-
-	// the unique id of this statechart instance
-	private String id;
-
-	// the nested regions of this state, sorted by priority
-
-	private List<RTRegion> regions = new ArrayList<RTRegion>();
-
-	private List<RTTransition> transitions = new ArrayList<RTTransition>();
-
-	// used to request time events from environment
-	protected RTTimingService timingService = null;
-
-	protected AbstractStatechart(String id) {
-		this.id = id;
-		this.timingService = new RTDefaultTimingService(this);
-	}
-
-	protected AbstractStatechart(String id, RTTimingService timingService) {
-		this.id = id;
-		this.timingService = timingService;
-	}
-
-	public List<RTRegion> getRegions() {
-		return regions;
-	}
-
-	protected List<RTTransition> getTransitions() {
-
-		return transitions;
-
-	}
-
-	// ------------------------------------------------------------------------
-	// INTERNAL STATECHART BEHAVIOUR
-	// ------------------------------------------------------------------------
-
+	
 	private void reactOn(Set<RTEvent> events) {
 
 		// pass events to our nested regions (in the order of their priority)
 		for (RTRegion region : regions) {
+			System.out.println("React on event " + events);
 			region.reactOn(events);
 		}
 	}

+ 5 - 5
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/ActionStatement.java

@@ -12,16 +12,16 @@ package org.yakindu.sct.simulation.runtime.sgraph;
 
 import org.yakindu.sct.simulation.runtime.ExecutionScope;
 import org.yakindu.sct.simulation.runtime.sgraph.RTAction;
-import org.yakindu.sct.simulation.runtime.stext.Statement;
+import org.yakindu.sct.simulation.runtime.stext.RTStatement;
 
 
 public class ActionStatement extends RTAction {
 
-	protected Statement statement;
+	protected RTStatement statement;
 	protected ExecutionScope scope;
 	
 	
-	public ActionStatement(Statement statement, ExecutionScope scope) {
+	public ActionStatement(RTStatement statement, ExecutionScope scope) {
 		super();
 		this.statement = statement;
 		this.scope = scope;
@@ -29,13 +29,13 @@ public class ActionStatement extends RTAction {
 	
 	
 
-	public Statement getStatement() {
+	public RTStatement getStatement() {
 		return statement;
 	}
 
 
 
-	public void setStatement(Statement statement) {
+	public void setStatement(RTStatement statement) {
 		this.statement = statement;
 	}
 

+ 62 - 59
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/RTStatechart.java

@@ -18,6 +18,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.yakindu.sct.core.simulation.ISGraphExecutionFacade;
+import org.yakindu.sct.core.simulation.ISGraphExecutionListener;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.simulation.runtime.ExecutionScope;
 import org.yakindu.sct.simulation.runtime.sgraph.AbstractStatechart;
 import org.yakindu.sct.simulation.runtime.sgraph.RTCompoundState;
@@ -30,61 +34,58 @@ import org.yakindu.sct.simulation.runtime.sgraph.RTTimingService;
 import org.yakindu.sct.simulation.runtime.sgraph.RTTransition;
 import org.yakindu.sct.simulation.runtime.stext.Variable;
 
-
-public class RTStatechart extends AbstractStatechart implements ExecutionScope {
-
+public class RTStatechart extends AbstractStatechart implements ExecutionScope,
+		ISGraphExecutionFacade {
 
 	protected Map<Object, Object> aliasToElementMap = new HashMap<Object, Object>();
 	protected Map<Object, Object> elementToAliasMap = new HashMap<Object, Object>();
 
-	protected List<RTSignalEvent> events = new ArrayList<RTSignalEvent>(); 
+	protected List<RTSignalEvent> events = new ArrayList<RTSignalEvent>();
 	protected Map<String, RTSignalEvent> eventMap = new HashMap<String, RTSignalEvent>();
 
-	protected List<Variable> variables = new ArrayList<Variable>(); 
+	protected List<Variable> variables = new ArrayList<Variable>();
 	protected Map<String, Variable> variableMap = new HashMap<String, Variable>();
-		
+
 	protected Set<RTState> currentStateConfigurartion = new HashSet<RTState>();
-	
-	protected StatechartListener listener;
-	
-	
+
+	protected List<ISGraphExecutionListener> listeners = new ArrayList<ISGraphExecutionListener>();
+
 	public RTStatechart(String id) {
 		super(id);
 	}
 
 	public RTStatechart(String id, RTTimingService timingService) {
 		super(id, timingService);
+		listeners = new ArrayList<ISGraphExecutionListener>();
 	}
 
-	
 	public RTTimingService getTimingService() {
 		return timingService;
 	}
-	
+
 	public void setTimingService(RTTimingService ts) {
 		timingService = ts;
 	}
-	
-	
-	public StatechartListener getListener() {
-		return listener;
+
+	public void removeExecutionListener(ISGraphExecutionListener listener) {
+		listeners.remove(listener);
 	}
 
-	public void setListener(StatechartListener listener) {
-		this.listener = listener;
+	public void addExecutionListener(ISGraphExecutionListener listener) {
+		listeners.add(listener);
 	}
 
 	/**
-	 * Adds a signal event definition to the interface of the statechart. 
-	 * only those events, that are registered should be used during operation.
-	 *  
+	 * Adds a signal event definition to the interface of the statechart. only
+	 * those events, that are registered should be used during operation.
+	 * 
 	 * @param event
 	 */
 	public void addSignalEvent(RTSignalEvent event) {
 		events.add(event);
 		eventMap.put(event.getId(), event);
 	}
-	
+
 	/**
 	 * Gets a signal event by its id.
 	 * 
@@ -94,7 +95,7 @@ public class RTStatechart extends AbstractStatechart implements ExecutionScope {
 	public RTSignalEvent getSignalEvent(String id) {
 		return eventMap.get(id);
 	}
-	
+
 	public Set<RTEvent> getRaisedEvents() {
 		return Collections.unmodifiableSet(raisedEvents);
 	}
@@ -105,48 +106,49 @@ public class RTStatechart extends AbstractStatechart implements ExecutionScope {
 	public List<RTSignalEvent> getSignalEvents() {
 		return Collections.unmodifiableList(events);
 	}
-	
-	
+
 	public void addVariable(Variable var) {
 		variables.add(var);
 		variableMap.put(var.getName(), var);
 	}
 
-	
 	public Object getValue(String varName) {
 		Variable var = getVariable(varName);
-		return (var != null) ? var.getValue() : null ;		
+		return (var != null) ? var.getValue() : null;
 	}
 
-	
 	public Variable getVariable(String varName) {
 		return variableMap.get(varName);
 	}
-	
-	public List<Variable>  getVariables() {
+
+	public List<Variable> getVariables() {
 		return Collections.unmodifiableList(variables);
 	}
 
-	
 	protected void stateLeft(RTState state) {
 		currentStateConfigurartion.remove(state);
-		if (listener != null) listener.stateLeft(state);
+		for (ISGraphExecutionListener listener : listeners) {
+			listener.stateLeft((Vertex) elementToAliasMap.get(state));
+		}
 	}
-	
+
 	protected void stateEntered(RTState state) {
 		currentStateConfigurartion.add(state);
-		if (listener != null) listener.stateEntered(state);
+		for (ISGraphExecutionListener listener : listeners) {
+			listener.stateEntered((Vertex) elementToAliasMap.get(state));
+		}
 	}
-	
+
 	protected void transitionFired(RTTransition trans) {
-		if (listener != null) listener.transitionFired(trans);
+		for (ISGraphExecutionListener listener : listeners) {
+			listener.transitionFired((Transition) elementToAliasMap.get(trans));
+		}
 	}
-	
+
 	public Set<RTState> getCurrentStateConfiguration() {
 		return Collections.unmodifiableSet(currentStateConfigurartion);
 	}
-	
-	
+
 	public void raise(String signal) {
 		setEvent(eventMap.get(signal));
 	}
@@ -155,70 +157,71 @@ public class RTStatechart extends AbstractStatechart implements ExecutionScope {
 		raisedEvents.remove(eventMap.get(signal));
 	}
 
-	
 	public void call(String procedureId) {
-		// TODO Auto-generated method stub		
+		// TODO Auto-generated method stub
 	}
 
-	
 	/**
-	 * If a node is registered with a key then it can be accessed by the key using this method.
-	 * Before a node can be accessed this way it must be registered using {@link #registerNode}. 
+	 * If a node is registered with a key then it can be accessed by the key
+	 * using this method. Before a node can be accessed this way it must be
+	 * registered using {@link #registerNode}.
+	 * 
 	 * @param alias
 	 * @return the node object that is registered for the given key.
 	 */
 	public Object getElementByAlias(Object alias) {
 		return aliasToElementMap.get(alias);
 	}
-	
+
 	/**
-	 * If a node is registered with a key then it can be accessed by the key using this method.
-	 * Before a node can be accessed this way it must be registered using {@link #registerNode}. 
+	 * If a node is registered with a key then it can be accessed by the key
+	 * using this method. Before a node can be accessed this way it must be
+	 * registered using {@link #registerNode}.
+	 * 
 	 * @param element
 	 * @return the node object that is registered for the given key.
 	 */
 	public Object getAliasByElement(Object element) {
 		return elementToAliasMap.get(element);
 	}
-	
+
 	/**
 	 * Nodes can optionally be regitered with a key for later lookup.
 	 * 
-	 * @param key the key object
-	 * @param element the node
+	 * @param key
+	 *            the key object
+	 * @param element
+	 *            the node
 	 */
 	public void defineAlias(Object alias, Object element) {
 		aliasToElementMap.put(alias, element);
 		elementToAliasMap.put(element, alias);
 	}
 
-	
 	public List<RTRegion> getAllRegions() {
 		List<RTRegion> allRegions = new ArrayList<RTRegion>();
-		
+
 		allRegions.addAll(getRegions());
 		for (RTRegion region : getRegions()) {
 			addAllRegions(allRegions, region);
 		}
 
-		
 		return allRegions;
 	}
 
-	
 	protected void addAllRegions(List<RTRegion> regions, RTRegion region) {
 		for (RTNode node : region.getNodes()) {
-			if (node instanceof RTCompoundState) addAllRegions(regions, (RTCompoundState) node);
+			if (node instanceof RTCompoundState)
+				addAllRegions(regions, (RTCompoundState) node);
 		}
 	}
-	
+
 	protected void addAllRegions(List<RTRegion> regions, RTCompoundState cState) {
 		regions.addAll(cState.getRegions());
-		
+
 		for (RTRegion region : cState.getRegions()) {
 			addAllRegions(regions, region);
 		}
 	}
-	
-	
+
 }

+ 0 - 12
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/ISGraphExtensionBuilder.java

@@ -1,12 +0,0 @@
-package org.yakindu.sct.simulation.runtime.sgraph.builder;
-
-/**
- * 
- * @author andreas muelder
- *
- */
-public interface ISGraphExtensionBuilder {
-
-	
-	
-}

+ 24 - 40
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/sgraph/builder/SGraphBuilder.java

@@ -13,13 +13,13 @@ package org.yakindu.sct.simulation.runtime.sgraph.builder;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import org.eclipse.emf.common.util.BasicEList;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.EcoreUtil2;
+import org.yakindu.sct.core.simulation.ISGraphExecutionBuilder;
 import org.yakindu.sct.model.sgraph.Choice;
 import org.yakindu.sct.model.sgraph.Effect;
 import org.yakindu.sct.model.sgraph.Entry;
@@ -36,9 +36,9 @@ import org.yakindu.sct.model.stext.stext.Expression;
 import org.yakindu.sct.model.stext.stext.ReactionTrigger;
 import org.yakindu.sct.model.stext.stext.RegularEventSpec;
 import org.yakindu.sct.model.stext.stext.TimeEventSpec;
+import org.yakindu.sct.model.stext.stext.TimeUnit;
 import org.yakindu.sct.model.stext.stext.Type;
 import org.yakindu.sct.model.stext.stext.VariableDefinition;
-import org.yakindu.sct.simulation.runtime.sgraph.ActionStatement;
 import org.yakindu.sct.simulation.runtime.sgraph.GuardExpression;
 import org.yakindu.sct.simulation.runtime.sgraph.PseudostateKind;
 import org.yakindu.sct.simulation.runtime.sgraph.RTAction;
@@ -54,10 +54,8 @@ import org.yakindu.sct.simulation.runtime.sgraph.RTState;
 import org.yakindu.sct.simulation.runtime.sgraph.RTStatechart;
 import org.yakindu.sct.simulation.runtime.sgraph.RTTimeEvent;
 import org.yakindu.sct.simulation.runtime.sgraph.RTTransition;
-import org.yakindu.sct.simulation.runtime.sgraph.TimeEventExpression;
 import org.yakindu.sct.simulation.runtime.stext.Function;
 import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
-import org.yakindu.sct.simulation.runtime.stext.RTTrigger.SignalEvent;
 import org.yakindu.sct.simulation.runtime.stext.Variable;
 import org.yakindu.sct.simulation.runtime.stext.builder.STextBuilder;
 
@@ -67,16 +65,15 @@ import org.yakindu.sct.simulation.runtime.stext.builder.STextBuilder;
  * @author andreas muelder
  * 
  */
-public class SGraphBuilder extends Function {
-
-	// TODO: Extract interface
-	private STextBuilder sTextBuilder;
+public class SGraphBuilder extends Function implements ISGraphExecutionBuilder {
 
 	protected static Comparator<RTRegion> regionComparator = new Comparator<RTRegion>() {
 		public int compare(RTRegion o1, RTRegion o2) {
 			return o1.getPriority() - o2.getPriority();
 		}
 	};
+	
+	
 
 	public RTStatechart build(Statechart source) {
 		RTStatechart sc = new RTStatechart(source.getName());
@@ -95,28 +92,6 @@ public class SGraphBuilder extends Function {
 		return statechart;
 	}
 
-	// TODO: This is an access to the sText meta model, we have to extract these
-	// dependencies
-	// to an own builder
-	@FunctionMethod("")
-	public Object build(RTStatechart statechart, VariableDefinition definition) {
-		Variable variable = new Variable();
-		variable.setName(definition.getName());
-		statechart.addVariable(variable);
-		statechart.defineAlias(definition, variable);
-		if (definition.getType() == Type.BOOLEAN) {
-			variable.setType(Boolean.class);
-			variable.setValue(false);
-		} else if (definition.getType() == Type.INTEGER) {
-			variable.setType(Integer.class);
-			variable.setValue(0);
-		} else if (definition.getType() == Type.REAL) {
-			variable.setType(Float.class);
-			variable.setValue(0.0f);
-		}
-		return null;
-	}
-
 	@FunctionMethod("")
 	public Object build(RTStatechart tParent, Event event) {
 		RTSignalEvent signalEvent = new RTSignalEvent(event.getName());
@@ -218,13 +193,14 @@ public class SGraphBuilder extends Function {
 		RTAction action = null;
 
 		Trigger trigger = transition.getTrigger();
-		// TODO: Das muzss hier raus:
+//		// TODO: Das muss hier raus:
 		if (trigger instanceof ReactionTrigger) {
 			EList<EventSpec> triggers = ((ReactionTrigger) trigger)
 					.getTriggers();
 			for (EventSpec eventSpec : triggers) {
 				if (eventSpec instanceof RegularEventSpec) {
-					String name = ((RegularEventSpec) eventSpec).getEvent()
+					Event event = ((RegularEventSpec) eventSpec).getEvent();
+					String name = event
 							.getName();
 					RTSignalEvent signalEvent = tParent
 							.getSignalEvent(name);
@@ -232,18 +208,26 @@ public class SGraphBuilder extends Function {
 						signalTriggers.add(signalEvent);
 					}
 				}
+				if(eventSpec instanceof TimeEventSpec){
+					TimeUnit unit = ((TimeEventSpec) eventSpec).getUnit();
+					final int value = ((TimeEventSpec) eventSpec).getValue();
+					timeTrigger = new RTTimeEvent("id") {
+						@Override
+						public long getDuration() {
+							//TODO unit
+							return value;
+						}
+					};
+					
+				}
 				// TODO: TimeEvent
 			}
-
-			Expression guardExpression = ((ReactionTrigger) trigger)
-					.getGuardExpression();
-			guard = new GuardExpression(
-					sTextBuilder.buildGuardExpression(guardExpression), tParent);
+//			//TODO
 		}
 
-		Effect effect = transition.getEffect();
-		action = new ActionStatement(
-				sTextBuilder.buildActionExpression(effect), tParent);
+//		Effect effect = transition.getEffect();
+//		action = new ActionStatement(
+//				sTextBuilder.buildActionExpression(effect), tParent);
 
 		RTTransition tTrans = new RTTransition("t@", transition.getPriority(),
 				null, signalTriggers, guard, action, fromNode, toNode);

+ 1 - 1
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Assign.java

@@ -17,7 +17,7 @@ import org.yakindu.sct.simulation.runtime.ExecutionScope;
  * @author terfloth@itemis.de
  *
  */
-public class Assign implements Statement {
+public class Assign implements RTStatement {
 	
 	protected VariableRef varRef;
 	protected RTExpression expression;

+ 9 - 5
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Function.java

@@ -75,7 +75,9 @@ public class Function {
 	public static Function lookup(Class<?> functionClass, String name,
 			Class<?>[] paramTypes) {
 
-		List<Method> functionMethods = getFunctionMethods(functionClass);
+		List<Method> functionMethods = new ArrayList<Method>();
+		addFunctionMethods(functionClass, functionMethods);
+		Collections.sort(functionMethods, new PolymorphicComparator());
 		for (Method fMethod : functionMethods) {
 			FunctionMethod fAnno = fMethod.getAnnotation(FunctionMethod.class);
 			if ((name.equals(fMethod.getName())) || name.equals(fAnno.value())) {
@@ -87,8 +89,8 @@ public class Function {
 		return null;
 	}
 
-	private static List<Method> getFunctionMethods(Class<?> functionClass) {
-
+	private static void addFunctionMethods(Class<?> functionClass,
+			List<Method> methodList) {
 		List<Method> result = new ArrayList<Method>();
 		Method[] methods = functionClass.getDeclaredMethods();
 		for (int i = 0; i < methods.length; i++) {
@@ -98,8 +100,10 @@ public class Function {
 				result.add(fMethod);
 			}
 		}
-		Collections.sort(result, new PolymorphicComparator());
-		return result;
+		methodList.addAll(result);
+		if (functionClass.getSuperclass() != null) {
+			addFunctionMethods(functionClass.getSuperclass(), methodList);
+		}
 	}
 
 	private static boolean isCallable(Class<?>[] paramTypes,

+ 1 - 1
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/ProcedureCall.java

@@ -12,7 +12,7 @@ package org.yakindu.sct.simulation.runtime.stext;
 
 import org.yakindu.sct.simulation.runtime.ExecutionScope;
 
-public class ProcedureCall implements Statement {
+public class ProcedureCall implements RTStatement {
 
 	protected String procedureId;
 	

+ 1 - 1
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Scope.java

@@ -20,7 +20,7 @@ import org.yakindu.sct.simulation.runtime.ExecutionScope;
  * 
  * @author terfloth@itemis.de
  */
-public class Scope implements ExecutionScope {
+public class RTScope implements ExecutionScope {
 
 	protected Map<String, Variable> variables = new HashMap<String, Variable>();
 	

+ 1 - 1
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Statement.java

@@ -12,7 +12,7 @@ package org.yakindu.sct.simulation.runtime.stext;
 
 import org.yakindu.sct.simulation.runtime.ExecutionScope;
 
-public interface Statement {
+public interface RTStatement {
 
 	void execute(ExecutionScope scope);
 }

+ 1 - 1
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/Raise.java

@@ -12,7 +12,7 @@ package org.yakindu.sct.simulation.runtime.stext;
 
 import org.yakindu.sct.simulation.runtime.ExecutionScope;
 
-public class Raise implements Statement {
+public class Raise implements RTStatement {
 
 	protected String signal;
 	

+ 2 - 2
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/StatementSequence.java

@@ -19,12 +19,12 @@ import org.yakindu.sct.simulation.runtime.ExecutionScope;
  *  
  * @author terfloth@itemis.de
  */
-public class StatementSequence extends ArrayList<Statement> implements Statement {
+public class StatementSequence extends ArrayList<RTStatement> implements RTStatement {
 
 	private static final long serialVersionUID = -7484316500582800045L;
 
 	public void execute(ExecutionScope scope) {
-		for (Statement stmt : this) {	
+		for (RTStatement stmt : this) {	
 			stmt.execute(scope);
 		}
 	}

+ 0 - 520
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/ExpressionBuilder.java

@@ -1,520 +0,0 @@
-/**
- * Copyright (c) 2010-2011 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.runtime.stext.builder;
-
-import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_AND;
-import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_OR;
-import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_XOR;
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.xtext.ParserRule;
-import org.eclipse.xtext.XtextFactory;
-import org.eclipse.xtext.nodemodel.INode;
-import org.eclipse.xtext.parser.IParseResult;
-import org.eclipse.xtext.parser.IParser;
-import org.yakindu.sct.model.stext.ui.internal.STextActivator;
-import org.yakindu.sct.simulation.runtime.stext.Assign;
-import org.yakindu.sct.simulation.runtime.stext.BinaryOperation;
-import org.yakindu.sct.simulation.runtime.stext.Conditional;
-import org.yakindu.sct.simulation.runtime.stext.Constant;
-import org.yakindu.sct.simulation.runtime.stext.Function;
-import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
-import org.yakindu.sct.simulation.runtime.stext.ProcedureCall;
-import org.yakindu.sct.simulation.runtime.stext.RTExpression;
-import org.yakindu.sct.simulation.runtime.stext.RTTrigger;
-import org.yakindu.sct.simulation.runtime.stext.Raise;
-import org.yakindu.sct.simulation.runtime.stext.Statement;
-import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
-import org.yakindu.sct.simulation.runtime.stext.UnaryOperation;
-import org.yakindu.sct.simulation.runtime.stext.VariableRef;
-
-import com.google.inject.Inject;
-
-/**
- * The ExpressionBuilder creates an executable structure from the textual
- * expression definition or the corresponding EMF based abstract syntax tree.
- * This AST is defined by the expression grammer of this plugin.<br>
- * <br>
- * Expression builder instances are state-less so a single instance can be used
- * to build expression runtime structures multiple times and in parallel.<br>
- * <br>
- * The current implementation mainly consist of a set of builder functions with
- * a name prefix 'build'. This class defines a build function for each grammar
- * rule. So when changing the grammer it will be necessary to change, add or
- * remove build methods for the affected grammar rules. The implementation
- * strongly relies on dynamic dispatch of build function calls and therefore
- * makes use of the 'pluggable adapter' pattern and Java reflection. <br>
- * <br>
- * Example: <code>
- * (new ExpressionBuilder()).build("a = 2*b; a <<= 2;");
- * </code>
- * 
- * @author terfloth@itemis.de
- * 
- */
-public class ExpressionBuilder extends Function {
-
-	@Inject
-	private IParser parser;
-
-	/** Builder functions always */
-	protected static Class<?>[] paramTypes = new Class[] { EObject.class };
-
-	protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
-
-	static {
-		assignFunctionMap.put("multAssign", "*");
-		assignFunctionMap.put("divAssign", "/");
-		assignFunctionMap.put("modAssign", "%");
-		assignFunctionMap.put("addAssign", "+");
-		assignFunctionMap.put("subAssign", "-");
-		assignFunctionMap.put("leftShiftAssign", "<<");
-		assignFunctionMap.put("rightShiftAssign", ">>");
-		assignFunctionMap.put("andAssign", "&");
-		assignFunctionMap.put("xorAssign", "^");
-		assignFunctionMap.put("orAssign", "|");
-	}
-
-	public ExpressionBuilder() {
-		parser = STextActivator.getInstance()
-				.getInjector("org.yakindu.sct.model.stext.SText")
-				.getInstance(IParser.class);
-	}
-
-	/**
-	 * Static helper method that creates a executable expression structure from
-	 * a expression string.
-	 * 
-	 * @param actionExpression
-	 * @return an executable statement object.
-	 */
-	public static Statement buildAction(String actionExpression) {
-		ExpressionBuilder builder = new ExpressionBuilder();
-		return builder.buildEffect(actionExpression);
-	}
-
-	/**
-	 * Static helper method that creates a executable expression structure from
-	 * a expression string.
-	 * 
-	 * @param guardExpression
-	 * @return an executable statement object.
-	 */
-	public static RTExpression buildGuard(String guardExpression) {
-		ExpressionBuilder builder = new ExpressionBuilder();
-		return builder.buildGuardExpression(guardExpression);
-	}
-
-	/**
-	 * Static helper method that creates a executable expression structure from
-	 * a expression string.
-	 * 
-	 * @param guardExpression
-	 * @return an executable statement object.
-	 */
-	public static List<RTTrigger> buildTriggers(String guardExpression) {
-		ExpressionBuilder builder = new ExpressionBuilder();
-		return builder.buildTriggerExpression(guardExpression);
-	}
-
-	/**
-	 * The primary builder method that creates a executable statement structure
-	 * from a expression string.
-	 * 
-	 * @param actionExpression
-	 * @return an executable statement object.
-	 */
-	public Statement buildEffect(String expr) {
-		ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
-		parserRule.setName("Statement");
-		IParseResult result = parser.parse(parserRule, new StringReader(expr));
-		if(result.hasSyntaxErrors()){
-			StringBuilder errorMessages = new StringBuilder();
-			Iterable<INode> syntaxErrors = result.getSyntaxErrors();
-			for (INode iNode : syntaxErrors) {
-				errorMessages.append(iNode.getSyntaxErrorMessage());
-				errorMessages.append("\n");
-			}
-			throw new RuntimeException("Could not parse expression, syntax errors: " + errorMessages);
-		}
-		EObject rootASTElement = result.getRootASTElement();
-		return (Statement) build(rootASTElement);
-	}
-
-	/**
-	 * The primary builder method that creates a executable guard expression
-	 * structure from an expression string.
-	 * 
-	 * @param actionExpression
-	 * @return an executable statement object.
-	 */
-	public RTExpression buildGuardExpression(String expr) {
-		EObject root = parser.parse(new StringReader(expr)).getRootASTElement();
-		return (RTExpression) build(root);
-	}
-
-	/**
-	 * The primary builder method that creates a executable guard expression
-	 * structure from an expression string.
-	 * 
-	 * @param actionExpression
-	 * @return an executable statement object.
-	 */
-	public List<RTTrigger> buildTriggerExpression(String expr) {
-		EObject root = parser.parse(new StringReader(expr)).getRootASTElement();
-		return (List<RTTrigger>) build(root);
-	}
-
-	@FunctionMethod("build")
-	public List<RTTrigger> buildTriggerExpression(EObject obj) {
-		List<RTTrigger> triggers = new ArrayList<RTTrigger>();
-
-		for (EObject child : obj.eContents()) {
-			RTTrigger trigger = (RTTrigger) build(child);
-			if (trigger != null)
-				triggers.add(trigger);
-		}
-
-		return triggers;
-	}
-
-	@FunctionMethod("build")
-	public RTTrigger buildTrigger(EObject obj) {
-		return (RTTrigger) build(getToOne(obj, "event"));
-	}
-
-	@FunctionMethod("build")
-	public RTTrigger buildSignalEvent(EObject obj) {
-		return new RTTrigger.SignalEvent(getString(obj, "identifier"));
-	}
-
-	@FunctionMethod("build")
-	public RTTrigger buildTimeEvent(EObject obj) {
-		return new RTTrigger.TimeEvent(buildRefExpression(obj, "duration"));
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildTimeConstant(EObject obj) {
-		int duration = getInteger(obj, "value");
-		String unit = getLiteral(obj, "unit");
-
-		if (unit != null) {
-			if ("second".equals(unit))
-				duration *= 1000;
-			else if ("nanosecond".equals(unit))
-				duration /= 1000;
-		}
-
-		return new Constant(duration);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildGuardExpression(EObject obj) {
-		return buildRefExpression(obj, "expression");
-	}
-
-	@FunctionMethod("build")
-	public Statement buildActionExpression(EObject obj) {
-		StatementSequence seq = new StatementSequence();
-
-		for (EObject child : obj.eContents()) {
-			Statement stmt = (Statement) build(child);
-			if (stmt != null)
-				seq.add(stmt);
-		}
-
-		return seq;
-	}
-
-	@FunctionMethod("build")
-	public Statement buildEventRaising(EObject obj) {
-
-		EObject event = getToOne(obj, "event");
-		return new Raise(getString(event, "identifier"));
-	}
-
-	@FunctionMethod("build")
-	public Statement buildProcedureCall(EObject obj) {
-
-		EObject event = getToOne(obj, "procedure");
-		return new ProcedureCall(getString(event, "identifier"));
-	}
-
-	@FunctionMethod("build")
-	public Statement buildAssignment(EObject obj) {
-
-		VariableRef var = (VariableRef) build(getToOne(obj, "variableReference"));
-		String operator = getLiteral(obj, "operator");
-		RTExpression exp = (RTExpression) build(getToOne(obj, "expression"));
-
-		if (!"assign".equals(operator)) {
-			String mappedOperator = assignFunctionMap.get(operator);
-			if (mappedOperator == null)
-				throw new BuilderException("Assignment operator '" + operator
-						+ "' can not be resolved to a function.");
-
-			exp = new BinaryOperation(mappedOperator, var, exp);
-		}
-
-		return new Assign(var, exp);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildConditionalExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-		RTExpression op3 = buildRefExpression(obj, "operand3");
-
-		if (op1 != null && op2 != null && op3 != null)
-			return new Conditional(op1, op2, op3);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildBooleanOrExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BinaryOperation.OR, op1, op2);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildBooleanAndExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BinaryOperation.AND, op1, op2);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseXorExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_XOR, op1, op2);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseOrExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_OR, op1, op2);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseAndExpression(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_AND, op1, op2);
-
-		return op1;
-	}
-
-	public RTExpression buildBinaryOperation(EObject obj) {
-
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-		String operator = getLiteral(obj, "operator");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(operator, op1, op2);
-
-		return op1;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildEqualityExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildRelationalExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildShiftExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildAdditiveExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildMultiplicativeExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildUnaryExpression(EObject obj) {
-
-		RTExpression operand = buildRefExpression(obj, "operand");
-		String operator = getLiteral(obj, "operator");
-
-		if (operand != null && operator != null)
-			return new UnaryOperation(operator, operand);
-
-		return operand;
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildNestedExpression(EObject obj) {
-		return buildRefExpression(obj, "expression");
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildLiteralValue(EObject obj) {
-
-		String value = getString(obj, "value");
-
-		// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
-		// um unterschiedliche Literaltypen unterscheiden zu koennen
-		if (value != null) {
-
-			if ("true".equals(value))
-				return new Constant(Boolean.TRUE);
-
-			if ("false".equals(value))
-				return new Constant(Boolean.FALSE);
-
-			try { // flaot
-				if (value.contains("."))
-					return new Constant(Float.parseFloat(value));
-			} catch (NumberFormatException e1) { /* need to be quite */
-			}
-
-			try { // hex int
-				if (value.startsWith("0x"))
-					return new Constant(new Integer(Integer.parseInt(
-							value.substring(2), 16)));
-			} catch (NumberFormatException e1) { /* need to be quite */
-			}
-
-			try { // int
-				return new Constant(new Integer(Integer.parseInt(value)));
-			} catch (NumberFormatException e1) { /* need to be quite */
-			}
-
-			if ((value.startsWith("'") && value.endsWith("'"))
-					|| (value.startsWith("\"") && value.endsWith("\"")))
-				return new Constant(value.substring(1, value.length() - 1));
-		}
-
-		return new Constant(value);
-	}
-
-	@FunctionMethod("build")
-	public RTExpression buildVariableReference(EObject obj) {
-
-		EObject var = getToOne(obj, "variable");
-		return new VariableRef(getString(var, "identifier"));
-	}
-
-	/**
-	 * Internal build method that performs the dynamic dispatch to the
-	 * appropriate (correctly named) builder function. The parameter is always a
-	 * EObject and since we have use dynamic EMF we match by naming conventions.
-	 * 
-	 * @param obj
-	 * @return
-	 */
-	protected Object build(EObject obj) {
-		if (obj == null)
-			return null;
-
-		Object[] params = new Object[] { obj };
-
-		Function f = ExpressionBuilder.lookup(this.getClass(), "build"
-				+ obj.eClass().getName(), paramTypes);
-		if (f != null)
-			return f.execute(params);
-
-		throw new BuilderException("No builder function for: "
-				+ obj.eClass().getName());
-	}
-
-	protected RTExpression buildRefExpression(EObject obj, String refName) {
-		return (RTExpression) build(getToOne(obj, refName));
-	}
-
-	protected EObject getToOne(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if (feature instanceof EReference) {
-			EReference ref = (EReference) feature;
-			return (EObject) obj.eGet(ref);
-		}
-		throw new BuilderException();
-	}
-
-	protected String getString(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if (feature instanceof EAttribute) {
-			EAttribute attr = (EAttribute) feature;
-			return (String) obj.eGet(attr);
-		}
-		throw new BuilderException();
-	}
-
-	protected Integer getInteger(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if (feature instanceof EAttribute) {
-			EAttribute attr = (EAttribute) feature;
-			return (Integer) obj.eGet(attr);
-		}
-		throw new BuilderException();
-	}
-
-	protected String getLiteral(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if (feature instanceof EAttribute) {
-			EAttribute attr = (EAttribute) feature;
-			String literalValue = ((Enumerator) obj.eGet(attr)).getName();
-
-			return ("NULL".equals(literalValue)) ? null : literalValue;
-		}
-		throw new BuilderException();
-	}
-
-}

+ 400 - 421
plugins/org.yakindu.sct.simulation.runtime/src/org/yakindu/sct/simulation/runtime/stext/builder/STextBuilder.java

@@ -1,421 +1,400 @@
-/**
- * Copyright (c) 2010-2011 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.runtime.stext.builder;
-
-import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.*;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import org.yakindu.sct.simulation.runtime.stext.*;
-
-/**
- * The ExpressionBuilder creates an executable structure from the textual expression definition 
- * or the corresponding EMF based abstract syntax tree. This AST is defined by the expression grammer 
- * of this plugin.<br>
- * <br>
- * Expression builder instances are state-less so a single instance can be used to build 
- * expression runtime structures multiple times and in parallel.<br>
- * <br>
- * The current implementation mainly consist of a set of builder functions with a name prefix 'build'. 
- * This class defines a build function for each grammar rule. So when changing the grammer it will be necessary
- * to change, add or remove build methods for the affected grammar rules. The implementation strongly relies on dynamic dispatch of build function calls and therefore
- * makes use of the 'pluggable adapter' pattern and Java reflection. <br>
- * <br>
- * Example:
- * <code>
- * (new ExpressionBuilder()).build("a = 2*b; a <<= 2;");
- * </code>
- * 
- * @author terfloth@itemis.de
- *
- */
-public class STextBuilder extends Function {
-
-	/** Builder functions always*/
-	protected static Class<?>[] paramTypes = new Class[]{EObject.class};
-
-	protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
-
-	static {
-		assignFunctionMap.put("multAssign", "*"); 
-		assignFunctionMap.put("divAssign", "/"); 
-		assignFunctionMap.put("modAssign", "%");
-		assignFunctionMap.put("addAssign", "+"); 
-		assignFunctionMap.put("subAssign", "-"); 
-		assignFunctionMap.put("leftShiftAssign", "<<"); 
-		assignFunctionMap.put("rightShiftAssign", ">>"); 
-		assignFunctionMap.put("andAssign", "&"); 
-		assignFunctionMap.put("xorAssign", "^"); 
-		assignFunctionMap.put("orAssign", "|");
-	}
-	
-	
-	@FunctionMethod("build")
-	public List<RTTrigger> buildTriggerExpression(EObject obj) {
-		List<RTTrigger> triggers = new ArrayList<RTTrigger>();
-
-		for (EObject child : obj.eContents()) {
-			RTTrigger trigger = (RTTrigger) build(child);
-			if(trigger != null) triggers.add(trigger);
-		}
-
-		return triggers;
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTTrigger buildTrigger(EObject obj) {
-		return (RTTrigger) build(getToOne(obj, "event"));
-	}
-	
-	@FunctionMethod("build")
-	public RTTrigger buildSignalEvent(EObject obj) {
-		return new RTTrigger.SignalEvent(getString(obj, "identifier"));
-	}
-	
-	@FunctionMethod("build")
-	public RTTrigger buildTimeEvent(EObject obj) {
-		return new RTTrigger.TimeEvent(buildRefExpression(obj, "duration"));
-	}
-	
-	@FunctionMethod("build")
-	public RTExpression buildTimeConstant(EObject obj) {
-		int duration = getInteger(obj, "value");
-		String unit = getLiteral(obj, "unit");
-		
-		if (unit != null) {
-			if ("second".equals(unit)) duration *= 1000;
-			else if ("nanosecond".equals(unit)) duration /= 1000;
-		}
-		
-		return new Constant(duration);
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTExpression buildGuardExpression(EObject obj) {
-		return buildRefExpression(obj, "expression");
-	}
-	
-	
-	@FunctionMethod("build")
-	public Statement buildActionExpression(EObject obj) {
-		StatementSequence seq = new StatementSequence();
-		
-		for (EObject child : obj.eContents()) {
-			Statement stmt = (Statement) build(child);
-			if(stmt != null) seq.add(stmt);
-		}
-		
-		return seq;
-	}
-	
-	
-	@FunctionMethod("build")
-	public Statement buildEventRaising(EObject obj) {
-		
-		EObject event = getToOne(obj, "event");		
-		return new Raise(getString(event, "identifier"));
-	}
-	
-
-	@FunctionMethod("build")
-	public Statement buildProcedureCall(EObject obj) {
-		
-		EObject event = getToOne(obj, "procedure");	
-		return new ProcedureCall(getString(event, "identifier"));
-	}
-	
-
-	@FunctionMethod("build")
-	public Statement buildVariableAssignment(EObject obj) {
-		
-		VariableRef var = (VariableRef) build(getToOne(obj, "variableReference"));
-		String operator = getLiteral(obj, "operator");
-		RTExpression exp = (RTExpression) build(getToOne(obj, "value"));
-
-		if (! "assign".equals(operator)) {
-			String mappedOperator = assignFunctionMap.get(operator);
-			if (mappedOperator == null) 
-				throw new BuilderException("Assignment operator '" + operator + "' can not be resolved to a function.");
-			
-			exp = new BinaryOperation(mappedOperator, var, exp);
-		}
-		
-		return new Assign(var, exp);
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildConditionalExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-		RTExpression op3 = buildRefExpression(obj, "operand3");
-
-		if (op1 != null && op2 != null && op3 != null)
-			return new Conditional(op1, op2, op3);
-		
-		return op1;
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildBooleanOrExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BinaryOperation.OR, op1, op2);
-		
-		return op1;
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildBooleanAndExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BinaryOperation.AND, op1, op2);
-		
-		return op1;
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseXorExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_XOR, op1, op2);
-		
-		return op1;
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseOrExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_OR, op1, op2);
-		
-		return op1;
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTExpression buildBitwiseAndExpression(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(BIT_AND, op1, op2);
-		
-		return op1;
-	}
-	
-
-	public RTExpression buildBinaryOperation(EObject obj) {
-		
-		RTExpression op1 = buildRefExpression(obj, "operand1");
-		RTExpression op2 = buildRefExpression(obj, "operand2");
-		String operator = getLiteral(obj, "operator");
-
-		if (op1 != null && op2 != null)
-			return new BinaryOperation(operator, op1, op2);
-		
-		return op1;
-	}
-
-	
-	@FunctionMethod("build")
-	public RTExpression buildEqualityExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTExpression buildRelationalExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-	
-	@FunctionMethod("build")
-	public RTExpression buildShiftExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-	
-	@FunctionMethod("build")
-	public RTExpression buildAdditiveExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTExpression buildMultiplicativeExpression(EObject obj) {
-		return buildBinaryOperation(obj);
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildUnaryExpression(EObject obj) {
-		
-		RTExpression operand = buildRefExpression(obj, "operand");
-		String operator = getLiteral(obj, "operator");
-
-		if (operand != null && operator != null)
-			return new UnaryOperation(operator, operand);
-		
-		return operand;
-	}
-	
-	
-	@FunctionMethod("build")
-	public RTExpression buildNestedExpression(EObject obj) {
-		return buildRefExpression(obj, "expression");
-	}
-	
-
-	@FunctionMethod("build")
-	public RTExpression buildLiteralValue(EObject obj) {
-		
-		String value = getString(obj, "value");	
-		
-		// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
-		// um unterschiedliche Literaltypen unterscheiden zu koennen
-		if (value != null) {
-			
-			if ("true".equals(value)) return new Constant(Boolean.TRUE);
-			
-			if ("false".equals(value)) return new Constant(Boolean.FALSE);
-
-			try { // flaot
-				if (value.contains("."))
-					return new Constant(Float.parseFloat(value));
-			} catch (NumberFormatException e1) { /* need to be quite */ }
-
-			try { // hex int
-				if (value.startsWith("0x"))
-					return new Constant(new Integer(Integer.parseInt(value.substring(2), 16)));
-			} catch (NumberFormatException e1) { /* need to be quite */ }
-						
-			try { // int
-				return new Constant(new Integer(Integer.parseInt(value)));
-			} catch (NumberFormatException e1) { /* need to be quite */ }
-			
-			if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith("\"") && value.endsWith("\"")) )
-				return new Constant(value.substring(1, value.length()-1));
-		}
-		
-		return new Constant(value);
-	}
-	
-
-	
-	@FunctionMethod("build")
-	public RTExpression buildVariableReference(EObject obj) {
-		
-		EObject var = getToOne(obj, "variable");	
-		return new VariableRef(getString(var, "identifier"));
-	}
-	
-
-	/**
-	 * Internal build method that performs the dynamic dispatch to the appropriate (correctly named) 
-	 * builder function. The parameter is always a EObject and since we have use dynamic EMF we match by 
-	 * naming conventions.
-	 * 
-	 * @param obj
-	 * @return
-	 */
-	protected Object build(EObject obj) {
-		if ( obj == null ) return null;
-		
-		Object[] params = new Object[]{obj};
-		
-		Function f = STextBuilder.lookup(this.getClass(), "build" + obj.eClass().getName(), paramTypes);
-		if (f != null) 
-			return f.execute(params);
-		
-		throw new BuilderException("No builder function for: " + obj.eClass().getName());
-	}
-	
-	
-	protected RTExpression buildRefExpression(EObject obj, String refName) {
-		return (RTExpression) build(getToOne(obj, refName));
-	}
-	
-
-	
-	protected EObject getToOne(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if ( feature instanceof EReference ) {
-			EReference ref = (EReference) feature;
-			return (EObject) obj.eGet(ref);
-		}
-		throw new BuilderException();
-	}
-	
-	
-	protected String getString(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if ( feature instanceof EAttribute ) {
-			EAttribute attr = (EAttribute) feature;
-			return (String) obj.eGet(attr);
-		}
-		throw new BuilderException();
-	}
-
-
-	protected Integer getInteger(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if ( feature instanceof EAttribute ) {
-			EAttribute attr = (EAttribute) feature;
-			return (Integer) obj.eGet(attr);
-		}
-		throw new BuilderException();
-	}
-
-	
-	protected String getLiteral(EObject obj, String name) {
-		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
-		if ( feature instanceof EAttribute ) {
-			EAttribute attr = (EAttribute) feature;
-			String literalValue = ((Enumerator) obj.eGet(attr)).getName();
-		
-			return ("NULL".equals(literalValue)) ? null : literalValue;
-		}
-		throw new BuilderException();
-	}
-	
-	
-
-}
-
+/**
+ * Copyright (c) 2010-2011 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.runtime.stext.builder;
+
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_AND;
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_OR;
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_XOR;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.yakindu.sct.core.simulation.ISGraphExecutionBuilder;
+import org.yakindu.sct.model.stext.stext.Type;
+import org.yakindu.sct.model.stext.stext.VariableDefinition;
+import org.yakindu.sct.simulation.runtime.sgraph.RTStatechart;
+import org.yakindu.sct.simulation.runtime.sgraph.builder.SGraphBuilder;
+import org.yakindu.sct.simulation.runtime.stext.Assign;
+import org.yakindu.sct.simulation.runtime.stext.BinaryOperation;
+import org.yakindu.sct.simulation.runtime.stext.Constant;
+import org.yakindu.sct.simulation.runtime.stext.Function;
+import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
+import org.yakindu.sct.simulation.runtime.stext.ProcedureCall;
+import org.yakindu.sct.simulation.runtime.stext.RTExpression;
+import org.yakindu.sct.simulation.runtime.stext.RTStatement;
+import org.yakindu.sct.simulation.runtime.stext.RTTrigger;
+import org.yakindu.sct.simulation.runtime.stext.Raise;
+import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
+import org.yakindu.sct.simulation.runtime.stext.UnaryOperation;
+import org.yakindu.sct.simulation.runtime.stext.Variable;
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
+
+/**
+ * The ExpressionBuilder creates an executable structure from the textual
+ * expression definition or the corresponding EMF based abstract syntax tree.
+ * This AST is defined by the expression grammer of this plugin.<br>
+ * <br>
+ * Expression builder instances are state-less so a single instance can be used
+ * to build expression runtime structures multiple times and in parallel.<br>
+ * <br>
+ * The current implementation mainly consist of a set of builder functions with
+ * a name prefix 'build'. This class defines a build function for each grammar
+ * rule. So when changing the grammer it will be necessary to change, add or
+ * remove build methods for the affected grammar rules. The implementation
+ * strongly relies on dynamic dispatch of build function calls and therefore
+ * makes use of the 'pluggable adapter' pattern and Java reflection. <br>
+ * <br>
+ * 
+ * @author terfloth@itemis.de
+ * @author andreas muelder
+ */
+public class STextBuilder extends SGraphBuilder implements ISGraphExecutionBuilder{
+
+	/** Builder functions always */
+	protected static Class<?>[] paramTypes = new Class[] { EObject.class };
+
+	protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
+
+	static {
+		assignFunctionMap.put("multAssign", "*");
+		assignFunctionMap.put("divAssign", "/");
+		assignFunctionMap.put("modAssign", "%");
+		assignFunctionMap.put("addAssign", "+");
+		assignFunctionMap.put("subAssign", "-");
+		assignFunctionMap.put("leftShiftAssign", "<<");
+		assignFunctionMap.put("rightShiftAssign", ">>");
+		assignFunctionMap.put("andAssign", "&");
+		assignFunctionMap.put("xorAssign", "^");
+		assignFunctionMap.put("orAssign", "|");
+	}
+	
+		@FunctionMethod("")
+		public Object build(RTStatechart statechart, VariableDefinition definition) {
+			Variable variable = new Variable();
+			variable.setName(definition.getName());
+			statechart.addVariable(variable);
+			statechart.defineAlias(definition, variable);
+			if (definition.getType() == Type.BOOLEAN) {
+				variable.setType(Boolean.class);
+				variable.setValue(false);
+			} else if (definition.getType() == Type.INTEGER) {
+				variable.setType(Integer.class);
+				variable.setValue(0);
+			} else if (definition.getType() == Type.REAL) {
+				variable.setType(Float.class);
+				variable.setValue(0.0f);
+			}
+			return null;
+		}
+	
+
+	@FunctionMethod("build")
+	public RTTrigger buildTrigger(EObject obj) {
+		return (RTTrigger) build(getToOne(obj, "event"));
+	}
+
+	@FunctionMethod("build")
+	public RTTrigger buildSignalEvent(EObject obj) {
+		return new RTTrigger.SignalEvent(getString(obj, "identifier"));
+	}
+
+	@FunctionMethod("build")
+	public RTTrigger buildTimeEvent(EObject obj) {
+		return new RTTrigger.TimeEvent(buildRefExpression(obj, "duration"));
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildTimeConstant(EObject obj) {
+		int duration = getInteger(obj, "value");
+		String unit = getLiteral(obj, "unit");
+
+		if (unit != null) {
+			if ("second".equals(unit))
+				duration *= 1000;
+			else if ("nanosecond".equals(unit))
+				duration /= 1000;
+		}
+
+		return new Constant(duration);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildGuardExpression(EObject obj) {
+		return buildRefExpression(obj, "expression");
+	}
+
+	@FunctionMethod("build")
+	public RTStatement buildReactionEffect(EObject obj) {
+		StatementSequence seq = new StatementSequence();
+		for (EObject child : obj.eContents()) {
+			RTStatement stmt = (RTStatement) build(child);
+			if (stmt != null)
+				seq.add(stmt);
+		}
+		return seq;
+	}
+
+	@FunctionMethod("build")
+	public RTStatement buildEventRaising(EObject obj) {
+
+		EObject event = getToOne(obj, "event");
+		return new Raise(getString(event, "name"));
+	}
+
+	@FunctionMethod("build")
+	public RTStatement buildOperationCall(EObject obj) {
+		EObject operation = getToOne(obj, "operation");
+		return new ProcedureCall(getString(operation, "name"));
+	}
+	
+
+	@FunctionMethod("build")
+	public RTStatement buildAssignment(EObject obj) {
+		EObject variable = getToOne(obj, "varRef");
+		if (variable == null)
+			throw new IllegalStateException("Unknown variable reference " + obj);
+		RTExpression exp = (RTExpression) build(getToOne(obj, "expression"));
+		return new Assign(new VariableRef(getString(variable, "name")), exp);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildLogicalOrExpression(EObject obj) {
+
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BinaryOperation.OR, op1, op2);
+
+		return op1;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildLogicalAndExpression(EObject obj) {
+
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BinaryOperation.AND, op1, op2);
+
+		return op1;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildBitwiseXorExpression(EObject obj) {
+
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_XOR, op1, op2);
+
+		return op1;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildBitwiseOrExpression(EObject obj) {
+
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_OR, op1, op2);
+
+		return op1;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildBitwiseAndExpression(EObject obj) {
+
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(BIT_AND, op1, op2);
+
+		return op1;
+	}
+
+	public RTExpression buildBinaryOperation(EObject obj) {
+		RTExpression op1 = buildRefExpression(obj, "leftOperand");
+		RTExpression op2 = buildRefExpression(obj, "rightOperand");
+		String operator = getLiteral(obj, "operator");
+
+		if (op1 != null && op2 != null)
+			return new BinaryOperation(operator, op1, op2);
+
+		return op1;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildLogicalRelationExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildShiftExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildAdditiveExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildNumericalMultiplyDivideExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildNumericalAddSubtractExpression(EObject obj) {
+		return buildBinaryOperation(obj);
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildUnaryExpression(EObject obj) {
+
+		RTExpression operand = buildRefExpression(obj, "operand");
+		String operator = getLiteral(obj, "operator");
+
+		if (operand != null && operator != null)
+			return new UnaryOperation(operator, operand);
+
+		return operand;
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildNestedExpression(EObject obj) {
+		return buildRefExpression(obj, "expression");
+	}
+
+	@FunctionMethod("build")
+	public RTExpression buildPrimitiveValueExpression(EObject obj) {
+
+		String value = getString(obj, "value");
+
+		// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
+		// um unterschiedliche Literaltypen unterscheiden zu koennen
+		if (value != null) {
+
+			if ("true".equals(value))
+				return new Constant(Boolean.TRUE);
+
+			if ("false".equals(value))
+				return new Constant(Boolean.FALSE);
+
+			try { // flaot
+				if (value.contains("."))
+					return new Constant(Float.parseFloat(value));
+			} catch (NumberFormatException e1) { /* need to be quite */
+			}
+
+			try { // hex int
+				if (value.startsWith("0x"))
+					return new Constant(new Integer(Integer.parseInt(
+							value.substring(2), 16)));
+			} catch (NumberFormatException e1) { /* need to be quite */
+			}
+
+			try { // int
+				return new Constant(new Integer(Integer.parseInt(value)));
+			} catch (NumberFormatException e1) { /* need to be quite */
+			}
+
+			if ((value.startsWith("'") && value.endsWith("'"))
+					|| (value.startsWith("\"") && value.endsWith("\"")))
+				return new Constant(value.substring(1, value.length() - 1));
+		}
+
+		return new Constant(value);
+	}
+
+	@FunctionMethod("build")
+	protected RTExpression buildElementReferenceExpression(EObject obj) {
+		// TODO: Do we really need an ElementReferenceExpression? Or is a
+		// VariableReferenceExpression enough?
+		EObject var = getToOne(obj, "value");
+		return new VariableRef(getString(var, "name"));
+	}
+
+	/**
+	 * build method that performs the dynamic dispatch to the appropriate
+	 * (correctly named) builder function. The parameter is always a EObject and
+	 * since we have use dynamic EMF we match by naming conventions.
+	 * 
+	 * @param obj
+	 * @return
+	 */
+	public Object build(EObject obj) {
+		if (obj == null)
+			return null;
+
+		Object[] params = new Object[] { obj };
+
+		Function f = STextBuilder.lookup(this.getClass(), "build"
+				+ obj.eClass().getName(), paramTypes);
+		if (f != null)
+			return f.execute(params);
+
+		throw new BuilderException("No builder function for: "
+				+ obj.eClass().getName());
+	}
+
+	protected RTExpression buildRefExpression(EObject obj, String refName) {
+		return (RTExpression) build(getToOne(obj, refName));
+	}
+
+	protected EObject getToOne(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if (feature instanceof EReference) {
+			EReference ref = (EReference) feature;
+			return (EObject) obj.eGet(ref);
+		}
+		throw new BuilderException();
+	}
+
+	protected String getString(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if (feature instanceof EAttribute) {
+			EAttribute attr = (EAttribute) feature;
+			return (String) obj.eGet(attr);
+		}
+		throw new BuilderException();
+	}
+
+	protected Integer getInteger(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if (feature instanceof EAttribute) {
+			EAttribute attr = (EAttribute) feature;
+			return (Integer) obj.eGet(attr);
+		}
+		throw new BuilderException();
+	}
+
+	protected String getLiteral(EObject obj, String name) {
+		EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
+		if (feature instanceof EAttribute) {
+			EAttribute attr = (EAttribute) feature;
+			String literalValue = ((Enumerator) obj.eGet(attr)).getName();
+
+			return ("NULL".equals(literalValue)) ? null : literalValue;
+		}
+		throw new BuilderException();
+	}
+
+}

+ 3 - 1
plugins/org.yakindu.sct.ui.simulation/META-INF/MANIFEST.MF

@@ -14,7 +14,9 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.debug.ui;bundle-version="3.7.0",
  org.eclipse.jdt.launching;bundle-version="3.6.0",
  org.eclipse.jdt.debug.ui;bundle-version="3.6.0",
- org.yakindu.sct.core.simulation;bundle-version="1.0.0"
+ org.yakindu.sct.simulation.core;bundle-version="1.0.0",
+ org.yakindu.sct.model.sgraph;bundle-version="1.0.0",
+ de.itemis.xtext.utils.jface;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Import-Package: org.eclipse.ui.dialogs

+ 20 - 0
plugins/org.yakindu.sct.ui.simulation/plugin.xml

@@ -51,4 +51,24 @@
 		  	 </contextualLaunch>
 	    </shortcut>
 	</extension>
+	
+<!-- Session Listener -->
+ <extension
+       point="org.yakindu.sct.simulation.core.sgraph.sessionlistener">
+    <ISimulationSessionListener class="org.yakindu.sct.ui.simulation.editor.HighlightingExecutionListener" />
+    <ISimulationSessionListener
+          class="org.yakindu.sct.ui.simulation.view.EventViewUpdater">
+    </ISimulationSessionListener>
+ </extension>
+ <extension
+       point="org.eclipse.ui.views">
+    <view
+          allowMultiple="false"
+          class="org.yakindu.sct.ui.simulation.view.EventView"
+          icon="icons/yakindu.png"
+          id="org.yakindu.sct.ui.simulation.eventview"
+          name="Event View"
+          restorable="true">
+    </view>
+ </extension>
 </plugin>

+ 83 - 0
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/editor/HighlightingExecutionListener.java

@@ -0,0 +1,83 @@
+package org.yakindu.sct.ui.simulation.editor;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.yakindu.sct.core.simulation.ISimulationSessionListener;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+import de.itemis.gmf.runtime.commons.highlighting.HighlightingParameters;
+import de.itemis.gmf.runtime.commons.highlighting.IHighlightingSupport;
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class HighlightingExecutionListener implements
+		ISimulationSessionListener {
+
+	private IHighlightingSupport highlightingSupport;
+
+	private HighlightingParameters parameters;
+
+	public HighlightingExecutionListener() {
+
+		IEditorPart activeEditor = ActiveEditorResolver.getActiveEditor();
+		if (activeEditor != null) {
+			// TODO The active editor should be adaptable to IHighlightSupport
+			// via registered factory
+			IHighlightingSupportAdapterFactory factory = new IHighlightingSupportAdapterFactory();
+			highlightingSupport = (IHighlightingSupport) factory.getAdapter(
+					activeEditor, IHighlightingSupport.class);
+
+		}
+
+		parameters = new HighlightingParameters();
+	}
+
+	public void stateEntered(final Vertex vertex) {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				System.out.println("Fading in..." + vertex);
+				highlightingSupport.fadeIn(vertex, parameters);
+			}
+		});
+	}
+
+	public void stateLeft(final Vertex vertex) {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				System.out.println("Fading out..." + vertex);
+				highlightingSupport.fadeOut(vertex, parameters);
+			}
+		});
+	}
+
+	public void transitionFired(final Transition transition) {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				System.out.println("Flashing..." + transition);
+				highlightingSupport.flash(transition, parameters);
+			}
+		});
+	}
+
+	public void simulationStateChanged(SimulationState oldState,
+			final SimulationState newState) {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				switch (newState) {
+				case STARTED:
+					highlightingSupport.lockEditor();
+					break;
+				case TERMINATED:
+					highlightingSupport.releaseEditor();
+					break;
+				}
+			}
+		});
+	}
+
+}

+ 1 - 1
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/launch/StatechartLaunchShortcut.java

@@ -69,7 +69,7 @@ public class StatechartLaunchShortcut implements ILaunchShortcut,
 					null, launchManager.generateLaunchConfigurationName(file
 							.getName()));
 
-			newConfig.setAttribute(FILE_NAME, file.getFullPath().toFile().getAbsolutePath());
+			newConfig.setAttribute(FILE_NAME, file.getLocation().toString());
 			return newConfig.doSave();
 			
 		} catch (CoreException e) {

+ 128 - 0
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/view/EventView.java

@@ -0,0 +1,128 @@
+package org.yakindu.sct.ui.simulation.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.part.ViewPart;
+import org.yakindu.sct.core.simulation.SGraphSimulationSession;
+import org.yakindu.sct.core.simulation.SGraphSimulationSessionRegistry;
+import org.yakindu.sct.model.sgraph.Event;
+import org.yakindu.sct.model.sgraph.NamedElement;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class EventView extends ViewPart {
+
+	public static final String ID = "org.yakindu.sct.ui.simulation.eventview";
+
+	private TableViewer viewer;
+
+	private List<Control> controls;
+
+	@Override
+	public void createPartControl(Composite parent) {
+		controls = new ArrayList<Control>();
+		parent.setLayout(new FillLayout());
+		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
+				| SWT.V_SCROLL | SWT.FULL_SELECTION);
+		viewer.getTable().setLinesVisible(true);
+		viewer.getTable().setHeaderVisible(true);
+		createColumns(viewer);
+		viewer.setContentProvider(new ArrayContentProvider());
+
+	}
+
+	private void createColumns(final TableViewer viewer) {
+		TableViewerColumn eventColumn = new TableViewerColumn(viewer, SWT.NONE);
+		eventColumn.getColumn().setText("event name");
+		eventColumn.getColumn().setWidth(120);
+		eventColumn.getColumn().setResizable(true);
+		eventColumn.getColumn().setMoveable(true);
+		eventColumn.setLabelProvider(new ColumnLabelProvider() {
+			@Override
+			public String getText(Object element) {
+				if (element instanceof NamedElement) {
+					return ((NamedElement) element).getName();
+				}
+				return super.getText(element);
+			}
+		});
+
+		TableViewerColumn executeColumn = new TableViewerColumn(viewer,
+				SWT.NONE);
+		executeColumn.getColumn().setText("execute event");
+		executeColumn.getColumn().setWidth(120);
+		executeColumn.getColumn().setResizable(true);
+		executeColumn.getColumn().setMoveable(true);
+		executeColumn.setLabelProvider(new ColumnLabelProvider());
+
+	}
+
+	@Override
+	public void setFocus() {
+		viewer.getTable().setFocus();
+	}
+
+	public void setViewerInput(List<Event> events) {
+		viewer.setInput(events);
+		TableItem[] items = viewer.getTable().getItems();
+		for (TableItem tableItem : items) {
+			final TableEditor editor = new TableEditor(viewer.getTable());
+			editor.horizontalAlignment = SWT.LEFT;
+			editor.grabHorizontal = true;
+			editor.grabVertical = true;
+			Button button = new Button(viewer.getTable(), SWT.FLAT);
+			button.setText("raise");
+			button.addSelectionListener(new ButtonListener(tableItem.getText()));
+			editor.setEditor(button, tableItem, 1);
+			controls.add(button);
+		}
+	}
+
+	public void clearViewerInput() {
+		for (Control control : controls) {
+			control.dispose();
+		}
+		viewer.setInput(null);
+	}
+
+	private static final class ButtonListener implements SelectionListener {
+
+		private final String eventName;
+
+		public ButtonListener(String eventName) {
+			this.eventName = eventName;
+		}
+
+		public void widgetSelected(SelectionEvent e) {
+			SGraphSimulationSession activeSession = SGraphSimulationSessionRegistry.INSTANCE
+					.getActiveSession();
+			if (activeSession != null) {
+				activeSession.raiseEvent(eventName);
+			}
+
+		}
+
+		public void widgetDefaultSelected(SelectionEvent e) {
+			// Nothing to do
+		}
+
+	}
+
+}

+ 96 - 0
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/view/EventViewUpdater.java

@@ -0,0 +1,96 @@
+package org.yakindu.sct.ui.simulation.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.PlatformUI;
+import org.yakindu.sct.core.simulation.ISimulationSessionListener;
+import org.yakindu.sct.model.sgraph.Event;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+
+public class EventViewUpdater implements ISimulationSessionListener {
+
+	public List<Event> getViewerInput() {
+		List<Event> events = new ArrayList<Event>();
+		Resource activeEditorResource = ActiveEditorResolver
+				.getActiveEditorResource();
+		TreeIterator<EObject> allContents = activeEditorResource
+				.getAllContents();
+		while (allContents.hasNext()) {
+			EObject next = allContents.next();
+			if (next instanceof Event) {
+				events.add((Event) next);
+			}
+		}
+		return events;
+
+	}
+
+	public void simulationStateChanged(SimulationState oldState,
+			SimulationState newState) {
+		switch (newState) {
+		case STARTED:
+			updateEventView();
+			break;
+		case TERMINATED:
+			clearEventView();
+			break;
+		}
+	}
+
+	protected EventView getEventView() {
+		IViewReference[] viewReferences = PlatformUI.getWorkbench()
+				.getActiveWorkbenchWindow().getActivePage().getViewReferences();
+		for (IViewReference ref : viewReferences) {
+			if (EventView.ID.equals(ref.getId())) {
+				return (EventView) ref.getView(false);
+
+			}
+		}
+		return null;
+	}
+
+	private void clearEventView() {
+		Display.getDefault().asyncExec(new Runnable() {
+
+			public void run() {
+				EventView eventView = getEventView();
+				if (eventView != null) {
+					eventView.clearViewerInput();
+				}
+			}
+		});
+	}
+
+	private void updateEventView() {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				EventView eventView = getEventView();
+				if (eventView != null) {
+					eventView.setViewerInput(getViewerInput());
+				}
+			}
+		});
+
+	}
+
+	public void stateEntered(Vertex vertex) {
+		// Nothing to do
+	}
+
+	public void stateLeft(Vertex vertex) {
+		// Nothing to do
+	}
+
+	public void transitionFired(Transition transition) {
+		// Nothing to do
+	}
+}