Explorar o código

Merge pull request #294 from Yakindu/issue-291

#291: Ensure effective boolean expression is used in checks.
Alexander Nyßen %!s(int64=9) %!d(string=hai) anos
pai
achega
7b92215e43

+ 15 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/ExpressionCode.xtend

@@ -151,4 +151,19 @@ class ExpressionCode {
 	
 	def dispatch CharSequence code(TypeCastExpression it) '''((«type.getTargetLanguageName») «operand.code»)'''
 
+	
+	// ensure we obtain an expression of type sc_boolean
+	
+	def dispatch CharSequence sc_boolean_code(Expression it) '''«it.code»'''
+	
+	def dispatch CharSequence sc_boolean_code(LogicalOrExpression it) '''(«it.code») ? bool_true : bool_false'''
+	
+	def dispatch CharSequence sc_boolean_code(LogicalAndExpression it) '''(«it.code») ? bool_true : bool_false'''
+	
+	def dispatch CharSequence sc_boolean_code(LogicalNotExpression it) '''(«it.code») ? bool_true : bool_false'''
+	
+	def dispatch CharSequence sc_boolean_code(LogicalRelationExpression it) '''(«it.code») ? bool_true : bool_false'''
+	
+	
+
 }

+ 2 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend

@@ -121,14 +121,14 @@ class FlowCode {
 	'''	
 
 	def dispatch CharSequence code(Check it) 
-		'''«IF condition != null»«condition.code»«ELSE»bool_true«ENDIF»'''
+		'''«IF condition != null»«condition.sc_boolean_code»«ELSE»bool_true«ENDIF»'''
 	
 	def dispatch CharSequence code(CheckRef it) 
 		'''«IF check != null»«check.shortName»(«scHandle»)«ELSE»bool_true«ENDIF»'''
 
 	def dispatch CharSequence code(If it) '''
 		«stepComment»
-		if («check.code») { 
+		if («check.code» == bool_true) { 
 			«thenStep.code»
 		} «IF (elseStep != null)» else {
 			«elseStep.code»

+ 11 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/FlowCode.xtend

@@ -24,6 +24,7 @@ import org.yakindu.sct.model.sexec.Sequence
 import org.yakindu.sct.model.sexec.StateSwitch
 import org.yakindu.sct.model.sexec.UnscheduleTimeEvent
 import org.yakindu.sct.model.sexec.naming.INamingService
+import org.yakindu.sct.model.sexec.If
 
 class FlowCode extends org.yakindu.sct.generator.c.FlowCode {
 	
@@ -91,6 +92,16 @@ class FlowCode extends org.yakindu.sct.generator.c.FlowCode {
 	
 	override dispatch CharSequence code(CheckRef it) 
 		'''«IF check != null»«check.shortName»()«ELSE»true«ENDIF»'''
+		
+    override dispatch CharSequence code(If it) '''
+		«stepComment»
+		if («check.code») { 
+			«thenStep.code»
+		} «IF (elseStep != null)» else {
+			«elseStep.code»
+		}
+		«ENDIF»
+	'''
 	
 	override dispatch CharSequence code(EnterState it) '''
 		stateConfVector[«state.stateVector.offset»] = «state.shortName»;