Forráskód Böngészése

added cpp generation projects

Kenneth Lausdahl 8 éve
szülő
commit
17846806f5

+ 26 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/META-INF/MANIFEST.MF

@@ -0,0 +1,26 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
+Bundle-Vendor: My Company
+Bundle-Version: 1.0.0.qualifier
+Bundle-SymbolicName: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests; singleton:=true
+Bundle-ActivationPolicy: lazy
+Require-Bundle: 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,
+ be.uantwerpen.ansymo.semanticadaptation.cg.cpp;bundle-version="1.0.0",
+ be.uantwerpen.ansymo.semanticadaptation;bundle-version="1.0.0",
+ be.uantwerpen.ansymo.semanticadaptation.tests;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests;x-internal=true
+Import-Package: org.hamcrest.core,
+ org.junit;version="4.5.0",
+ org.junit.runners.model;version="4.5.0",
+ org.junit.runner;version="4.5.0",
+ org.junit.runners;version="4.5.0",
+ org.junit.runner.manipulation;version="4.5.0",
+ org.junit.runner.notification;version="4.5.0"

+ 5 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/build.properties

@@ -0,0 +1,5 @@
+source.. = src/,\
+           src-gen/,\
+           xtend-gen/
+bin.includes = .,\
+               META-INF/

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

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

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

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

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

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

+ 47 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/pom.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<relativePath>../pom.xml</relativePath>
+		<groupId>be.uantwerpen.ansymo.semanticadaptation</groupId>
+		<artifactId>parent</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests</artifactId>
+	<packaging>eclipse-test-plugin</packaging>
+
+	<name>be.uantwerpen.ansymo.semanticadaptation Code Generation to C++ Tests</name>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-clean-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>gen-clean</id>
+						<phase>clean</phase>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.eclipse.xtend</groupId>
+				<artifactId>xtend-maven-plugin</artifactId>
+			</plugin>
+
+
+			<plugin>
+				<!-- Remember that these tests only run in integration so between package and install http://www.vogella.com/tutorials/EclipseTycho/article.html -->
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-surefire-plugin</artifactId>
+				<version>${tycho-version}</version>
+				<configuration>
+					<useUIHarness>false</useUIHarness>
+					<useUIThread>false</useUIThread>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

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

@@ -0,0 +1,91 @@
+/*
+ * generated by Xtext 2.10.0
+ */
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
+
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
+import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
+import com.google.inject.Inject
+import java.util.regex.Pattern
+import org.eclipse.emf.ecore.EObject
+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.Test
+import org.junit.runner.RunWith
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.CppGenerator
+import org.eclipse.xtext.generator.InMemoryFileSystemAccess
+import org.eclipse.xtext.generator.IGeneratorContext
+
+@RunWith(XtextRunner)
+@InjectWith(SemanticAdaptationInjectorProvider)
+class CgCppBasicTest extends AbstractSemanticAdaptationTest {
+
+	// @Inject CppGenerator underTest
+	@Inject extension ParseHelper<SemanticAdaptation>
+	@Inject extension  ValidationTestHelper
+
+	@Test def powerwindow_model_only() { __parseNoErrors('input/powerwindow_model_only.sa') }
+
+	def __parseNoErrors(String filename) {
+		val model = __parse(filename)
+		__assertNoParseErrors(model, filename)
+
+		val fsa = new InMemoryFileSystemAccess()
+		val IGeneratorContext ctxt = null;
+		new CppGenerator().doGenerate(model.eResource, fsa, ctxt)
+
+		// println(fsa.textFiles)
+///println('Hello World!')
+		System.out.println(fsa.allFiles)
+	// cppGen.doGenerate(root,null,null);
+	}
+
+	def __parseNoErrorsPrint(String filename) {
+		val root = __parse(filename)
+		print_ast(root)
+		__assertNoParseErrors(root, filename)
+	}
+
+	def __parse(String filename) {
+		val model = readFile('input/powerwindow_controller_delay.sa').parse
+		val controller = readFile('input/powerwindow_model_only.sa').parse(model.eResource.resourceSet)
+		val algebraicloop = readFile('input/powerwindow_algebraic_loop_delay.sa').parse(
+			controller.eResource.resourceSet)
+		return readFile(filename).parse(algebraicloop.eResource.resourceSet)
+	}
+
+	def __assertNoParseErrors(EObject root, String filename) {
+		try {
+			root.assertNoErrors
+		} catch (AssertionError e) {
+			val p = Pattern.compile(".*, offset (?<offset>[0-9]+), length (?<length>[0-9]+)")
+			val code = readFile(filename)
+			for (String line : e.message.split("\n")) {
+				val m = p.matcher(line)
+				m.matches()
+				val count = __occurrencesInString(code.subSequence(0, Integer.valueOf(m.group("offset"))).toString(),
+					"\n")
+				print(filename + " at line " + (count + 1) + ": ")
+				println(line)
+			}
+			throw e
+		}
+	}
+
+	def __occurrencesInString(String str, String findstr) {
+		var lastIndex = 0
+		var count = 0
+		while (lastIndex != -1) {
+			lastIndex = str.indexOf(findstr, lastIndex)
+			if (lastIndex != -1) {
+				count++
+				lastIndex += findstr.length()
+			}
+		}
+		return count
+	}
+
+}

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

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

+ 17 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/build.properties

@@ -0,0 +1,17 @@
+source.. = src/,\
+           src-gen/,\
+           xtend-gen/
+bin.includes = .,\
+               META-INF/,\
+               plugin.xml
+additional.bundles = org.eclipse.xtext.xbase,\
+                     org.eclipse.xtext.common.types,\
+                     org.eclipse.xtext.xtext.generator,\
+                     org.eclipse.emf.codegen.ecore,\
+                     org.eclipse.emf.mwe.utils,\
+                     org.eclipse.emf.mwe2.launch,\
+                     org.eclipse.emf.mwe2.lib,\
+                     org.objectweb.asm,\
+                     org.apache.commons.logging,\
+                     org.apache.log4j,\
+                     com.ibm.icu

+ 5 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/plugin.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="windows-1252"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+</plugin>

+ 22 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/pom.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<relativePath>../pom.xml</relativePath>
+		<groupId>be.uantwerpen.ansymo.semanticadaptation</groupId>
+		<artifactId>parent</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>be.uantwerpen.ansymo.semanticadaptation.cg.cpp</artifactId>
+	<packaging>eclipse-plugin</packaging>
+
+	<name>be.uantwerpen.ansymo.semanticadaptation Code Generation to C++</name>
+
+	<properties>
+    <main.basedir>${project.parent.basedir}</main.basedir>
+	</properties>
+
+
+</project>

+ 21 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/CppGenerator.xtend

@@ -0,0 +1,21 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp
+
+import be.uantwerpen.ansymo.semanticadaptation.generator.SemanticAdaptationGenerator
+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 {
+	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
+
+		for (type : resource.allContents.filter(typeof(SemanticAdaptation)).toIterable)
+			fsa.generateFile(type.name + ".cpp", '''
+				«FOR state : type.elements.filter(AtomicFMU)»
+					«state.name» = «state.path»
+				«ENDFOR»
+			''')
+
+	}
+}

+ 84 - 66
DSL_SemanticAdaptation/pom.xml

@@ -15,6 +15,8 @@
 		<module>be.uantwerpen.ansymo.semanticadaptation.tests</module>
 		<module>be.uantwerpen.ansymo.semanticadaptation.ide</module>
 		<module>be.uantwerpen.ansymo.semanticadaptation.ui</module>
+		<module>be.uantwerpen.ansymo.semanticadaptation.cg.cpp</module>
+	  <module>be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests</module>
 		<!--module>../my.mavenized.herolanguage.ui</module>
 				<module>../my.mavenized.herolanguage.tests</module>
 				<module>../my.mavenized.herolanguage.sdk</module>
@@ -26,7 +28,7 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<xtext.version>2.11.0</xtext.version>
 
- <main.basedir>${project.basedir}</main.basedir>
+		<main.basedir>${project.basedir}</main.basedir>
 	</properties>
 
 	<repositories>
@@ -44,73 +46,89 @@
 
 
 		<!--repository>
-      <id>mvn</id>
-      <url>http://mvnrepository.com/artifact</url>
-    </repository-->
+				<id>mvn</id>
+				<url>http://mvnrepository.com/artifact</url>
+			</repository-->
 
-	</repositories>
-	<build>
-		<pluginManagement>
-			<plugins>
-				<!-- xtend-maven-plugin is in pluginManagement instead of in plugins 
-						 so that it doesn't run before the exec-maven-plugin's *.mwe2 gen; this way 
-						 we can list it after. -->
+		</repositories>
+		<build>
+			<pluginManagement>
+				<plugins>
 
+					<!-- Configure the compiler for all Overture Projects -->
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-compiler-plugin</artifactId>
+						<version>3.5.1</version>
+						<configuration>
+							<source>1.8</source>
+							<target>1.8</target>
+						</configuration>
+					</plugin>
+
+
+
+
+
+					<!-- xtend-maven-plugin is in pluginManagement instead of in plugins 
+							 so that it doesn't run before the exec-maven-plugin's *.mwe2 gen; this way 
+							 we can list it after. -->
+
+					<plugin>
+						<groupId>org.eclipse.xtend</groupId>
+						<artifactId>xtend-maven-plugin</artifactId>
+						<version>${xtext.version}</version>
+						<executions>
+							<execution>
+								<goals>
+									<goal>compile</goal>
+									<goal>xtend-install-debug-info</goal>
+									<goal>testCompile</goal>
+									<goal>xtend-test-install-debug-info</goal>
+								</goals>
+							</execution>
+						</executions>
+						<configuration>
+
+							<xtendAsPrimaryDebugSource>true</xtendAsPrimaryDebugSource>
+							<!--outputDirectory>${project.build.directory}/xtend-gen/main</outputDirectory-->
+							<testOutputDirectory>${project.build.directory}/xtend-gen/test</testOutputDirectory>
+							<writeTraceFiles>true</writeTraceFiles>
+
+
+							<outputDirectory>xtend-gen</outputDirectory>
+						</configuration>
+					</plugin>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-clean-plugin</artifactId>
+						<version>2.5</version>
+						<executions>
+							<execution>
+								<id>gen-clean</id>
+								<goals>
+									<goal>clean</goal>
+								</goals>
+								<configuration>
+									<filesets>
+										<fileset>
+											<directory>${basedir}/xtend-gen</directory>
+										</fileset>
+									</filesets>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</pluginManagement>
+
+			<plugins>
 				<plugin>
-					<groupId>org.eclipse.xtend</groupId>
-					<artifactId>xtend-maven-plugin</artifactId>
-					<version>${xtext.version}</version>
-					<executions>
-						<execution>
-							<goals>
-								<goal>compile</goal>
-								<goal>xtend-install-debug-info</goal>
-								<goal>testCompile</goal>
-								<goal>xtend-test-install-debug-info</goal>
-							</goals>
-						</execution>
-					</executions>
-					<configuration>
-
-						<xtendAsPrimaryDebugSource>true</xtendAsPrimaryDebugSource>
-            <!--outputDirectory>${project.build.directory}/xtend-gen/main</outputDirectory-->
-            <testOutputDirectory>${project.build.directory}/xtend-gen/test</testOutputDirectory>
-            <writeTraceFiles>true</writeTraceFiles>
-
-
-						<outputDirectory>xtend-gen</outputDirectory>
-					</configuration>
-				</plugin>
-				<plugin>
-					<groupId>org.apache.maven.plugins</groupId>
-					<artifactId>maven-clean-plugin</artifactId>
-					<version>2.5</version>
-					<executions>
-						<execution>
-							<id>gen-clean</id>
-							<goals>
-								<goal>clean</goal>
-							</goals>
-							<configuration>
-								<filesets>
-									<fileset>
-										<directory>${basedir}/xtend-gen</directory>
-									</fileset>
-								</filesets>
-							</configuration>
-						</execution>
-					</executions>
+					<groupId>org.eclipse.tycho</groupId>
+					<artifactId>tycho-maven-plugin</artifactId>
+					<version>${tycho-version}</version>
+					<extensions>true</extensions>
 				</plugin>
 			</plugins>
-		</pluginManagement>
-
-		<plugins>
-			<plugin>
-				<groupId>org.eclipse.tycho</groupId>
-				<artifactId>tycho-maven-plugin</artifactId>
-				<version>${tycho-version}</version>
-				<extensions>true</extensions>
-			</plugin>
-		</plugins>
-	</build>
-</project>
+		</build>
+	</project>