Browse Source

incomplete merge

Claudio Gomes 5 years ago
parent
commit
cdbfcb333e
14 changed files with 464 additions and 53 deletions
  1. 2 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.canonical/src/be/uantwerpen/ansymo/semanticadaptation/cg/canonical/SemanticAdaptationCanonicalGenerator.xtend
  2. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/src/be/uantwerpen/ansymo/semanticadaptation/cg/chain/SemanticAdaptationChainGenerator.xtend
  3. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend
  4. 2 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  5. 5 14
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InnerFMUData.java
  6. 12 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java
  7. 3 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend
  8. 406 18
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend
  9. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/FmuGenerator.xtend
  10. 15 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend
  11. 6 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescription.xtend
  12. 6 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend
  13. 2 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend
  14. 2 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

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

@@ -1257,7 +1257,7 @@ class SemanticAdaptationCanonicalGenerator {
 					Log.println("External port " + newExternalPort.qualifiedName + " bound to port " + port.qualifiedName)
 				} else {
 					Log.println("Error: External port " + externalPortName + " already declared.")
-					throw new Exception("Error: External port " + externalPortName + " already declared. Please rename it to avoid clashes.")
+					throw new Exception("Error: External port " + externalPortName + " already declared. Please rename it, or connect it to an internal fmu port, to avoid clashes.")
 				}
 			} else {
 				Log.println("Port " + port.qualifiedName + " has an incoming connection.")
@@ -1510,7 +1510,7 @@ class SemanticAdaptationCanonicalGenerator {
 					Log.println("External port " + newExternalPort.qualifiedName + " bound to port " + port.qualifiedName)
 				} else {
 					Log.println("Error: External port " + externalPortName + " already declared.")
-					throw new Exception("Error: External port " + externalPortName + " already declared. Please rename it to avoid clashes.")
+					throw new Exception("Error: External port " + externalPortName + " already declared. Please rename it, or connect it to an internal fmu port, to avoid clashes.")
 				}
 			} else {
 				Log.println("Port " + port.qualifiedName + " has an incoming connection.")

+ 1 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/src/be/uantwerpen/ansymo/semanticadaptation/cg/chain/SemanticAdaptationChainGenerator.xtend

@@ -22,8 +22,7 @@ class SemanticAdaptationChainGenerator extends SemanticAdaptationCustomGenerator
 		Log.push("Generating cpp code...")
 		
 		val cppGen = new CppGenerator();
-		val IGeneratorContext ctxt = null;
-		cppGen.doGenerate(canonical_sa.eResource, fsa,ctxt);
+		cppGen.doGenerate(canonical_sa.eResource, fsa);
 		
 		Log.pop("Generating cpp code... DONE")
 		

+ 1 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend

@@ -92,8 +92,7 @@ class CgCppAutoTest extends AbstractSemanticAdaptationTest {
 		__assertNoParseErrors(model, hdFile)
 
 		val fsa = new InMemoryFileSystemAccess()
-		val IGeneratorContext ctxt = null;
-		new CppGenerator().doGenerate(model.eResource, fsa,ctxt)
+		new CppGenerator().doGenerate(model.eResource, fsa)
 
 		System.out.println(fsa.allFiles)
 	}

+ 2 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -114,7 +114,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		val fsa = new InMemoryFileSystemAccess()
 		val IGeneratorContext ctxt = null;
 		val cppGen = new CppGenerator();
-		cppGen.doGenerate(model.eResource, fsa, ctxt);
+		cppGen.doGenerate(model.eResource, fsa);
 
 		for (files : fsa.allFiles.entrySet) {
 			val filename2 = files.key.substring(14);
@@ -164,7 +164,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		val fsa = new InMemoryFileSystemAccess();
 		val IGeneratorContext ctxt = null;
 		val cppGen = new CppGenerator();
-		cppGen.doGenerate(model.eResource, fsa, ctxt);
+		cppGen.doGenerate(model.eResource, fsa);
 
 		if (saRootDir.exists) {
 			BuildUtilities.deleteFolder(saRootDir);

+ 5 - 14
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/InnerFMUData.java

@@ -2,30 +2,21 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 
 public class InnerFMUData {
 	private String name;
-	private String typeName;
+	private String path;
 	private String guid;
-	public InnerFMUData(String name, String typeName, String guid)
+	public InnerFMUData(String name, String path, String guid)
 	{
 		this.name = name;
-		this.typeName = typeName;
+		this.path = path;
 		this.guid = guid;
 	}
 	public String getName() {
 		return name;
 	}
-	public void setName(String name) {
-		this.name = name;
-	}
-	public String getTypeName() {
-		return typeName;
-	}
-	public void setTypeName(String typeName) {
-		this.typeName = typeName;
+	public String getPath() {
+		return path;
 	}
 	public String getGuid() {
 		return guid;
 	}
-	public void setGuid(String guid) {
-		this.guid = guid;
-	}
 }

+ 12 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java

@@ -16,6 +16,18 @@ public class BuildUtilities {
 		System.out.println("Stored file: " + file);
 	}
 
+	public static String stripDelimiters(String input){
+		if (input==null)
+			return null;
+		return  input.substring(1, input.length()-1);
+	}
+	
+	public static String svPort(String input){
+		if (input==null)
+			return null;
+		return  input.substring(1, input.length()-1);
+	}
+	
 	public static void copyFile(File sourceFile, File sinkFile) throws IOException {
 	  Files.copy(sourceFile.toPath(), sinkFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
 	}

+ 3 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ControlConditionSwitch.xtend

@@ -34,7 +34,7 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 	) {
 		super(adaptationClassName, adaptationName, "", mSVars, SASVs, params, inVars, outVars, crtlVars);
 	}
-
+	
 	override ReturnInformation caseAssignment(Assignment object) {
 
 		if (object.lvalue.owner !== null) {
@@ -96,14 +96,14 @@ class ControlConditionSwitch extends RulesConditionSwitch {
 
 	override ReturnInformation caseDoStepFun(DoStepFun object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''this->do_step(this->«object.fmu.name»,«doSwitch(object.h).code»,«doSwitch(object.t).code»)''';
+		retVal.code = '''this->do_step(«object.fmu.name»,«doSwitch(object.t).code»,«doSwitch(object.t).code»-t,«doSwitch(object.h).code»);''';
 		retVal.type = SVType.Integer;
 		return retVal;
 	}
 
 	override ReturnInformation caseDoStep(DoStep object) {
 		var retVal = new ReturnInformation();
-		retVal.code = '''this->do_step(«object.fmu.name»,«doSwitch(object.h).code»,«doSwitch(object.t).code»)''';
+		retVal.code = '''this->do_step(«object.fmu.name»,«doSwitch(object.t).code»,«doSwitch(object.t).code»-t,«doSwitch(object.h).code»);''';
 		return retVal;
 	}
 

+ 406 - 18
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -29,21 +29,34 @@ import java.util.List
 import org.eclipse.emf.common.util.EList
 import org.eclipse.emf.ecore.resource.Resource
 import org.eclipse.xtext.generator.IFileSystemAccess2
-import org.eclipse.xtext.generator.IGeneratorContext
+import be.uantwerpen.ansymo.semanticadaptation.log.Log
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.common.CommonPlugin
 
-class CppGenerator extends SemanticAdaptationGenerator {
+class CppGenerator {
 	private var IFileSystemAccess2 fsa;
 	private List<File> resourcePaths = newArrayList();
 
-	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
+	def void doGenerate(Resource resource, IFileSystemAccess2 fsa) {
+		Log.push("CppGenerator.doGenerate")
+		val adaptationFolderURI = resource.URI.trimSegments(1)
+		Log.println("Adaptation folder URI: " + adaptationFolderURI)
+		doGenerate(resource, fsa, adaptationFolderURI)
+		Log.pop("CppGenerator.doGenerate")
+	}
+	
+	def void doGenerate(Resource resource, IFileSystemAccess2 fsa, URI adaptationFolderURI) {
+		Log.push("CppGenerator.doGenerate " + adaptationFolderURI)
 		this.fsa = fsa;
 		for (SemanticAdaptation type : resource.allContents.toIterable.filter(SemanticAdaptation)) {
-			type.compile;
+			type.compile(adaptationFolderURI);
 		}
+		Log.pop("CppGenerator.doGenerate"  + adaptationFolderURI)
 	}
+	
 
 	// TODO: Verify adaptation.name is not a C++ keyword
-	def void compile(SemanticAdaptation adaptation) {
+	def void compile(SemanticAdaptation adaptation, URI adaptationFolderURI) {
 		for (Adaptation adap : adaptation.elements.filter(Adaptation)) {
 			// Value used for scoping variables in the .sa file
 			val adapInteralRefName = adap.name;
@@ -52,15 +65,21 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			val adapClassName = adap.name.toFirstUpper;
 
 			// This is the external name used in the model description file for the semantic adaptation FMU
-			val adapExternalName = adap.type.name;
+			val adapExternalName = adap.name;
 
+   
 			// List of inner FMUs
 			var ArrayList<InnerFMUData> innerFMUsData = newArrayList();
 			val innerFmus = adap.inner.eAllContents.toList.filter(InnerFMU);
+   			
 			if (innerFmus.isEmpty) {
 				throw new IncorrectAmountOfElementsException("The adaptation does not contain any InnerFMUs.")
 			}
-
+			
+			if (innerFmus.size > 1) {
+				throw new IncorrectAmountOfElementsException("Only one InnerFmu is supported.")
+			}
+			
 			/*
 			 * This map will contain scalar variables from the FMUs defined in InnerFMU.
 			 * The structure is fmuName -> (SVName -> mappedSV) where SVName = mappedSV.name for easy lookup.
@@ -74,18 +93,34 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			// TODO: Add support for multiple inner fmus. Only partially supported
 			var ModelDescription md;
 			for (fmu : adap.inner.eAllContents.toList.filter(InnerFMU)) {
-				val fmuFile = new File(fmu.path.replace('\"', ''));
+				Log.push("Loading fmu " + fmu.path)
+				val fmuFile = getFMUFile(fmu.path, adaptationFolderURI)
 				this.resourcePaths.add(fmuFile);
 				md = new ModelDescription(fmu.name, fmu.type.name, fmuFile);
-				innerFMUsData.add(new InnerFMUData(fmu.name, fmu.type.name, md.guid));
-				// fmus.add(fmu.name -> fmu.type.name);
+	
+				innerFMUsData.add(new InnerFMUData(fmu.name, fmu.path, md.guid));
 				val LinkedHashMap<String, MappedScalarVariable> mSV = newLinkedHashMap();
+	
+				Log.push("Loading fmu variables")
 				for (sv : md.sv.values) {
-					var mappedSv = new MappedScalarVariable(sv);
-					mappedSv.define = (mappedSv.mappedSv.owner + mappedSv.mappedSv.name).toUpperCase;
-					mSV.put(mappedSv.mappedSv.name, mappedSv);
+					// Only declared ports are considered.
+					val svInPort = fmu.inports.findFirst[Port p | p.name==sv.name || BuildUtilities.stripDelimiters(p.alias) == sv.name]
+					val svOutPort = fmu.outports.findFirst[Port p | p.name==sv.name || BuildUtilities.stripDelimiters(p.alias) == sv.name]
+					if (svInPort !== null || svOutPort !== null){
+						val svPort = if (svInPort !== null) svInPort else svOutPort
+						val svPortRef = svPort.name;
+						var mappedSv = new MappedScalarVariable(sv);
+						mappedSv.define = (mappedSv.mappedSv.owner + svPortRef).toUpperCase;
+						mSV.put(mappedSv.mappedSv.name, mappedSv);
+						Log.println("Variable " + sv.name + " declared.")
+					} else {
+						Log.println("Variable " + sv.name + " undeclared.")
+					}
 				}
 				mappedScalarVariables.put(fmu.name, mSV);
+				Log.pop("Loading fmu variables")
+									
+				mappedScalarVariables.put(fmu.name, mSV);
 			}
 
 			// C++ Defines for accessing FMU scalar variables.
@@ -170,7 +205,20 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				mappedScalarVariables, SASVs, params, if(inVars !== null) inVars.value else null,
 				if(outVars !== null) outVars.value else null, if(crtlVars !== null) crtlVars.value else null,
 				inPortsWithSrcDep);
-
+   
+								  
+																										 
+   
+						   
+																											 
+																						 
+															 
+																							 
+																											
+
+								  
+																										 
+   
 				// Compile the out rules
 				val outRules = if(adap.out !== null) adap.out as InOutRules else null;
 				val outRuleResult = compileInOutRuleBlocks(IORuleType.Output, outRules, adapClassName,
@@ -180,9 +228,23 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 				// 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);
+				 
+					  
+													 
+													  
+	 
+	 
 
 				/*
 				 * Compile the constructor, destructor and initialize functions
@@ -204,7 +266,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				/*
 				 * Compile getRuleThis function
 				 */
+																				 
 				val String getRuleThisSource = compileGetRuleThis(adapClassName);
+																				 
 
 				/*
 				 * The in and out rules have populated the semantic adaptation scalar variables we can generate the getFmiValue* and setFmiValue functions.
@@ -214,6 +278,18 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 				// Compile the state functions
 				val Pair<String,String> stateFunctions = compileStateFunctions(adapClassName);
+								  
+				  
+										
+					  
+				   
+				   
+							  
+							   
+								
+						
+	 
+														
 
 				// Compile the source file
 				val String sourceInclude = '''#include "«adapClassName».h"''';
@@ -237,9 +313,14 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				if (inVars !== null)
 					allGVars.putAll(inVars.value);
 				if (outVars !== null)
+									  
 					allGVars.putAll(outVars.value);
 				if (crtlVars !== null)
 					allGVars.putAll(crtlVars.value);
+										
+					  
+	 
+													  
 
 				// Compile the header file
 				val headerFile = compileHeader(
@@ -260,6 +341,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				val modelDescCreator = new ModelDescriptionCreator(adapExternalName);
 				val modelDescription = modelDescCreator.generateModelDescription(SASVs.values);
 				fsa.generateFile("modelDescription.xml", modelDescription);
+   
+																																									  
+																																							 
 
 				// Compile the fmu.cpp file
 				val fmuCppFile = FmuGenerator.genFmuCppFile(adapClassName);
@@ -270,6 +354,15 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 			}
 		}
+  		
+  		def getFMUFile(String fmuUnresolvedPath, URI adaptationFolderURI) {
+			var resolvedFolderURI = CommonPlugin.resolve(adaptationFolderURI);
+			val fmuCompleteURI = URI.createFileURI(resolvedFolderURI.toFileString + File.separatorChar + fmuUnresolvedPath.replace('\"', ''))
+			var fmuPath = fmuCompleteURI.toFileString
+			Log.println("Resolved fmu path: " + fmuPath)
+			val fmuFile = new File(fmuPath);
+			return fmuFile
+		}
 
 		def String compileParams(LinkedHashMap<String, GlobalInOutVariable> gVars, EList<ParamDeclarations> params) {
 			val paramsConditionSwitch = new ParamConditionSwitch(gVars);
@@ -280,6 +373,8 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			}
 			return paramsConstructorSource;
 		}
+								 
+  
 
 		def calcSADefines(Collection<SAScalarVariable> variables) {
 			var ArrayList<String> defines = newArrayList();
@@ -303,7 +398,51 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			return defines.join("\n");
 		}
 
+											
+  
+
 		def Pair<String,String> compileStateFunctions(String saName)
+  
+		
+	 
+									 
+											   
+												   
+	 
+	 
+	 
+												
+   
+										  
+							
+			
+   
+  
+														  
+   
+												
+   
+		
+	 
+									 
+											   
+												   
+	 
+	 
+	 
+												
+   
+										  
+							
+			
+   
+  
+														  
+   
+												
+   
+  
+														   
 		{
 			return
 			'''
@@ -314,11 +453,24 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			-> 
 			'''
 			fmi2FMUstate «saName»::getInternalFMUState()
+   
+						
 			{
 				InternalState* s = new InternalState();
 				*s = this->internalState;
 				return s;
 			}
+					
+	
+					
+	
+				   
+	
+					   
+	
+					
+	
+					  
 			
 			void «saName»::setInternalFMUState(fmi2FMUstate state)
 			{
@@ -331,11 +483,27 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			}''';			
 		}
 
+   
 		// Compiles the final source file
+									  
+	
 		def String compileSource(String include, String constructor, String getRuleThis, String getFunctions,
+																						   
+																						   
 			String setFunctions, String inFunctions, String outFunctions, String controlFunction, String stateFunctions) {
+																						   
+															
 			return '''
 				«include»
+											   
+   
+								   
+						
+					 
+					
+	
+						
+						 
 				
 				namespace adaptation 
 				{
@@ -358,6 +526,37 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				}
 				
 			'''
+	
+
+   
+	
+								   
+																									   
+																												 
+			 
+			   
+	
+						 
+	 
+					
+	 
+					
+	 
+					 
+	 
+					 
+	 
+					
+	 
+						
+	 
+					 
+	 
+					   
+	
+	 
+	
+	  
 		}
 
 		/*
@@ -369,9 +568,22 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			LinkedHashMap<String, GlobalInOutVariable> globalVariables, ArrayList<InnerFMUData> fmus,
 			Collection<ScalarVariable> sVars, String stateFunctions) {
 			return '''
+
+	
 				
 					#ifndef SRC_«adapClassName.toUpperCase»_H
 					#define SRC_«adapClassName.toUpperCase»_H
+			   
+				
+	
+   
+													 
+		
+													   
+									  
+														
+								 
+																																												 
 				
 					#include "SemanticAdaptation.h"
 					#include "HyfMath.h"
@@ -383,6 +595,15 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					
 					namespace adaptation
 					{
+			 
+																																																																		  
+						 
+									
+	   
+																					   
+																						
+																						   
+																						   
 						
 						«fmusDefines»
 						
@@ -392,19 +613,33 @@ class CppGenerator extends SemanticAdaptationGenerator {
 						{
 							public:
 								«adapClassName»(shared_ptr<std::string> fmiInstanceName, shared_ptr<string> resourceLocation, const fmi2CallbackFunctions* functions);
-								void initialize();
+								void initialize(bool loggingOn);
 								virtual ~«adapClassName»();
 								
 								void setFmiValue(fmi2ValueReference id, int value);
 								void setFmiValue(fmi2ValueReference id, bool value);
 								void setFmiValue(fmi2ValueReference id, double value);
 								void setFmiValue(fmi2ValueReference id, string value);
+					
+													
+	   
+													 
+	   
+						 
+											  
+				 
 							
 								int getFmiValueInteger(fmi2ValueReference id);
 								bool getFmiValueBoolean(fmi2ValueReference id);
 								double getFmiValueReal(fmi2ValueReference id);
 								string getFmiValueString(fmi2ValueReference id);
 								
+				  
+				  
+								
+				  
+				  
+								
 							protected:
 								«stateFunctions»
 								
@@ -455,9 +690,50 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			var ArrayList<String> initialisations = newArrayList();
 			if (reactiveOrDealyed == ReactiveOrDelayed.DELAYED) {
 				initialisations.add('''this->reactiveness = ReactiveOrDelayed::Delayed;''');
+   
 
 			} else if (reactiveOrDealyed == ReactiveOrDelayed.REACTIVE) {
+																										  
+												 
 				initialisations.add('''this->reactiveness = ReactiveOrDelayed::Reactive;''');
+   
+					
+					
+										  
+			   
+						  
+															   
+														 
+																 
+								  
+																																													
+	
+											 
+									  
+												   
+		
+   
+			
+																																							   
+																																											   
+	   
+				  
+			  
+			   
+				
+											 
+									  
+												   
+		
+   
+			
+																																							   
+																																											   
+	   
+				  
+			  
+			   
+				
 			}
 
 			if (machineType == MooreOrMealy.MOORE) {
@@ -471,10 +747,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				pathCount++;
 				initialisations.add('''
 					auto «pathName» = make_shared<string>(*resourceLocation);
-					«pathName»->append(string("«fmu.typeName».fmu"));
+					«pathName»->append(string(«fmu.getPath»));
 					auto «fmu.name»Fmu = make_shared<fmi2::Fmu>(*«pathName»);
 					«fmu.name»Fmu->initialize();
-					this->«fmu.name» = «fmu.name»Fmu->instantiate("«fmu.name»",fmi2CoSimulation, "«fmu.guid»", true, true, shared_from_this());
+					this->«fmu.name» = «fmu.name»Fmu->instantiate("«fmu.name»",fmi2CoSimulation, "«fmu.guid»", true, loggingOn, shared_from_this());
 					
 					if(this->«fmu.name»->component == NULL)
 						this->lastErrorState = fmi2Fatal;
@@ -491,7 +767,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					«crtlCons»
 				}
 				
-				void «adapClassName»::initialize()
+				void «adapClassName»::initialize(bool loggingOn)
 				{
 					«initialisations.join("\r\n")»
 				}
@@ -530,6 +806,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					cpp.add(
 						'''
 							«functionSignature»
+	   
+												
+				  
 							{
 								«Utilities.getDebug(functionSignature)»
 								switch (id)
@@ -544,6 +823,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 									{
 										«functionReturn»;
 									}
+				  
+				
+		 
+							
 								}
 								
 							}
@@ -602,11 +885,22 @@ class CppGenerator extends SemanticAdaptationGenerator {
 						}
 					'''
 				);
+	
+   
 
+						
 			}
 
 			return cpp.join("\n");
 		}
+	
+															 
+													  
+											 
+																					 
+								  
+		   
+														   
 
 		/*
 		 * Compiles the source file function executeInternalControlFlow.
@@ -617,11 +911,35 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			LinkedHashMap<String, SAScalarVariable> SASVs, LinkedHashMap<String, GlobalInOutVariable> params,
 			LinkedHashMap<String, GlobalInOutVariable> inVars, LinkedHashMap<String, GlobalInOutVariable> outVars,
 			LinkedHashMap<String, GlobalInOutVariable> crtlVars) {
+   
 			var cpp = "";
+   
 			val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, inVars,
+																																								  
+																																												 
+				 
+		   
+				   
+				 
+		  
+		  
+		 
+			   
+	  
+	   
 				outVars, crtlVars);
 			if (crtlRuleBlock !== null)
 				cpp += visitor.doSwitch(crtlRuleBlock).code;
+										 
+  
+				 
+		  
+		  
+		 
+			   
+	  
+	   
+	 
 
 			return new InOutRulesBlockResult(cpp, visitor.functionSignatures);
 		}
@@ -633,13 +951,28 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		def String removeEmptyArgumentParenthesis(String content) {
 			return content.substring(0, content.length - 2);
 		}
+	
+																											  
+																								   
+																								   
+																										
+														
+  
+											 
 		
 		def String removeArgumentParenthesis(String content) {
 			val startParen = content.indexOf('(');
+							 
+											   
 			
 			return content.substring(0,startParen);
 		}
 
+										
+  
+ 
+ 
+ 
 		/*
 		 * Calculates necessary information on global in/out variables
 		 */
@@ -647,6 +980,11 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			LinkedHashMap<String, GlobalInOutVariable> params) {
 
 			val visitor = new RulesConditionSwitch("", "", "", null, null, params, null, null, null)
+	  
+														 
+	 
+	 
+	  
 			return visitor.getGlobalVars(gVars);
 		}
 
@@ -675,8 +1013,58 @@ class CppGenerator extends SemanticAdaptationGenerator {
 						outVars, crtlVars)
 				else
 					new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars, SASVs, params, inVars,
+											 
+  
+ 
+											  
+															  
+  
+ 
+ 
+   
+																			  
+																										
+											  
+	
+												  
+					
+						
+							 
+						
+																												  
+												
+													
+													
+													 
+																												  
+												
+													
+													
+													 
 						outVars, crtlVars);
 
+	
+   
+																			  
+																										
+											  
+	
+												  
+					
+						
+							 
+						
+																												  
+												
+													
+													
+													 
+													  
+							
+	 
+  
+	
+ 
 			val functionName = "create" + ioType + "Rules()";
 			var String cpp = "";
 			var List<String> allFunctionSignatures = newArrayList();

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/FmuGenerator.xtend

@@ -63,7 +63,7 @@ class FmuGenerator {
 			g_adaptation = make_shared<adaptation::«adapClassName»>(name, resourceLoc, functions);
 			try
 			{
-				g_adaptation->initialize();
+				g_adaptation->initialize(loggingOn);
 			} catch (adaptation::SemanticAdaptationFmiException& e)
 			{
 				return NULL;

+ 15 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/InRulesConditionSwitch.xtend

@@ -8,6 +8,7 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 
 class InRulesConditionSwitch extends RulesConditionSwitch {
 
@@ -52,7 +53,20 @@ class InRulesConditionSwitch extends RulesConditionSwitch {
 		var retVal = new ReturnInformation();
 
 		if (inOutputFunction) {
-			retVal.code = '''setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr).code»)''';
+			val lValOwnerName = object.lvalue.owner.name
+			val lValRefName = if (object.lvalue.ref instanceof Port) 
+								(if (((object.lvalue.ref) as Port).alias !== null )
+									BuildUtilities.stripDelimiters(((object.lvalue.ref) as Port).alias) 
+								else 
+									object.lvalue.ref.name) 
+							  else object.lvalue.ref.name
+			val objExpr = object.expr
+			val switchResultCode = doSwitch(objExpr).code
+			val varDefine = mSVars.get(lValOwnerName).get(lValRefName).define
+			retVal.code = 
+				'''
+					setValue(«lValOwnerName»,«varDefine»,«switchResultCode»);
+				''';
 			return retVal;
 		} else {
 			return super.caseAssignment(object);

+ 6 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescription.xtend

@@ -79,7 +79,12 @@ class ModelDescription {
 				
 			for (var j = 0; j < node.childNodes.length; j++) {
 				val subNode = node.childNodes.item(j);
-				if (subNode.nodeType == Node.ELEMENT_NODE) {
+				if (subNode.nodeType == Node.ELEMENT_NODE && (
+						subNode.nodeName=="Real" || 
+						subNode.nodeName=="String" || // There are other subnodes possible that are non type nodes.
+						subNode.nodeName=="Integer" || // In that case, we get an exception if we don't check for the name directly.
+						subNode.nodeName=="Boolean" 
+						)) {
 					val startAttribute = subNode.attributes.getNamedItem("start");
 					if (startAttribute !== null) {
 						sv.start = startAttribute.nodeValue;

+ 6 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/OutRulesConditionSwitch.xtend

@@ -34,11 +34,14 @@ public class OutRulesConditionSwitch extends RulesConditionSwitch {
 
 	override ReturnInformation casePort(Port object) {
 		var retVal = new ReturnInformation();
-
-		val type = mSVars.get(this.externalVariableOwner).get(object.name).mappedSv.type;
-		val define = mSVars.get(this.externalVariableOwner).get(object.name).define;
+		val portName = if (object.alias !== null) BuildUtilities.stripDelimiters(object.alias) else object.name; // remove delimiters from string
+		val fmu_sVar = mSVars.get(this.externalVariableOwner)
+		val sVar = fmu_sVar.get(portName)
+		val type = sVar.mappedSv.type;
+		val define = mSVars.get(this.externalVariableOwner).get(portName).define;
 		retVal.code = '''getValue«Conversions.fmiTypeToGetValueString(type)»(«this.externalVariableOwner»,«define»)''';
 		retVal.type = type;
 		return retVal;
 	}
+	
 }

+ 2 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/RulesConditionSwitch.xtend

@@ -99,7 +99,7 @@ class RulesConditionSwitch extends BasicConditionSwitch {
 	 */
 	public def String createFunctionSignature(String functionName, String type, int count,
 		List<String> functionSignatures) {
-		val functionSignature = this.functionPrefix + functionName + count + "(double dt, double h)";
+		val functionSignature = this.functionPrefix + functionName + count + "(double dt, double H, double h)";
 		functionSignatures.add(type + " " + functionSignature);
 		return type + " " + this.adaptationClassName + "::" + functionSignature;
 	}
@@ -390,7 +390,7 @@ class RulesConditionSwitch extends BasicConditionSwitch {
 		var retVal = new ReturnInformation();
 		val left = doSwitch(object.left);
 		val right = doSwitch(object.right);
-		retVal.appendCode('''«left.code»; «forLoopIterVar»<=«right.code»; «forLoopIterVar»++''')
+		retVal.appendCode('''«left.code»; «forLoopIterVar»<«right.code»; «forLoopIterVar»++''')
 		return retVal;
 	}
 

+ 2 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

@@ -47,7 +47,7 @@ CompositeFMU:
 	('output' 'ports' outports+=Port ("," outports+=Port)* )?;
 
 Adaptation:
-	({Adaptation} 'semantic' 'adaptation' (reactiveness=ReactiveOrDelayed)? (machine=MooreOrMealy)? type=FMUType (name=ID)? | // this is a type or a name?
+	({Adaptation} 'semantic' 'adaptation' (reactiveness=ReactiveOrDelayed)? (machine=MooreOrMealy)? name=ID | // this is a type or a name?
 	{AdaptationWithSpecificMaster} 'semantic' 'adaptation' (reactiveness=ReactiveOrDelayed)? (machine=MooreOrMealy)? type=FMUType (name=ID)? 'without' 'master')
 	'at' path=STRING // to be generated here
 	inner=InnerFMUDeclaration
@@ -186,7 +186,7 @@ Port:
 	// TODO: add internal destination/source of port
 	// Unity conversions: https://pint.readthedocs.io/en/0.7.2/
 	(type=TypeDefinition)?
-	name=ID 
+	name=ID (alias=STRING)?  // Needs string name because some FMU's have weird port names.
 	(':=' initval=LiteralOrArray)? 
 	( multiplicity=Multiplicity )?
 	( '(' unity=Unity ')' )?