Browse Source

Changed hex literal tests to long

Andreas Mülder 10 years ago
parent
commit
6cd1763d42

+ 6 - 3
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/StextStatementInterpreter.xtend

@@ -106,11 +106,12 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 		if(ts.isRealType(type)) return Double.valueOf(value)
 		throw new IllegalArgumentException
 	}
+
 	def dispatch Object typeCast(Boolean value, Type type) {
 		if(ts.isBooleanType(type)) return value
 		throw new IllegalArgumentException
 	}
-	
+
 	def dispatch Object typeCast(String value, Type type) {
 		if(ts.isStringType(type)) return value
 		throw new IllegalArgumentException
@@ -124,11 +125,13 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 		var scopeVariable = context.resolve(assignment.varRef)
 		var result = assignment.expression.execute
 		if (assignment.operator == AssignmentOperator::ASSIGN) {
+
 			//Strong typing, use the type of the scopeVariable instead of using new runtime type
-			scopeVariable.value = typeCast(result, scopeVariable.type.type)
+			scopeVariable.value = if(result != null) typeCast(result, scopeVariable.type.type) else null
 		} else {
 			var operator = AbstractStatementInterpreter::assignFunctionMap.get(assignment.operator.getName())
-			scopeVariable.value = typeCast(evaluate(operator, scopeVariable.getValue, result),scopeVariable.type.type)
+			scopeVariable.value = if(result != null) typeCast(evaluate(operator, scopeVariable.getValue, result),
+				scopeVariable.type.type) else null
 		}
 		scopeVariable.value
 	}

+ 4 - 4
test-plugins/org.yakindu.sct.simulation.core.sexec.test/src/org/yakindu/sct/model/sexec/interpreter/test/STextInterpreterTest.java

@@ -58,7 +58,7 @@ public class STextInterpreterTest extends AbstractSTextTest {
 	@Test
 	public void testHexVariableAssignment() {
 		executeWithDefaultScope("intVar = 0xFF");
-		assertEquals(0xFF, getIntValue());
+		assertEquals(0xFFL, getIntValue());
 	}
 
 	@Test
@@ -124,20 +124,20 @@ public class STextInterpreterTest extends AbstractSTextTest {
 	@Test
 	public void testBitwiseXor() {
 		executeWithDefaultScope("intVar = 0xF0F0 ^ 0xFF00");
-		assertEquals(0x0FF0, getContext().getVariable("intVar").getValue());
+		assertEquals(0x0FF0L, getContext().getVariable("intVar").getValue());
 
 	}
 
 	@Test
 	public void testBitwiseOr() {
 		executeWithDefaultScope("intVar = 0xF0F0 | 0xFFFF");
-		assertEquals(0xFFFF, getContext().getVariable("intVar").getValue());
+		assertEquals(0xFFFFL, getContext().getVariable("intVar").getValue());
 	}
 
 	@Test
 	public void testBitwiseAnd() {
 		executeWithDefaultScope("intVar = 0xF0F0 & 0xFFFF");
-		assertEquals(0x0F0F0, getContext().getVariable("intVar").getValue());
+		assertEquals(0x0F0F0L, getContext().getVariable("intVar").getValue());
 	}
 
 	@Test