Browse Source

Almost working window - needs return information adjustment

Casper Thule 7 years ago
parent
commit
09a02042e2
21 changed files with 790 additions and 452 deletions
  1. 3 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  2. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/modelDescription.xml
  3. 208 199
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.cpp
  4. 64 70
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.h
  5. 4 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/window_sa_canonical.BASE.sa
  6. 19 18
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF
  7. 82 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ConnectedVariable.java
  8. 2 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ControlConditionSwitch.xtend
  9. 9 10
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Conversions.java
  10. 187 85
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend
  11. 23 15
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesConditionSwitch.xtend
  12. 19 7
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InRulesConditionSwitch.xtend
  13. 37 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MappedScalarVariable.java
  14. 9 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend
  15. 0 19
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend
  16. 37 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreatorV2.java
  17. 10 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/OutRulesConditionSwitch.xtend
  18. 44 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ReturnInformation.java
  19. 18 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SAScalarVariable.java
  20. 9 9
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVType.java
  21. 5 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java

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

@@ -35,9 +35,9 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Inject extension  ValidationTestHelper
 
 	@Test def powerwindow_model_only() {
-//		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
-		__parseNoErrorsWithValidation('test_input/single_folder_spec/window',
-			'test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
+		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
+//		__parseNoErrorsWithValidation('test_input/single_folder_spec/window',
+//			'test_input/single_folder_spec/window/window_sa_canonical.BASE.sa');
 	}
 
 	def __parseNoErrorsWithValidation(String directory, String filename) {

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/modelDescription.xml

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?><fmiModelDescription fmiVersion="2.0" guid="71e95519-506e-48ca-9de6-55cb071ea842" modelName="windowSA" variableNamingConvention="flat">
+<?xml version="1.0" encoding="UTF-8"?><fmiModelDescription fmiVersion="2.0" guid="124d182d-3cfe-4fa6-bb9e-97e1bbb40fb4" modelName="WindowSA" variableNamingConvention="flat">
     <ModelVariables>
         <ScalarVariable causality="output" name="disp" valueReference="0" variability="continuous">
             <Real/>

+ 208 - 199
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.cpp

@@ -1,219 +1,228 @@
-#include "windowSA.h"
-
-windowSA::windowSA(shared_ptr<std::string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
-{
-	stored_window_reaction_torque = 0.0;
-	stored_window_height = 0.0;
-	
-	this->stored_windowsa_reaction_force = 0.0;
-	this->stored_windowsa_displacement = 0.0;
-	this->stored_windowsa_speed = 0.0;
-	
-	this->displacement = 0.0;
-	this->reaction_force = 0.0;
-	this->speed = 0.0;
-	this->b = 10.0;
-	this->r = 0.11;
-	
-	const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("Window.fmu"))->c_str();
-	auto windowFmu = make_shared<fmi2::Fmu>(path);
-	windowFmu->initialize();
-	this->window = windowFmu->instantiate("Window",fmi2CoSimulation, "{29e3eae4-7ed5-4ccc-a0e7-7d8198e20bc0}", true, true, make_shared<Callback>()); 
-}
-
-
-windowSA* windowSA::getRuleThis()
+#include "windowSA.h"
+
+namespace adaptation 
 {
-	return this;
-}
-
-
-bool windowSA::in_rule_condition1(){
-	return true;
-}
-void windowSA::in_rule_body1(){
-	if(this->isSetreaction_force){
-		this->stored_windowsa_reaction_force = this->reaction_force;
-	}
-}
-void windowSA::in_rule_flush1(){
-	setValue(window,WINDOWREACTION_FORCE,this->stored_windowsa_reaction_force);
-}
-bool windowSA::in_rule_condition2(){
-	return true;
-}
-void windowSA::in_rule_body2(){
-	if(this->isSetdisplacement){
-		this->stored_windowsa_displacement = this->displacement;
+	WindowSA::WindowSA(shared_ptr<string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
+	{
+		stored_window_reaction_torque = 0.0;
+		stored_window_height = 0.0;
+		
+		this->stored_windowsa_reaction_force = 0.0;
+		this->stored_windowsa_displacement = 0.0;
+		this->stored_windowsa_speed = 0.0;
+		
+		this->displacement = 0.0;
+		this->reaction_force = 0.0;
+		this->speed = 0.0;
+		this->b = 10.0;
+		this->r = 0.11;
+		
+		const char* path = Fmu::combinePath(resourceLocation, make_shared<string>("Window.fmu"))->c_str();
+		auto windowFmu = make_shared<fmi2::Fmu>(path);
+		windowFmu->initialize();
+		this->window = windowFmu->instantiate("Window",fmi2CoSimulation, "{29e3eae4-7ed5-4ccc-a0e7-7d8198e20bc0}", true, true, make_shared<Callback>()); 
 	}
-}
-void windowSA::in_rule_flush2(){
-	setValue(window,WINDOWDISPLACEMENT,this->stored_windowsa_displacement);
-}
-bool windowSA::in_rule_condition3(){
-	return true;
-}
-void windowSA::in_rule_body3(){
-	if(this->isSetspeed){
-		this->stored_windowsa_speed = this->speed;
+	WindowSA::~WindowSA()
+	{
 	}
-}
-void windowSA::in_rule_flush3(){
-	setValue(window,WINDOWSPEED,this->stored_windowsa_speed);
-}
-shared_ptr<list<Rule<windowSA>>> windowSA::createInputRules()
-{
-	auto list = make_shared<list<Rule<windowSA>>>()
-	
-	list->push_back(
-		(Rule<windowSA>){
-			&windowSA::bool in_rule_condition1();,
-			&windowSA::void in_rule_body1();
-			&windowSA::void in_rule_flush1();
-		});
 	
+	WindowSA* WindowSA::getRuleThis()
+	{
+		return this;
+	}
 	
-	list->push_back(
-		(Rule<windowSA>){
-			&windowSA::bool in_rule_condition2();,
-			&windowSA::void in_rule_body2();
-			&windowSA::void in_rule_flush2();
-		});
+	double  WindowSA::getFmiValueReal(fmi2ValueReference id)
+	{
+		switch (id)
+		{
+			case WINDOWDISP:
+			{
+				return this->disp;
+			}
+			case WINDOWFRICTION:
+			{
+				return this->friction;
+			}
+			case WINDOWTAU:
+			{
+				return this->tau;
+			}
+			default:
+			{
+				return 0.0;
+			}
+		}
+		
+	}
 	
+	string  WindowSA::getFmiValueString(fmi2ValueReference id)
+	{
+		return "";
+	}
 	
-	list->push_back(
-		(Rule<windowSA>){
-			&windowSA::bool in_rule_condition3();,
-			&windowSA::void in_rule_body3();
-			&windowSA::void in_rule_flush3();
-		});
+	int  WindowSA::getFmiValueInteger(fmi2ValueReference id)
+	{
+		return 0;
+	}
 	
+	bool  WindowSA::getFmiValueBoolean(fmi2ValueReference id)
+	{
+		return false;
+	}
 	
-	return list;
+	void WindowSA::setFmiValue(fmi2ValueReference id, double value)
+	{
+		switch (id)	
+			{
+				case WINDOWDISPLACEMENT:
+				{
+					this->displacement = value;
+					this->isSetdisplacement = true;
+					break;
+				}
+				case WINDOWREACTION_FORCE:
+				{
+					this->reaction_force = value;
+					this->isSetreaction_force = true;
+					break;
+				}
+				case WINDOWSPEED:
+				{
+					this->speed = value;
+					this->isSetspeed = true;
+					break;
+				}
+				default:
+				{
+				}
+			}
+	}
 	
-}
-
-bool windowSA::out_rule_condition1(){
-	return true;
-}
-void windowSA::out_rule_body1(){
-	this->stored_window_reaction_torque = getValue(window,WINDOWTAU);
-}
-void windowSA::out_rule_flush1(){
-	this->tau = -this->stored_window_reaction_torque;
-}
-bool windowSA::out_rule_condition2(){
-	return true;
-}
-void windowSA::out_rule_body2(){
-	this->stored_window_height = getValue(window,WINDOWDISP);
-}
-void windowSA::out_rule_flush2(){
-	this->disp = this->stored_window_height * 100;
-}
-shared_ptr<list<Rule<windowSA>>> windowSA::createOutputRules()
-{
-	auto list = make_shared<list<Rule<windowSA>>>()
+	void WindowSA::setFmiValue(fmi2ValueReference id, string value)
+	{
+	}
 	
-	list->push_back(
-		(Rule<windowSA>){
-			&windowSA::bool out_rule_condition1();,
-			&windowSA::void out_rule_body1();
-			&windowSA::void out_rule_flush1();
-		});
+	void WindowSA::setFmiValue(fmi2ValueReference id, int value)
+	{
+	}
 	
+	void WindowSA::setFmiValue(fmi2ValueReference id, bool value)
+	{
+	}
 	
-	list->push_back(
-		(Rule<windowSA>){
-			&windowSA::bool out_rule_condition2();,
-			&windowSA::void out_rule_body2();
-			&windowSA::void out_rule_flush2();
-		});
+	bool WindowSA::in_rule_condition1(){
+		return true;
+	}
+	void WindowSA::in_rule_body1(){
+		if(this->isSetreaction_force){
+			this->stored_windowsa_reaction_force = this->reaction_force;
+		}
+	}
+	void WindowSA::in_rule_flush1(){
+		setValue(window,WINDOWREACTION_FORCE,this->stored_windowsa_reaction_force);
+	}
+	bool WindowSA::in_rule_condition2(){
+		return true;
+	}
+	void WindowSA::in_rule_body2(){
+		if(this->isSetdisplacement){
+			this->stored_windowsa_displacement = this->displacement;
+		}
+	}
+	void WindowSA::in_rule_flush2(){
+		setValue(window,WINDOWDISPLACEMENT,this->stored_windowsa_displacement);
+	}
+	bool WindowSA::in_rule_condition3(){
+		return true;
+	}
+	void WindowSA::in_rule_body3(){
+		if(this->isSetspeed){
+			this->stored_windowsa_speed = this->speed;
+		}
+	}
+	void WindowSA::in_rule_flush3(){
+		setValue(window,WINDOWSPEED,this->stored_windowsa_speed);
+	}
+	shared_ptr<list<Rule<WindowSA>>> WindowSA::createInputRules()
+	{
+		auto list = make_shared<list<Rule<WindowSA>>>()
+		
+		list->push_back(
+			(Rule<WindowSA>){
+				&WindowSA::in_rule_condition1();,
+				&WindowSA::in_rule_body1();
+				&WindowSA::in_rule_flush1();
+			});
+		
+		
+		list->push_back(
+			(Rule<WindowSA>){
+				&WindowSA::in_rule_condition2();,
+				&WindowSA::in_rule_body2();
+				&WindowSA::in_rule_flush2();
+			});
+		
+		
+		list->push_back(
+			(Rule<WindowSA>){
+				&WindowSA::in_rule_condition3();,
+				&WindowSA::in_rule_body3();
+				&WindowSA::in_rule_flush3();
+			});
+		
+		
+		return list;
+		
+	}
 	
 	
-	return list;
+	void windowSA::executeInternalControlFlow(double h, double dt)
+	{
+		this->doStep(window,h,dt);
+	}
 	
-}
-
-void windowSA::executeInternalControlFlow(double h, double dt)
-{
-	this->doStep(window,h,dt);
-}
-double  windowSA::getFmiValueDouble(fmi2ValueReference id)
-{
-	switch (id)
+	bool WindowSA::out_rule_condition1(){
+		return true;
+	}
+	void WindowSA::out_rule_body1(){
+		this->stored_window_reaction_torque = getValueReal(window,WINDOWTAU);
+	}
+	void WindowSA::out_rule_flush1(){
+		this->tau = -this->stored_window_reaction_torque;
+	}
+	bool WindowSA::out_rule_condition2(){
+		return true;
+	}
+	void WindowSA::out_rule_body2(){
+		this->stored_window_height = getValueReal(window,WINDOWDISP);
+	}
+	void WindowSA::out_rule_flush2(){
+		this->disp = this->stored_window_height * 100;
+	}
+	shared_ptr<list<Rule<WindowSA>>> WindowSA::createOutputRules()
 	{
-		case WINDOWDISP:
-		{
-			return this->disp;
-		}
-		case WINDOWFRICTION:
-		{
-			return this->friction;
-		}
-		case WINDOWTAU:
-		{
-			return this->tau;
-		}
-		default:
-		{
-			return 0.0;
-		}
+		auto list = make_shared<list<Rule<WindowSA>>>()
+		
+		list->push_back(
+			(Rule<WindowSA>){
+				&WindowSA::out_rule_condition1();,
+				&WindowSA::out_rule_body1();
+				&WindowSA::out_rule_flush1();
+			});
+		
+		
+		list->push_back(
+			(Rule<WindowSA>){
+				&WindowSA::out_rule_condition2();,
+				&WindowSA::out_rule_body2();
+				&WindowSA::out_rule_flush2();
+			});
+		
+		
+		return list;
+		
 	}
 	
+
 }
-
-String  windowSA::getFmiValueString(fmi2ValueReference id)
-{
-	return "";
-}
-
-int  windowSA::getFmiValueInteger(fmi2ValueReference id)
-{
-	return 0;
-}
-
-bool  windowSA::getFmiValueBool(fmi2ValueReference id)
-{
-	return false;
-}
-
-void windowSA::setFmiValue(fmi2ValueReference id, double value)
-{
-	switch (id)	
-		{
-			case WINDOWDISPLACEMENT:
-			{
-				this->displacement = value;
-				this->isSetdisplacement = true;
-				break;
-			}
-			case WINDOWREACTION_FORCE:
-			{
-				this->reaction_force = value;
-				this->isSetreaction_force = true;
-				break;
-			}
-			case WINDOWSPEED:
-			{
-				this->speed = value;
-				this->isSetspeed = true;
-				break;
-			}
-			default:
-			{
-			}
-		}
-}
-
-void windowSA::setFmiValue(fmi2ValueReference id, String value)
-{
-}
-
-void windowSA::setFmiValue(fmi2ValueReference id, int value)
-{
-}
-
-void windowSA::setFmiValue(fmi2ValueReference id, bool value)
-{
-}
+

+ 64 - 70
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/correct/windowSA.h

@@ -1,78 +1,72 @@
-#define WINDOWDISP 0
-#define WINDOWDISPLACEMENT 1
-#define WINDOWFRICTION 2
-#define WINDOWREACTION_FORCE 3
-#define WINDOWSPEED 4
-#define WINDOWTAU 5
-#define WINDOWV 6
-#define WINDOWB 7
-#define WINDOWR 8
-
 #include "SemanticAdaptation.h"
 #include <memory>
 #include "Fmu.h"
 
 using namespace std;
-using namespace fmi2
+using namespace fmi2;
 
-class windowSA : public SemanticAdaptation<windowSA>{
-	public:
-		windowSA();
-		virtual ~windowSA();
-		
-		void setFmiValue(fmi2ValueReference id, int value);
-		void setFmiValue(fmi2ValueReference id, bool value);
-		void setFmiValue(fmi2ValueReference id, double value);
-	
-		int getFmiValueInteger(fmi2ValueReference id);
-		bool getFmiValueBoolean(fmi2ValueReference id);
-		double getFmiValueDouble(fmi2ValueReference id);
-	private:
-		
-		windowSA* getRuleThis();
-		
-		/*in rules*/
-		bool in_rule_condition1();
-		void in_rule_body1();
-		void in_rule_flush1();
-		bool in_rule_condition2();
-		void in_rule_body2();
-		void in_rule_flush2();
-		bool in_rule_condition3();
-		void in_rule_body3();
-		void in_rule_flush3();
-		shared_ptr<list<Rule<windowSA>>> createInputRules;
-		
-		/*out rules*/
-		bool out_rule_condition1();
-		void out_rule_body1();
-		void out_rule_flush1();
-		bool out_rule_condition2();
-		void out_rule_body2();
-		void out_rule_flush2();
-		shared_ptr<list<Rule<windowSA>>> createOutputRules;
-		
-		void executeInternalControlFlow(double h, double dt);
-		
-		shared_ptr<Fmu> window;
-		
-		double disp;
-		double displacement;
-		bool isSetdisplacement;								
-		double friction;
-		double reaction_force;
-		bool isSetreaction_force;								
-		double speed;
-		bool isSetspeed;								
-		double tau;
-		double v;
-		double b;
-		double r;
-		
-		double stored_window_reaction_torque;
-		double stored_window_height;
+namespace adaptation
+{
+
+	class WindowSA : public SemanticAdaptation<WindowSA>{
+		public:
+			WindowSA(shared_ptr<string> resourceLocation);
+			virtual ~WindowSA();
+			
+			void setFmiValue(fmi2ValueReference id, int value);
+			void setFmiValue(fmi2ValueReference id, bool value);
+			void setFmiValue(fmi2ValueReference id, double value);
 		
-		double stored_windowsa_reaction_force;
-		double stored_windowsa_displacement;
-		double stored_windowsa_speed;
+			int getFmiValueInteger(fmi2ValueReference id);
+			bool getFmiValueBoolean(fmi2ValueReference id);
+			double getFmiValueDouble(fmi2ValueReference id);
+		private:
+			
+			WindowSA* getRuleThis();
+			
+			/*in rules*/
+			bool in_rule_condition1();
+			void in_rule_body1();
+			void in_rule_flush1();
+			bool in_rule_condition2();
+			void in_rule_body2();
+			void in_rule_flush2();
+			bool in_rule_condition3();
+			void in_rule_body3();
+			void in_rule_flush3();
+			shared_ptr<list<Rule<WindowSA>>> createInputRules();
+			
+			/*out rules*/
+			bool out_rule_condition1();
+			void out_rule_body1();
+			void out_rule_flush1();
+			bool out_rule_condition2();
+			void out_rule_body2();
+			void out_rule_flush2();
+			shared_ptr<list<Rule<WindowSA>>> createOutputRules();
+			
+			void executeInternalControlFlow(double h, double dt);
+			
+			shared_ptr<FmuComponent> window;
+			
+			double disp;
+			double displacement;
+			bool isSetdisplacement;
+			double friction;
+			double reaction_force;
+			bool isSetreaction_force;
+			double speed;
+			bool isSetspeed;
+			double tau;
+			double v;
+			double b;
+			double r;
+			
+			double stored_window_reaction_torque;
+			double stored_window_height;
+			
+			double stored_windowsa_reaction_force;
+			double stored_windowsa_displacement;
+			double stored_windowsa_speed;
+	}
 }

+ 4 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/window_sa_canonical.BASE.sa

@@ -17,8 +17,8 @@ input ports 	reaction_force,
 				displacement,
 				speed
 
-output ports	disp,
-				tau
+	output ports	disp,
+					tau
 
 
 control {
@@ -69,13 +69,13 @@ out var stored_window_reaction_torque := 0.0,
 out rules {
 
 	true -> {
-		stored_window_reaction_torque := window.tau;
+		stored_window_reaction_torque := window.reaction_torque;
 	} --> {
 		windowSA.tau := - stored_window_reaction_torque;
 	};
 	
 	true -> {
-		stored_window_height := window.disp;
+		stored_window_height := window.height;
 	} --> {
 		windowSA.disp := stored_window_height * 100;
 	};

+ 19 - 18
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF

@@ -1,18 +1,19 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: be.uantwerpen.ansymo.semanticadaptation.cg.cpp
-Bundle-Vendor: University of Antwerp, Ansymo Lab
-Bundle-Version: 1.0.0.qualifier
-Bundle-SymbolicName: be.uantwerpen.ansymo.semanticadaptation.cg.cpp; singleton:=true
-Bundle-ActivationPolicy: lazy
-Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
- org.junit;bundle-version="4.7.0",
- org.eclipse.xtext.junit4,
- org.eclipse.xtext.xbase.junit,
- org.eclipse.xtext.xbase.lib,
- org.eclipse.jdt.core,
- org.eclipse.xtext.testing,
- org.eclipse.xtext.xbase.testing
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.apache.log4j
-Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+Bundle-Vendor: University of Antwerp, Ansymo Lab
+Bundle-Version: 1.0.0.qualifier
+Bundle-SymbolicName: be.uantwerpen.ansymo.semanticadaptation.cg.cpp; singleton:=true
+Bundle-ActivationPolicy: lazy
+Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
+ org.junit;bundle-version="4.7.0",
+ org.eclipse.xtext.junit4,
+ org.eclipse.xtext.xbase.junit,
+ org.eclipse.xtext.xbase.lib,
+ org.eclipse.jdt.core,
+ org.eclipse.xtext.testing,
+ org.eclipse.xtext.xbase.testing,
+ org.eclipse.xtext.util
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Import-Package: org.apache.log4j
+Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp

+ 82 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ConnectedVariable.java

@@ -0,0 +1,82 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+public class ConnectedVariable {
+
+	private SVCausality causality;
+	private SVType type;
+	private String name;
+	private String owner;
+	private InputOutputType inOut;
+	private String value;
+	private ConnectedVariable conVar;
+	private MappedScalarVariable mapSV;
+	
+	public ConnectedVariable() {
+		
+	}
+
+	public SVCausality getCausality() {
+		return causality;
+	}
+
+	public void setCausality(SVCausality causality) {
+		this.causality = causality;
+	}
+
+	public SVType getType() {
+		return type;
+	}
+
+	public void setType(SVType type) {
+		this.type = type;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getOwner() {
+		return owner;
+	}
+
+	public void setOwner(String owner) {
+		this.owner = owner;
+	}
+
+	public InputOutputType getInOut() {
+		return inOut;
+	}
+
+	public void setInOut(InputOutputType inOut) {
+		this.inOut = inOut;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+
+	public ConnectedVariable getConVar() {
+		return conVar;
+	}
+
+	public void setConVar(ConnectedVariable conVar) {
+		this.conVar = conVar;
+	}
+
+	public MappedScalarVariable getMapSV() {
+		return mapSV;
+	}
+
+	public void setMapSV(MappedScalarVariable mapSV) {
+		this.mapSV = mapSV;
+	}
+
+}

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

@@ -10,8 +10,8 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
 
 class ControlConditionSwitch extends InOutRulesConditionSwitch {
 
-	new(String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars) {
-		super(adaptationName, scalars, "");
+	new(String adaptationClassName, String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars) {
+		super(adaptationClassName, adaptationName, "", null);
 	}
 
 	override String caseControlRuleBlock(ControlRuleBlock obj) {

+ 9 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/Conversions.java

@@ -8,12 +8,12 @@ public class Conversions {
 		switch (t) {
 		case Real:
 			return "double";
-		case Int:
+		case Integer:
 			return "int";
-		case Bool:
+		case Boolean:
 			return "bool";
 		case String:
-			return "String";
+			return "string";
 		default:
 			throw new InvalidConversionException("The value type: " + t + " is invalid.");
 		}
@@ -23,9 +23,9 @@ public class Conversions {
 		switch (t) {
 		case Real:
 			return "Double";
-		case Int:
+		case Integer:
 			return "Integer";
-		case Bool:
+		case Boolean:
 			return "Bool";
 		case String:
 			return "String";
@@ -33,14 +33,14 @@ public class Conversions {
 			throw new InvalidConversionException("The value type: " + t + " is invalid.");
 		}
 	}
-	
+
 	public static String fmiTypeToCppDefaultValue(SVType t) throws InvalidConversionException {
 		switch (t) {
 		case Real:
 			return "0.0";
-		case Int:
+		case Integer:
 			return "0";
-		case Bool:
+		case Boolean:
 			return "false";
 		case String:
 			return "\"\"";
@@ -48,6 +48,5 @@ public class Conversions {
 			throw new InvalidConversionException("The value type: " + t + " is invalid.");
 		}
 	}
-	
-	
+
 }

+ 187 - 85
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -14,6 +14,9 @@ import java.util.LinkedHashMap
 import org.eclipse.emf.ecore.resource.Resource
 import org.eclipse.xtext.generator.IFileSystemAccess2
 import org.eclipse.xtext.generator.IGeneratorContext
+import java.util.Collection
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
+import org.eclipse.emf.common.util.EList
 
 class CppGenerator extends SemanticAdaptationGenerator {
 
@@ -34,146 +37,212 @@ class CppGenerator extends SemanticAdaptationGenerator {
 // TODO: Add initial value to inputs in the model description file
 	def void compile(SemanticAdaptation adaptation) {
 		for (Adaptation type : adaptation.elements.filter(Adaptation)) {
-
+			val adapInteralRefName = type.name;
+			val adapClassName = type.name.toFirstUpper;
+			val adapExternalName = type.type.name;
 			var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
 			var ArrayList<Pair<String, String>> fmus = newArrayList();
 			var LinkedHashMap<String, ScalarVariable> sVars = newLinkedHashMap();
 			var String genSource = "";
 			var ModelDescription md;
+			var LinkedHashMap<String, Collection<ScalarVariable>> scalarVariables = newLinkedHashMap();
+			var LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables = newLinkedHashMap();			
+
 			// Load Model Description file
 			val innerFmus = type.inner.eAllContents.toList.filter(InnerFMU);
-			if(innerFmus.size > 1)
-			{
+			if (innerFmus.size > 1) {
 				throw new IncorrectAmountOfElementsException("Only one InnerFmu is supported.")
 			}
-			if(innerFmus.isEmpty)
-			{
+			if (innerFmus.isEmpty) {
 				throw new IncorrectAmountOfElementsException("The adaptation does not contain any InnerFMUs.")
 			}
-			
+
+			var ArrayList<SAScalarVariable> SASVs = calcSASVsFromInportsOutports(adapInteralRefName, type.inports, type.outports)
+
 			for (fmu : type.inner.eAllContents.toList.filter(InnerFMU)) {
 				// TODO: Merge this with ModelDescriptionCreator
 				md = new ModelDescription(fmu.name, fmu.type.name, new File(fmu.path.replace('\"', '')));
 				fmus.add(fmu.name -> fmu.type.name);
 				svDefs.putAll(md.svDef);
 				sVars.putAll(md.sv);
+				scalarVariables.put(fmu.name, md.sv.values);
 
-				mdCreator.name = type.name;
+				mdCreator.name = adapExternalName;
 				mdCreator.CalcContent(md);
 				fsa.generateFile("modelDescription.xml", mdCreator.modelDescription);
 			}
 
+			/*
+			 * We might have conflicting scalar variables, 
+			 * and therefore the scalar variables cannot be directly mapped to the mdCreator.
+			 * mappedScalarVariables is therefore: HashMap (fmuName -> HashMap(SVName->mappedSV))
+			 */
+			for (mdSv : scalarVariables.entrySet) {
+				val LinkedHashMap<String, MappedScalarVariable> msv = newLinkedHashMap();
+				for (sv : mdSv.value) {
+					var mappedSv = new MappedScalarVariable(sv);
+					mappedSv.define = (mappedSv.mappedSv.owner + mappedSv.mappedSv.name).toUpperCase;
+					msv.put(mappedSv.mappedSv.name, mappedSv);
+				}
+				mappedScalarVariables.put(mdSv.key, msv);
+			}
+			
 			// Compile the in rules
 			val inRuleResult = compileInOutRuleBlocks(InputOutputType.Input, adaptation.eAllContents.toIterable.filter(
-				InRulesBlock).map[x|x as InOutRules], svDefs, type.name);
+				InRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables);
 			genSource += inRuleResult.generatedCpp;
 
 			// Compile the out rules
 			val outRuleResult = compileInOutRuleBlocks(InputOutputType.Output, adaptation.eAllContents.toIterable.
-				filter(OutRulesBlock).map[x|x as InOutRules], svDefs, type.name);
+				filter(OutRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables);
 			genSource += outRuleResult.generatedCpp;
 
+			/*
+			 * We now have the explicit input and output values determined in the SA. 
+			 * This along with the model descriptions should be enough to create a model description for the SA FMU. 
+			 */
 			// Generate the Control Rules
 			val crtlRuleResult = compileControlRuleBlock(adaptation.eAllContents.toIterable.filter(ControlRuleBlock),
-				type.name, svDefs);
+				adapClassName, adapInteralRefName, svDefs);
 			genSource += crtlRuleResult.generatedCpp;
 
-			// Compile the includes and constructor 
-			val String include = '''#include "«type.name».h"''';
-			val String constructor = compileConstructor(type.name, outRuleResult, inRuleResult, sVars, fmus.head.key,
-				fmus.head.value, md.guid);
-			val String getRuleThis = compileGetRuleThis(type.name);
-			genSource = include + "\n\n" + constructor + "\n\n" + getRuleThis + "\n\n" + genSource;
+			// Compile the source file includes, namespace and constructor 
+			val String include = '''#include "«adapClassName.toFirstLower».h"''';
+			val String constructor = compileDeAndConstructor(adapClassName, outRuleResult, inRuleResult, sVars,
+				fmus.head.key, fmus.head.value, md.guid);
+			val String getRuleThis = compileGetRuleThis(adapClassName);
 
 			// Compile the get functions
-			val String getFuncs = compileGetFmuValue(type.name, sVars, svDefs);
-			genSource += "\n" + getFuncs;
+			val String getFuncs = compileGetFmuValue(adapClassName, sVars, svDefs);
 
 			// Compile the set functions
-			val String setFuncs = compileSetFmuValue(type.name, sVars, svDefs);
-			genSource += "\n" + setFuncs;
+			val String setFuncs = compileSetFmuValue(adapClassName, sVars, svDefs);
 
 			// Generate the source file for the SA
-			fsa.generateFile(type.name + ".cpp", genSource);
+			val source = compileSource(
+				include,
+				constructor,
+				getRuleThis,
+				getFuncs,
+				setFuncs,
+				inRuleResult.generatedCpp,
+				crtlRuleResult.generatedCpp,
+				outRuleResult.generatedCpp
+			);
+
+			fsa.generateFile(adapClassName.toFirstLower + ".cpp", source);
 
 			// Compile defines for the scalar variables
 			var genDef = calcDefines(svDefs).join("\n");
 			// Compile the class definition file for the SA
-			val String header = compileHeader(type.name, inRuleResult, outRuleResult, crtlRuleResult, fmus, sVars);
+			val String header = compileHeader(adapClassName, inRuleResult, outRuleResult, crtlRuleResult, fmus, sVars,
+				genDef);
 
 			// Generate the header file for the SA
-			fsa.generateFile(type.name + ".h", genDef + "\n\n" + header);
+			fsa.generateFile(adapClassName.toLowerCase + ".h", header);
 		}
 	}
 
+	// Compiles the final source file
+	def String compileSource(String include, String constructor, String getRuleThis, String getFunctions,
+		String setFunctions, String inFunctions, String controlFunction, String outFunctions) {
+		return '''
+			«include»
+			
+			namespace adaptation 
+			{
+				«constructor»
+				
+				«getRuleThis»
+				
+				«getFunctions»
+				
+				«setFunctions»
+				
+				«inFunctions»
+				
+				«controlFunction»
+				
+				«outFunctions»
+			
+			}
+			
+		'''
+	}
+
 	/*
-	 * Compiles the header file
+	 * Compiles the header file split into two: The first part contains the includes and using namespace definitions and start the ,
+	 * the second part contains the class
 	 */
 	def String compileHeader(String adaptationName, InOutRulesBlockResult inRulesResult,
 		InOutRulesBlockResult outRulesResult, RulesBlockResult crtlRulesResult, ArrayList<Pair<String, String>> fmus,
-		LinkedHashMap<String, ScalarVariable> sVars) {
+		LinkedHashMap<String, ScalarVariable> sVars, String defines) {
 		return '''
 			#include "SemanticAdaptation.h"
 			#include <memory>
 			#include "Fmu.h"
 			
 			using namespace std;
-			using namespace fmi2
+			using namespace fmi2;
 			
-			class «adaptationName» : public SemanticAdaptation<«adaptationName»>{
-				public:
-					«adaptationName»();
-					virtual ~«adaptationName»();
-					
-					void setFmiValue(fmi2ValueReference id, int value);
-					void setFmiValue(fmi2ValueReference id, bool value);
-					void setFmiValue(fmi2ValueReference id, double value);
-				
-					int getFmiValueInteger(fmi2ValueReference id);
-					bool getFmiValueBoolean(fmi2ValueReference id);
-					double getFmiValueDouble(fmi2ValueReference id);
-				private:
-					
-					«adaptationName»* getRuleThis();
-					
-					/*in rules*/
-					«inRulesResult.functionSignatures.join("\n")»
-					
-					/*out rules*/
-					«outRulesResult.functionSignatures.join("\n")»
-					
-					«crtlRulesResult.functionSignatures.join("\n")»
-					
-					«FOR fmu : fmus»
-						shared_ptr<Fmu> «fmu.key»;
-					«ENDFOR»
-					
-					«FOR sv : sVars.entrySet»
-						«Conversions.fmiTypeToCppType(sv.value.type)» «sv.value.name»;
-						«IF sv.value.causality == SVCausality.input»
-							bool isSet«sv.value.name»;								
-						«ENDIF»
-					«ENDFOR»
-					
-					«FOR v : outRulesResult.globalVars.entrySet»
-						«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
-					«ENDFOR»
+			namespace adaptation
+			{
+			
+				class «adaptationName» : public SemanticAdaptation<«adaptationName»>{
+					public:
+						«adaptationName»(shared_ptr<string> resourceLocation);
+						virtual ~«adaptationName»();
+						
+						void setFmiValue(fmi2ValueReference id, int value);
+						void setFmiValue(fmi2ValueReference id, bool value);
+						void setFmiValue(fmi2ValueReference id, double value);
 					
-					«FOR v : inRulesResult.globalVars.entrySet»
-						«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
-					«ENDFOR»
+						int getFmiValueInteger(fmi2ValueReference id);
+						bool getFmiValueBoolean(fmi2ValueReference id);
+						double getFmiValueDouble(fmi2ValueReference id);
+					private:
+						
+						«adaptationName»* getRuleThis();
+						
+						/*in rules*/
+						«inRulesResult.functionSignatures.join("\n")»
+						
+						/*out rules*/
+						«outRulesResult.functionSignatures.join("\n")»
+						
+						«crtlRulesResult.functionSignatures.join("\n")»
+						
+						«FOR fmu : fmus»
+							shared_ptr<FmuComponent> «fmu.key»;
+						«ENDFOR»
+						
+						«FOR sv : sVars.entrySet»
+							«Conversions.fmiTypeToCppType(sv.value.type)» «sv.value.name»;
+							«IF sv.value.causality == SVCausality.input»
+								bool isSet«sv.value.name»;
+							«ENDIF»
+						«ENDFOR»
+						
+						«FOR v : outRulesResult.globalVars.entrySet»
+							«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
+						«ENDFOR»
+						
+						«FOR v : inRulesResult.globalVars.entrySet»
+							«Conversions.fmiTypeToCppType(v.value.key)» «v.key»;
+						«ENDFOR»
+				}
 			}
 		''';
 	}
 
 	/*
-	 * Compiles the source file constructor 
+	 * Compiles the source file constructor and destructor
 	 */
-	def String compileConstructor(String adaptationName, InOutRulesBlockResult outRuleResult,
+	def String compileDeAndConstructor(String adaptationName, InOutRulesBlockResult outRuleResult,
 		InOutRulesBlockResult inRuleResult, LinkedHashMap<String, ScalarVariable> sVars, String fmuName,
 		String fmuTypeName, String guid) {
 		return '''
-			«adaptationName»::«adaptationName»(shared_ptr<std::string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
+			«adaptationName»::«adaptationName»(shared_ptr<string> resourceLocation) : SemanticAdaptation(createInputRules(),createOutputRules())
 			{
 				«FOR v : outRuleResult.globalVars.entrySet»
 					«(v.key)» = «v.value.value»;
@@ -194,6 +263,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				«fmuName»Fmu->initialize();
 				this->«fmuName» = «fmuName»Fmu->instantiate("«fmuTypeName»",fmi2CoSimulation, "«guid»", true, true, make_shared<Callback>()); 
 			}
+			«adaptationName»::~«adaptationName»()
+			{
+			}
 		''';
 	}
 
@@ -218,7 +290,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		var sVarsOrdered = sVars.entrySet.filter[value.causality === SVCausality.output].groupBy[value.type];
 
 		for (SVType type : SVType.values) {
-			val functionSignature = '''«Conversions.fmiTypeToCppType(type)»  «adaptationName»::getFmiValue«Conversions.fmiTypeToCppTypeName(type)»(fmi2ValueReference id)''';
+			val functionSignature = '''«Conversions.fmiTypeToCppType(type)»  «adaptationName»::getFmiValue«type.toString»(fmi2ValueReference id)''';
 			val functionReturn = '''return «Conversions.fmiTypeToCppDefaultValue(type)»''';
 			if (sVarsOrdered.containsKey(type)) {
 				cpp.add(
@@ -300,10 +372,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 	 * Compiles the source file function executeInternalControlFlow.
 	 * Calculates necessary information on function signatures necessary for generation of the header file.
 	 */
-	def RulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String name,
-		LinkedHashMap<String, Pair<String, Integer>> svDefs) {
+	def RulesBlockResult compileControlRuleBlock(Iterable<ControlRuleBlock> crtlRuleBlocks, String adaptationClassName,
+		String adaptationName, LinkedHashMap<String, Pair<String, Integer>> svDefs) {
 		var cpp = "";
-		val visitor = new ControlConditionSwitch(name, svDefs);
+		val visitor = new ControlConditionSwitch(adaptationClassName, adaptationName, svDefs);
 		for (crtlRule : crtlRuleBlocks) {
 			cpp += visitor.doSwitch(crtlRule);
 		}
@@ -311,16 +383,23 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		return new RulesBlockResult(cpp, visitor.functionSignatures);
 	}
 
+	def String SplitAtSpaceAndRemoveFirst(String content) {
+		content.substring(content.indexOf(" ") + 1, content.length);
+	}
+
 	/*
 	 * Compiles the source file functions <in/out>_rule_<condition, body, flush>.
 	 * Calculates necessary information on global in/out variables necessary for generation of the header file.
 	 * Calculates necessary information on function signatures necessary for generation of the header file.
 	 */
 	def InOutRulesBlockResult compileInOutRuleBlocks(InputOutputType ioType, Iterable<InOutRules> rulesBlocks,
-		LinkedHashMap<String, Pair<String, Integer>> svDefs, String name) {
-		val visitor = if(ioType == InputOutputType.Input) new InRulesConditionSwitch(name,
-				svDefs) else new OutRulesConditionSwitch(name, svDefs);
-		val functionName = "create" + ioType + "Rules";
+		String adaptationClassName, String adaptationName,
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars) {
+		val visitor = if (ioType == InputOutputType.Input)
+				new InRulesConditionSwitch(adaptationClassName, adaptationName, mSVars)
+			else
+				new OutRulesConditionSwitch(adaptationClassName, adaptationName, mSVars);
+		val functionName = "create" + ioType + "Rules()";
 		var String cpp = "";
 		val ruleBlock = rulesBlocks.head;
 		if (ruleBlock !== null) {
@@ -331,20 +410,20 @@ class CppGenerator extends SemanticAdaptationGenerator {
 					createRulesFunction.add( 
 					'''
 						list->push_back(
-							(Rule<«name»>){
-								&«name»::«visitor.functionSignatures.get(i)»,
-								&«name»::«visitor.functionSignatures.get(i+1)»
-								&«name»::«visitor.functionSignatures.get(i+2)»
+							(Rule<«adaptationClassName»>){
+								&«adaptationClassName»::«visitor.functionSignatures.get(i).SplitAtSpaceAndRemoveFirst»,
+								&«adaptationClassName»::«visitor.functionSignatures.get(i+1).SplitAtSpaceAndRemoveFirst»
+								&«adaptationClassName»::«visitor.functionSignatures.get(i+2).SplitAtSpaceAndRemoveFirst»
 							});
 						
 					''');
 				}
-				val functionPrefix = '''shared_ptr<list<Rule<«name»>>>''';
+				val functionPrefix = '''shared_ptr<list<Rule<«adaptationClassName»>>>''';
 				visitor.functionSignatures.add(functionPrefix + " " + functionName + ";")
 				cpp += '''
-					«functionPrefix» «name»::«functionName»()
+					«functionPrefix» «adaptationClassName»::«functionName»
 					{
-						auto list = make_shared<list<Rule<«name»>>>()
+						auto list = make_shared<list<Rule<«adaptationClassName»>>>()
 						
 						«createRulesFunction.join("\n")»
 						
@@ -370,4 +449,27 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		}
 		return defines;
 	}
+
+	def ArrayList<SAScalarVariable> calcSASVsFromInportsOutports(String definePrefix, EList<Port> inports, EList<Port> outports) {
+		var saSVs = newArrayList();
+		
+		var int valueReference = 0;
+		for (inport : inports) {
+			var saSV = new SAScalarVariable();
+			saSV.valueReference = valueReference++;
+			saSV.name = inport.name;
+			saSV.defineName = (definePrefix + inport.name).toUpperCase
+			saSVs.add(saSV);
+		}
+
+		for (outport : outports) {
+			var saSV = new SAScalarVariable();
+			saSV.valueReference = valueReference++;
+			saSV.defineName = (definePrefix + outport.name).toUpperCase
+			saSV.name = outport.name;
+			saSVs.add(saSV);
+		}
+		
+		return saSVs;
+	}
 }

+ 23 - 15
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InOutRulesConditionSwitch.xtend

@@ -23,22 +23,30 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Declaration
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Literal
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.OutRulesBlock
+import java.util.ArrayList
 
 abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String> {
 
 	protected var LinkedHashMap<String, Pair<SVType, Object>> globalVars = newLinkedHashMap();
 	private var Pair<SVType, Object> lastVal;
 	protected final String adaptationName;
-	protected final LinkedHashMap<String, Pair<String, Integer>> scalars;
+	protected final String adaptationClassName;
 	private Integer count = 0;
 	private final String functionPrefix;
 	protected List<String> functionSignatures = newArrayList();
 	protected String externalVariableOwner;
-
-	new(String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars, String functionPrefix) {
+	protected final LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars;
+
+	new(
+		String adaptationClassName,
+		String adaptationName,
+		String functionPrefix,
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars
+	) {
 		this.adaptationName = adaptationName;
-		this.scalars = scalars;
+		this.adaptationClassName = adaptationClassName;
 		this.functionPrefix = functionPrefix;
+		this.mSVars = mSVars;
 	}
 
 	/**
@@ -47,8 +55,8 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 	 */
 	protected def String createFunctionSignature(String functionName, String type) {
 		val functionSignature = this.functionPrefix + functionName + this.count + "()";
-		this.functionSignatures.add(type + " " + functionSignature+";");
-		return type + " " + this.adaptationName + "::" + functionSignature;
+		this.functionSignatures.add(type + " " + functionSignature + ";");
+		return type + " " + this.adaptationClassName + "::" + functionSignature;
 	}
 
 	def void incrementCount() {
@@ -72,15 +80,19 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 		for (gVar : object.globalInVars) {
 			doSwitch(gVar)
 		}
-		for (dataRule : object.eAllContents.toIterable.filter(DataRule)) {
+		for (DataRule dataRule : object.eAllContents.toIterable.filter(DataRule)) {
 			this.incrementCount;
 			cpp += doSwitch(dataRule);
 		}
 		return cpp;
 	}
 
-	override String caseBoolLiteral(BoolLiteral object) {
-		return '''«object.value»''';
+	override String caseDataRule(DataRule object) {
+		return '''
+			«doSwitch(object.condition)»
+			«doSwitch(object.statetransitionfunction)»
+			«doSwitch(object.outputfunction)»
+		'''
 	}
 
 	override String caseRuleCondition(RuleCondition object) {
@@ -111,12 +123,8 @@ abstract class InOutRulesConditionSwitch extends SemanticAdaptationSwitch<String
 		''';
 	}
 
-	override String caseDataRule(DataRule object) {
-		return '''
-			«doSwitch(object.condition)»
-			«doSwitch(object.statetransitionfunction)»
-			«doSwitch(object.outputfunction)»
-		'''
+	override String caseBoolLiteral(BoolLiteral object) {
+		return '''«object.value»''';
 	}
 
 	override String defaultCase(EObject object) {

+ 19 - 7
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/InRulesConditionSwitch.xtend

@@ -3,25 +3,37 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
 import java.util.LinkedHashMap
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
+import java.util.ArrayList
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
 
 class InRulesConditionSwitch extends InOutRulesConditionSwitch {
 
-	private Boolean inOutput = false;
+	private Boolean inOutputFunction = false;
+	private Boolean inTransitionFunction = false;
 
-	new(String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars) {
-		super(adaptationName, scalars, "in_rule_");
+	new(String adaptationClassName, String adaptationName, LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars) {
+		super(adaptationClassName, adaptationName, "in_rule_", mSVars
+		);
+	}
+	
+	override String caseStateTransitionFunction(StateTransitionFunction object) {
+		this.inTransitionFunction = true;
+		val returnVal = super.caseStateTransitionFunction(object);
+		this.inTransitionFunction = false;
+		return returnVal;
 	}
 
 	override String caseCompositeOutputFunction(CompositeOutputFunction object) {
-		this.inOutput = true;
+		this.inOutputFunction = true;
 		val returnVal = super.caseCompositeOutputFunction(object);
-		this.inOutput = false;
+		this.inOutputFunction = false;
 		return returnVal;
 	}
 
 	override String caseAssignment(Assignment object) {
-		if (inOutput) {	'''
-			setValue(«object.lvalue.owner.name»,«scalars.get(object.lvalue.owner.name+object.lvalue.ref.name).key»,«doSwitch(object.expr)»);
+		// We need to record the assignments such that we can get the correct variability and such later on. In this case we are in input		
+		if (inOutputFunction) {	'''
+			setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr)»);
 		''';
 		} else {
 			super.caseAssignment(object);

+ 37 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MappedScalarVariable.java

@@ -0,0 +1,37 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+public class MappedScalarVariable {
+
+	private String define;
+	private int valueReference;
+	private ScalarVariable mappedSV;
+	public MappedScalarVariable(ScalarVariable sv) {
+		this.mappedSV = sv;
+	}
+	
+	public ScalarVariable getMappedSv()
+	{
+		return this.mappedSV;
+	}
+	
+	public void setDefine(String define)
+	{
+		this.define = define;
+	}
+	
+	public String getDefine()
+	{
+		return this.define;
+	}
+	
+	public void setValueReference(int valueReference)
+	{
+		this.valueReference = valueReference;
+	}
+	
+	public int getValueReference()
+	{
+		return this.valueReference;
+	}
+
+}

+ 9 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescription.xtend

@@ -20,6 +20,7 @@ class ModelDescription {
 	private final Document md;
 	private final String name;
 	private final String type;
+	//Get rid of these. We need more information anyways.
 	private var LinkedHashMap<String, Pair<String, Integer>> svDefs = newLinkedHashMap();
 	private var LinkedHashMap<String, ScalarVariable> svs = newLinkedHashMap();
 	private var String guid;
@@ -63,11 +64,15 @@ class ModelDescription {
 			val valueRef = node.attributes.getNamedItem("valueReference").nodeValue;
 			val name = this.name + nodeName;
 			val define = name.toUpperCase;
+			
 			this.svDefs.put(name, define -> Integer.parseInt(valueRef));
-			val sv = ScalarVariable.Create().setCausality(
-				SVCausality.valueOf(node.attributes.getNamedItem("causality").nodeValue)).setName(nodeName).setOwner(
-				this.name).setValueReference(valueRef).setIndex((i + 1).toString).setVariability(
-				node.attributes.getNamedItem("variability").nodeValue);
+			val sv = ScalarVariable.Create()
+				.setCausality(SVCausality.valueOf(node.attributes.getNamedItem("causality").nodeValue))
+				.setName(nodeName)
+				.setOwner(this.name)
+				.setValueReference(valueRef)
+				.setIndex((i + 1).toString)
+				.setVariability(node.attributes.getNamedItem("variability").nodeValue);
 
 			for (var j = 0; j < node.childNodes.length; j++) {
 				val subNode = node.childNodes.item(j);

+ 0 - 19
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend

@@ -46,25 +46,6 @@ public class ModelDescriptionCreator {
 		return this.sVars;
 	}
 
-	private def Document getModelDescription(File path) {
-		var ZipFile fmu = new ZipFile(path);
-		var Enumeration<? extends ZipEntry> entries = fmu.entries();
-		var boolean entryFound = false;
-		var ZipEntry locatedEntry;
-
-		while (!entryFound && entries.hasMoreElements()) {
-			var ZipEntry entry = entries.nextElement();
-			if (entry.name.equalsIgnoreCase("modelDescription.xml"))
-				locatedEntry = entry;
-		}
-		var DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
-		var DocumentBuilder builder = fac.newDocumentBuilder();
-		val is = fmu.getInputStream(locatedEntry)
-		var Document doc = builder.parse(is);
-		is.close();
-		return doc;
-	}
-
 	def void CalcContent(ModelDescription md) {
 		sVars.addAll(md.getSv().values);
 	}

+ 37 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreatorV2.java

@@ -0,0 +1,37 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+import org.eclipse.xtext.xbase.lib.Pair;
+
+// TODO: Add ports not mentioned in the sa file to the model description
+public class ModelDescriptionCreatorV2 {
+
+	ArrayList<SAScalarVariable> SVs;
+	ArrayList<SAScalarVariable> outputSVs;
+	
+	public ModelDescriptionCreatorV2(String adaptationName,
+			LinkedHashMap<String, Pair<SVType, Object>> globalOutputVars,
+			LinkedHashMap<String, Pair<SVType, Object>> globalInputVars,
+			LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables) {
+		int valueRef = 1;
+		
+		for (Entry<String, Pair<SVType, Object>> outputVar : globalOutputVars.entrySet()) {
+			// Find the corresponding correct SV value
+			MappedScalarVariable foundSV = null;
+			for (Entry<String, LinkedHashMap<String, MappedScalarVariable>> mSV : mappedScalarVariables.entrySet()) {
+				if (mSV.getValue().containsKey(outputVar.getKey())) {
+					foundSV = mSV.getValue().get(outputVar.getKey());
+					break;
+				}
+			}
+			if(foundSV != null)
+			{
+				SAScalarVariable saSV = new SAScalarVariable();
+			}
+		}
+
+	}
+}

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

@@ -7,17 +7,24 @@ import org.eclipse.xtext.xbase.lib.Pair;
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment;
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Port
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StateTransitionFunction
+import java.util.ArrayList
 
 public class OutRulesConditionSwitch extends InOutRulesConditionSwitch {
 
 
 	private boolean inBody = false;
 
-	new(String adaptationName, LinkedHashMap<String, Pair<String, Integer>> scalars) {
-		super(adaptationName, scalars, "out_rule_");
+	new(String adaptationClassName, 
+		String adaptationName,  
+
+		LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars) {
+		super(adaptationClassName, adaptationName, "out_rule_", mSVars);
 	}
 	
 	override String casePort(Port object){
-		return '''getValue(«this.externalVariableOwner»,«this.scalars.get(this.externalVariableOwner+object.name).key»)'''
+		//TODO getValueBoolean, getValueInteger, getValueString, getValueReal
+		val type = mSVars.get(this.externalVariableOwner).get(object.name).mappedSv.type.toString;
+		val define = mSVars.get(this.externalVariableOwner).get(object.name).define;
+		return '''getValue«type»(«this.externalVariableOwner»,«define»)'''
 	}
 }

+ 44 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ReturnInformation.java

@@ -0,0 +1,44 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+public class ReturnInformation {
+
+	private ScalarVariable sv;
+	private SVType type;
+	private String code;
+	
+	
+	public ReturnInformation() {
+		// TODO Auto-generated constructor stub
+	}
+
+
+	public String getCode() {
+		return code;
+	}
+
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+
+	public ScalarVariable getSv() {
+		return sv;
+	}
+
+
+	public void setSv(ScalarVariable sv) {
+		this.sv = sv;
+	}
+
+
+	public SVType getType() {
+		return type;
+	}
+
+
+	public void setType(SVType type) {
+		this.type = type;
+	}
+
+}

+ 18 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SAScalarVariable.java

@@ -0,0 +1,18 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+public class SAScalarVariable {
+
+	public MappedScalarVariable sv = null;
+	public String defineName;
+	public Integer valueReference;
+	private String name;
+	
+	public SAScalarVariable() {
+		// TODO Auto-generated constructor stub
+	}
+
+	public void setName(String name) {
+	  this.name = name;
+	}
+
+}

+ 9 - 9
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVType.java

@@ -1,9 +1,9 @@
-package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
-
-//Changing these names must be reflected in the ModelDescriptionBuilder as well
-public enum SVType {
-	Real,
-	String,
-	Int,
-	Bool
-}
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+//Changing these names must be reflected in the ModelDescriptionBuilder as well
+public enum SVType {
+	Real,
+	String,
+	Integer,
+	Boolean
+}

+ 5 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java

@@ -1,7 +1,5 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
 
-import java.util.Optional;
-
 public class ScalarVariable {
 	private String owner;
 	private String name;
@@ -17,7 +15,11 @@ public class ScalarVariable {
 	private ScalarVariable() {
 
 	}
-
+	
+	protected ScalarVariable(ScalarVariable var) {
+		
+	}
+	
 	public static ScalarVariable Create() {
 		return new ScalarVariable();
 	}