Browse Source

fixed bugs in canonical generation: step size should have an explicit type, and ctrl rules block of single inner fmu should not use min.

Claudio Gomes 2 years ago
parent
commit
c74a5d00a7

+ 18 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.canonical/src/be/uantwerpen/ansymo/semanticadaptation/cg/canonical/SemanticAdaptationCanonicalGenerator.xtend

@@ -411,19 +411,28 @@ class SemanticAdaptationCanonicalGenerator {
 			throw new Exception("Does not make sense. At least one inner FMU is expected.")
 		}
 		
-		val minExpression = SemanticAdaptationFactory.eINSTANCE.createMin()
+		var Expression returnExpression = null
 		
-		Log.println("Creating min(...) expression with the following arguments:")
-		
-		for(varDecl : stepVariables){
+		if (stepVariables.size == 1){
 			val varRef = SemanticAdaptationFactory.eINSTANCE.createVariable()
-			varRef.ref = varDecl
-			minExpression.args.add(varRef)
-			Log.println(varDecl.name)
+			varRef.ref = stepVariables.first
+			returnExpression = varRef
+			Log.println("Single inner fmu: return " + stepVariables.first.name)
+		} else {
+			Log.println("Creating min(...) expression with the following arguments:")
+			
+			val minExpression = SemanticAdaptationFactory.eINSTANCE.createMin()
+			for(varDecl : stepVariables){
+				val varRef = SemanticAdaptationFactory.eINSTANCE.createVariable()
+				varRef.ref = varDecl
+				minExpression.args.add(varRef)
+				Log.println(varDecl.name)
+			}
+			returnExpression = minExpression
 		}
 		
 		rule.returnstatement = SemanticAdaptationFactory.eINSTANCE.createReturnStatement()
-		rule.returnstatement.expr = minExpression
+		rule.returnstatement.expr = returnExpression
 		
 		Log.pop("appendReturnCosimStep")
 	}
@@ -441,6 +450,7 @@ class SemanticAdaptationCanonicalGenerator {
 		val step_var = SemanticAdaptationFactory.eINSTANCE.createSingleVarDeclaration()		
 		step_var.name = "H_" + fmu.name
 		step_var.expr = doStep
+		step_var.type = "Real"
 		
 		val step_decl = SemanticAdaptationFactory.eINSTANCE.createDeclaration()
 		step_decl.declarations.add(step_var)

+ 6 - 16
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -163,6 +163,7 @@ class CppGenerator {
 			var inVars = if(inRuleBlock !== null) compileRuleBlockVars(inRuleBlock.globalInVars, params);
 			var outVars = if(outRuleBlock !== null) compileRuleBlockVars(outRuleBlock.globalOutVars, params);
 			val crtlVars = if(crtlRuleBlock !== null) compileRuleBlockVars(crtlRuleBlock.globalCtrlVars, params);
+			
 			/*
 			 * Support for source dependency: output ports tau <- loop_sa.tau
 			 * Only carried out for outVars.
@@ -231,23 +232,12 @@ class CppGenerator {
 
 				// Compile the Control Rules. These might use the out vars, so pass these along.
 				val crtlRules = if(adap.control !== null) adap.control else null;
-	  
-																						 
-				val crtlRuleResult = compileControlRuleBlock(crtlRules, adapClassName, adapInteralRefName,
 																						 
-				  
-				  
-			
-							
-					mappedScalarVariables, SASVs, params, if(inVars !== null) inVars.value else null,
-											 
-					if(outVars !== null) outVars.value else null, if(crtlVars !== null) crtlVars.value else null);
-				 
-					  
-													 
-													  
-	 
-	 
+				val crtlRuleResult = compileControlRuleBlock(crtlRules, adapClassName, adapInteralRefName, 
+																mappedScalarVariables, SASVs, params, 
+																if(inVars !== null) inVars.value else null,
+											 					if(outVars !== null) outVars.value else null, 
+											 					if(crtlVars !== null) crtlVars.value else null);
 
 				/*
 				 * Compile the constructor, destructor and initialize functions