Browse Source

chain and tests running

Cláudio Gomes 6 years ago
parent
commit
2825ad3d9d
10 changed files with 76 additions and 43 deletions
  1. 3 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.canonical/src/be/uantwerpen/ansymo/semanticadaptation/cg/canonical/SemanticAdaptationCanonicalGenerator.xtend
  2. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/META-INF/MANIFEST.MF
  3. 1 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/plugin.xml
  4. 9 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/src/be/uantwerpen/ansymo/semanticadaptation/cg/chain/SemanticAdaptationChainGenerator.xtend
  5. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppAutoTest.xtend
  6. 7 8
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend
  7. 2 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF
  8. 3 8
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java
  9. 33 9
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend
  10. 16 12
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescription.xtend

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

@@ -61,7 +61,7 @@ class SemanticAdaptationCanonicalGenerator {
 	
 	String CANONICAL_SUFIX = "_canonical"
 	
-	def doGenerate(Adaptation adaptation, IFileSystemAccess2 fsa, URI mainFile) {
+	def Adaptation doGenerate(Adaptation adaptation, IFileSystemAccess2 fsa, URI mainFile) {
 		Log.push("Generating canonical semantic adaptation for file...")
 		
 		Log.println(prettyprint_model(adaptation, "File Read"))
@@ -90,6 +90,8 @@ class SemanticAdaptationCanonicalGenerator {
 		}
 		
 		Log.pop("Generating canonical semantic adaptation for file... DONE")
+		
+		return adaptation
 	}
 	
 	def prettyprint_model(Adaptation sa, String title){

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/META-INF/MANIFEST.MF

@@ -10,4 +10,4 @@ Import-Package: be.uantwerpen.ansymo.semanticadaptation.log
 Require-Bundle: be.uantwerpen.ansymo.semanticadaptation;bundle-version="1.0.0",
  be.uantwerpen.ansymo.semanticadaptation.cg.canonical;bundle-version="1.0.0",
  org.eclipse.xtext.generator;bundle-version="2.11.0",
- org.eclipse.emf.common.source;bundle-version="2.12.0"
+ be.uantwerpen.ansymo.semanticadaptation.cg.cpp;bundle-version="1.0.0"

+ 1 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.chain/plugin.xml

@@ -3,6 +3,7 @@
 <plugin>
    <extension
          id="chain_generator_extension"
+         name="chain_generator_extension"
          point="be.uantwerpen.ansymo.semanticadaptation.generator_extension">
       <generator
             class="be.uantwerpen.ansymo.semanticadaptation.cg.chain.SemanticAdaptationChainGenerator">

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

@@ -4,6 +4,7 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.chain
 
 import be.uantwerpen.ansymo.semanticadaptation.cg.canonical.SemanticAdaptationCanonicalGenerator
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationCustomGenerator
 import be.uantwerpen.ansymo.semanticadaptation.log.Log
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
@@ -15,7 +16,14 @@ class SemanticAdaptationChainGenerator extends SemanticAdaptationCustomGenerator
 	override void generate(Adaptation sa, IFileSystemAccess2 fsa, URI mainFile){
 		Log.push("SemanticAdaptationChainGenerator.generate")
 		
-		(new SemanticAdaptationCanonicalGenerator).doGenerate(sa, fsa, mainFile)
+		val canonical_sa = (new SemanticAdaptationCanonicalGenerator).doGenerate(sa, fsa, mainFile)
+		
+		Log.push("Generating cpp code...")
+		
+		val cppGen = new CppGenerator();
+		cppGen.doGenerate(canonical_sa.eResource, fsa);
+		
+		Log.pop("Generating cpp code... DONE")
 		
 		Log.pop("SemanticAdaptationChainGenerator.generate")
 	}

+ 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)
 	}

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

@@ -6,6 +6,7 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.BuildUtilities
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import be.uantwerpen.ansymo.semanticadaptation.testframework.StaticGenerators
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
 import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
 import com.google.inject.Inject
@@ -13,19 +14,19 @@ import java.io.File
 import java.io.FileWriter
 import java.nio.file.Files
 import java.util.regex.Pattern
+import org.eclipse.emf.common.CommonPlugin
+import org.eclipse.emf.common.util.URI
 import org.eclipse.emf.ecore.EObject
 import org.eclipse.emf.ecore.resource.ResourceSet
-import org.eclipse.xtext.generator.IGeneratorContext
 import org.eclipse.xtext.generator.InMemoryFileSystemAccess
 import org.eclipse.xtext.testing.InjectWith
 import org.eclipse.xtext.testing.XtextRunner
 import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
+import org.junit.Assert
+import org.junit.Ignore
 import org.junit.Test
 import org.junit.runner.RunWith
-import be.uantwerpen.ansymo.semanticadaptation.testframework.StaticGenerators
-import org.junit.Ignore
-import org.junit.Assert
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
@@ -71,9 +72,8 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		val correctFileDirectory = new File(directory + File.separator + "correct");
 
 		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);
@@ -124,9 +124,8 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		__assertNoParseErrors(model, filename)
 
 		val fsa = new InMemoryFileSystemAccess();
-		val IGeneratorContext ctxt = null;
 		val cppGen = new CppGenerator();
-		cppGen.doGenerate(model.eResource, fsa, ctxt);
+		cppGen.doGenerate(model.eResource, fsa, CommonPlugin.resolve(URI.createFileURI(".")));
 
 		if (saRootDir.exists) {
 			BuildUtilities.deleteFolder(srcGenPath);

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/META-INF/MANIFEST.MF

@@ -15,5 +15,6 @@ Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  org.eclipse.xtext.xbase.testing,
  org.eclipse.xtext.util
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.apache.log4j
+Import-Package: be.uantwerpen.ansymo.semanticadaptation.log,
+ org.apache.log4j
 Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation

+ 3 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java

@@ -1,17 +1,12 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.StandardCopyOption;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
+
+import be.uantwerpen.ansymo.semanticadaptation.log.Log;
 
 public class BuildUtilities {
 //	public List<File> copyNativeLibFiles(File outfolder) {
@@ -81,7 +76,7 @@ public class BuildUtilities {
 		FileWriter writer = new FileWriter(file);
 		writer.write(content);
 		writer.close();
-		System.out.println("Stored file: " + file);
+		Log.println("Stored file: " + file);
 	}
 
 	public static void copyFile(File sourceFile, File sinkFile) throws IOException {

+ 33 - 9
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -9,6 +9,7 @@ import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.exceptions.IncorrectAmountOfElementsException
+import be.uantwerpen.ansymo.semanticadaptation.log.Log
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Adaptation
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InOutRules
@@ -25,23 +26,34 @@ import java.util.LinkedHashMap
 import java.util.List
 import org.eclipse.emf.common.util.EList
 import org.eclipse.emf.ecore.resource.Resource
-import org.eclipse.xtext.generator.AbstractGenerator
 import org.eclipse.xtext.generator.IFileSystemAccess2
-import org.eclipse.xtext.generator.IGeneratorContext
+import org.eclipse.emf.common.CommonPlugin
+import org.eclipse.emf.common.util.URI
 
-class CppGenerator extends AbstractGenerator {
+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) {
+		Log.push("CppGenerator.compile")
 		for (Adaptation adap : adaptation.elements.filter(Adaptation)) {
 			// Value used for scoping variables in the .sa file
 			val adapInteralRefName = adap.name;
@@ -70,14 +82,15 @@ class CppGenerator extends AbstractGenerator {
 			 * The mappedSV contains the original scalar variable and extra data such as define name.
 			 */
 			var LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mappedScalarVariables = newLinkedHashMap();
-
+			
 			/*
 			 * Loading the FMU defined in InnerFMU, the related model description file and its scalar variables.
 			 */
 			// TODO: Add support for multiple inner fmus
 			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);
 				fmus.add(fmu.name -> fmu.type.name);
@@ -88,6 +101,7 @@ class CppGenerator extends AbstractGenerator {
 					mSV.put(mappedSv.mappedSv.name, mappedSv);
 				}
 				mappedScalarVariables.put(fmu.name, mSV);
+				Log.pop("Loading fmu " + fmu.path)
 			}
 
 			// C++ Defines for accessing FMU scalar variables.
@@ -194,6 +208,16 @@ class CppGenerator extends AbstractGenerator {
 			fsa.generateFile("Fmu.cpp", fmuCppFile);
 
 		}
+		Log.pop("CppGenerator.compile")
+	}
+	
+	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) {

+ 16 - 12
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/ModelDescription.xtend

@@ -1,23 +1,24 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
-import org.w3c.dom.Document
-import java.util.LinkedHashMap
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVVariability
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ScalarVariable
-import java.util.zip.ZipFile
+import be.uantwerpen.ansymo.semanticadaptation.log.Log
+import java.io.File
 import java.util.Enumeration
+import java.util.LinkedHashMap
 import java.util.zip.ZipEntry
-import java.io.File
-import javax.xml.parsers.DocumentBuilderFactory
+import java.util.zip.ZipFile
 import javax.xml.parsers.DocumentBuilder
-import javax.xml.xpath.XPathFactory
+import javax.xml.parsers.DocumentBuilderFactory
+import javax.xml.soap.Node
 import javax.xml.xpath.XPath
-import javax.xml.xpath.XPathExpression
 import javax.xml.xpath.XPathConstants
+import javax.xml.xpath.XPathExpression
+import javax.xml.xpath.XPathFactory
+import org.w3c.dom.Document
 import org.w3c.dom.NodeList
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVCausality
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVVariability
-import javax.xml.soap.Node
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
 
 class ModelDescription {
 	private final Document md;
@@ -29,10 +30,12 @@ class ModelDescription {
 	private var String guid;
 
 	new(String name, String type, File path) {
+		Log.push("Loading model description for fmu " + name)
 		this.name = name;
 		this.type = type;
 		
-
+		Log.println("Source fmu absolute path: " + path.absolutePath)
+		
 		var ZipFile fmu = new ZipFile(path);
 		var Enumeration<? extends ZipEntry> entries = fmu.entries();
 		var boolean entryFound = false;
@@ -52,6 +55,7 @@ class ModelDescription {
 		this.md = builder.parse(is);
 		is.close();
 		calcExtractInformation();
+		Log.pop("Loading model description for fmu " + name)
 	}
 
 	private def calcExtractInformation() {