Browse Source

interpreter can handle operations now

terfloth@itemis.de 13 years ago
parent
commit
c7a3fe657d

+ 34 - 8
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/impl/ExecutionFlowInterpreter.xtend

@@ -46,6 +46,8 @@ import org.yakindu.sct.simulation.core.runtime.IExecutionContext
 import org.yakindu.sct.simulation.core.runtime.IExecutionContextListener
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable
+import org.yakindu.base.types.Type
+import org.yakindu.sct.model.stext.stext.OperationDefinition
 
 /**
  * 
@@ -137,7 +139,7 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 
 
 
-	def dispatch addToScope(VariableDefinition variable){
+	def dispatch void addToScope(VariableDefinition variable){
 		var fqName = provider.qualifiedName(variable).toString
 		if(variable.type.^boolean){
 			executionContext.declareVariable(new ExecutionVariable(fqName ,typeof(Boolean),false))
@@ -151,10 +153,9 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 		else if (variable.type.string){
 			executionContext.declareVariable(new ExecutionVariable(fqName,typeof(String),""))
 		}
-		null 
 	}  
 	
-	def dispatch addToScope(EventDefinition event){
+	def dispatch void addToScope(EventDefinition event){
 		var fqName = provider.qualifiedName(event).toString
 		if(event.type.^boolean){
 				executionContext.declareEvent(new ExecutionEvent(fqName,typeof(Boolean),null))
@@ -171,15 +172,40 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 		else if (event.type.string){
 			executionContext.declareEvent(new ExecutionEvent(fqName,typeof(String),""))
 		}
-		null 
-	} 
+		 
+	}
 	
-	def dispatch addToScope(TimeEvent event){
-		executionContext.declareEvent(new ExecutionEvent(event.name, typeof(Long)))
-		null 
+	
+	def dispatch void addToScope(OperationDefinition op){
+		var fqName = provider.qualifiedName(op).toString
+		var type = op.type.mappedType
+		
+		executionContext.declareVariable(new ExecutionVariable(fqName, type, type.defaultValue))
 	}
 	
+	def Class<?> mappedType(Type it) {
+		if(it.^boolean)		{ typeof(Boolean) } 
+		else if(it.integer)	{ typeof(Integer) }
+		else if(it.real)	{ typeof(Float) }
+		else if(it.^void)	{ typeof(Void)	}
+		else if(it.string)	{ typeof(String) }
+		else null 
+	} 
+	
+	def Object defaultValue(Class<?> type) {
+		switch (type) {
+			case typeof(Boolean) : true
+			case typeof(Integer) : 0
+			case typeof(Float) : 0.0
+			case typeof(Void) : null
+			case typeof(String) : ""
+		}
+	}
 	
+	def dispatch void addToScope(TimeEvent event){
+		executionContext.declareEvent(new ExecutionEvent(event.name, typeof(Long))) 
+	}
+
 	override enter() {
 		for(step : flow.enterSequence.steps){
 			step.execute

+ 149 - 72
plugins/org.yakindu.sct.model.sexec.interpreter/xtend-gen/org/yakindu/sct/model/sexec/interpreter/impl/ExecutionFlowInterpreter.java

@@ -44,6 +44,7 @@ import org.yakindu.sct.model.stext.naming.StextNameProvider;
 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.IExecutionContext;
@@ -162,97 +163,167 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
     this.execute(this.erc);
   }
   
-  protected Object _addToScope(final VariableDefinition variable) {
-    Object _xblockexpression = null;
-    {
-      QualifiedName _qualifiedName = this.provider.qualifiedName(variable);
-      String fqName = _qualifiedName.toString();
-      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);
+  protected void _addToScope(final VariableDefinition variable) {
+    QualifiedName _qualifiedName = this.provider.qualifiedName(variable);
+    String fqName = _qualifiedName.toString();
+    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);
+    } 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);
+      } 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);
+        } 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);
+          }
+        }
+      }
+    }
+  }
+  
+  protected void _addToScope(final EventDefinition event) {
+    QualifiedName _qualifiedName = this.provider.qualifiedName(event);
+    String fqName = _qualifiedName.toString();
+    Type _type = event.getType();
+    boolean _isBoolean = this.ts.isBoolean(_type);
+    if (_isBoolean) {
+      ExecutionEvent _executionEvent = new ExecutionEvent(fqName, Boolean.class, null);
+      this.executionContext.declareEvent(_executionEvent);
+    } else {
+      Type _type_1 = event.getType();
+      boolean _isInteger = this.ts.isInteger(_type_1);
+      if (_isInteger) {
+        ExecutionEvent _executionEvent_1 = new ExecutionEvent(fqName, Integer.class, null);
+        this.executionContext.declareEvent(_executionEvent_1);
       } 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);
+        Type _type_2 = event.getType();
+        boolean _isReal = this.ts.isReal(_type_2);
+        if (_isReal) {
+          ExecutionEvent _executionEvent_2 = new ExecutionEvent(fqName, Float.class, null);
+          this.executionContext.declareEvent(_executionEvent_2);
         } 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);
+          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);
           } else {
-            Type _type_3 = variable.getType();
-            boolean _isString = this.ts.isString(_type_3);
+            Type _type_4 = event.getType();
+            boolean _isString = this.ts.isString(_type_4);
             if (_isString) {
-              ExecutionVariable _executionVariable_3 = new ExecutionVariable(fqName, String.class, "");
-              this.executionContext.declareVariable(_executionVariable_3);
+              ExecutionEvent _executionEvent_4 = new ExecutionEvent(fqName, String.class, "");
+              this.executionContext.declareEvent(_executionEvent_4);
             }
           }
         }
       }
-      _xblockexpression = (null);
     }
-    return _xblockexpression;
   }
   
-  protected Object _addToScope(final EventDefinition event) {
-    Object _xblockexpression = null;
-    {
-      QualifiedName _qualifiedName = this.provider.qualifiedName(event);
-      String fqName = _qualifiedName.toString();
-      Type _type = event.getType();
-      boolean _isBoolean = this.ts.isBoolean(_type);
-      if (_isBoolean) {
-        ExecutionEvent _executionEvent = new ExecutionEvent(fqName, Boolean.class, null);
-        this.executionContext.declareEvent(_executionEvent);
+  protected void _addToScope(final OperationDefinition op) {
+    QualifiedName _qualifiedName = this.provider.qualifiedName(op);
+    String fqName = _qualifiedName.toString();
+    Type _type = op.getType();
+    Class<? extends Object> type = this.mappedType(_type);
+    Object _defaultValue = this.defaultValue(type);
+    ExecutionVariable _executionVariable = new ExecutionVariable(fqName, type, _defaultValue);
+    this.executionContext.declareVariable(_executionVariable);
+  }
+  
+  public Class<? extends Object> mappedType(final Type it) {
+    Class<? extends Object> _xifexpression = null;
+    boolean _isBoolean = this.ts.isBoolean(it);
+    if (_isBoolean) {
+      _xifexpression = Boolean.class;
+    } else {
+      Class<? extends Object> _xifexpression_1 = null;
+      boolean _isInteger = this.ts.isInteger(it);
+      if (_isInteger) {
+        _xifexpression_1 = Integer.class;
       } else {
-        Type _type_1 = event.getType();
-        boolean _isInteger = this.ts.isInteger(_type_1);
-        if (_isInteger) {
-          ExecutionEvent _executionEvent_1 = new ExecutionEvent(fqName, Integer.class, null);
-          this.executionContext.declareEvent(_executionEvent_1);
+        Class<? extends Object> _xifexpression_2 = null;
+        boolean _isReal = this.ts.isReal(it);
+        if (_isReal) {
+          _xifexpression_2 = Float.class;
         } else {
-          Type _type_2 = event.getType();
-          boolean _isReal = this.ts.isReal(_type_2);
-          if (_isReal) {
-            ExecutionEvent _executionEvent_2 = new ExecutionEvent(fqName, Float.class, null);
-            this.executionContext.declareEvent(_executionEvent_2);
+          Class<? extends Object> _xifexpression_3 = null;
+          boolean _isVoid = this.ts.isVoid(it);
+          if (_isVoid) {
+            _xifexpression_3 = Void.class;
           } 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);
+            Class<String> _xifexpression_4 = null;
+            boolean _isString = this.ts.isString(it);
+            if (_isString) {
+              _xifexpression_4 = String.class;
             } 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);
-              }
+              _xifexpression_4 = null;
             }
+            _xifexpression_3 = _xifexpression_4;
           }
+          _xifexpression_2 = _xifexpression_3;
         }
+        _xifexpression_1 = _xifexpression_2;
       }
-      _xblockexpression = (null);
+      _xifexpression = _xifexpression_1;
     }
-    return _xblockexpression;
+    return _xifexpression;
   }
   
-  protected Object _addToScope(final TimeEvent event) {
-    Object _xblockexpression = null;
-    {
-      String _name = event.getName();
-      ExecutionEvent _executionEvent = new ExecutionEvent(_name, Long.class);
-      this.executionContext.declareEvent(_executionEvent);
-      _xblockexpression = (null);
+  public Object defaultValue(final Class<? extends Object> type) {
+    Object _switchResult = null;
+    boolean _matched = false;
+    if (!_matched) {
+      if (Objects.equal(type,Boolean.class)) {
+        _matched=true;
+        _switchResult = true;
+      }
     }
-    return _xblockexpression;
+    if (!_matched) {
+      if (Objects.equal(type,Integer.class)) {
+        _matched=true;
+        _switchResult = 0;
+      }
+    }
+    if (!_matched) {
+      if (Objects.equal(type,Float.class)) {
+        _matched=true;
+        _switchResult = 0.0;
+      }
+    }
+    if (!_matched) {
+      if (Objects.equal(type,Void.class)) {
+        _matched=true;
+        _switchResult = null;
+      }
+    }
+    if (!_matched) {
+      if (Objects.equal(type,String.class)) {
+        _matched=true;
+        _switchResult = "";
+      }
+    }
+    return ((Comparable<Object>)_switchResult);
+  }
+  
+  protected void _addToScope(final TimeEvent event) {
+    String _name = event.getName();
+    ExecutionEvent _executionEvent = new ExecutionEvent(_name, Long.class);
+    this.executionContext.declareEvent(_executionEvent);
   }
   
   public void enter() {
@@ -492,13 +563,19 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
     }
   }
   
-  public Object addToScope(final Declaration event) {
+  public void addToScope(final Declaration event) {
     if (event instanceof TimeEvent) {
-      return _addToScope((TimeEvent)event);
+      _addToScope((TimeEvent)event);
+      return;
     } else if (event instanceof EventDefinition) {
-      return _addToScope((EventDefinition)event);
+      _addToScope((EventDefinition)event);
+      return;
+    } else if (event instanceof OperationDefinition) {
+      _addToScope((OperationDefinition)event);
+      return;
     } else if (event instanceof VariableDefinition) {
-      return _addToScope((VariableDefinition)event);
+      _addToScope((VariableDefinition)event);
+      return;
     } else {
       throw new IllegalArgumentException("Unhandled parameter types: " +
         Arrays.<Object>asList(event).toString());

+ 13 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/impl/ExecutionOperation.java

@@ -0,0 +1,13 @@
+package org.yakindu.sct.simulation.core.runtime.impl;
+
+public class ExecutionOperation extends AbstractSlot {
+
+	protected Class<?>[] paramTypes;
+	
+	public ExecutionOperation(String name, Object value, Class<?> type, Class<?>... paramTypes) {
+		super(name, type, value);
+		this.paramTypes = paramTypes;
+	}
+
+
+}