Browse Source

added optional type declaration to var declarations. Can be used to support type inference.

Cláudio Gomes 3 years ago
parent
commit
b6cb1b4752

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa.BASE.sa

@@ -3,7 +3,7 @@ at "./path/to/WindowSA.fmu"
 
 	for inner fmu Window window
 		at "./path/to/Window.fmu"
-		with input ports displacement (rad), speed (rad/s), reaction_force (N)
+		with input ports displacement(rad), speed (rad/s), reaction_force (N)
 		with output ports height (cm), reaction_torque (N.m)
 
 output ports disp (m)  <- window.height, tau

+ 56 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa_canonical_types.BASE.sa

@@ -0,0 +1,56 @@
+semantic adaptation reactive mealy WindowSA windowSA
+at "./path/to/WindowSA.fmu"
+
+	for inner fmu Window window
+		at "./path/to/Window.fmu"
+		with input ports Real displacement (rad), Real speed (rad/s), Real reaction_force (N)
+		with output ports Real height (m), Real reaction_torque (N.m)
+
+input ports 	Real reaction_force,
+				Real displacement,
+				Real speed
+
+output ports	Real disp,
+				Real tau
+
+param 	Real INIT_WINDOWSA_REACTION_FORCE := 0.0,
+		Real INIT_WINDOWSA_DISPLACEMENT := 0.0,
+		Real INIT_WINDOWSA_SPEED := 0.0,
+		Real INIT_WINDOW_REACTION_TORQUE := 0.0,
+		Real INIT_WINDOW_REACTION_HEIGHT := 0.0;
+
+control rules {
+	var Real H_window := do_step(window, t, H);
+	return H_window;
+}
+
+in var 	Real stored_windowsa_reaction_force := INIT_WINDOWSA_REACTION_FORCE, 
+		Real stored_windowsa_displacement := INIT_WINDOWSA_DISPLACEMENT, 
+		Real stored_windowsa_speed := INIT_WINDOWSA_SPEED;
+
+in rules {
+	true -> {
+		stored_windowsa_reaction_force := windowSA.reaction_force;
+		stored_windowsa_displacement := windowSA.displacement;			
+		stored_windowsa_speed := windowSA.speed;
+	} --> {
+		window.reaction_force := stored_windowsa_reaction_force;
+		window.displacement := stored_windowsa_displacement; 
+		window.speed := stored_windowsa_speed;
+	};
+}
+
+out var Real stored_window_reaction_torque := INIT_WINDOW_REACTION_TORQUE,
+		Real stored_window_height := INIT_WINDOW_REACTION_HEIGHT;
+
+out rules {
+	true -> {
+		stored_window_reaction_torque := window.reaction_torque;
+		stored_window_height := window.height;
+	} --> {
+		windowSA.disp := stored_window_height / 100;
+	};
+	true -> { } --> {
+		windowSA.tau := -stored_window_reaction_torque;
+	};
+}

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

@@ -185,15 +185,20 @@ Port:
 	// TODO: add initial values to ports (to do 1st, 2nd, ... order stuff)
 	// TODO: add internal destination/source of port
 	// Unity conversions: https://pint.readthedocs.io/en/0.7.2/
+	(TypeDefinition)?
 	name=ID 
 	(':=' initval=LiteralOrArray)? 
-	( multiplicity=Multiplicity )? 
+	( multiplicity=Multiplicity )?
 	( '(' unity=Unity ')' )? 
 	(('->' targetdependency+=SpecifiedPort)
 		| ('<-' sourcedependency+=SpecifiedPort)
 	)?;
 	// TODO: -> output port of wrapped FMU to output port of SA FMU (only used in SA!)
 
+TypeDefinition:
+	'Real' | 'Integer' | 'String' | 'Bool'
+;
+
 Multiplicity:
 	'[' (lower=INT '..')? upper=INT ']';
 
@@ -233,7 +238,7 @@ Declaration:
 	'var' declarations+=SingleVarDeclaration ("," declarations+=SingleVarDeclaration)* ';'
 ;
 SingleVarDeclaration:
-	name=ID (':=' expr=Expression)?
+	(TypeDefinition)? name=ID (':=' expr=Expression)?
 ;
 
 ParamDeclarations:
@@ -242,7 +247,7 @@ ParamDeclarations:
 ;
 
 SingleParamDeclaration:
-	name=ID ':=' expr=Expression
+	(TypeDefinition)? name=ID ':=' expr=Expression
 ;
 
 ReturnStatement: