Browse Source

Created new tests
Started working on generating a modeldescription file based on the window sa

Casper Thule 4 years ago
parent
commit
8a3fc24769
18 changed files with 442 additions and 111 deletions
  1. 3 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend
  2. 7 9
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  3. BIN
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu
  4. 30 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/modelDescription.xml
  5. 0 13
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa
  6. 0 23
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_controller_delay.sa
  7. 0 27
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_model_only.sa
  8. 26 8
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend
  9. 26 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MapEntry.java
  10. 113 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionBuilder.java
  11. 101 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionCreator.xtend
  12. 9 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVCausality.java
  13. 9 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/SVType.java
  14. 91 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java
  15. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/power_window_case_study/window_sa_canonical.BASE.sa
  16. 22 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/BasicParserTest.xtend
  17. 0 23
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/ParserFolderTest.xtend
  18. 4 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/window_sa_canonical.BASE.sa

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

@@ -47,9 +47,9 @@ class CgCppAutoTest extends AbstractSemanticAdaptationTest {
 		listf("test_input/single_folder_spec", files);
 		val test = new ArrayList();
 		test.add(files.get(0));
-		val test2 = new ArrayList();
-		test2.add(files.get(1));
-		return Arrays.asList(test.toArray(), test2.toArray());
+		//val test2 = new ArrayList();
+		//test2.add(files.get(1));
+		return Arrays.asList(test.toArray());
 	}
 
 	def static void listf(String directoryName, List<List<File>> files) {

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

@@ -29,8 +29,8 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Inject extension ParseHelper<SemanticAdaptation>
 	@Inject extension  ValidationTestHelper
 
-	@Ignore
-	@Test def powerwindow_model_only() { __parseNoErrors('input/powerwindow_model_only.sa') }
+	
+	@Test def powerwindow_model_only() { __parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa') }
 
 	def __parseNoErrors(String filename) {
 		val model = __parse(filename)
@@ -38,9 +38,10 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 
 		val fsa = new InMemoryFileSystemAccess()
 		val IGeneratorContext ctxt = null;
-		new CppGenerator().doGenerate(model.eResource, fsa, ctxt)
-
-		System.out.println(fsa.allFiles)
+		new CppGenerator().doGenerate(model.eResource, fsa, ctxt);
+		
+		
+		System.out.println(fsa.allFiles)		
 	}
 
 	def __parseNoErrorsPrint(String filename) {
@@ -50,10 +51,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	}
 
 	def __parse(String filename) {
-		val model = readFile(filename).parse
-
-		return __parse('input/powerwindow_algebraic_loop_delay.sa',
-			__parse('input/powerwindow_controller_delay.sa', model.eResource.resourceSet).eResource.resourceSet)
+		return readFile(filename).parse
 	}
 
 	def __parse(String filename, ResourceSet resourceSetToUse) {

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window/Window.fmu


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

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<fmiModelDescription fmiVersion="2.0" modelName="SingleWatertank" guid="{cfc65592-9ece-4563-9705-1581b6e7071c}" generationTool="20-sim" numberOfEventIndicators="0" copyright="Controllab Products B.V." license="-">
+<CoSimulation modelIdentifier="SingleWatertank" needsExecutionTool="false" canHandleVariableCommunicationStepSize="true" canInterpolateInputs="false" maxOutputDerivativeOrder="0" canRunAsynchronuously="false" canBeInstantiatedOnlyOncePerProcess="true" canNotUseMemoryManagementFunctions="true" canGetAndSetFMUstate="false" canSerializeFMUstate="false" providesDirectionalDerivative="false" />
+
+<ModelVariables>
+<ScalarVariable name="reaction_force" valueReference="1" variability="continuous" causality="input">
+<Real start="0.0" />
+</ScalarVariable>
+<ScalarVariable name="displacement" valueReference="2" variability="continuous" causality="input">
+<Real start="0.0" />
+</ScalarVariable>
+<ScalarVariable name="speed" valueReference="3" variability="continuous" causality="input">
+<Real start="0.0" />
+</ScalarVariable>
+
+<ScalarVariable name="disp" valueReference="4" variability="continuous" causality="output">
+<Real />
+</ScalarVariable>
+<ScalarVariable name="tau" valueReference="5" variability="continuous" causality="output">
+<Real />
+</ScalarVariable>
+
+</ModelVariables>
+<ModelStructure>
+<Outputs>
+<Unknown index="4" />
+<Unknown index="5" />
+</Outputs>
+</ModelStructure>
+</fmiModelDescription>

+ 0 - 13
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_algebraic_loop_delay.sa

@@ -1,13 +0,0 @@
-import PowerWindowModel
-import Controller_SA
-
-module Algebraic_Loop_SA
-
-// this one could be joined with the one below, if we assume certain priorities in executing the rules
-semantic adaptation WindowSA window_sa
-at "./path/to/WindowSA.fmu"
-for fmu window
-out rules {
-	reaction_torque := -reaction_torque;
-	delay at reaction_torque and height;
-}

+ 0 - 23
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_controller_delay.sa

@@ -1,23 +0,0 @@
-import PowerWindowModel
-
-module Controller_SA
-
-semantic adaptation ArmatureCurrentSA armature_current_sa
-at "./path/to/ArmatureCurrentSA.fmu"
-for fmu controller
-triggered by signal == true
-in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
-	armature_current >! 5 -> obj_detected := true;
-	otherwise -> obj_detected := false;
-}
-
-semantic adaptation InOutSA in_out_sa
-at "./path/to/InOutSA.fmu"
-for fmu controller
-out rules with zero order hold {
-	"up" -> up := 1;
-	"stop" -> { up := 0; down := 0; };
-	"down" -> down := 1;
-	delay at up and down;
-}
-

+ 0 - 27
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/window2/powerwindow_model_only.sa

@@ -1,27 +0,0 @@
-module PowerWindowModel
-
-fmu Environment environment
-at "./path/to/Environment.fmu"
-output ports passenger_up, passenger_down, driver_up, driver_down
-
-fmu Controller controller
-at "./path/to/Controller.fmu"
-input ports obj_detected, passenger_up, passenger_down, driver_up, driver_down
-output ports up, down, stop
-
-fmu Power power
-at "./path/to/Power.fmu"
-input ports up, down, reaction_torque (N.m)
-output ports armature_current (mA), motor_speed (m/s)
-
-fmu Window window
-at "./path/to/Window.fmu"
-input ports motor_speed (m/s), reaction_force (N)
-output ports height (cm), reaction_torque (N.m)
-
-fmu Obstacle obstacle
-at "./path/to/Obstacle.fmu"
-input ports height (m)
-output ports reaction_force (N)
-
-power.armature_current -> controller.obj_detected

+ 26 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -1,21 +1,39 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
 
 import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationGenerator
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
 import org.eclipse.emf.ecore.resource.Resource
 import org.eclipse.xtext.generator.IFileSystemAccess2
 import org.eclipse.xtext.generator.IGeneratorContext
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.AtomicFMU
 
 class CppGenerator extends SemanticAdaptationGenerator {
+
+	var ModelDescriptionCreator mdCreator = new ModelDescriptionCreator()
+
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
 
-		for (type : resource.resourceSet.allContents.filter(typeof(SemanticAdaptation)).toIterable)
-			fsa.generateFile(type.name + ".cpp", '''
-				«FOR state : type.elements.filter(AtomicFMU)»
-					«state.name» = «state.path»
-				«ENDFOR»
-			''')
+		for (type : resource.allContents.toIterable.filter(SemanticAdaptation)){
+				fsa.generateFile(type.name + ".cpp", type.compile)
+				mdCreator.name = type.name;
+				fsa.generateFile("modelDescription.xml", mdCreator.modelDescription);
+		}
+	}
+
+// TODO: Verify adaptation.name is not a C++ keyword
+// TODO: Add initial value to inputs in the model description file
+	def CharSequence compile(SemanticAdaptation adaptation) {
+		var adaptationCharSequence = newArrayList()
+		for (type : adaptation.elements.filter(Adaptation)) {
+			mdCreator.CreateInputsOutput(type);
+			adaptationCharSequence.add(type.compile)
+		}
+
+		return adaptationCharSequence.join('''\n''');
+	}
 
+	def CharSequence compile(Adaptation adaptation) {
+		
+		return '''compiling «adaptation.toString»''';
 	}
 }

+ 26 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/MapEntry.java

@@ -0,0 +1,26 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.Map.Entry;
+
+public class MapEntry<K, V> implements Entry<K, V> {
+    private final K key;
+    private V value;
+    public MapEntry(final K key) {
+        this.key = key;
+    }
+    public MapEntry(final K key, final V value) {
+        this.key = key;
+        this.value = value;
+    }
+    public K getKey() {
+        return key;
+    }
+    public V getValue() {
+        return value;
+    }
+    public V setValue(final V value) {
+        final V oldValue = this.value;
+        this.value = value;
+        return oldValue;
+    }
+}

+ 113 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ModelDescriptionBuilder.java

@@ -0,0 +1,113 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.commons.cli.MissingArgumentException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ModelDescriptionBuilder {
+	private DocumentBuilderFactory docFactory;
+	private DocumentBuilder docBuilder;
+	private Document doc;
+	private Element rootElement;
+	private Element modelVariables;
+	private Element outputs;
+	private int valueReferenceCounter = 1;
+
+	public ModelDescriptionBuilder() throws ParserConfigurationException {
+		docFactory = DocumentBuilderFactory.newInstance();
+		docBuilder = docFactory.newDocumentBuilder();
+		doc = docBuilder.newDocument();
+		doc.setXmlStandalone(true);
+	}
+
+	public void CreateTemplate(String modelName, String guid) throws ParserConfigurationException {
+		rootElement = doc.createElement("fmiModelDescription");
+		doc.appendChild(rootElement);
+		rootElement.setAttribute("fmiVersion", "2.0");
+		rootElement.setAttribute("modelName", modelName);
+		rootElement.setAttribute("guid", guid);
+		rootElement.setAttribute("variableNamingConvention", "structured");
+
+		modelVariables = doc.createElement("ModelVariables");
+		rootElement.appendChild(modelVariables);
+
+		outputs = doc.createElement("Outputs");
+		rootElement.appendChild(outputs);
+	}
+
+	public String getNextValueReference() {
+		return Integer.toString(valueReferenceCounter++);
+	}
+
+	public void addScalarVariable(ScalarVariable var) {
+		Element sv = doc.createElement("ScalarVariable");
+		modelVariables.appendChild(sv);
+		if (var.getName() != null)
+			sv.setAttribute("name", var.getName());
+
+		if (var.getValueReference() != null)
+			sv.setAttribute("valueReference", var.getValueReference());
+
+		if (var.getDescription() != null)
+			sv.setAttribute("description", var.getDescription());
+
+		if (var.getVariability() != null)
+			sv.setAttribute("variability", var.getVariability());
+
+		if (var.getCausality() != null) {
+			sv.setAttribute("causality", var.getCausality().name());
+			if (var.getCausality() == SVCausality.output) {
+				outputs.appendChild(createUnknown(Integer.toString(modelVariables.getChildNodes().getLength())));
+			}
+		}
+
+		if (var.getType() != null) {
+			Element svType = getSvType(var.getType());
+			sv.appendChild(svType);
+			if (var.getStart() != null) {
+				svType.setAttribute("start", var.getStart());
+			}
+		}
+
+	}
+
+	private Element createUnknown(String index) {
+		Element e = doc.createElement("Unknown");
+		e.setAttribute("index", index);
+		return e;
+	}
+
+	private Element getSvType(SVType type) {
+		return doc.createElement(type.name());
+	}
+
+	@Override
+	public String toString() {
+		try {
+			StringWriter sw = new StringWriter();
+			TransformerFactory tf = TransformerFactory.newInstance();
+			Transformer transformer = tf.newTransformer();
+			transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+			transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+			transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+			transformer.transform(new DOMSource(doc), new StreamResult(sw));
+			return sw.toString();
+		} catch (Exception ex) {
+			throw new RuntimeException("Error converting to String", ex);
+		}
+	}
+
+}

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

@@ -0,0 +1,101 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.List;
+import java.util.Vector;
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InnerFMU
+import java.io.File
+import org.w3c.dom.Document
+import java.util.zip.ZipFile
+import java.util.Enumeration
+import java.util.zip.ZipEntry
+import javax.xml.parsers.DocumentBuilderFactory
+import javax.xml.parsers.DocumentBuilder
+import java.util.HashMap
+import java.util.Map
+import javax.xml.xpath.XPathFactory
+import javax.xml.xpath.XPath
+import javax.xml.xpath.XPathExpression
+import org.w3c.dom.Node
+import javax.xml.xpath.XPathConstants
+import java.util.UUID
+
+public class ModelDescriptionCreator {
+	private List<ScalarVariable> sVars = new Vector<ScalarVariable>();
+	private ModelDescriptionBuilder mdBuilder = new ModelDescriptionBuilder();
+	private String mdName;
+	private String guid;
+	def String getModelDescription(){
+		if(mdName === null){
+			throw new IllegalStateException("Model Description name is missing");		
+		}
+		mdBuilder.CreateTemplate(mdName, UUID.randomUUID().toString);
+		for(sVar : sVars)
+		{
+			mdBuilder.addScalarVariable(sVar);
+		}
+		
+		return mdBuilder.toString();
+	}
+
+	def void setName(String name){
+		mdName = name;
+	}
+	
+	private def Document getModelDescription(File path) {
+		System.out.println(path.absolutePath);
+		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 CreateInputsOutput(Adaptation adaptation) {
+		var Map<String, Document> wrappedFMUs = new HashMap<String, Document>();
+
+		var test = adaptation.inner.eAllContents.toIterable.filter(InnerFMU);
+		for (type : test) {
+			var file = new File(type.path.replace('\"', ''));
+			var modelDesc = getModelDescription(file);
+			wrappedFMUs.put(type.name, modelDesc);
+		}
+
+		val XPathFactory xPathfactory = XPathFactory.newInstance();
+		val XPath xpath = xPathfactory.newXPath();
+
+		for (port : adaptation.inports) {
+			for (Map.Entry<String,Document> entry : wrappedFMUs.entrySet()) {
+				// Get the input type
+				val XPathExpression expr = xpath.compile(
+					"/fmiModelDescription/ModelVariables/ScalarVariable[@name='" + port.name + "']/*[1]");
+				val Node nl = expr.evaluate(entry.value, XPathConstants.NODE) as Node;
+				sVars.add(
+					ScalarVariable.Create().setName(port.name).setValueReference(mdBuilder.nextValueReference).setCausality(
+						SVCausality.input).setType(SVType.valueOf(nl.nodeName)));
+			}
+		}
+
+		for (port : adaptation.outports) {
+			for (Map.Entry<String,Document> entry : wrappedFMUs.entrySet()) {
+				val XPathExpression expr = xpath.compile(
+					"/fmiModelDescription/ModelVariables/ScalarVariable[@name='" + port.name + "']/*[1]");
+				val Node nl = expr.evaluate(entry.value, XPathConstants.NODE) as Node;
+				sVars.add(
+					ScalarVariable.Create().setName(port.name).setValueReference(mdBuilder.nextValueReference).setCausality(
+						SVCausality.output).setType(SVType.valueOf(nl.nodeName)));
+			}
+		}
+	}
+}

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

@@ -0,0 +1,9 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+//Changing these names must be reflected in the ModelDescriptionBuilder as well
+public enum SVCausality {
+	output,
+	local,
+	input,
+	parameter,
+}

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

@@ -0,0 +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
+}

+ 91 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/ScalarVariable.java

@@ -0,0 +1,91 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp;
+
+import java.util.Optional;
+
+public class ScalarVariable {
+	private String name;
+	private String valueReference;
+	private String description;
+	private String variability;
+	private SVCausality causality;
+	private String initial;
+	private SVType type;
+	private String start;
+	private ScalarVariable(){
+		
+	}
+	public static ScalarVariable Create(){
+		return new ScalarVariable();
+	}
+	public String getName() {
+		return name;
+	}
+
+	public ScalarVariable setName(String name) {
+		this.name = name;
+		return this;
+	}
+
+	public String getValueReference() {
+		return valueReference;
+	}
+
+	public ScalarVariable setValueReference(String valueReference) {
+		this.valueReference = valueReference;
+		return this;
+	}
+
+	public String getVariability() {
+		return variability;
+	}
+
+	public ScalarVariable setVariability(String variability) {
+		this.variability = variability;
+		return this;
+	}
+
+	public SVCausality getCausality() {
+		return causality;
+	}
+
+	public ScalarVariable setCausality(SVCausality causality) {
+		this.causality = causality;
+		return this;
+	}
+
+	public String getInitial() {
+		return initial;
+	}
+
+	public ScalarVariable setInitial(String initial) {
+		this.initial = initial;
+		return this;
+	}
+
+	public SVType getType() {
+		return type;
+	}
+
+	public ScalarVariable setType(SVType type) {
+		this.type = type;
+		return this;
+	}
+
+	public String getStart() {
+		return start;
+	}
+
+	public ScalarVariable setStart(String start) {
+		this.start = start;
+		return this;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public ScalarVariable setDescription(String description) {
+		this.description = description;
+		return this;
+	}
+}

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

@@ -4,7 +4,7 @@ semantic adaptation reactive mealy WindowSA windowSA
 at "./path/to/WindowSA.fmu"
 
 	for inner fmu Window window
-		at "./path/to/WindowSA.fmu"
+		at "./path/to/Window.fmu"
 		with input ports displacement (rad), speed (rad/s), reaction_force (N)
 		with output ports height (m), reaction_torque (N.m)
 

+ 22 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/BasicParserTest.xtend

@@ -16,12 +16,34 @@ import static org.junit.Assert.fail
 import static com.google.common.collect.Iterables.isEmpty
 import static com.google.common.collect.Iterables.filter
 import org.eclipse.xtext.diagnostics.Severity
+import java.io.BufferedReader
+import java.io.FileReader
 
 abstract class BasicParserTest extends AbstractSemanticAdaptationTest {
 
 	@Inject extension ParseHelper<SemanticAdaptation>
 	@Inject extension  ValidationTestHelper
 
+	def getDependencies(File file) {
+		var List<String> dependencies = newArrayList;
+		val BufferedReader in = new BufferedReader(new FileReader(file));
+		var continue = true;
+		while (continue) {
+			val line = in.readLine();
+			if (line.contains("module")) {
+				continue = false;
+			} else if (line.contains("import")) {
+				val module = line.substring(line.indexOf("import") + 7, line.length());
+				dependencies.add(module);
+			}
+			continue = in.ready && continue;
+		}
+
+		in.close();
+
+		return dependencies;
+	}
+
 	def __parseNoErrors(File filename) {
 		val model = __parse(filename)
 		__assertNoParseErrors(model, filename)

+ 0 - 23
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/ParserFolderTest.xtend

@@ -61,27 +61,4 @@ abstract class ParserFolderTest extends BasicParserTest {
 
 		__assertNoParseErrors(model, null)
 	}
-
-	def getModuleName(File file) {
-	}
-
-	def getDependencies(File file) {
-		var List<String> dependencies = newArrayList;
-		val BufferedReader in = new BufferedReader(new FileReader(file));
-		var continue = true;
-		while (continue) {
-			val line = in.readLine();
-			if (line.contains("module")) {
-				continue = false;
-			} else if (line.contains("import")) {
-				val module = line.substring(line.indexOf("import") + 7, line.length());
-				dependencies.add(module);
-			}
-			continue = in.ready && continue;
-		}
-
-		in.close();
-
-		return dependencies;
-	}
 }

+ 4 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/testInputs/single_folder_spec/window2/window_sa_canonical.BASE.sa

@@ -4,7 +4,7 @@ semantic adaptation reactive mealy WindowSA windowSA
 at "./path/to/WindowSA.fmu"
 
 	for inner fmu Window window
-		at "./path/to/WindowSA.fmu"
+		at "./path/to/Window.fmu"
 		with input ports displacement (rad), speed (rad/s), reaction_force (N)
 		with output ports height (m), reaction_torque (N.m)
 
@@ -26,9 +26,9 @@ control {
 	return H;
 }
 
-in var 	stored_windowsa_reaction_force := 0, 
-		stored_windowsa_displacement := 0, 
-		stored_windowsa_speed := 0;
+in var 	stored_windowsa_reaction_force := 0.0, 
+		stored_windowsa_displacement := 0.0, 
+		stored_windowsa_speed := 0.0;
 
 in rules {
 	true -> {