Procházet zdrojové kódy

Added Interpreter functions to handle String literals

Andreas Mülder před 14 roky
rodič
revize
3b6c108508

+ 9 - 0
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/impl/ExecutionFlowInterpreter.xtend

@@ -180,6 +180,9 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 	def isVoid(Type type){
 		return type == null || type.name == "void"
 	}
+	def isString(Type type){
+		return type != null && type.name =="string"
+	}
 // end TODO
 
 	def dispatch addToScope(VariableDefinition variable){
@@ -193,6 +196,9 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 		else if(isReal(variable.type)){
 			executionContext.declareVariable(new ExecutionVariable(fqName,typeof(Float),Float::parseFloat("0.0")))
 		}
+		else if (isString(variable.type)){
+			executionContext.declareVariable(new ExecutionVariable(fqName,typeof(String),""))
+		}
 		null 
 	}  
 	
@@ -210,6 +216,9 @@ class ExecutionFlowInterpreter extends AbstractExecutionFacade implements IExecu
 		else if(isVoid(event.type)){
 				executionContext.declareEvent(new ExecutionEvent(fqName,typeof(Void)))
 		}
+		else if (isString(event.type)){
+			executionContext.declareEvent(new ExecutionEvent(fqName,typeof(String),""))
+		}
 		null 
 	} 
 	

+ 5 - 0
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/stext/StextStatementInterpreter.xtend

@@ -52,6 +52,8 @@ import org.yakindu.sct.model.stext.stext.AssignmentExpression
 import org.yakindu.sct.model.stext.stext.EventRaisingExpression
 import org.yakindu.sct.model.stext.stext.VariableDefinition
 import org.yakindu.sct.model.stext.stext.EventDefinition
+import org.yakindu.sct.model.stext.stext.impl.StringLiteralImpl
+import org.yakindu.sct.model.stext.stext.StringLiteral
 
 /**
  * 
@@ -264,5 +266,8 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 	def dispatch valueLiteral(RealLiteral literal){
 		return literal.value
 	}
+	def dispatch valueLiteral(StringLiteral literal){
+		return literal.value
+	}
 		
 }

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

@@ -226,6 +226,19 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
     return _operator_or;
   }
   
+  public boolean isString(final Type type) {
+    boolean _operator_and = false;
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(type, null);
+    if (!_operator_notEquals) {
+      _operator_and = false;
+    } else {
+      String _name = type.getName();
+      boolean _operator_equals = ObjectExtensions.operator_equals(_name, "string");
+      _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _operator_equals);
+    }
+    return _operator_and;
+  }
+  
   protected Object _addToScope(final VariableDefinition variable) throws NumberFormatException {
     Object _xblockexpression = null;
     {
@@ -250,6 +263,13 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
             float _parseFloat = Float.parseFloat("0.0");
             ExecutionVariable _executionVariable_2 = new ExecutionVariable(fqName, java.lang.Float.class, ((Float)_parseFloat));
             this.executionContext.declareVariable(_executionVariable_2);
+          } else {
+            Type _type_3 = variable.getType();
+            boolean _isString = this.isString(_type_3);
+            if (_isString) {
+              ExecutionVariable _executionVariable_3 = new ExecutionVariable(fqName, java.lang.String.class, "");
+              this.executionContext.declareVariable(_executionVariable_3);
+            }
           }
         }
       }
@@ -287,6 +307,13 @@ public class ExecutionFlowInterpreter extends AbstractExecutionFacade implements
             if (_isVoid) {
               ExecutionEvent _executionEvent_3 = new ExecutionEvent(fqName, java.lang.Void.class);
               this.executionContext.declareEvent(_executionEvent_3);
+            } else {
+              Type _type_4 = event.getType();
+              boolean _isString = this.isString(_type_4);
+              if (_isString) {
+                ExecutionEvent _executionEvent_4 = new ExecutionEvent(fqName, java.lang.String.class, "");
+                this.executionContext.declareEvent(_executionEvent_4);
+              }
             }
           }
         }

+ 8 - 0
plugins/org.yakindu.sct.model.sexec.interpreter/xtend-gen/org/yakindu/sct/model/sexec/interpreter/stext/StextStatementInterpreter.java

@@ -43,6 +43,7 @@ import org.yakindu.sct.model.stext.stext.RealLiteral;
 import org.yakindu.sct.model.stext.stext.RelationalOperator;
 import org.yakindu.sct.model.stext.stext.ShiftExpression;
 import org.yakindu.sct.model.stext.stext.ShiftOperator;
+import org.yakindu.sct.model.stext.stext.StringLiteral;
 import org.yakindu.sct.model.stext.stext.TypedElementReferenceExpression;
 import org.yakindu.sct.model.stext.stext.UnaryOperator;
 import org.yakindu.sct.simulation.core.runtime.ExecutionException;
@@ -465,6 +466,11 @@ public class StextStatementInterpreter extends AbstractStatementInterpreter {
     return _value;
   }
   
+  protected Comparable<? extends Object> _valueLiteral(final StringLiteral literal) {
+    String _value = literal.getValue();
+    return _value;
+  }
+  
   public Object execute(final Statement expression) throws ExecutionException {
     if ((expression instanceof ActiveStateReferenceExpression)) {
       return _execute((ActiveStateReferenceExpression)expression);
@@ -565,6 +571,8 @@ public class StextStatementInterpreter extends AbstractStatementInterpreter {
       return _valueLiteral((IntLiteral)bool);
     } else if ((bool instanceof RealLiteral)) {
       return _valueLiteral((RealLiteral)bool);
+    } else if ((bool instanceof StringLiteral)) {
+      return _valueLiteral((StringLiteral)bool);
     } else {
       throw new IllegalArgumentException("Unhandled parameter types: " +
         java.util.Arrays.<Object>asList(bool).toString());