浏览代码

- Fixed type inference of typealias on arrays (#1084)

- better log messages during simulation errors
 - type cast for type aliases
Andreas Mülder 8 年之前
父节点
当前提交
ad33e4075e

+ 14 - 8
plugins/org.yakindu.base.expressions/src/org/yakindu/base/expressions/inferrer/ExpressionsTypeInferrer.java

@@ -10,13 +10,13 @@
  */
 package org.yakindu.base.expressions.inferrer;
 
+import static org.yakindu.base.types.typesystem.ITypeSystem.ANY;
 import static org.yakindu.base.types.typesystem.ITypeSystem.BOOLEAN;
 import static org.yakindu.base.types.typesystem.ITypeSystem.INTEGER;
 import static org.yakindu.base.types.typesystem.ITypeSystem.NULL;
 import static org.yakindu.base.types.typesystem.ITypeSystem.REAL;
 import static org.yakindu.base.types.typesystem.ITypeSystem.STRING;
 import static org.yakindu.base.types.typesystem.ITypeSystem.VOID;
-import static org.yakindu.base.types.typesystem.ITypeSystem.ANY;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -54,6 +54,7 @@ import org.yakindu.base.types.EnumerationType;
 import org.yakindu.base.types.Enumerator;
 import org.yakindu.base.types.Operation;
 import org.yakindu.base.types.Parameter;
+import org.yakindu.base.types.ParameterizedType;
 import org.yakindu.base.types.Property;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.TypeAlias;
@@ -291,15 +292,20 @@ public class ExpressionsTypeInferrer extends AbstractTypeSystemInferrer implemen
 	}
 
 	public InferenceResult doInfer(TypeSpecifier specifier) {
-		List<InferenceResult> bindings = new ArrayList<>();
-		EList<TypeSpecifier> arguments = specifier.getTypeArguments();
-		for (TypeSpecifier typeSpecifier : arguments) {
-			InferenceResult binding = inferTypeDispatch(typeSpecifier);
-			if (binding != null) {
-				bindings.add(binding);
+		if (specifier.getType() instanceof ParameterizedType
+				&& ((ParameterizedType) specifier.getType()).getParameter().size() > 0) {
+			List<InferenceResult> bindings = new ArrayList<>();
+			EList<TypeSpecifier> arguments = specifier.getTypeArguments();
+			for (TypeSpecifier typeSpecifier : arguments) {
+				InferenceResult binding = inferTypeDispatch(typeSpecifier);
+				if (binding != null) {
+					bindings.add(binding);
+				}
+				Type type = inferTypeDispatch(specifier.getType()).getType();
+				return InferenceResult.from(type, bindings);
 			}
 		}
-		return InferenceResult.from(inferTypeDispatch(specifier.getType()).getType(), bindings);
+		return inferTypeDispatch(specifier.getType());
 
 	}
 }

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

@@ -40,6 +40,8 @@ import com.google.inject.Inject;
  */
 public abstract class AbstractExecutionFlowSimulationEngine implements ISimulationEngine, IExecutionControl {
 
+	private static final String ERROR_MSG = "An unexpected error ocurred during simulation.";
+
 	public static final int ERROR_DURING_SIMULATION = 765;
 
 	@Inject
@@ -69,16 +71,12 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 		}
 	}
 
-	protected void handleException(Exception e) {
-		if (e instanceof WrappedException) {
-			WrappedException e1 = (WrappedException)e;
-			handleException(e1.getCause().getMessage(), e1.getCause());
-		} else handleException(e.getMessage(), e);
-	}
-	
-	protected void handleException(String message, Throwable t) {
+	protected void handleException(Throwable t) {
+		if (t instanceof WrappedException) {
+			t = ((WrappedException) t).getCause();
+		}
 		Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID, ERROR_DURING_SIMULATION,
-				message, t);
+				ERROR_MSG, t);
 		SimulationCoreActivator.getDefault().getLog().log(errorStatus);
 		IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
 		try {

+ 13 - 9
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/StextStatementInterpreter.xtend

@@ -93,41 +93,45 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 		typeCast(operand, expression.type.originType)
 	}
 
-	def dispatch Object typeCast(Long value, Type type) {
+	def Object cast(Object value, Type type){
+		typeCast(value, type.originType)
+	}
+
+	def protected dispatch Object typeCast(Long value, Type type) {
 		if(type instanceof EnumerationType) return value
 		if(ts.isSuperType(type, ts.getType(GenericTypeSystem.INTEGER))) return value
 		if(ts.isSuperType(type, ts.getType(GenericTypeSystem.REAL))) return Double.valueOf(value)
 		throw new IllegalArgumentException("unknown type " + type.name)
 	}
 
-	def dispatch Object typeCast(Float value, Type type) {
+	def protected dispatch Object typeCast(Float value, Type type) {
 		if(ts.isSuperType(type, ts.getType(GenericTypeSystem.INTEGER))) return value.longValue
 		if(ts.isSuperType(type, ts.getType(GenericTypeSystem.REAL))) return Double.valueOf(value)
 		throw new IllegalArgumentException("Invalid cast from Float to " + type.name)
 	}
 
-	def dispatch Object typeCast(Double value, Type type) {
+	def protected dispatch Object typeCast(Double value, Type type) {
 		if(ts.isSuperType(type, ts.getType(ITypeSystem.INTEGER))) return value.longValue
 		if(ts.isSuperType(type, ts.getType(ITypeSystem.REAL))) return Double.valueOf(value)
 		throw new IllegalArgumentException("Invalid cast from Double to " + type.name)
 	}
 
-	def dispatch Object typeCast(Boolean value, Type type) {
+	def protected dispatch Object typeCast(Boolean value, Type type) {
 		if(ts.isSuperType(type, ts.getType(ITypeSystem.BOOLEAN))) return value
 		throw new IllegalArgumentException("Invalid cast from Boolean to " + type.name)
 	}
 
-	def dispatch Object typeCast(String value, Type type) {
+	def protected dispatch Object typeCast(String value, Type type) {
 		if(ts.isSuperType(type, ts.getType(ITypeSystem.STRING))) return value
 		throw new IllegalArgumentException("Invalid cast from String to " + type.name)
 	}
 
-	def dispatch Object typeCast(Enumerator value, Type type) {
+	def protected dispatch Object typeCast(Enumerator value, Type type) {
 		if(ts.isSuperType(type, value.owningEnumeration)) return value
 		throw new IllegalArgumentException("Invalid cast from Enumerator to " + type.name)
 	}
 
-	def dispatch Object typeCast(Object value, Type type) {
+	def protected dispatch Object typeCast(Object value, Type type) {
 		if(ts.isSame(type, ts.getType(ITypeSystem.ANY))) return value
 		return value
 	}
@@ -139,11 +143,11 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 
 		if (assignment.operator == AssignmentOperator::ASSIGN) {
 			// Strong typing, use the type of the scopeVariable instead of using new runtime type
-			scopeVariable.value = if(result != null) typeCast(result, scopeVariable.type) else null
+			scopeVariable.value = if(result != null) cast(result, scopeVariable.type) else null
 		} else {
 			var operator = AbstractStatementInterpreter::assignFunctionMap.get(assignment.operator.getName())
 			scopeVariable.value = if (result != null)
-				typeCast(evaluate(operator, scopeVariable.getValue, result), scopeVariable.type)
+				cast(evaluate(operator, scopeVariable.getValue, result), scopeVariable.type)
 			else
 				null
 		}