|
|
@@ -1,14 +1,21 @@
|
|
|
package org.yakindu.sct.model.sexec.interpreter.impl;
|
|
|
|
|
|
import com.google.common.base.Objects;
|
|
|
+import com.google.common.collect.Iterables;
|
|
|
import com.google.inject.Inject;
|
|
|
import com.google.inject.name.Named;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import org.eclipse.emf.common.util.EList;
|
|
|
import org.eclipse.xtext.naming.QualifiedName;
|
|
|
import org.eclipse.xtext.xbase.lib.Conversions;
|
|
|
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
|
|
import org.eclipse.xtext.xbase.lib.InputOutput;
|
|
|
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
|
|
+import org.eclipse.xtext.xbase.lib.ListExtensions;
|
|
|
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
|
|
import org.yakindu.base.types.ITypeSystemAccess;
|
|
|
import org.yakindu.base.types.Type;
|
|
|
import org.yakindu.sct.model.sexec.Call;
|
|
|
@@ -38,16 +45,20 @@ import org.yakindu.sct.model.sexec.interpreter.IExecutionFlowInterpreter;
|
|
|
import org.yakindu.sct.model.sexec.interpreter.IStatementInterpreter;
|
|
|
import org.yakindu.sct.model.sexec.interpreter.ITimingService;
|
|
|
import org.yakindu.sct.model.sgraph.Declaration;
|
|
|
+import org.yakindu.sct.model.sgraph.Event;
|
|
|
import org.yakindu.sct.model.sgraph.Scope;
|
|
|
import org.yakindu.sct.model.sgraph.Statement;
|
|
|
import org.yakindu.sct.model.stext.naming.StextNameProvider;
|
|
|
+import org.yakindu.sct.model.stext.stext.Direction;
|
|
|
import org.yakindu.sct.model.stext.stext.EventDefinition;
|
|
|
import org.yakindu.sct.model.stext.stext.InterfaceScope;
|
|
|
import org.yakindu.sct.model.stext.stext.InternalScope;
|
|
|
import org.yakindu.sct.model.stext.stext.OperationDefinition;
|
|
|
import org.yakindu.sct.model.stext.stext.VariableDefinition;
|
|
|
import org.yakindu.sct.simulation.core.runtime.AbstractExecutionFacade;
|
|
|
+import org.yakindu.sct.simulation.core.runtime.IEventSlot;
|
|
|
import org.yakindu.sct.simulation.core.runtime.IExecutionContext;
|
|
|
+import org.yakindu.sct.simulation.core.runtime.ISlot;
|
|
|
import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
|
|
|
import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable;
|
|
|
|
|
|
@@ -77,6 +88,16 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
|
|
|
private ExecutionFlow flow;
|
|
|
|
|
|
+ private List<EventDefinition> inEvents;
|
|
|
+
|
|
|
+ private List<EventDefinition> outEvents;
|
|
|
+
|
|
|
+ private List<EventDefinition> localEvents;
|
|
|
+
|
|
|
+ private List<TimeEvent> timeEvents;
|
|
|
+
|
|
|
+ private Map<Declaration,ISlot> slotMap;
|
|
|
+
|
|
|
private int nextSVIdx;
|
|
|
|
|
|
private TraceBeginRunCycle brc;
|
|
|
@@ -85,6 +106,8 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
|
|
|
public void initialize(final ExecutionFlow flow) {
|
|
|
this.flow = flow;
|
|
|
+ HashMap<Declaration,ISlot> _hashMap = new HashMap<Declaration,ISlot>();
|
|
|
+ this.slotMap = _hashMap;
|
|
|
EList<Scope> _scopes = flow.getScopes();
|
|
|
for (final Scope scope : _scopes) {
|
|
|
this.declareContents(scope);
|
|
|
@@ -98,6 +121,78 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
this.brc = _createTraceBeginRunCycle;
|
|
|
TraceEndRunCycle _createTraceEndRunCycle = SexecFactory.eINSTANCE.createTraceEndRunCycle();
|
|
|
this.erc = _createTraceEndRunCycle;
|
|
|
+ EList<Scope> _scopes_1 = flow.getScopes();
|
|
|
+ final Function1<Scope,Iterable<EventDefinition>> _function = new Function1<Scope,Iterable<EventDefinition>>() {
|
|
|
+ public Iterable<EventDefinition> apply(final Scope s) {
|
|
|
+ EList<Declaration> _declarations = s.getDeclarations();
|
|
|
+ Iterable<EventDefinition> _filter = Iterables.<EventDefinition>filter(_declarations, EventDefinition.class);
|
|
|
+ final Function1<EventDefinition,Boolean> _function = new Function1<EventDefinition,Boolean>() {
|
|
|
+ public Boolean apply(final EventDefinition e) {
|
|
|
+ Direction _direction = e.getDirection();
|
|
|
+ boolean _equals = Objects.equal(_direction, Direction.IN);
|
|
|
+ return Boolean.valueOf(_equals);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Iterable<EventDefinition> _filter_1 = IterableExtensions.<EventDefinition>filter(_filter, _function);
|
|
|
+ return _filter_1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<Iterable<EventDefinition>> _map = ListExtensions.<Scope, Iterable<EventDefinition>>map(_scopes_1, _function);
|
|
|
+ Iterable<EventDefinition> _flatten = Iterables.<EventDefinition>concat(_map);
|
|
|
+ List<EventDefinition> _list = IterableExtensions.<EventDefinition>toList(_flatten);
|
|
|
+ this.inEvents = _list;
|
|
|
+ EList<Scope> _scopes_2 = flow.getScopes();
|
|
|
+ final Function1<Scope,Iterable<EventDefinition>> _function_1 = new Function1<Scope,Iterable<EventDefinition>>() {
|
|
|
+ public Iterable<EventDefinition> apply(final Scope s) {
|
|
|
+ EList<Declaration> _declarations = s.getDeclarations();
|
|
|
+ Iterable<EventDefinition> _filter = Iterables.<EventDefinition>filter(_declarations, EventDefinition.class);
|
|
|
+ final Function1<EventDefinition,Boolean> _function = new Function1<EventDefinition,Boolean>() {
|
|
|
+ public Boolean apply(final EventDefinition e) {
|
|
|
+ Direction _direction = e.getDirection();
|
|
|
+ boolean _equals = Objects.equal(_direction, Direction.OUT);
|
|
|
+ return Boolean.valueOf(_equals);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Iterable<EventDefinition> _filter_1 = IterableExtensions.<EventDefinition>filter(_filter, _function);
|
|
|
+ return _filter_1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<Iterable<EventDefinition>> _map_1 = ListExtensions.<Scope, Iterable<EventDefinition>>map(_scopes_2, _function_1);
|
|
|
+ Iterable<EventDefinition> _flatten_1 = Iterables.<EventDefinition>concat(_map_1);
|
|
|
+ List<EventDefinition> _list_1 = IterableExtensions.<EventDefinition>toList(_flatten_1);
|
|
|
+ this.outEvents = _list_1;
|
|
|
+ EList<Scope> _scopes_3 = flow.getScopes();
|
|
|
+ final Function1<Scope,Iterable<EventDefinition>> _function_2 = new Function1<Scope,Iterable<EventDefinition>>() {
|
|
|
+ public Iterable<EventDefinition> apply(final Scope s) {
|
|
|
+ EList<Declaration> _declarations = s.getDeclarations();
|
|
|
+ Iterable<EventDefinition> _filter = Iterables.<EventDefinition>filter(_declarations, EventDefinition.class);
|
|
|
+ final Function1<EventDefinition,Boolean> _function = new Function1<EventDefinition,Boolean>() {
|
|
|
+ public Boolean apply(final EventDefinition e) {
|
|
|
+ Direction _direction = e.getDirection();
|
|
|
+ boolean _equals = Objects.equal(_direction, Direction.LOCAL);
|
|
|
+ return Boolean.valueOf(_equals);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ Iterable<EventDefinition> _filter_1 = IterableExtensions.<EventDefinition>filter(_filter, _function);
|
|
|
+ return _filter_1;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<Iterable<EventDefinition>> _map_2 = ListExtensions.<Scope, Iterable<EventDefinition>>map(_scopes_3, _function_2);
|
|
|
+ Iterable<EventDefinition> _flatten_2 = Iterables.<EventDefinition>concat(_map_2);
|
|
|
+ List<EventDefinition> _list_2 = IterableExtensions.<EventDefinition>toList(_flatten_2);
|
|
|
+ this.localEvents = _list_2;
|
|
|
+ EList<Scope> _scopes_4 = flow.getScopes();
|
|
|
+ final Function1<Scope,Iterable<TimeEvent>> _function_3 = new Function1<Scope,Iterable<TimeEvent>>() {
|
|
|
+ public Iterable<TimeEvent> apply(final Scope s) {
|
|
|
+ EList<Declaration> _declarations = s.getDeclarations();
|
|
|
+ Iterable<TimeEvent> _filter = Iterables.<TimeEvent>filter(_declarations, TimeEvent.class);
|
|
|
+ return _filter;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<Iterable<TimeEvent>> _map_3 = ListExtensions.<Scope, Iterable<TimeEvent>>map(_scopes_4, _function_3);
|
|
|
+ Iterable<TimeEvent> _flatten_3 = Iterables.<TimeEvent>concat(_map_3);
|
|
|
+ List<TimeEvent> _list_3 = IterableExtensions.<TimeEvent>toList(_flatten_3);
|
|
|
+ this.timeEvents = _list_3;
|
|
|
Sequence _initSequence = flow.getInitSequence();
|
|
|
this.execute(_initSequence);
|
|
|
}
|
|
|
@@ -135,6 +230,7 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
this.executionContext.flush();
|
|
|
this.nextSVIdx = 0;
|
|
|
this.execute(this.brc);
|
|
|
+ this.clearOutEvents();
|
|
|
ExecutionState[] _stateConfiguration = this.executionContext.getStateConfiguration();
|
|
|
int _size = ((List<ExecutionState>)Conversions.doWrapArray(_stateConfiguration)).size();
|
|
|
boolean _lessThan = (this.nextSVIdx < _size);
|
|
|
@@ -156,81 +252,120 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
boolean _lessThan_1 = (this.nextSVIdx < _size_1);
|
|
|
_while = _lessThan_1;
|
|
|
}
|
|
|
- this.executionContext.resetRaisedEvents();
|
|
|
+ this.clearEvents();
|
|
|
this.execute(this.erc);
|
|
|
}
|
|
|
|
|
|
+ public void clearOutEvents() {
|
|
|
+ final Procedure1<EventDefinition> _function = new Procedure1<EventDefinition>() {
|
|
|
+ public void apply(final EventDefinition e) {
|
|
|
+ ExecutionFlowInterpreter.this.unraise(e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ IterableExtensions.<EventDefinition>forEach(this.outEvents, _function);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clearEvents() {
|
|
|
+ final Procedure1<EventDefinition> _function = new Procedure1<EventDefinition>() {
|
|
|
+ public void apply(final EventDefinition e) {
|
|
|
+ ExecutionFlowInterpreter.this.unraise(e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ IterableExtensions.<EventDefinition>forEach(this.inEvents, _function);
|
|
|
+ final Procedure1<EventDefinition> _function_1 = new Procedure1<EventDefinition>() {
|
|
|
+ public void apply(final EventDefinition e) {
|
|
|
+ ExecutionFlowInterpreter.this.unraise(e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ IterableExtensions.<EventDefinition>forEach(this.localEvents, _function_1);
|
|
|
+ final Procedure1<TimeEvent> _function_2 = new Procedure1<TimeEvent>() {
|
|
|
+ public void apply(final TimeEvent e) {
|
|
|
+ ExecutionFlowInterpreter.this.unraise(e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ IterableExtensions.<TimeEvent>forEach(this.timeEvents, _function_2);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void unraise(final Event it) {
|
|
|
+ ISlot _get = this.slotMap.get(it);
|
|
|
+ ((IEventSlot) _get).unraise();
|
|
|
+ }
|
|
|
+
|
|
|
protected void _addToScope(final VariableDefinition variable) {
|
|
|
QualifiedName _qualifiedName = this.provider.qualifiedName(variable);
|
|
|
String fqName = _qualifiedName.toString();
|
|
|
+ ExecutionVariable varSlot = null;
|
|
|
Type _type = variable.getType();
|
|
|
boolean _isBoolean = this.ts.isBoolean(_type);
|
|
|
if (_isBoolean) {
|
|
|
ExecutionVariable _executionVariable = new ExecutionVariable(fqName, Boolean.class, Boolean.valueOf(false));
|
|
|
- this.executionContext.declareVariable(_executionVariable);
|
|
|
+ varSlot = _executionVariable;
|
|
|
} else {
|
|
|
Type _type_1 = variable.getType();
|
|
|
boolean _isInteger = this.ts.isInteger(_type_1);
|
|
|
if (_isInteger) {
|
|
|
ExecutionVariable _executionVariable_1 = new ExecutionVariable(fqName, Integer.class, Integer.valueOf(0));
|
|
|
- this.executionContext.declareVariable(_executionVariable_1);
|
|
|
+ varSlot = _executionVariable_1;
|
|
|
} else {
|
|
|
Type _type_2 = variable.getType();
|
|
|
boolean _isReal = this.ts.isReal(_type_2);
|
|
|
if (_isReal) {
|
|
|
- float _parseFloat = Float.parseFloat("0.0");
|
|
|
- ExecutionVariable _executionVariable_2 = new ExecutionVariable(fqName, Float.class, Float.valueOf(_parseFloat));
|
|
|
- this.executionContext.declareVariable(_executionVariable_2);
|
|
|
+ ExecutionVariable _executionVariable_2 = new ExecutionVariable(fqName, Float.class, Float.valueOf(0.0f));
|
|
|
+ varSlot = _executionVariable_2;
|
|
|
} else {
|
|
|
Type _type_3 = variable.getType();
|
|
|
boolean _isString = this.ts.isString(_type_3);
|
|
|
if (_isString) {
|
|
|
ExecutionVariable _executionVariable_3 = new ExecutionVariable(fqName, String.class, "");
|
|
|
- this.executionContext.declareVariable(_executionVariable_3);
|
|
|
+ varSlot = _executionVariable_3;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ this.executionContext.declareVariable(varSlot);
|
|
|
+ this.slotMap.put(variable, varSlot);
|
|
|
}
|
|
|
|
|
|
protected void _addToScope(final EventDefinition event) {
|
|
|
QualifiedName _qualifiedName = this.provider.qualifiedName(event);
|
|
|
String fqName = _qualifiedName.toString();
|
|
|
+ ExecutionEvent eventSlot = null;
|
|
|
Type _type = event.getType();
|
|
|
boolean _isBoolean = this.ts.isBoolean(_type);
|
|
|
if (_isBoolean) {
|
|
|
ExecutionEvent _executionEvent = new ExecutionEvent(fqName, Boolean.class, Boolean.valueOf(false));
|
|
|
- this.executionContext.declareEvent(_executionEvent);
|
|
|
+ eventSlot = _executionEvent;
|
|
|
} else {
|
|
|
Type _type_1 = event.getType();
|
|
|
boolean _isInteger = this.ts.isInteger(_type_1);
|
|
|
if (_isInteger) {
|
|
|
ExecutionEvent _executionEvent_1 = new ExecutionEvent(fqName, Integer.class, Integer.valueOf(0));
|
|
|
- this.executionContext.declareEvent(_executionEvent_1);
|
|
|
+ eventSlot = _executionEvent_1;
|
|
|
} else {
|
|
|
Type _type_2 = event.getType();
|
|
|
boolean _isReal = this.ts.isReal(_type_2);
|
|
|
if (_isReal) {
|
|
|
- float _parseFloat = Float.parseFloat("0.0");
|
|
|
- ExecutionEvent _executionEvent_2 = new ExecutionEvent(fqName, Float.class, Float.valueOf(_parseFloat));
|
|
|
- this.executionContext.declareEvent(_executionEvent_2);
|
|
|
+ ExecutionEvent _executionEvent_2 = new ExecutionEvent(fqName, Float.class, Float.valueOf(0.0f));
|
|
|
+ eventSlot = _executionEvent_2;
|
|
|
} else {
|
|
|
Type _type_3 = event.getType();
|
|
|
boolean _isVoid = this.ts.isVoid(_type_3);
|
|
|
if (_isVoid) {
|
|
|
ExecutionEvent _executionEvent_3 = new ExecutionEvent(fqName, Void.class);
|
|
|
- this.executionContext.declareEvent(_executionEvent_3);
|
|
|
+ eventSlot = _executionEvent_3;
|
|
|
} else {
|
|
|
Type _type_4 = event.getType();
|
|
|
boolean _isString = this.ts.isString(_type_4);
|
|
|
if (_isString) {
|
|
|
ExecutionEvent _executionEvent_4 = new ExecutionEvent(fqName, String.class, "");
|
|
|
- this.executionContext.declareEvent(_executionEvent_4);
|
|
|
+ eventSlot = _executionEvent_4;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ this.executionContext.declareEvent(eventSlot);
|
|
|
+ this.slotMap.put(event, eventSlot);
|
|
|
}
|
|
|
|
|
|
protected void _addToScope(final OperationDefinition op) {
|
|
|
@@ -240,7 +375,9 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
Class<? extends Object> type = this.mappedType(_type);
|
|
|
Object _defaultValue = this.defaultValue(type);
|
|
|
ExecutionVariable _executionVariable = new ExecutionVariable(fqName, type, _defaultValue);
|
|
|
- this.executionContext.declareVariable(_executionVariable);
|
|
|
+ final ExecutionVariable opSlot = _executionVariable;
|
|
|
+ this.executionContext.declareVariable(opSlot);
|
|
|
+ this.slotMap.put(op, opSlot);
|
|
|
}
|
|
|
|
|
|
public Class<? extends Object> mappedType(final Type it) {
|
|
|
@@ -321,7 +458,9 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
|
|
|
protected void _addToScope(final TimeEvent event) {
|
|
|
String _name = event.getName();
|
|
|
ExecutionEvent _executionEvent = new ExecutionEvent(_name, Long.class);
|
|
|
- this.executionContext.declareEvent(_executionEvent);
|
|
|
+ final ExecutionEvent eventSlot = _executionEvent;
|
|
|
+ this.executionContext.declareEvent(eventSlot);
|
|
|
+ this.slotMap.put(event, eventSlot);
|
|
|
}
|
|
|
|
|
|
public void enter() {
|