summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Karlitschek2012-05-16 05:42:42 (EDT)
committerPeter Karlitschek2012-05-16 05:42:42 (EDT)
commitfa0f7f8bc0ffbd23b18bef9bbb4c4512d006f85c (patch)
tree81739c28893e259a8ece91f149d374a1b6a42aaa
parent2b774ae76666b7bbd0432b7940fc0b0e34d43b67 (diff)
downloadorg.eclipse.etrice-fa0f7f8bc0ffbd23b18bef9bbb4c4512d006f85c.zip
org.eclipse.etrice-fa0f7f8bc0ffbd23b18bef9bbb4c4512d006f85c.tar.gz
org.eclipse.etrice-fa0f7f8bc0ffbd23b18bef9bbb4c4512d006f85c.tar.bz2
Commit current status of cpp codegenerator before pulling Henrikschange/8118/1refs/changes/18/8118/1
changes.
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/.classpath8
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/.project34
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF17
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/Main.classbin0 -> 5142 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.classbin0 -> 6150 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend116
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.classbin0 -> 1809 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.classbin0 -> 3232 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$1.classbin0 -> 1639 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$2.classbin0 -> 1548 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$3.classbin0 -> 1639 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$4.classbin0 -> 1548 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.classbin0 -> 17709 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend218
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.classbin0 -> 2290 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend52
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.classbin0 -> 1484 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/build.properties4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java116
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend116
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java31
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java69
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend218
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend52
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java47
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java169
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java595
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.java41
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/.classpath7
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/.gitignore2
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/.project28
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/META-INF/MANIFEST.MF21
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/build.properties6
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/icons/eTrice-launch.gifbin0 -> 894 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/plugin.xml32
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/Activator.java53
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorConfigTab.java236
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationDelegate.java61
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationTabGroup.java24
-rw-r--r--plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorMainTab.java32
42 files changed, 2420 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/.classpath b/plugins/org.eclipse.etrice.generator.cpp/.classpath
new file mode 100644
index 0000000..54357e3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="xtend-gen"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.generator.cpp/.project b/plugins/org.eclipse.etrice.generator.cpp/.project
new file mode 100644
index 0000000..0732648
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.generator.cpp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f287d53
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5d8d9d2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: C++ Generator
+Bundle-SymbolicName: org.eclipse.etrice.generator.cpp
+Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.1.0",
+ org.eclipse.etrice.generator;bundle-version="0.1.0",
+ org.eclipse.core.resources;bundle-version="3.6.0",
+ org.eclipse.core.runtime;bundle-version="3.6.0",
+ org.eclipse.ui;bundle-version="3.7.0",
+ org.eclipse.ui.ide;bundle-version="3.7.0",
+ org.eclipse.xtext.xtend2.lib;bundle-version="2.1.1",
+ org.eclipse.etrice.generator.doc;bundle-version="0.1.0",
+ org.eclipse.xtext;bundle-version="2.1.1"
+Bundle-Version: 0.2.0.qualifier
+Bundle-Vendor: eTrice (Incubation)
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.eclipse.etrice.generator.cpp
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/Main.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/Main.class
new file mode 100644
index 0000000..c16afb9
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/Main.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.class
new file mode 100644
index 0000000..750fb90
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
new file mode 100644
index 0000000..8fb9d90
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
+import java.util.List
+import org.eclipse.xtext.util.Pair
+
+
+@Singleton
+class CppExtensions implements ILanguageExtension {
+
+ @Inject AbstractTransitionChainGenerator chainGenerator
+
+
+ override String getTypedDataDefinition(Message m) {
+ return chainGenerator.generateTypedData(m)
+ }
+
+
+ def String getCppHeaderFileName(RoomClass rc) {rc.name+".h"}
+ def String getCppSourceFileName(RoomClass rc) {rc.name+".cpp"}
+
+ override String accessLevelPrivate() {""}
+ override String accessLevelProtected() {""}
+ override String accessLevelPublic() {""}
+
+ override String memberAccess() {"this->"}
+ override String selfPointer(String classname, boolean hasArgs) {""}
+ override String selfPointer(boolean hasArgs) { "" }
+
+ override String operationScope(String classname, boolean isDeclaration) {""}
+
+
+ override String memberInDeclaration(String namespace, String member) {
+ return member
+ }
+
+ override String memberInUse(String namespace, String member) {
+ return namespace+"."+member
+ }
+
+ override boolean usesInheritance() {
+ return true
+ }
+
+ override String genEnumeration(String name, List<Pair<String, String>> entries) {
+ '''
+ «FOR entry: entries»
+ public static final int «entry.first» = «entry.second»;
+ «ENDFOR»
+ '''.toString
+ }
+
+ override String booleanConstant(boolean b) {
+ b.toString
+ }
+
+ override String pointerLiteral() { "" }
+ override String nullPointer() { "null" }
+ override String voidPointer() { "Object" }
+
+ override String arrayDeclaration(String type, int size, String name, boolean isRef) {
+ type+" "+name+"[]";
+ }
+
+ override String constructorName(String cls) {
+ cls
+ }
+ override String destructorName(String cls) {
+ cls+"_dtor"
+ }
+ override String constructorReturnType() {
+ ""
+ }
+ override String destructorReturnType() {
+ "void"
+ }
+
+ def getIncludeGuardString(String filename){
+ '''_«filename.toUpperCase»_H_'''
+ }
+
+ def generateIncludeGuardBegin(String filename){'''
+ #ifndef «filename.getIncludeGuardString»
+ #define «filename.getIncludeGuardString»
+ '''
+ }
+
+ def generateIncludeGuardEnd(String filename){'''
+ #endif /* «filename.getIncludeGuardString» */
+ '''
+ }
+
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.class
new file mode 100644
index 0000000..2d41b79
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.class
new file mode 100644
index 0000000..0bed8d5
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$1.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$1.class
new file mode 100644
index 0000000..c13ade3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$1.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$2.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$2.class
new file mode 100644
index 0000000..d9cc97d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$2.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$3.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$3.class
new file mode 100644
index 0000000..b41de37
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$3.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$4.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$4.class
new file mode 100644
index 0000000..6f25c01
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen$4.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.class
new file mode 100644
index 0000000..5d653cf
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
new file mode 100644
index 0000000..41bb1a4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.ComplexType
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+
+import org.eclipse.etrice.generator.base.ILogger
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+
+@Singleton
+class DataClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers typeHelpers
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ logger.logInfo("generating code")
+ for (dc: root.usedDataClasses) {
+ var path = dc.generationTargetPath + dc.getPath
+
+ // header file
+ logger.logInfo("generating DataClass header '"+dc.getCppHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppHeaderFileName, root.generateHeaderFile(dc))
+
+ // source file
+ logger.logInfo("generating DataClass source '"+dc.getCppSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppSourceFileName, root.generateSourceFile(dc))
+
+ }
+
+ }
+
+ def generateHeaderFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+
+ '''
+ «generateIncludeGuardBegin(dc.name)»
+ «var models = root.getReferencedModels(dc)»
+ «FOR model : models»
+ «FOR classes : model.dataClasses»
+ #include «classes.path»«classes.name».h;
+ «ENDFOR»
+ «ENDFOR»
+
+ «helpers.userCode(dc.userCode1)»
+
+
+ class «dc.name»«IF dc.base!=null» : public «dc.base.name»«ENDIF» {
+
+ «helpers.userCode(dc.userCode2)»
+
+ «helpers.attributes(dc.attributes)»
+
+ «helpers.attributeSettersGettersImplementation(dc.attributes, dc.name)»
+
+ «helpers.operationsDeclaration(dc.operations, dc.name)»
+
+ // default constructor
+ «dc.name»();
+ «dc.name»(const «dc.name»& rhs);
+ operator=(const «dc.name»& rhs);
+
+ // constructor using fields
+ «dc.name»(«dc.argList»);
+
+ };
+
+ «generateIncludeGuardEnd(dc.name)»
+
+ '''
+ }
+
+ def generateSourceFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+
+ '''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of DataClass «dc.name»
+ *
+ */
+
+ #include "«dc.getCppHeaderFileName»"
+
+ #include <string.h>
+
+ «helpers.userCode(dc.userCode3)»
+
+««« TODO: do we need setters and getters for C and C++ ?
+
+ «dc.name»::«dc.name»() {
+ «dc.attributes.attributeInitialization(true)»
+ «IF ctor!=null»
+
+ {
+ // user defined constructor body
+ «FOR l : ctor.detailCode.commands»
+ «l»
+ «ENDFOR»
+ }
+ «ENDIF»
+ }
+
+ // constructor using fields
+ «dc.name»::«dc.name»(«dc.argList»)
+ «IF dc.base!=null»
+ :«dc.base.name»(«dc.base.paramList»),
+ «ENDIF»
+ «FOR a : dc.attributes»
+ «a.name»(«a.name»),
+ «ENDFOR»
+ {
+ }
+
+ «helpers.operationsImplementation(dc.operations, dc.name)»
+
+ // deep copy
+ void «dc.name»_deepCopy(«dc.name»* source, «dc.name»* target) {
+ memcpy(target, source, sizeof(«dc.name»));
+ }
+
+ '''}
+
+ def paramList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.paramList.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def paramList(List<Attribute> attributes) {
+ '''«FOR a: attributes SEPARATOR ", "»«a.name»«ENDFOR»'''
+ }
+
+ def argList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.argList.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def deepCopy(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = deepCopy(dc.attributes).toString + result
+ dc = dc.base
+ }
+ return result
+ }
+
+ def deepCopy(List<Attribute> attributes) {
+ '''
+ «FOR a : attributes»
+ «IF a.refType.type instanceof ComplexType»
+ if («a.name»!=null) {
+ «IF a.size==0»
+ copy.«a.name» = «a.name».deepCopy();
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i].deepCopy();
+ }
+ «ENDIF»
+ }
+ «ELSE»
+ «IF a.size==0»
+ copy.«a.name» = «a.name»;
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i];
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.class
new file mode 100644
index 0000000..19f3dda
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
new file mode 100644
index 0000000..3f2fea7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.xtext.generator.IGenerator
+import org.eclipse.etrice.generator.generic.PrepareFileSystem
+
+@Singleton
+class MainGen implements IGenerator {
+
+ @Inject DataClassGen dataClassGen
+// @Inject ProtocolClassGen protocolClassGen
+// @Inject ActorClassGen actorClassGen
+// @Inject SubSystemClassGen subsystemClassGen
+// @Inject SubSystemRunnerGen subsystemRunnerGen
+ @Inject PrepareFileSystem prepFS
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ prepFS.prepare(resource)
+ for (e: resource.contents){
+ if (e instanceof Root) {
+ doGenerate(e as Root)
+ }
+ }
+ }
+
+ def void doGenerate(Root e) {
+ dataClassGen.doGenerate(e);
+// protocolClassGen.doGenerate(e);
+// actorClassGen.doGenerate(e);
+// subsystemClassGen.doGenerate(e);
+
+ if (!e.library) {
+// subsystemRunnerGen.doGenerate(e);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.class b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.class
new file mode 100644
index 0000000..72df407
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/bin/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.class
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.cpp/build.properties b/plugins/org.eclipse.etrice.generator.cpp/build.properties
new file mode 100644
index 0000000..41eb6ad
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java
new file mode 100644
index 0000000..2b03f7a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/Main.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.etrice.generator.base.AbstractGenerator;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.cpp.setup.GeneratorModule;
+import org.eclipse.xtext.generator.IGenerator;
+
+import com.google.inject.Inject;
+
+public class Main extends AbstractGenerator {
+
+ public static final String OPTION_LIB = "-lib";
+ public static final String OPTION_GEN_INST_DIAG = "-genInstDiag";
+ public static final String OPTION_SAVE_GEN_MODEL = "-saveGenModel";
+
+ /**
+ * print usage message to stderr
+ */
+ private static void printUsage() {
+ output.println(Main.class.getName()+" [-saveGenModel <genmodel path>] [-genInstDiag] [-lib] <list of model file paths>");
+ output.println(" <list of model file paths> # model file paths may be specified as");
+ output.println(" # e.g. C:\\path\\to\\model\\mymodel.room");
+ output.println(" -saveGenModel <genmodel path> # if specified the generator model will be saved to this location");
+ output.println(" -genInstDiag # if specified an instance diagram is created for each subsystem");
+ output.println(" -lib # if specified all classes are generated and no instances");
+ }
+
+ public static void main(String[] args) {
+ int ret = createAndRunGenerator(new GeneratorModule(), args);
+ if (isTerminateOnError() && ret!=GENERATOR_OK)
+ System.exit(ret);
+ }
+
+ @Inject
+ private IGenerator mainGenerator;
+
+ @Inject
+ protected org.eclipse.etrice.generator.doc.gen.MainGen mainDocGenerator;
+
+ public int runGenerator(String[] args) {
+ if (args.length == 0) {
+ logger.logError(Main.class.getName()+" - aborting: no arguments!", null);
+ printUsage();
+ return GENERATOR_ERROR;
+ }
+
+ // parsing arguments
+ String genModelPath = null;
+ List<String> uriList = new ArrayList<String>();
+ boolean genInstDiag = false;
+ boolean asLibrary = false;
+ for (int i=0; i<args.length; ++i) {
+ if (args[i].equals(OPTION_SAVE_GEN_MODEL)) {
+ if (++i<args.length) {
+ genModelPath = args[i]+"/genmodel.egm";
+ }
+ }
+ else if (args[i].equals(OPTION_GEN_INST_DIAG)) {
+ genInstDiag = true;
+ }
+ else if (args[i].equals(OPTION_LIB)) {
+ asLibrary = true;
+ }
+ else {
+ uriList.add(args[i]);
+ }
+ }
+
+ setupRoomModel();
+
+ if (!runGenerator(uriList, genModelPath, genInstDiag, asLibrary))
+ return GENERATOR_ERROR;
+
+ return GENERATOR_OK;
+ }
+
+ protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genInstDiag, boolean asLibrary) {
+ ResourceSet rs = resourceSetProvider.get();
+
+ loadModels(uriList, rs);
+
+ if (!validateModels(rs))
+ return false;
+
+ Root genModel = createGeneratorModel(rs, asLibrary, genModelPath);
+ if (genModel==null)
+ return false;
+
+ logger.logInfo("-- starting code generation");
+ fileAccess.setOutputPath("src-gen/");
+ mainGenerator.doGenerate(genModel.eResource(), fileAccess);
+
+ if (genInstDiag) {
+ mainDocGenerator.doGenerate(genModel);
+ }
+ logger.logInfo("-- finished code generation");
+
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
new file mode 100644
index 0000000..8fb9d90
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
+import java.util.List
+import org.eclipse.xtext.util.Pair
+
+
+@Singleton
+class CppExtensions implements ILanguageExtension {
+
+ @Inject AbstractTransitionChainGenerator chainGenerator
+
+
+ override String getTypedDataDefinition(Message m) {
+ return chainGenerator.generateTypedData(m)
+ }
+
+
+ def String getCppHeaderFileName(RoomClass rc) {rc.name+".h"}
+ def String getCppSourceFileName(RoomClass rc) {rc.name+".cpp"}
+
+ override String accessLevelPrivate() {""}
+ override String accessLevelProtected() {""}
+ override String accessLevelPublic() {""}
+
+ override String memberAccess() {"this->"}
+ override String selfPointer(String classname, boolean hasArgs) {""}
+ override String selfPointer(boolean hasArgs) { "" }
+
+ override String operationScope(String classname, boolean isDeclaration) {""}
+
+
+ override String memberInDeclaration(String namespace, String member) {
+ return member
+ }
+
+ override String memberInUse(String namespace, String member) {
+ return namespace+"."+member
+ }
+
+ override boolean usesInheritance() {
+ return true
+ }
+
+ override String genEnumeration(String name, List<Pair<String, String>> entries) {
+ '''
+ «FOR entry: entries»
+ public static final int «entry.first» = «entry.second»;
+ «ENDFOR»
+ '''.toString
+ }
+
+ override String booleanConstant(boolean b) {
+ b.toString
+ }
+
+ override String pointerLiteral() { "" }
+ override String nullPointer() { "null" }
+ override String voidPointer() { "Object" }
+
+ override String arrayDeclaration(String type, int size, String name, boolean isRef) {
+ type+" "+name+"[]";
+ }
+
+ override String constructorName(String cls) {
+ cls
+ }
+ override String destructorName(String cls) {
+ cls+"_dtor"
+ }
+ override String constructorReturnType() {
+ ""
+ }
+ override String destructorReturnType() {
+ "void"
+ }
+
+ def getIncludeGuardString(String filename){
+ '''_«filename.toUpperCase»_H_'''
+ }
+
+ def generateIncludeGuardBegin(String filename){'''
+ #ifndef «filename.getIncludeGuardString»
+ #define «filename.getIncludeGuardString»
+ '''
+ }
+
+ def generateIncludeGuardEnd(String filename){'''
+ #endif /* «filename.getIncludeGuardString» */
+ '''
+ }
+
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java
new file mode 100644
index 0000000..a398053
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppLanguageGenerator.java
@@ -0,0 +1,31 @@
+package org.eclipse.etrice.generator.cpp.gen;
+
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
+
+public class CppLanguageGenerator extends AbstractTransitionChainGenerator {
+
+ @Override
+ protected String[] generateArglistAndTypedData(VarDecl data) {
+ if (data==null)
+ return new String[] {"", "", ""};
+
+ String typeName = data.getRefType().getType().getName();
+ String castTypeName = typeName;
+ if (data.getRefType().getType() instanceof PrimitiveType) {
+ typeName = ((PrimitiveType)data.getRefType().getType()).getTargetName();
+ String ct = ((PrimitiveType)data.getRefType().getType()).getCastName();
+ if (ct!=null && !ct.isEmpty())
+ castTypeName = ct;
+ }
+
+ // TODO: reinterpret_cast
+ String typedData = typeName+" "+data.getName() + " = ("+castTypeName+") generic_data;\n";
+ String dataArg = ", "+data.getName();
+ String typedArgList = ", "+typeName+" "+data.getName();
+
+ return new String[]{dataArg, typedData, typedArgList};
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java
new file mode 100644
index 0000000..dbd98bd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
+import org.eclipse.etrice.generator.base.ILogger;
+
+import com.google.inject.Inject;
+
+/**
+ * @author hrentz
+ *
+ */
+public class CppTranslationProvider extends DefaultTranslationProvider {
+
+ @Inject ILogger logger;
+
+ @Override
+ public boolean translateMembers() {
+ return true;
+ }
+
+ @Override
+ public boolean translateTags() {
+ return true;
+ }
+
+ @Override
+ public String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String index, String orig) {
+ if (index==null)
+ return orig;
+
+ StringBuilder argtext = new StringBuilder();
+ for (String arg : args) {
+ argtext.append(", "+arg);
+ }
+
+ // TODO: overload operator[] ???
+ return item.getName()+".get("+index+")."+msg.getName()+"("+argtext.toString()+")";
+ }
+
+ @Override
+ public String translateTag(String tag, DetailCode code) {
+ if (tag.equals("ifitem.index"))
+ return "ifitem.getIdx()";
+
+ logger.logInfo("unrecognized tag '"+tag+"' in "
+ +RoomNameProvider.getDetailCodeLocation(code)+" of "
+ +RoomNameProvider.getClassLocation(RoomNameProvider.getModelClass(code)));
+ return TAG_START+"?"+tag+"?"+TAG_END;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
new file mode 100644
index 0000000..41bb1a4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.ComplexType
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+
+import org.eclipse.etrice.generator.base.ILogger
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+
+@Singleton
+class DataClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers typeHelpers
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ logger.logInfo("generating code")
+ for (dc: root.usedDataClasses) {
+ var path = dc.generationTargetPath + dc.getPath
+
+ // header file
+ logger.logInfo("generating DataClass header '"+dc.getCppHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppHeaderFileName, root.generateHeaderFile(dc))
+
+ // source file
+ logger.logInfo("generating DataClass source '"+dc.getCppSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppSourceFileName, root.generateSourceFile(dc))
+
+ }
+
+ }
+
+ def generateHeaderFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+
+ '''
+ «generateIncludeGuardBegin(dc.name)»
+ «var models = root.getReferencedModels(dc)»
+ «FOR model : models»
+ «FOR classes : model.dataClasses»
+ #include «classes.path»«classes.name».h;
+ «ENDFOR»
+ «ENDFOR»
+
+ «helpers.userCode(dc.userCode1)»
+
+
+ class «dc.name»«IF dc.base!=null» : public «dc.base.name»«ENDIF» {
+
+ «helpers.userCode(dc.userCode2)»
+
+ «helpers.attributes(dc.attributes)»
+
+ «helpers.attributeSettersGettersImplementation(dc.attributes, dc.name)»
+
+ «helpers.operationsDeclaration(dc.operations, dc.name)»
+
+ // default constructor
+ «dc.name»();
+ «dc.name»(const «dc.name»& rhs);
+ operator=(const «dc.name»& rhs);
+
+ // constructor using fields
+ «dc.name»(«dc.argList»);
+
+ };
+
+ «generateIncludeGuardEnd(dc.name)»
+
+ '''
+ }
+
+ def generateSourceFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+
+ '''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of DataClass «dc.name»
+ *
+ */
+
+ #include "«dc.getCppHeaderFileName»"
+
+ #include <string.h>
+
+ «helpers.userCode(dc.userCode3)»
+
+««« TODO: do we need setters and getters for C and C++ ?
+
+ «dc.name»::«dc.name»() {
+ «dc.attributes.attributeInitialization(true)»
+ «IF ctor!=null»
+
+ {
+ // user defined constructor body
+ «FOR l : ctor.detailCode.commands»
+ «l»
+ «ENDFOR»
+ }
+ «ENDIF»
+ }
+
+ // constructor using fields
+ «dc.name»::«dc.name»(«dc.argList»)
+ «IF dc.base!=null»
+ :«dc.base.name»(«dc.base.paramList»),
+ «ENDIF»
+ «FOR a : dc.attributes»
+ «a.name»(«a.name»),
+ «ENDFOR»
+ {
+ }
+
+ «helpers.operationsImplementation(dc.operations, dc.name)»
+
+ // deep copy
+ void «dc.name»_deepCopy(«dc.name»* source, «dc.name»* target) {
+ memcpy(target, source, sizeof(«dc.name»));
+ }
+
+ '''}
+
+ def paramList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.paramList.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def paramList(List<Attribute> attributes) {
+ '''«FOR a: attributes SEPARATOR ", "»«a.name»«ENDFOR»'''
+ }
+
+ def argList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.argList.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def deepCopy(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = deepCopy(dc.attributes).toString + result
+ dc = dc.base
+ }
+ return result
+ }
+
+ def deepCopy(List<Attribute> attributes) {
+ '''
+ «FOR a : attributes»
+ «IF a.refType.type instanceof ComplexType»
+ if («a.name»!=null) {
+ «IF a.size==0»
+ copy.«a.name» = «a.name».deepCopy();
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i].deepCopy();
+ }
+ «ENDIF»
+ }
+ «ELSE»
+ «IF a.size==0»
+ copy.«a.name» = «a.name»;
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i];
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
new file mode 100644
index 0000000..3f2fea7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.xtext.generator.IGenerator
+import org.eclipse.etrice.generator.generic.PrepareFileSystem
+
+@Singleton
+class MainGen implements IGenerator {
+
+ @Inject DataClassGen dataClassGen
+// @Inject ProtocolClassGen protocolClassGen
+// @Inject ActorClassGen actorClassGen
+// @Inject SubSystemClassGen subsystemClassGen
+// @Inject SubSystemRunnerGen subsystemRunnerGen
+ @Inject PrepareFileSystem prepFS
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ prepFS.prepare(resource)
+ for (e: resource.contents){
+ if (e instanceof Root) {
+ doGenerate(e as Root)
+ }
+ }
+ }
+
+ def void doGenerate(Root e) {
+ dataClassGen.doGenerate(e);
+// protocolClassGen.doGenerate(e);
+// actorClassGen.doGenerate(e);
+// subsystemClassGen.doGenerate(e);
+
+ if (!e.library) {
+// subsystemRunnerGen.doGenerate(e);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
new file mode 100644
index 0000000..011fc41
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/setup/GeneratorModule.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.setup;
+
+import org.eclipse.etrice.generator.base.AbstractGenerator;
+import org.eclipse.etrice.generator.base.GeneratorBaseModule;
+import org.eclipse.etrice.generator.base.ITranslationProvider;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.cpp.gen.CppLanguageGenerator;
+import org.eclipse.etrice.generator.cpp.gen.CppTranslationProvider;
+import org.eclipse.etrice.generator.cpp.gen.MainGen;
+import org.eclipse.xtext.generator.IGenerator;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+
+
+
+import com.google.inject.Binder;
+
+public class GeneratorModule extends GeneratorBaseModule {
+
+// @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ binder.bind(AbstractGenerator.class).to(Main.class);
+ binder.bind(IGenerator.class).to(MainGen.class);
+
+ // bind language specific code to generic Interfaces
+ binder.bind(ILanguageExtension.class).to(CppExtensions.class);
+ binder.bind(AbstractTransitionChainGenerator.class).to(CppLanguageGenerator.class);
+
+ binder.bind(ITranslationProvider.class).to(CppTranslationProvider.class);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
new file mode 100644
index 0000000..a306184
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
@@ -0,0 +1,169 @@
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.RoomClass;
+import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class CppExtensions implements ILanguageExtension {
+ @Inject
+ private AbstractTransitionChainGenerator chainGenerator;
+
+ public String getTypedDataDefinition(final Message m) {
+ String _generateTypedData = this.chainGenerator.generateTypedData(m);
+ return _generateTypedData;
+ }
+
+ public String getCppHeaderFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _operator_plus = StringExtensions.operator_plus(_name, ".h");
+ return _operator_plus;
+ }
+
+ public String getCppSourceFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _operator_plus = StringExtensions.operator_plus(_name, ".cpp");
+ return _operator_plus;
+ }
+
+ public String accessLevelPrivate() {
+ return "";
+ }
+
+ public String accessLevelProtected() {
+ return "";
+ }
+
+ public String accessLevelPublic() {
+ return "";
+ }
+
+ public String memberAccess() {
+ return "this->";
+ }
+
+ public String selfPointer(final String classname, final boolean hasArgs) {
+ return "";
+ }
+
+ public String selfPointer(final boolean hasArgs) {
+ return "";
+ }
+
+ public String operationScope(final String classname, final boolean isDeclaration) {
+ return "";
+ }
+
+ public String memberInDeclaration(final String namespace, final String member) {
+ return member;
+ }
+
+ public String memberInUse(final String namespace, final String member) {
+ String _operator_plus = StringExtensions.operator_plus(namespace, ".");
+ String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, member);
+ return _operator_plus_1;
+ }
+
+ public boolean usesInheritance() {
+ return true;
+ }
+
+ public String genEnumeration(final String name, final List<Pair<String,String>> entries) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Pair<String,String> entry : entries) {
+ _builder.append("public static final int ");
+ String _first = entry.getFirst();
+ _builder.append(_first, "");
+ _builder.append(" = ");
+ String _second = entry.getSecond();
+ _builder.append(_second, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ String _string = _builder.toString();
+ return _string;
+ }
+
+ public String booleanConstant(final boolean b) {
+ String _string = ((Boolean)b).toString();
+ return _string;
+ }
+
+ public String pointerLiteral() {
+ return "";
+ }
+
+ public String nullPointer() {
+ return "null";
+ }
+
+ public String voidPointer() {
+ return "Object";
+ }
+
+ public String arrayDeclaration(final String type, final int size, final String name, final boolean isRef) {
+ String _operator_plus = StringExtensions.operator_plus(type, " ");
+ String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, name);
+ String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, "[]");
+ return _operator_plus_2;
+ }
+
+ public String constructorName(final String cls) {
+ return cls;
+ }
+
+ public String destructorName(final String cls) {
+ String _operator_plus = StringExtensions.operator_plus(cls, "_dtor");
+ return _operator_plus;
+ }
+
+ public String constructorReturnType() {
+ return "";
+ }
+
+ public String destructorReturnType() {
+ return "void";
+ }
+
+ public StringConcatenation getIncludeGuardString(final String filename) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("_");
+ String _upperCase = filename.toUpperCase();
+ _builder.append(_upperCase, "");
+ _builder.append("_H_");
+ return _builder;
+ }
+
+ public StringConcatenation generateIncludeGuardBegin(final String filename) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("#ifndef ");
+ StringConcatenation _includeGuardString = this.getIncludeGuardString(filename);
+ _builder.append(_includeGuardString, "");
+ _builder.newLineIfNotEmpty();
+ _builder.append("#define ");
+ StringConcatenation _includeGuardString_1 = this.getIncludeGuardString(filename);
+ _builder.append(_includeGuardString_1, "");
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ public StringConcatenation generateIncludeGuardEnd(final String filename) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("#endif /* ");
+ StringConcatenation _includeGuardString = this.getIncludeGuardString(filename);
+ _builder.append(_includeGuardString, "");
+ _builder.append(" */");
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
new file mode 100644
index 0000000..e1942d8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
@@ -0,0 +1,595 @@
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.ComplexType;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.StandardOperation;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.ILogger;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class DataClassGen {
+ @Inject
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ private CppExtensions stdExt;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ @Inject
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private TypeHelpers typeHelpers;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ this.logger.logInfo("generating code");
+ EList<DataClass> _usedDataClasses = root.getUsedDataClasses();
+ for (final DataClass dc : _usedDataClasses) {
+ {
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(dc);
+ String _path = this.roomExt.getPath(dc);
+ String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
+ String path = _operator_plus;
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(dc);
+ String _operator_plus_1 = StringExtensions.operator_plus("generating DataClass header \'", _cppHeaderFileName);
+ String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, "\' in \'");
+ String _operator_plus_3 = StringExtensions.operator_plus(_operator_plus_2, path);
+ String _operator_plus_4 = StringExtensions.operator_plus(_operator_plus_3, "\'");
+ this.logger.logInfo(_operator_plus_4);
+ this.fileAccess.setOutputPath(path);
+ String _cppHeaderFileName_1 = this.stdExt.getCppHeaderFileName(dc);
+ StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, dc);
+ this.fileAccess.generateFile(_cppHeaderFileName_1, _generateHeaderFile);
+ String _cppSourceFileName = this.stdExt.getCppSourceFileName(dc);
+ String _operator_plus_5 = StringExtensions.operator_plus("generating DataClass source \'", _cppSourceFileName);
+ String _operator_plus_6 = StringExtensions.operator_plus(_operator_plus_5, "\' in \'");
+ String _operator_plus_7 = StringExtensions.operator_plus(_operator_plus_6, path);
+ String _operator_plus_8 = StringExtensions.operator_plus(_operator_plus_7, "\'");
+ this.logger.logInfo(_operator_plus_8);
+ this.fileAccess.setOutputPath(path);
+ String _cppSourceFileName_1 = this.stdExt.getCppSourceFileName(dc);
+ StringConcatenation _generateSourceFile = this.generateSourceFile(root, dc);
+ this.fileAccess.generateFile(_cppSourceFileName_1, _generateSourceFile);
+ }
+ }
+ }
+
+ public StringConcatenation generateHeaderFile(final Root root, final DataClass dc) {
+ StringConcatenation _xblockexpression = null;
+ {
+ EList<StandardOperation> _operations = dc.getOperations();
+ final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isConstructor = RoomHelpers.isConstructor(op);
+ return ((Boolean)_isConstructor);
+ }
+ };
+ Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
+ StandardOperation _head = IterableExtensions.<StandardOperation>head(_filter);
+ final StandardOperation ctor = _head;
+ EList<StandardOperation> _operations_1 = dc.getOperations();
+ final Function1<StandardOperation,Boolean> _function_1 = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isDestructor = op.isDestructor();
+ return ((Boolean)_isDestructor);
+ }
+ };
+ Iterable<StandardOperation> _filter_1 = IterableExtensions.<StandardOperation>filter(_operations_1, _function_1);
+ StandardOperation _head_1 = IterableExtensions.<StandardOperation>head(_filter_1);
+ final StandardOperation dtor = _head_1;
+ StringConcatenation _builder = new StringConcatenation();
+ String _name = dc.getName();
+ StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name);
+ _builder.append(_generateIncludeGuardBegin, "");
+ _builder.newLineIfNotEmpty();
+ EList<RoomModel> _referencedModels = root.getReferencedModels(dc);
+ EList<RoomModel> models = _referencedModels;
+ _builder.newLineIfNotEmpty();
+ {
+ for(final RoomModel model : models) {
+ {
+ EList<DataClass> _dataClasses = model.getDataClasses();
+ for(final DataClass classes : _dataClasses) {
+ _builder.append("#include ");
+ String _path = this.roomExt.getPath(classes);
+ _builder.append(_path, "");
+ String _name_1 = classes.getName();
+ _builder.append(_name_1, "");
+ _builder.append(".h;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ DetailCode _userCode1 = dc.getUserCode1();
+ StringConcatenation _userCode = this.helpers.userCode(_userCode1);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class ");
+ String _name_2 = dc.getName();
+ _builder.append(_name_2, "");
+ {
+ DataClass _base = dc.getBase();
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
+ if (_operator_notEquals) {
+ _builder.append(" : public ");
+ DataClass _base_1 = dc.getBase();
+ String _name_3 = _base_1.getName();
+ _builder.append(_name_3, "");
+ }
+ }
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ DetailCode _userCode2 = dc.getUserCode2();
+ StringConcatenation _userCode_1 = this.helpers.userCode(_userCode2);
+ _builder.append(_userCode_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _attributes_1 = this.helpers.attributes(_attributes);
+ _builder.append(_attributes_1, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<Attribute> _attributes_2 = dc.getAttributes();
+ String _name_4 = dc.getName();
+ StringConcatenation _attributeSettersGettersImplementation = this.helpers.attributeSettersGettersImplementation(_attributes_2, _name_4);
+ _builder.append(_attributeSettersGettersImplementation, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ EList<StandardOperation> _operations_2 = dc.getOperations();
+ String _name_5 = dc.getName();
+ StringConcatenation _operationsDeclaration = this.helpers.operationsDeclaration(_operations_2, _name_5);
+ _builder.append(_operationsDeclaration, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// default constructor");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_6 = dc.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_7 = dc.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("(const ");
+ String _name_8 = dc.getName();
+ _builder.append(_name_8, " ");
+ _builder.append("& rhs);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("operator=(const ");
+ String _name_9 = dc.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("& rhs);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// constructor using fields");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_10 = dc.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("(");
+ String _argList = this.argList(dc);
+ _builder.append(_argList, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ String _name_11 = dc.getName();
+ StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_11);
+ _builder.append(_generateIncludeGuardEnd, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public StringConcatenation generateSourceFile(final Root root, final DataClass dc) {
+ StringConcatenation _xblockexpression = null;
+ {
+ EList<StandardOperation> _operations = dc.getOperations();
+ final Function1<StandardOperation,Boolean> _function = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isConstructor = RoomHelpers.isConstructor(op);
+ return ((Boolean)_isConstructor);
+ }
+ };
+ Iterable<StandardOperation> _filter = IterableExtensions.<StandardOperation>filter(_operations, _function);
+ StandardOperation _head = IterableExtensions.<StandardOperation>head(_filter);
+ final StandardOperation ctor = _head;
+ EList<StandardOperation> _operations_1 = dc.getOperations();
+ final Function1<StandardOperation,Boolean> _function_1 = new Function1<StandardOperation,Boolean>() {
+ public Boolean apply(final StandardOperation op) {
+ boolean _isDestructor = op.isDestructor();
+ return ((Boolean)_isDestructor);
+ }
+ };
+ Iterable<StandardOperation> _filter_1 = IterableExtensions.<StandardOperation>filter(_operations_1, _function_1);
+ StandardOperation _head_1 = IterableExtensions.<StandardOperation>head(_filter_1);
+ final StandardOperation dtor = _head_1;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of DataClass ");
+ String _name = dc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* ");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(dc);
+ _builder.append(_cppHeaderFileName, "");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include <string.h>");
+ _builder.newLine();
+ _builder.newLine();
+ DetailCode _userCode3 = dc.getUserCode3();
+ StringConcatenation _userCode = this.helpers.userCode(_userCode3);
+ _builder.append(_userCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ String _name_1 = dc.getName();
+ _builder.append(_name_1, "");
+ _builder.append("::");
+ String _name_2 = dc.getName();
+ _builder.append(_name_2, "");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _attributeInitialization = this.helpers.attributeInitialization(_attributes, true);
+ _builder.append(_attributeInitialization, " ");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(ctor, null);
+ if (_operator_notEquals) {
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("// user defined constructor body");
+ _builder.newLine();
+ {
+ DetailCode _detailCode = ctor.getDetailCode();
+ EList<String> _commands = _detailCode.getCommands();
+ for(final String l : _commands) {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append(l, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// constructor using fields");
+ _builder.newLine();
+ String _name_3 = dc.getName();
+ _builder.append(_name_3, "");
+ _builder.append("::");
+ String _name_4 = dc.getName();
+ _builder.append(_name_4, "");
+ _builder.append("(");
+ String _argList = this.argList(dc);
+ _builder.append(_argList, "");
+ _builder.append(") ");
+ _builder.newLineIfNotEmpty();
+ {
+ DataClass _base = dc.getBase();
+ boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_base, null);
+ if (_operator_notEquals_1) {
+ _builder.append("\t");
+ _builder.append(":");
+ DataClass _base_1 = dc.getBase();
+ String _name_5 = _base_1.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("(");
+ DataClass _base_2 = dc.getBase();
+ String _paramList = this.paramList(_base_2);
+ _builder.append(_paramList, " ");
+ _builder.append("),");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<Attribute> _attributes_1 = dc.getAttributes();
+ for(final Attribute a : _attributes_1) {
+ _builder.append("\t");
+ String _name_6 = a.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("(");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("),");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ EList<StandardOperation> _operations_2 = dc.getOperations();
+ String _name_8 = dc.getName();
+ StringConcatenation _operationsImplementation = this.helpers.operationsImplementation(_operations_2, _name_8);
+ _builder.append(_operationsImplementation, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// deep copy");
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_9 = dc.getName();
+ _builder.append(_name_9, "");
+ _builder.append("_deepCopy(");
+ String _name_10 = dc.getName();
+ _builder.append(_name_10, "");
+ _builder.append("* source, ");
+ String _name_11 = dc.getName();
+ _builder.append(_name_11, "");
+ _builder.append("* target) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("memcpy(target, source, sizeof(");
+ String _name_12 = dc.getName();
+ _builder.append(_name_12, " ");
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ public String paramList(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(dc, null);
+ Boolean _xwhileexpression = _operator_notEquals;
+ while (_xwhileexpression) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _paramList = this.paramList(_attributes);
+ String _string = _paramList.toString();
+ String _operator_plus = StringExtensions.operator_plus(_string, result);
+ result = _operator_plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(dc, null);
+ if (_operator_notEquals_1) {
+ String _operator_plus_1 = StringExtensions.operator_plus(", ", result);
+ result = _operator_plus_1;
+ }
+ }
+ boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(dc, null);
+ _xwhileexpression = _operator_notEquals_2;
+ }
+ return result;
+ }
+
+ public StringConcatenation paramList(final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ boolean hasAnyElements = false;
+ for(final Attribute a : attributes) {
+ if (!hasAnyElements) {
+ hasAnyElements = true;
+ } else {
+ _builder.appendImmediate(", ", "");
+ }
+ String _name = a.getName();
+ _builder.append(_name, "");
+ }
+ }
+ return _builder;
+ }
+
+ public String argList(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(dc, null);
+ Boolean _xwhileexpression = _operator_notEquals;
+ while (_xwhileexpression) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _argList = this.helpers.argList(_attributes);
+ String _string = _argList.toString();
+ String _operator_plus = StringExtensions.operator_plus(_string, result);
+ result = _operator_plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(dc, null);
+ if (_operator_notEquals_1) {
+ String _operator_plus_1 = StringExtensions.operator_plus(", ", result);
+ result = _operator_plus_1;
+ }
+ }
+ boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(dc, null);
+ _xwhileexpression = _operator_notEquals_2;
+ }
+ return result;
+ }
+
+ public String deepCopy(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(dc, null);
+ Boolean _xwhileexpression = _operator_notEquals;
+ while (_xwhileexpression) {
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _deepCopy = this.deepCopy(_attributes);
+ String _string = _deepCopy.toString();
+ String _operator_plus = StringExtensions.operator_plus(_string, result);
+ result = _operator_plus;
+ DataClass _base = dc.getBase();
+ dc = _base;
+ }
+ boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(dc, null);
+ _xwhileexpression = _operator_notEquals_1;
+ }
+ return result;
+ }
+
+ public StringConcatenation deepCopy(final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Attribute a : attributes) {
+ {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ if ((_type instanceof ComplexType)) {
+ _builder.append("if (");
+ String _name = a.getName();
+ _builder.append(_name, "");
+ _builder.append("!=null) {");
+ _builder.newLineIfNotEmpty();
+ {
+ int _size = a.getSize();
+ boolean _operator_equals = ObjectExtensions.operator_equals(((Integer)_size), ((Integer)0));
+ if (_operator_equals) {
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" = ");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, " ");
+ _builder.append(".deepCopy();");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("for (int i=0;i<");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, " ");
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_4 = a.getName();
+ _builder.append(_name_4, " ");
+ _builder.append("[i] = ");
+ String _name_5 = a.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("[i].deepCopy();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ {
+ int _size_1 = a.getSize();
+ boolean _operator_equals_1 = ObjectExtensions.operator_equals(((Integer)_size_1), ((Integer)0));
+ if (_operator_equals_1) {
+ _builder.append("copy.");
+ String _name_6 = a.getName();
+ _builder.append(_name_6, "");
+ _builder.append(" = ");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("for (int i=0;i<");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, "");
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_9 = a.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("[i] = ");
+ String _name_10 = a.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("[i];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.java
new file mode 100644
index 0000000..0455f08
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.java
@@ -0,0 +1,41 @@
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.etrice.generator.cpp.gen.DataClassGen;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.generic.PrepareFileSystem;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.IGenerator;
+import org.eclipse.xtext.xbase.lib.BooleanExtensions;
+
+@SuppressWarnings("all")
+@Singleton
+public class MainGen implements IGenerator {
+ @Inject
+ private DataClassGen dataClassGen;
+
+ @Inject
+ private PrepareFileSystem prepFS;
+
+ public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
+ this.prepFS.prepare(resource);
+ EList<EObject> _contents = resource.getContents();
+ for (final EObject e : _contents) {
+ if ((e instanceof Root)) {
+ this.doGenerate(((Root) e));
+ }
+ }
+ }
+
+ public void doGenerate(final Root e) {
+ this.dataClassGen.doGenerate(e);
+ boolean _isLibrary = e.isLibrary();
+ boolean _operator_not = BooleanExtensions.operator_not(_isLibrary);
+ if (_operator_not) {
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/.classpath b/plugins/org.eclipse.etrice.generator.launch.cpp/.classpath
new file mode 100644
index 0000000..8a8f166
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/.gitignore b/plugins/org.eclipse.etrice.generator.launch.cpp/.gitignore
new file mode 100644
index 0000000..f68b3dd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/.gitignore
@@ -0,0 +1,2 @@
+bin
+
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/.project b/plugins/org.eclipse.etrice.generator.launch.cpp/.project
new file mode 100644
index 0000000..1b23712
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.generator.launch.cpp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.generator.launch.cpp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..dcfadd0
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Aug 30 16:50:14 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.launch.cpp/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..af784af
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: eTrice Java Generator Launcher
+Bundle-SymbolicName: org.eclipse.etrice.generator.launch.java;singleton:=true
+Bundle-Version: 0.2.0.qualifier
+Bundle-Activator: org.eclipse.etrice.generator.launch.cpp.Activator
+Require-Bundle: org.eclipse.etrice.generator;bundle-version="0.1.0",
+ org.eclipse.etrice.generator.cpp;bundle-version="0.1.0",
+ org.eclipse.etrice.generator.launch;bundle-version="0.1.0",
+ org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.debug.core,
+ org.eclipse.debug.ui,
+ org.eclipse.jdt.ui;bundle-version="3.7.0",
+ org.eclipse.jdt.core;bundle-version="3.7.0",
+ org.eclipse.core.variables;bundle-version="3.2.500"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.jdt.launching,
+ org.eclipse.ui.dialogs
+Bundle-Vendor: eTrice (Incubation)
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/build.properties b/plugins/org.eclipse.etrice.generator.launch.cpp/build.properties
new file mode 100644
index 0000000..285b8bf
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/icons/eTrice-launch.gif b/plugins/org.eclipse.etrice.generator.launch.cpp/icons/eTrice-launch.gif
new file mode 100644
index 0000000..ca39064
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/icons/eTrice-launch.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/plugin.xml b/plugins/org.eclipse.etrice.generator.launch.cpp/plugin.xml
new file mode 100644
index 0000000..7e7991e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.debug.core.launchConfigurationTypes">
+ <launchConfigurationType
+ delegate="org.eclipse.etrice.generator.launch.cpp.CppGeneratorLaunchConfigurationDelegate"
+ delegateDescription="Generates C++ source code from ROOM models"
+ delegateName="eTrice C++ Generator Delegate"
+ id="org.eclipse.etrice.generator.launch.cpp.launchConfigurationType"
+ modes="run,debug"
+ name="eTrice C++ Generator">
+ </launchConfigurationType>
+ </extension>
+ <extension
+ point="org.eclipse.debug.ui.launchConfigurationTypeImages">
+ <launchConfigurationTypeImage
+ configTypeID="org.eclipse.etrice.generator.launch.cpp.launchConfigurationType"
+ icon="icons/eTrice-launch.gif"
+ id="org.eclipse.etrice.generator.launch.cpp.launchConfigurationTypeImage">
+ </launchConfigurationTypeImage>
+ </extension>
+ <extension
+ point="org.eclipse.debug.ui.launchConfigurationTabGroups">
+ <launchConfigurationTabGroup
+ class="org.eclipse.etrice.generator.launch.cpp.CppGeneratorLaunchConfigurationTabGroup"
+ description="Tab Group for eTrice C++ Generator Launch Configurations"
+ id="org.eclipse.etrice.generator.launch.cpp.launchConfigurationTabGroup"
+ type="org.eclipse.etrice.generator.launch.cpp.launchConfigurationType">
+ </launchConfigurationTabGroup>
+ </extension>
+</plugin>
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/Activator.java b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/Activator.java
new file mode 100644
index 0000000..00142a2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/Activator.java
@@ -0,0 +1,53 @@
+package org.eclipse.etrice.generator.launch.cpp;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.etrice.generator.launch.java"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public void log(Exception e) {
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorConfigTab.java b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorConfigTab.java
new file mode 100644
index 0000000..35ea59b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorConfigTab.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.launch.cpp;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class CppGeneratorConfigTab extends AbstractLaunchConfigurationTab {
+
+ public static final String GEN_INSTANCE_DIAGRAM = "GenInstanceDiagram";
+ public static final String GEN_MODEL_PATH = "GenModelPath";
+ public static final String SAVE_GEN_MODEL = "SaveGenModel";
+ public static final String LIB = "Lib";
+
+ private Button libButton;
+ private Button instanceDiagramButton;
+ private Button saveGenModel;
+ private Text genModelPath;
+ private Button browsePath;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
+ */
+ @Override
+ public String getName() {
+ return "C++ Generator";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ // Create main composite
+ Composite mainComposite = new Composite(parent,SWT.NONE);
+ setControl(mainComposite);
+
+ GridLayout layout= new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 10;
+ layout.marginWidth = 10;
+ mainComposite.setLayout(layout);
+
+ libButton = createCheckButton(mainComposite, "generate all classes as library");
+ libButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
+ libButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ saveGenModel = createCheckButton(mainComposite, "save generator model");
+ saveGenModel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
+ saveGenModel.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handleSaveGenModelSelected();
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ handleSaveGenModelSelected();
+ }
+
+ });
+ genModelPath = new Text(mainComposite, SWT.SINGLE | SWT.BORDER);
+ genModelPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ genModelPath.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validate();
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+ });
+ browsePath = createPushButton(mainComposite, "Browse...", null);
+ //browsePath.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1));
+ browsePath.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handlePathButtonSelected();
+ }
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ handlePathButtonSelected();
+ }
+ });
+ instanceDiagramButton = createCheckButton(mainComposite, "generate instance diagram");
+ instanceDiagramButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
+ instanceDiagramButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ validate();
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ }
+
+ /**
+ *
+ */
+ protected void handleSaveGenModelSelected() {
+ boolean save = saveGenModel.getSelection();
+ genModelPath.setEnabled(save);
+ browsePath.setEnabled(save);
+ validate();
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+
+ /**
+ *
+ */
+ private void validate() {
+ if (saveGenModel.getSelection())
+ if (genModelPath.getText().trim().isEmpty()) {
+ setErrorMessage("generator model path must not be empty");
+ return;
+ }
+ setErrorMessage(null);
+ }
+
+ /**
+ *
+ */
+ protected void handlePathButtonSelected() {
+ ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(),
+ ResourcesPlugin.getWorkspace().getRoot(),
+ false,
+ "select a container for the generator model");
+ dialog.showClosedProjects(false);
+ dialog.open();
+ Object[] results = dialog.getResult();
+ if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) {
+ IPath path = (IPath)results[0];
+ //path = path.append("genmodel.rim");
+ String fname = path.toString();
+ fname = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", fname);
+ genModelPath.setText(fname);
+ setErrorMessage(null);
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ libButton.setSelection(configuration.getAttribute(LIB, false));
+ boolean save = configuration.getAttribute(SAVE_GEN_MODEL, false);
+ saveGenModel.setSelection(save);
+ genModelPath.setEnabled(save);
+ browsePath.setEnabled(save);
+ genModelPath.setText(configuration.getAttribute(GEN_MODEL_PATH, ""));
+ instanceDiagramButton.setSelection(configuration.getAttribute(GEN_INSTANCE_DIAGRAM, false));
+ }
+ catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ @Override
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(LIB, libButton.getSelection());
+ configuration.setAttribute(SAVE_GEN_MODEL, saveGenModel.getSelection());
+ configuration.setAttribute(GEN_MODEL_PATH, genModelPath.getText());
+ configuration.setAttribute(GEN_INSTANCE_DIAGRAM, instanceDiagramButton.getSelection());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#canSave()
+ */
+ @Override
+ public boolean canSave() {
+ if (saveGenModel.getSelection())
+ return !genModelPath.getText().trim().isEmpty();
+
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationDelegate.java b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationDelegate.java
new file mode 100644
index 0000000..1d6a25f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationDelegate.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.launch.cpp;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.etrice.generator.base.ILineOutput;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class CppGeneratorLaunchConfigurationDelegate extends GeneratorLaunchConfigurationDelegate {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate#addArguments(org.eclipse.debug.core.ILaunchConfiguration, java.lang.StringBuffer)
+ */
+ @Override
+ protected void addArguments(ILaunchConfiguration configuration, StringBuffer argString) throws CoreException {
+ if (configuration.getAttribute(CppGeneratorConfigTab.LIB, false)) {
+ argString.append(" "+Main.OPTION_LIB);
+ }
+ if (configuration.getAttribute(CppGeneratorConfigTab.SAVE_GEN_MODEL, false)) {
+ argString.append(" "+Main.OPTION_SAVE_GEN_MODEL);
+ argString.append(" "+configuration.getAttribute(CppGeneratorConfigTab.GEN_MODEL_PATH, "?"));
+ }
+ if (configuration.getAttribute(CppGeneratorConfigTab.GEN_INSTANCE_DIAGRAM, false))
+ argString.append(" "+Main.OPTION_GEN_INST_DIAG);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate#runGenerator(java.lang.String[], org.eclipse.etrice.generator.launch.ILineOutput)
+ */
+ @Override
+ protected void runGenerator(String[] args, ILineOutput out) {
+ org.eclipse.etrice.generator.cpp.Main.setOutput(out);
+ org.eclipse.etrice.generator.cpp.Main.setTerminateOnError(false);
+ org.eclipse.etrice.generator.cpp.Main.main(args);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.launch.GeneratorLaunchConfigurationDelegate#getConsoleName()
+ */
+ @Override
+ protected String getConsoleName() {
+ return "eTrice C++ Generator Console";
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationTabGroup.java b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationTabGroup.java
new file mode 100644
index 0000000..930e2fd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorLaunchConfigurationTabGroup.java
@@ -0,0 +1,24 @@
+package org.eclipse.etrice.generator.launch.cpp;
+
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.EnvironmentTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.debug.ui.RefreshTab;
+
+public class CppGeneratorLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+ @Override
+ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
+ new CppGeneratorMainTab(),
+ new CppGeneratorConfigTab(),
+ new RefreshTab(),
+ new EnvironmentTab(),
+ new CommonTab()
+ };
+ setTabs(tabs);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorMainTab.java b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorMainTab.java
new file mode 100644
index 0000000..bbf846c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.launch.cpp/src/org/eclipse/etrice/generator/launch/cpp/CppGeneratorMainTab.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.launch.cpp;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.etrice.generator.launch.GeneratorMainTab;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class CppGeneratorMainTab extends GeneratorMainTab {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.launch.GeneratorMainTab#isValidModelFile(org.eclipse.core.resources.IResource)
+ */
+ @Override
+ protected boolean isValidModelFile(IResource resource) {
+ return resource.getName().endsWith(".room");
+ }
+
+}