Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/.classpath16
-rw-r--r--plugins/org.eclipse.etrice.generator.c/.gitignore2
-rw-r--r--plugins/org.eclipse.etrice.generator.c/.project90
-rw-r--r--plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.jdt.core.prefs16
-rw-r--r--plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs6
-rw-r--r--plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF38
-rw-r--r--plugins/org.eclipse.etrice.generator.c/about.html54
-rw-r--r--plugins/org.eclipse.etrice.generator.c/build.properties14
-rw-r--r--plugins/org.eclipse.etrice.generator.c/issues.txt14
-rw-r--r--plugins/org.eclipse.etrice.generator.c/plugin.xml42
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java238
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend440
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend214
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend104
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend690
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend516
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend710
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend160
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Validator.java52
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java78
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java414
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java264
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java498
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/MainGen.java122
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java1144
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java1735
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java1156
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java308
28 files changed, 4328 insertions, 4807 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/.classpath b/plugins/org.eclipse.etrice.generator.c/.classpath
index c31ca403f..1260f31c3 100644
--- a/plugins/org.eclipse.etrice.generator.c/.classpath
+++ b/plugins/org.eclipse.etrice.generator.c/.classpath
@@ -1,8 +1,8 @@
-<?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="src" path="xtend-gen"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?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="src" path="xtend-gen"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.generator.c/.gitignore b/plugins/org.eclipse.etrice.generator.c/.gitignore
index ba077a403..092357e47 100644
--- a/plugins/org.eclipse.etrice.generator.c/.gitignore
+++ b/plugins/org.eclipse.etrice.generator.c/.gitignore
@@ -1 +1 @@
-bin
+bin
diff --git a/plugins/org.eclipse.etrice.generator.c/.project b/plugins/org.eclipse.etrice.generator.c/.project
index 0bbb7217b..726568e6c 100644
--- a/plugins/org.eclipse.etrice.generator.c/.project
+++ b/plugins/org.eclipse.etrice.generator.c/.project
@@ -1,45 +1,45 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.etrice.generator.c</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>
- <buildCommand>
- <name>org.eclipse.xtend.typesystem.xsd.ui.xsdBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
- <nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.generator.c</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>
+ <buildCommand>
+ <name>org.eclipse.xtend.typesystem.xsd.ui.xsdBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ <nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.jdt.core.prefs
index 956262663..23ea67ad4 100644
--- a/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
-#Mon Dec 06 13:36:04 CET 2010
-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
+#Mon Dec 06 13:36:04 CET 2010
+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.c/.settings/org.eclipse.xtend.shared.ui.prefs b/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs
index 0ff0ffe3f..756b7f257 100644
--- a/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs
+++ b/plugins/org.eclipse.etrice.generator.c/.settings/org.eclipse.xtend.shared.ui.prefs
@@ -1,3 +1,3 @@
-#Sat Jul 17 15:02:10 CEST 2010
-eclipse.preferences.version=1
-metamodelContributor=org.eclipse.xtend.typesystem.emf.ui.EmfMetamodelContributor,org.eclipse.xtend.shared.ui.core.metamodel.jdt.oaw.OawClassicMetamodelContributor,org.eclipse.xtend.typesystem.uml2.ui.Uml2MetamodelContributor,org.eclipse.xtend.typesystem.xsd.ui.XSDMetamodelContributor,org.eclipse.xtend.shared.ui.core.metamodel.jdt.javabean.JavaBeanMetamodelContributor
+#Sat Jul 17 15:02:10 CEST 2010
+eclipse.preferences.version=1
+metamodelContributor=org.eclipse.xtend.typesystem.emf.ui.EmfMetamodelContributor,org.eclipse.xtend.shared.ui.core.metamodel.jdt.oaw.OawClassicMetamodelContributor,org.eclipse.xtend.typesystem.uml2.ui.Uml2MetamodelContributor,org.eclipse.xtend.typesystem.xsd.ui.XSDMetamodelContributor,org.eclipse.xtend.shared.ui.core.metamodel.jdt.javabean.JavaBeanMetamodelContributor
diff --git a/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
index 43c6eb2af..b4da0a598 100644
--- a/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
@@ -1,19 +1,19 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: eTrice C Generator
-Bundle-Vendor: eTrice (Incubation)
-Bundle-Version: 0.1.0.qualifier
-Bundle-SymbolicName: org.eclipse.etrice.generator.c;singleton:=true
-Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.1.0",
- org.eclipse.etrice.generator;bundle-version="0.1.0",
- org.eclipse.emf.mwe2.launch;bundle-version="1.0.1";resolution:=optional,
- 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"
-Import-Package: org.apache.log4j
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Export-Package: org.eclipse.etrice.generator.c
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: eTrice C Generator
+Bundle-Vendor: eTrice (Incubation)
+Bundle-Version: 0.1.0.qualifier
+Bundle-SymbolicName: org.eclipse.etrice.generator.c;singleton:=true
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.1.0",
+ org.eclipse.etrice.generator;bundle-version="0.1.0",
+ org.eclipse.emf.mwe2.launch;bundle-version="1.0.1";resolution:=optional,
+ 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"
+Import-Package: org.apache.log4j
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.eclipse.etrice.generator.c
diff --git a/plugins/org.eclipse.etrice.generator.c/about.html b/plugins/org.eclipse.etrice.generator.c/about.html
index c258ef55d..f47dbddbb 100644
--- a/plugins/org.eclipse.etrice.generator.c/about.html
+++ b/plugins/org.eclipse.etrice.generator.c/about.html
@@ -1,28 +1,28 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
-<title>About</title>
-</head>
-<body lang="EN-US">
-<h2>About This Content</h2>
-
-<p>June 5, 2006</p>
-<h3>License</h3>
-
-<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
-indicated below, the Content is provided to you under the terms and conditions of the
-Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
-at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
-For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
-
-<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
-being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
-apply to your use of any object code in the Content. Check the Redistributor's license that was
-provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
-indicated below, the terms and conditions of the EPL still apply to any source code in the Content
-and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
-
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
</html> \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/build.properties b/plugins/org.eclipse.etrice.generator.c/build.properties
index 23835701f..016308267 100644
--- a/plugins/org.eclipse.etrice.generator.c/build.properties
+++ b/plugins/org.eclipse.etrice.generator.c/build.properties
@@ -1,7 +1,7 @@
-source.. = src/,\
- xtend-gen/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- icons/
-jre.compilation.profile = JavaSE-1.6
+source.. = src/,\
+ xtend-gen/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
+jre.compilation.profile = JavaSE-1.6
diff --git a/plugins/org.eclipse.etrice.generator.c/issues.txt b/plugins/org.eclipse.etrice.generator.c/issues.txt
index b8125a97e..ee05d29ef 100644
--- a/plugins/org.eclipse.etrice.generator.c/issues.txt
+++ b/plugins/org.eclipse.etrice.generator.c/issues.txt
@@ -1,7 +1,7 @@
-Issues for codegenerators:
-
-- unify all include guards
-- unify all generated sourcefile documentation
-- unify function signatures, argument lists
-
-SubSystemClassGen.xtend : /* TODO: only include used Actor Classes for current SubSystem */
+Issues for codegenerators:
+
+- unify all include guards
+- unify all generated sourcefile documentation
+- unify function signatures, argument lists
+
+SubSystemClassGen.xtend : /* TODO: only include used Actor Classes for current SubSystem */
diff --git a/plugins/org.eclipse.etrice.generator.c/plugin.xml b/plugins/org.eclipse.etrice.generator.c/plugin.xml
index d3f5e1d66..4fbc72de2 100644
--- a/plugins/org.eclipse.etrice.generator.c/plugin.xml
+++ b/plugins/org.eclipse.etrice.generator.c/plugin.xml
@@ -1,21 +1,21 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
-
- <extension point="org.eclipse.ui.newWizards">
- <category
- id="org.eclipse.etrice.core.ui.wizardCategory"
- name="eTrice"/>
- <wizard
- id="org.eclipse.etrice.generator.java.newwizard.EmptyProjectWizard"
- name="Empty eTrice Java Project"
- class="org.eclipse.etrice.generator.c.newwizard.EmptyProjectWizard"
- category="org.eclipse.etrice.core.ui.wizardCategory"
- project="true"
- icon="icons/NewETriceProject.gif">
- <description>Create an empty Java plug-in project with eTrice dependencies</description>
- <selection class="org.eclipse.core.resources.IResource"/>
- </wizard>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.etrice.core.ui.wizardCategory"
+ name="eTrice"/>
+ <wizard
+ id="org.eclipse.etrice.generator.java.newwizard.EmptyProjectWizard"
+ name="Empty eTrice Java Project"
+ class="org.eclipse.etrice.generator.c.newwizard.EmptyProjectWizard"
+ category="org.eclipse.etrice.core.ui.wizardCategory"
+ project="true"
+ icon="icons/NewETriceProject.gif">
+ <description>Create an empty Java plug-in project with eTrice dependencies</description>
+ <selection class="org.eclipse.core.resources.IResource"/>
+ </wizard>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
index 35ddee8a2..3d1c8b641 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
@@ -1,119 +1,119 @@
-/*******************************************************************************
- * 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.c;
-
-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.doc.gen.InstanceDiagramGen; // TODO: fix import
-import org.eclipse.etrice.generator.c.gen.Validator;
-import org.eclipse.etrice.generator.c.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) {
- createAndRunGenerator(new GeneratorModule(), args);
- }
-
- @Inject
- private IGenerator mainGenerator;
-
- @Inject
- protected InstanceDiagramGen instanceDiagramGenerator;
-
- @Inject
- private Validator validator;
-
- public void runGenerator(String[] args) {
- if (args.length == 0) {
- logger.logError(Main.class.getName()+" - aborting: no arguments!", null);
- printUsage();
- return;
- }
-
- // 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 = convertToURI(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(convertToURI(args[i]));
- }
- }
-
- setupRoomModel();
-
- runGenerator(uriList, genModelPath, genInstDiag, asLibrary);
- }
-
- 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;
-
- if (!validator.validate(genModel))
- return false;
-
- logger.logInfo("-- starting code generation");
- fileAccess.setOutputPath("src-gen/");
- mainGenerator.doGenerate(genModel.eResource(), fileAccess);
-
- if (genInstDiag) {
- instanceDiagramGenerator.doGenerate(genModel);
- }
- logger.logInfo("-- finished code generation");
-
- return true;
- }
-}
+/*******************************************************************************
+ * 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.c;
+
+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.doc.gen.InstanceDiagramGen; // TODO: fix import
+import org.eclipse.etrice.generator.c.gen.Validator;
+import org.eclipse.etrice.generator.c.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) {
+ createAndRunGenerator(new GeneratorModule(), args);
+ }
+
+ @Inject
+ private IGenerator mainGenerator;
+
+ @Inject
+ protected InstanceDiagramGen instanceDiagramGenerator;
+
+ @Inject
+ private Validator validator;
+
+ public void runGenerator(String[] args) {
+ if (args.length == 0) {
+ logger.logError(Main.class.getName()+" - aborting: no arguments!", null);
+ printUsage();
+ return;
+ }
+
+ // 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 = convertToURI(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(convertToURI(args[i]));
+ }
+ }
+
+ setupRoomModel();
+
+ runGenerator(uriList, genModelPath, genInstDiag, asLibrary);
+ }
+
+ 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;
+
+ if (!validator.validate(genModel))
+ return false;
+
+ logger.logInfo("-- starting code generation");
+ fileAccess.setOutputPath("src-gen/");
+ mainGenerator.doGenerate(genModel.eResource(), fileAccess);
+
+ if (genInstDiag) {
+ instanceDiagramGenerator.doGenerate(genModel);
+ }
+ logger.logInfo("-- finished code generation");
+
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
index ab0300045..5a19bfc60 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
@@ -1,253 +1,189 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.ActorClass
-import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.generator.base.ILogger
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
-import org.eclipse.etrice.generator.etricegen.Root
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-
-import org.eclipse.etrice.generator.extensions.RoomExtensions
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.TypeHelpers
-
-
-@Singleton
-class ActorClassGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CExtensions stdExt
- @Inject extension RoomExtensions roomExt
-
- @Inject extension ProcedureHelpers helpers
- @Inject extension TypeHelpers
- @Inject extension StateMachineGen stateMachineGen
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (xpac: root.xpActorClasses) {
- var path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath
-
- // header file
- logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCHeaderFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(xpac.actorClass.getCHeaderFileName, root.generateHeaderFile(xpac, xpac.actorClass))
-
- // source file
- if(hasBehaviorAnnotation(xpac, "BehaviorManual") == false){
- logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCSourceFileName +"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(xpac.actorClass.getCSourceFileName , root.generateSourceFile(xpac, xpac.actorClass))
- }
- }
- }
-
- def hasBehaviorAnnotation(ExpandedActorClass xpac, String annotation) {
- if (xpac.actorClass.annotations != null){
- if(xpac.actorClass.annotations.findFirst(e|e.name == annotation) != null){
- return true;
- }
- }
- return false;
- }
-
- def generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
- /**
- * @author generated by eTrice
- *
- * Header File of ActorClass «xpac.name»
- *
- */
-
- «generateIncludeGuardBegin(xpac.name)»
-
- #include "etDatatypes.h"
-
- «FOR dataClass : root.getReferencedDataClasses(ac)»#include "«dataClass.name».h"
- «ENDFOR»
-
- «FOR pc : root.getReferencedProtocolClasses(ac)»#include "«pc.name».h"
- «ENDFOR»
-
- «helpers.UserCode(ac.userCode1)»
-
- typedef struct «xpac.name» «xpac.name»;
-
- /* const part of ActorClass (ROM) */
- typedef struct «xpac.name»_const {
- const «xpac.name»* actor;
- /* Ports */
- «FOR ep : ac.getEndPorts()»
- const «ep.getPortClassName()» «ep.name»;
- «ENDFOR»
-
- } «xpac.name»_const;
-
- /* variable part of ActorClass (RAM) */
- struct «xpac.name» {
- const «xpac.name»_const* constData;
- };
-
- void «xpac.name»_init(«xpac.name»* self);
-
- void «xpac.name»_ReceiveMessage(void* self, etInt16 localId, const etMessage* msg);
-
-
-««« public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null»«ac.base.name»«ELSE»ActorClassBase«ENDIF» {
-«««
-«««
-««« //--------------------- ports
-««« «FOR ep : ac.getEndPorts()»
-««« protected «ep.getPortClassName()» «ep.name» = null;
-««« «ENDFOR»
-««« //--------------------- saps
-««« «FOR sap : ac.strSAPs»
-««« protected «sap.getPortClassName()» «sap.name» = null;
-««« «ENDFOR»
-««« //--------------------- services
-««« «FOR svc : ac.serviceImplementations»
-««« protected «svc.getPortClassName()» «svc.spp.name» = null;
-««« «ENDFOR»
-«««
-««« //--------------------- interface item IDs
-««« «FOR ep : ac.getEndPorts()»
-««« protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)+1»;
-««« «ENDFOR»
-««« «FOR sap : ac.strSAPs»
-««« protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)+1»;
-««« «ENDFOR»
-««« «FOR svc : ac.serviceImplementations»
-««« protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)+1»;
-««« «ENDFOR»
-«««
-««« «helpers.Attributes(ac.attributes)»
-««« «helpers.OperationsDeclaration(ac.operations, ac.name)»
-«««
-««« //--------------------- construction
-««« public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
-««« «IF ac.base==null»
-««« super(parent, name, port_addr[0][0], peer_addr[0][0]);
-««« «ELSE»
-««« super(parent, name, port_addr, peer_addr);
-««« «ENDIF»
-««« setClassName("«ac.name»");
-«««
-««« «ac.attributes.attributeInitialization»
-«««
-««« // own ports
-««« «FOR ep : ac.getEndPorts()»
-««« «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»);
-««« «ENDFOR»
-««« // own saps
-««« «FOR sap : ac.strSAPs»
-««« «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0]);
-««« «ENDFOR»
-««« // own service implementations
-««« «FOR svc : ac.serviceImplementations»
-««« «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»]);
-««« «ENDFOR»
-««« }
-«««
-«««
-««« //--------------------- lifecycle functions
-««« public void init(){
-««« initUser();
-««« }
-«««
-««« public void start(){
-««« startUser();
-««« }
-«««
-««« «IF !ac.overridesStop()»
-««« public void stop(){
-««« stopUser();
-««« }
-««« «ENDIF»
-«««
-««« public void destroy(){
-««« destroyUser();
-««« }
-«««
-«««
-«««
-««« «IF ac.stateMachine != null»
-««« «stateMachineGen.genStateMachine(xpac, ac)»
-««« «ELSEIF !xpac.hasStateMachine()»
-««« //--------------------- no state machine
-««« @Override
-««« public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {
-««« handleSystemEvent(ifitem, evt, data);
-««« }
-«««
-««« @Override
-««« public void executeInitTransition(){
-««« }
-««« «ENDIF»
-««« };
-
- «helpers.UserCode(ac.userCode2)»
-
- «generateIncludeGuardEnd(xpac.name)»
-
- '''
- }
-
- def generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
- /**
- * @author generated by eTrice
- *
- * Source File of ActorClass «xpac.name»
- *
- */
-
- #include "«xpac.getCHeaderFileName»"
-
- #include "etLogger.h"
-
- #include "etMSCLogger.h"
-
- «helpers.UserCode(xpac.userCode3)»
-
- void «xpac.name»_init(«xpac.name»* self){
- ET_MSC_LOGGER_SYNC_ENTRY("«xpac.name»", "init")
- «FOR port : xpac.actorClass.endPorts.filter(e|e.conjugated)»
- «FOR message : port.protocol.incomingMessages»
- «port.getPortClassName()»_«message.name»(&self->constData->«port.name»);
- «ENDFOR»
- «ENDFOR»
- «FOR port : xpac.actorClass.endPorts.filter(e| !e.conjugated)»
- «FOR message : port.protocol.outgoingMessages»
- «port.getPortClassName()»_«message.name»(&self->constData->«port.name»);
- «ENDFOR»
- «ENDFOR»
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
-
- void «xpac.name»_ReceiveMessage(void* self, etInt16 localId, const etMessage* msg){
- ET_MSC_LOGGER_SYNC_ENTRY("«xpac.name»", "ReceiveMessage")
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- '''
- }
-
-// def msgArgs(Message msg) {
-// '''«IF msg.data!=null»«msg.data.defaultValue()»«ENDIF»'''
-// }
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.generator.base.ILogger
+import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+
+import org.eclipse.etrice.generator.extensions.RoomExtensions
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+
+@Singleton
+class ActorClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers
+ @Inject extension StateMachineGen stateMachineGen
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (xpac: root.xpActorClasses) {
+ var path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath
+
+ // header file
+ logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(xpac.actorClass.getCHeaderFileName, root.generateHeaderFile(xpac, xpac.actorClass))
+
+ // header file
+ logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCSourceFileName +"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(xpac.actorClass.getCSourceFileName , root.generateSourceFile(xpac, xpac.actorClass))
+ }
+ }
+
+ def generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
+ #ifndef _«xpac.name»_H_
+ #define _«xpac.name»_H_
+
+ #include "etDatatypes.h"
+
+ package «ac.getPackage»;
+
+««« import org.eclipse.etrice.runtime.java.messaging.Address;
+««« import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+««« import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+««« import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
+««« import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
+««« import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
+««« import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
+
+
+ «FOR dataClass : root.getReferencedDataClasses(ac)»#include "«dataClass.name».h"
+ «ENDFOR»
+
+ «FOR pc : root.getReferencedProtocolClasses(ac)»#include "«pc.name».h"
+ «ENDFOR»
+
+ «helpers.UserCode(ac.userCode1)»
+
+
+ public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null»«ac.base.name»«ELSE»ActorClassBase«ENDIF» {
+
+ «helpers.UserCode(ac.userCode2)»
+
+ //--------------------- ports
+ «FOR ep : ac.getEndPorts()»
+ protected «ep.getPortClassName()» «ep.name» = null;
+ «ENDFOR»
+ //--------------------- saps
+ «FOR sap : ac.strSAPs»
+ protected «sap.getPortClassName()» «sap.name» = null;
+ «ENDFOR»
+ //--------------------- services
+ «FOR svc : ac.serviceImplementations»
+ protected «svc.getPortClassName()» «svc.spp.name» = null;
+ «ENDFOR»
+
+ //--------------------- interface item IDs
+ «FOR ep : ac.getEndPorts()»
+ protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)+1»;
+ «ENDFOR»
+ «FOR sap : ac.strSAPs»
+ protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)+1»;
+ «ENDFOR»
+ «FOR svc : ac.serviceImplementations»
+ protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)+1»;
+ «ENDFOR»
+
+ «helpers.Attributes(ac.attributes)»
+ «helpers.OperationsDeclaration(ac.operations, ac.name)»
+
+ //--------------------- construction
+ public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
+ «IF ac.base==null»
+ super(parent, name, port_addr[0][0], peer_addr[0][0]);
+ «ELSE»
+ super(parent, name, port_addr, peer_addr);
+ «ENDIF»
+ setClassName("«ac.name»");
+
+ «ac.attributes.attributeInitialization»
+
+ // own ports
+ «FOR ep : ac.getEndPorts()»
+ «ep.name» = new «ep.getPortClassName()»(this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»);
+ «ENDFOR»
+ // own saps
+ «FOR sap : ac.strSAPs»
+ «sap.name» = new «sap.getPortClassName()»(this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0]);
+ «ENDFOR»
+ // own service implementations
+ «FOR svc : ac.serviceImplementations»
+ «svc.spp.name» = new «svc.getPortClassName()»(this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»]);
+ «ENDFOR»
+ }
+
+
+ //--------------------- lifecycle functions
+ public void init(){
+ initUser();
+ }
+
+ public void start(){
+ startUser();
+ }
+
+ «IF !ac.overridesStop()»
+ public void stop(){
+ stopUser();
+ }
+ «ENDIF»
+
+ public void destroy(){
+ destroyUser();
+ }
+
+ «IF ac.stateMachine != null»
+ «stateMachineGen.genStateMachine(xpac, ac)»
+ «ELSEIF !xpac.hasStateMachine()»
+ //--------------------- no state machine
+ @Override
+ public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) {
+ handleSystemEvent(ifitem, evt, data);
+ }
+
+ @Override
+ public void executeInitTransition(){
+ }
+ «ENDIF»
+ };
+
+ #endif /* _«xpac.name»_H_ */
+
+ '''
+ }
+
+ def generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {'''
+ #include "«xpac.getCHeaderFileName»"
+
+ '''
+ }
+
+ def msgArgs(Message msg) {
+ '''«IF msg.data!=null»«msg.data.defaultValue()»«ENDIF»'''
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
index 25bb074b7..33afb139e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
@@ -1,108 +1,108 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-/*
- collection of convenience functions for code generation
-*/
-
-
-package org.eclipse.etrice.generator.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.core.room.RoomClass
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
-import org.eclipse.etrice.generator.etricegen.TransitionChain
-import org.eclipse.etrice.generator.generic.ILanguageExtension
-import org.eclipse.etrice.generator.generic.LanguageGenerator
-
-
-
-@Singleton
-class CExtensions implements ILanguageExtension {
-
- @Inject LanguageGenerator languageGen
-
-
- override String getTypedDataDefinition(Message m) {
- return languageGen.getTypedData(m)
- }
-
- // in C no access levels can be defined
- override String accessLevelPrivate(){""}
- override String accessLevelProtected(){""}
- override String accessLevelPublic(){""}
-
- override String memberAccess(){"self->"}
- override String selfPointer(String classname, int argumentCount){
- if (argumentCount>0){
- classname+"* self, "
- }
- else {
- classname+"* self"
- }
- }
-
- override String operationScope(String classname, boolean isDeclaration){classname+"_"}
-
- /* TODO: unify OUT and in an add for loop (also for Java) */
- override String outMessageId(String classname, String messagename){
- return classname+"_OUT_"+messagename;
- }
-
- override String inMessageId(String classname, String messagename){
- return classname+"_IN_"+messagename;
- }
-
-
-
-
- //**** C-Specific
- /* TODO: move specific code elsewhere */
- // used
- def String getCHeaderFileName(RoomClass rc) {
- return rc.name+".h";
- }
-
- // used
- def String getCSourceFileName(RoomClass rc) {
- return rc.name+".c";
- }
-
- def String getInstSourceFileName(RoomClass rc) {
- return rc.name+"_Inst.h";
- }
-
- def getIncludeGuardString(String filename){
- '''_«filename.toUpperCase»_H_'''
- }
-
- def generateIncludeGuardBegin(String filename){'''
- #ifndef «filename.getIncludeGuardString»
- #define «filename.getIncludeGuardString»
- '''
- }
-
- def generateIncludeGuardEnd(String filename){'''
- #endif /* «filename.getIncludeGuardString» */
- '''
- }
-
- //-------------------------------------------------------
- // transition chain visitor
-
- def String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc) {
- return languageGen.getExecuteChain(ac, tc)
- }
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
+import org.eclipse.etrice.generator.etricegen.TransitionChain
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.LanguageGenerator
+
+
+
+@Singleton
+class CExtensions implements ILanguageExtension {
+
+ @Inject LanguageGenerator languageGen
+
+
+ override String getTypedDataDefinition(Message m) {
+ return languageGen.getTypedData(m)
+ }
+
+ // in C no access levels can be defined
+ override String accessLevelPrivate(){""}
+ override String accessLevelProtected(){""}
+ override String accessLevelPublic(){""}
+
+ override String memberAccess(){"self->"}
+ override String selfPointer(String classname, int argumentCount){
+ if (argumentCount>0){
+ classname+"* self, "
+ }
+ else {
+ classname+"* self"
+ }
+ }
+
+ override String operationScope(String classname, boolean isDeclaration){classname+"_"}
+
+ /* TODO: unify OUT and in an add for loop (also for Java) */
+ override String outMessageId(String classname, String messagename){
+ return classname+"_OUT_"+messagename;
+ }
+
+ override String inMessageId(String classname, String messagename){
+ return classname+"_IN_"+messagename;
+ }
+
+
+
+
+ //**** C-Specific
+ /* TODO: move specific code elsewhere */
+ // used
+ def String getCHeaderFileName(RoomClass rc) {
+ return rc.name+".h";
+ }
+
+ // used
+ def String getCSourceFileName(RoomClass rc) {
+ return rc.name+".c";
+ }
+
+ def String getInstSourceFileName(RoomClass rc) {
+ return rc.name+"_Inst.h";
+ }
+
+ def getIncludeGuardString(String filename){
+ '''_«filename.toUpperCase»_H_'''
+ }
+
+ def generateIncludeGuardBegin(String filename){'''
+ #ifndef «filename.getIncludeGuardString»
+ #define «filename.getIncludeGuardString»
+ '''
+ }
+
+ def generateIncludeGuardEnd(String filename){'''
+ #endif /* «filename.getIncludeGuardString» */
+ '''
+ }
+
+ //-------------------------------------------------------
+ // transition chain visitor
+
+ def String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc) {
+ return languageGen.getExecuteChain(ac, tc)
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
index c4398b24a..95622ae79 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/MainGen.xtend
@@ -1,53 +1,53 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.c.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.extensions.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);
- }
- }
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.c.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.extensions.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.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
index acbba5822..318ff490e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.xtend
@@ -1,346 +1,346 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.core.room.ProtocolClass
-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.extensions.RoomExtensions
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-
-
-@Singleton
-class ProtocolClassGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CExtensions stdExt
- @Inject extension RoomExtensions roomExt
- @Inject extension ProcedureHelpers helpers
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (pc: root.usedProtocolClasses) {
- var path = pc.generationTargetPath+pc.getPath
-
- logger.logInfo("generating ProtocolClass header '"+pc.getCHeaderFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(pc.getCHeaderFileName, root.generateHeaderFile(pc))
-
- logger.logInfo("generating ProtocolClass source '"+pc.getCSourceFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(pc.getCSourceFileName, root.generateSourceFile(pc))
-
- }
- }
-
-
- def generateHeaderFile(Root root, ProtocolClass pc) {'''
- /**
- * @author generated by eTrice
- *
- * Header File of ProtocolClass «pc.name»
- *
- */
-
- «generateIncludeGuardBegin(pc.name)»
-
- #include "etDatatypes.h"
- #include "etPort.h"
-
- «helpers.UserCode(pc.userCode1)»
-
- «FOR dataClass : root.getReferencedDataClasses(pc)»#include "«dataClass.name».h"
- «ENDFOR»
-
- /* message IDs */
- enum {
- «pc.name»_MSG_MIN = 0,
- /* IDs for outgoing messages */
- «FOR message : pc.getAllOutgoingMessages()»
- «outMessageId(pc.name, message.name)» = «pc.getAllOutgoingMessages().indexOf(message)+1»,
- «ENDFOR»
- /* IDs for incoming messages */
- «FOR message : pc.getAllIncomingMessages()»
- «inMessageId(pc.name, message.name)» = «pc.getAllIncomingMessages().indexOf(message)+pc.getAllOutgoingMessages().size+1»,
- «ENDFOR»
- /* error if msgID >= MSG_MAX */
- «pc.name»_MSG_MAX = «pc.getAllOutgoingMessages().size + pc.getAllIncomingMessages().size+1»
- };
-
- /*--------------------- port classes */
- «portClassHeader(pc, false)»
- «portClassHeader(pc, true)»
-««« «portClass(pc, false)»
-««« «portClass(pc, true)»
-
- /*--------------------- debug helpers */
-
- /* get message string for message id */
- const char* «pc.name»_getMessageString(int msg_id);
-
- «helpers.UserCode(pc.userCode2)»
-
-
- «generateIncludeGuardEnd(pc.name)»
-
- '''
- }
-
- def generateSourceFile(Root root, ProtocolClass pc) {'''
- /**
- * @author generated by eTrice
- *
- * Source File of ProtocolClass «pc.name»
- *
- */
-
- #include "«pc.getCHeaderFileName»"
-
- #include "etMSCLogger.h"
-
- /*--------------------- port classes */
- «portClassSource(pc, false)»
- «portClassSource(pc, true)»
-
- /*--------------------- debug helpers */
- «generateDebugHelpersImplementation(root, pc)»
- '''
- }
-
-
-
- def portClass(ProtocolClass pc, Boolean conj) {'''
-««« «var name = pc.getPortClassName(conj)»
-««« «var pclass = pc.getPortClass(conj)»
-
-««« // port class
-««« static public class «name» extends PortBase {
-««« «IF pclass!=null»
-««« «helpers.UserCode(pclass.userCode)»
-««« «ENDIF»
-««« // constructors
-««« public «name»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
-««« super(actor, name, localId, 0, addr, peerAddress);
-««« DebuggingService.getInstance().addPortInstance(this);
-««« }
-««« public «name»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
-««« super(actor, name, localId, idx, addr, peerAddress);
-««« DebuggingService.getInstance().addPortInstance(this);
-««« }
-«««
-««« @Override
-««« public void receive(Message m) {
-««« if (!(m instanceof EventMessage))
-««« return;
-««« EventMessage msg = (EventMessage) m;
-««« if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
-««« System.out.println("unknown");
-««« else {
-««« if (messageStrings[msg.getEvtId()] != "timerTick"){
-««« // TODOTS: model switch for activation
-««« DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
-««« }
-««« «IF pc.handlesReceive(conj)»
-««« switch (msg.getEvtId()) {
-««« «FOR hdlr : pc.getReceiveHandlers(conj)»
-««« case «hdlr.msg.getCodeName()»:
-««« {
-««« «FOR command : hdlr.detailCode.commands»
-««« «command»
-««« «ENDFOR»
-««« }
-««« break;
-««« «ENDFOR»
-««« default:
-««« «ENDIF»
-««« if (msg instanceof EventWithDataMessage)
-««« getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
-««« else
-««« getActor().receiveEvent(this, msg.getEvtId(), null);
-««« «IF pc.handlesReceive(conj)»
-««« }
-««« «ENDIF»
-««« }
-««« }
-«««
-««« «IF pclass!=null»
-««« «helpers.Attributes(pclass.attributes)»
-««« «helpers.OperationsDeclaration(pclass.operations, name)»
-««« «ENDIF»
-«««
-««« // sent messages
-««« «FOR m : pc.getOutgoing(conj)»
-««« «sendMessage(m, conj)»
-««« «ENDFOR»
-««« }
-
-««« // replicated port class
-««« static public class «name»Repl {
-««« private ArrayList<«name»> ports;
-««« private int replication;
-«««
-««« public «name»Repl(IEventReceiver actor, String name, int localId, Address[] addr,
-««« Address[] peerAddress) {
-««« replication = addr.length;
-««« ports = new ArrayList<«pc.name».«name»>(replication);
-««« for (int i=0; i<replication; ++i) {
-««« ports.add(new «name»(
-««« actor, name+i, localId, i, addr[i], peerAddress[i]));
-««« }
-««« }
-«««
-««« public int getReplication() {
-««« return replication;
-««« }
-«««
-««« public int getIndexOf(InterfaceItemBase ifitem){
-««« return ifitem.getIdx();
-««« }
-«««
-««« public «name» get(int i) {
-««« return ports.get(i);
-««« }
-«««
-««« «IF conj»
-««« // incoming messages
-««« «FOR m : pc.getAllIncomingMessages()»
-««« «messageSignature(m)»{
-««« for (int i=0; i<replication; ++i) {
-««« ports.get(i).«messageCall(m)»;
-««« }
-««« }
-««« «ENDFOR»
-««« «ELSE»
-««« // outgoing messages
-««« «FOR m : pc.getAllOutgoingMessages()»
-««« «messageSignature(m)»{
-««« for (int i=0; i<replication; ++i) {
-««« ports.get(i).«messageCall(m)»;
-««« }
-««« }
-««« «ENDFOR»
-««« «ENDIF»
-««« }
-
- '''
- }
-
- def portClassHeader(ProtocolClass pc, Boolean conj){
- '''
- «var portClassName = pc.getPortClassName(conj)»
- «var pClass = pc.getPortClass(conj)»
-
- typedef etPort «portClassName»;
-
- «IF !conj»
-««« send functions for outgoing messages
- «FOR message : pc.getAllOutgoingMessages()»
- void «portClassName»_«message.name»(const «portClassName»* self);
- «ENDFOR»
- «ELSE»
-««« send functions for incoming messages
- «FOR message : pc.getAllIncomingMessages()»
- void «portClassName»_«message.name»(const «portClassName»* self);
- «ENDFOR»
- «ENDIF»
-
-
-««« «ClassOperationSignature(portClassName, "MyOperation1", "int a, int b", "void", true)»
-««« «ClassOperationSignature(portClassName, "MyOperation2", "", "int", false)»
-
-
- '''
- }
-
- def portClassSource(ProtocolClass pc, Boolean conj){
- '''
- «var portClassName = pc.getPortClassName(conj)»
- «var pClass = pc.getPortClass(conj)»
-
- «IF !conj»
-««« send functions for outgoing messages
- «FOR message : pc.getAllOutgoingMessages()»
- void «portClassName»_«message.name»(const «portClassName»* self){
- ET_MSC_LOGGER_SYNC_ENTRY("«portClassName»", "«message.name»")
- etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));
- msg->address = self->peerAddress;
- msg->evtID = «outMessageId(pc.name, message.name)»;
- etMessageService_pushMessage(self->msgService, msg);
- ET_MSC_LOGGER_SYNC_EXIT
- }
- «ENDFOR»
- «ELSE»
-««« send functions for incoming messages
- «FOR message : pc.getAllIncomingMessages()»
- void «portClassName»_«message.name»(const «portClassName»* self){
- ET_MSC_LOGGER_SYNC_ENTRY("«portClassName»", "«message.name»")
- etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));
- msg->address = self->peerAddress;
- msg->evtID = «inMessageId(pc.name, message.name)»;
- etMessageService_pushMessage(self->msgService, msg);
- ET_MSC_LOGGER_SYNC_EXIT
- }
- «ENDFOR»
- «ENDIF»
-
-
- '''
- }
-
-
- def messageSignature(ProtocolClass pc, Message m) {'''
- void «pc.name»_«m.name» («IF m.data!=null»«m.data.refType.type.name» «m.data.name»«ENDIF»)
- '''
- }
-
- def messageCall(Message m) {'''
- «m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)
- '''}
-
-// def sendMessage(Message m, boolean conj) {'''
-// «var dir = if (conj) "IN" else "OUT"»
-// «var hdlr = m.getSendHandler(conj)»
-// «messageSignature(m)»{
-// if (getPeerAddress()!=null)
-// «IF m.data==null»getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), «dir»_«m.name»));
-// «ELSE»getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), «dir»_«m.name», «m.data.name»«IF (!m.data.ref)».deepCopy()«ENDIF»));
-// «ENDIF»
-// }
-// '''
-// }
-
- def generateDebugHelpersImplementation(Root root, ProtocolClass pc){'''
-
- /* TODO: make this optional or different for smaller footprint */
- /* message names as strings for debugging (generate MSC) */
- static const char* «pc.name»_messageStrings[] = {"MIN", «FOR m : pc.getAllOutgoingMessages()»"«m.name»",«ENDFOR»«FOR m : pc.getAllIncomingMessages()»"«m.name»", «ENDFOR»"MAX"};
-
- const char* «pc.name»_getMessageString(int msg_id) {
- if (msg_id<«pc.name»_MSG_MIN || msg_id>«pc.name»_MSG_MAX+1){
- /* id out of range */
- return "Message ID out of range";
- }
- else{
- return «pc.name»_messageStrings[msg_id];
- }
- }
- '''
- }
-
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.core.room.ProtocolClass
+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.extensions.RoomExtensions
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+
+
+@Singleton
+class ProtocolClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (pc: root.usedProtocolClasses) {
+ var path = pc.generationTargetPath+pc.getPath
+
+ logger.logInfo("generating ProtocolClass header '"+pc.getCHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(pc.getCHeaderFileName, root.generateHeaderFile(pc))
+
+ logger.logInfo("generating ProtocolClass source '"+pc.getCSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(pc.getCSourceFileName, root.generateSourceFile(pc))
+
+ }
+ }
+
+
+ def generateHeaderFile(Root root, ProtocolClass pc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ProtocolClass «pc.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(pc.name)»
+
+ #include "etDatatypes.h"
+ #include "etPort.h"
+
+ «helpers.UserCode(pc.userCode1)»
+
+ «FOR dataClass : root.getReferencedDataClasses(pc)»#include "«dataClass.name».h"
+ «ENDFOR»
+
+ /* message IDs */
+ enum {
+ «pc.name»_MSG_MIN = 0,
+ /* IDs for outgoing messages */
+ «FOR message : pc.getAllOutgoingMessages()»
+ «outMessageId(pc.name, message.name)» = «pc.getAllOutgoingMessages().indexOf(message)+1»,
+ «ENDFOR»
+ /* IDs for incoming messages */
+ «FOR message : pc.getAllIncomingMessages()»
+ «inMessageId(pc.name, message.name)» = «pc.getAllIncomingMessages().indexOf(message)+pc.getAllOutgoingMessages().size+1»,
+ «ENDFOR»
+ /* error if msgID >= MSG_MAX */
+ «pc.name»_MSG_MAX = «pc.getAllOutgoingMessages().size + pc.getAllIncomingMessages().size+1»
+ };
+
+ /*--------------------- port classes */
+ «portClassHeader(pc, false)»
+ «portClassHeader(pc, true)»
+««« «portClass(pc, false)»
+««« «portClass(pc, true)»
+
+ /*--------------------- debug helpers */
+
+ /* get message string for message id */
+ const char* «pc.name»_getMessageString(int msg_id);
+
+ «helpers.UserCode(pc.userCode2)»
+
+
+ «generateIncludeGuardEnd(pc.name)»
+
+ '''
+ }
+
+ def generateSourceFile(Root root, ProtocolClass pc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass «pc.name»
+ *
+ */
+
+ #include "«pc.getCHeaderFileName»"
+
+ #include "etMSCLogger.h"
+
+ /*--------------------- port classes */
+ «portClassSource(pc, false)»
+ «portClassSource(pc, true)»
+
+ /*--------------------- debug helpers */
+ «generateDebugHelpersImplementation(root, pc)»
+ '''
+ }
+
+
+
+ def portClass(ProtocolClass pc, Boolean conj) {'''
+««« «var name = pc.getPortClassName(conj)»
+««« «var pclass = pc.getPortClass(conj)»
+
+««« // port class
+««« static public class «name» extends PortBase {
+««« «IF pclass!=null»
+««« «helpers.UserCode(pclass.userCode)»
+««« «ENDIF»
+««« // constructors
+««« public «name»(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+««« super(actor, name, localId, 0, addr, peerAddress);
+««« DebuggingService.getInstance().addPortInstance(this);
+««« }
+««« public «name»(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+««« super(actor, name, localId, idx, addr, peerAddress);
+««« DebuggingService.getInstance().addPortInstance(this);
+««« }
+«««
+««« @Override
+««« public void receive(Message m) {
+««« if (!(m instanceof EventMessage))
+««« return;
+««« EventMessage msg = (EventMessage) m;
+««« if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+««« System.out.println("unknown");
+««« else {
+««« if (messageStrings[msg.getEvtId()] != "timerTick"){
+««« // TODOTS: model switch for activation
+««« DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
+««« }
+««« «IF pc.handlesReceive(conj)»
+««« switch (msg.getEvtId()) {
+««« «FOR hdlr : pc.getReceiveHandlers(conj)»
+««« case «hdlr.msg.getCodeName()»:
+««« {
+««« «FOR command : hdlr.detailCode.commands»
+««« «command»
+««« «ENDFOR»
+««« }
+««« break;
+««« «ENDFOR»
+««« default:
+««« «ENDIF»
+««« if (msg instanceof EventWithDataMessage)
+««« getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+««« else
+««« getActor().receiveEvent(this, msg.getEvtId(), null);
+««« «IF pc.handlesReceive(conj)»
+««« }
+««« «ENDIF»
+««« }
+««« }
+«««
+««« «IF pclass!=null»
+««« «helpers.Attributes(pclass.attributes)»
+««« «helpers.OperationsDeclaration(pclass.operations, name)»
+««« «ENDIF»
+«««
+««« // sent messages
+««« «FOR m : pc.getOutgoing(conj)»
+««« «sendMessage(m, conj)»
+««« «ENDFOR»
+««« }
+
+««« // replicated port class
+««« static public class «name»Repl {
+««« private ArrayList<«name»> ports;
+««« private int replication;
+«««
+««« public «name»Repl(IEventReceiver actor, String name, int localId, Address[] addr,
+««« Address[] peerAddress) {
+««« replication = addr.length;
+««« ports = new ArrayList<«pc.name».«name»>(replication);
+««« for (int i=0; i<replication; ++i) {
+««« ports.add(new «name»(
+««« actor, name+i, localId, i, addr[i], peerAddress[i]));
+««« }
+««« }
+«««
+««« public int getReplication() {
+««« return replication;
+««« }
+«««
+««« public int getIndexOf(InterfaceItemBase ifitem){
+««« return ifitem.getIdx();
+««« }
+«««
+««« public «name» get(int i) {
+««« return ports.get(i);
+««« }
+«««
+««« «IF conj»
+««« // incoming messages
+««« «FOR m : pc.getAllIncomingMessages()»
+««« «messageSignature(m)»{
+««« for (int i=0; i<replication; ++i) {
+««« ports.get(i).«messageCall(m)»;
+««« }
+««« }
+««« «ENDFOR»
+««« «ELSE»
+««« // outgoing messages
+««« «FOR m : pc.getAllOutgoingMessages()»
+««« «messageSignature(m)»{
+««« for (int i=0; i<replication; ++i) {
+««« ports.get(i).«messageCall(m)»;
+««« }
+««« }
+««« «ENDFOR»
+««« «ENDIF»
+««« }
+
+ '''
+ }
+
+ def portClassHeader(ProtocolClass pc, Boolean conj){
+ '''
+ «var portClassName = pc.getPortClassName(conj)»
+ «var pClass = pc.getPortClass(conj)»
+
+ typedef etPort «portClassName»;
+
+ «IF !conj»
+««« send functions for outgoing messages
+ «FOR message : pc.getAllOutgoingMessages()»
+ void «portClassName»_«message.name»(const «portClassName»* self);
+ «ENDFOR»
+ «ELSE»
+««« send functions for incoming messages
+ «FOR message : pc.getAllIncomingMessages()»
+ void «portClassName»_«message.name»(const «portClassName»* self);
+ «ENDFOR»
+ «ENDIF»
+
+
+««« «ClassOperationSignature(portClassName, "MyOperation1", "int a, int b", "void", true)»
+««« «ClassOperationSignature(portClassName, "MyOperation2", "", "int", false)»
+
+
+ '''
+ }
+
+ def portClassSource(ProtocolClass pc, Boolean conj){
+ '''
+ «var portClassName = pc.getPortClassName(conj)»
+ «var pClass = pc.getPortClass(conj)»
+
+ «IF !conj»
+««« send functions for outgoing messages
+ «FOR message : pc.getAllOutgoingMessages()»
+ void «portClassName»_«message.name»(const «portClassName»* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("«portClassName»", "«message.name»")
+ etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));
+ msg->address = self->peerAddress;
+ msg->evtID = «outMessageId(pc.name, message.name)»;
+ etMessageService_pushMessage(self->msgService, msg);
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+ «ENDFOR»
+ «ELSE»
+««« send functions for incoming messages
+ «FOR message : pc.getAllIncomingMessages()»
+ void «portClassName»_«message.name»(const «portClassName»* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("«portClassName»", "«message.name»")
+ etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));
+ msg->address = self->peerAddress;
+ msg->evtID = «inMessageId(pc.name, message.name)»;
+ etMessageService_pushMessage(self->msgService, msg);
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+ «ENDFOR»
+ «ENDIF»
+
+
+ '''
+ }
+
+
+ def messageSignature(ProtocolClass pc, Message m) {'''
+ void «pc.name»_«m.name» («IF m.data!=null»«m.data.refType.type.name» «m.data.name»«ENDIF»)
+ '''
+ }
+
+ def messageCall(Message m) {'''
+ «m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)
+ '''}
+
+// def sendMessage(Message m, boolean conj) {'''
+// «var dir = if (conj) "IN" else "OUT"»
+// «var hdlr = m.getSendHandler(conj)»
+// «messageSignature(m)»{
+// if (getPeerAddress()!=null)
+// «IF m.data==null»getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), «dir»_«m.name»));
+// «ELSE»getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), «dir»_«m.name», «m.data.name»«IF (!m.data.ref)».deepCopy()«ENDIF»));
+// «ENDIF»
+// }
+// '''
+// }
+
+ def generateDebugHelpersImplementation(Root root, ProtocolClass pc){'''
+
+ /* TODO: make this optional or different for smaller footprint */
+ /* message names as strings for debugging (generate MSC) */
+ static const char* «pc.name»_messageStrings[] = {"MIN", «FOR m : pc.getAllOutgoingMessages()»"«m.name»",«ENDFOR»«FOR m : pc.getAllIncomingMessages()»"«m.name»", «ENDFOR»"MAX"};
+
+ const char* «pc.name»_getMessageString(int msg_id) {
+ if (msg_id<«pc.name»_MSG_MIN || msg_id>«pc.name»_MSG_MAX+1){
+ /* id out of range */
+ return "Message ID out of range";
+ }
+ else{
+ return «pc.name»_messageStrings[msg_id];
+ }
+ }
+ '''
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend
index 44fdc9e43..d5d802277 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/StateMachineGen.xtend
@@ -1,258 +1,258 @@
-/*******************************************************************************
- * 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.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import java.util.List
-import org.eclipse.etrice.core.room.ActorClass
-import org.eclipse.etrice.core.room.NonInitialTransition
-import org.eclipse.etrice.core.room.Transition
-import org.eclipse.etrice.core.room.TriggeredTransition
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
-import org.eclipse.etrice.generator.etricegen.TransitionChain
-import static extension org.eclipse.etrice.generator.extensions.RoomNameProv.*
-import org.eclipse.etrice.generator.extensions.RoomExtensions
-import org.eclipse.etrice.generator.generic.LanguageGenerator
-
-
-@Singleton
-class StateMachineGen {
-
- @Inject extension CExtensions stdExt
- @Inject extension RoomExtensions roomExt
- @Inject LanguageGenerator languageGen
-
- def genStateMachine(ExpandedActorClass xpac, ActorClass ac) {'''
- //******************************************
- // START of generated code for FSM
- //******************************************
-
- // State IDs for FSM
- «var offset = ac.getNumberOfInheritedBaseStates()»
- «var baseStates = ac.stateMachine.getBaseStateList()»
- «FOR state : baseStates»
- protected static final int «state.getStateId()» = «baseStates.indexOf(state)+2+offset»;
- «ENDFOR»
- protected static final String stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStates() SEPARATOR ","»"«state.getStatePathName()»"
- «ENDFOR»};
-
- // history
- // TODOHRR: history defined in ActorClassBase, init in constructor
- // history = new int[5];
- // for (int i = 0; i < history.length; i++) {
- // history[i] = NO_STATE;
- // }
- protected int history[] = {NO_STATE,NO_STATE«FOR state : ac.getAllBaseStates()»,NO_STATE«ENDFOR»};
-
- «var List<TransitionChain> chains = xpac.getOwnTransitionChains()»
- «var offset_tc = xpac.getTransitionChains().size-chains.size»
- // transition chains
- «FOR tc : chains»
- protected static final int «tc.getChainId()» = «chains.indexOf(tc)+1+offset_tc»;
- «ENDFOR»
-
- «var triggers = xpac.getOwnTriggers()»
- // triggers for FSM
- «FOR mif : triggers»protected static final int «xpac.getTriggerCodeName(mif)» = IFITEM_«mif.from.name» + EVT_SHIFT*«xpac.getMessageID(mif)»;
- «ENDFOR»
-
- // receiveEvent contains the main implementation of the FSM
- @Override
- public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {
- int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;
- int chain = NOT_CAUGHT;
- int catching_state = NO_STATE;
- boolean is_handler = false;
- boolean skip_entry = false;
-
- if (!handleSystemEvent(ifitem, evt, generic_data)) {
- switch (state) {
- «FOR state : xpac.stateMachine.getLeafStateList()»
- case «state.getStateId()»:
- «var atlist = xpac.getActiveTriggers(state)»
- «IF !atlist.isEmpty»
- switch(trigger) {
- «FOR at : atlist»
- case «xpac.getTriggerCodeName(at.trigger)»:
- «var needData = xpac.hasGuard(at)»
- «IF needData»{ «at.msg.getTypedDataDefinition()»«ENDIF»
- «FOR tt : at.transitions SEPARATOR " else "»
- «var chain = xpac.getChain(tt)»
- «guard(chain.transition, at.trigger, xpac)»
- {
- chain = «chain.getChainId()»;
- catching_state = «chain.getContextId()»;
- «IF chain.isHandler()»is_handler = true;«ENDIF»
- «IF chain.skipEntry»skip_entry = true;«ENDIF»
- }
- «ENDFOR»
- «IF needData»}«ENDIF»
- break;
- «ENDFOR»
- }
- «ENDIF»
- break;
- «ENDFOR»
- }
- }
- if (chain != NOT_CAUGHT) {
- exitTo(state, catching_state, is_handler);
- int next = executeTransitionChain(chain, ifitem, generic_data);
- next = enterHistory(next, is_handler, skip_entry);
- setState(next);
- }
- }
-
- private void setState(int new_state) {
- DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
- if (stateStrings[new_state]!="Idle") {
- // TODOTS: model switch for activation
- System.out.println(getInstancePath() + " -> " + stateStrings[new_state]);
- }
- this.state = new_state;
- }
-
- @Override
- public void executeInitTransition() {
- «var initt = xpac.stateMachine.getInitTransition()»
- int chain = «xpac.getChain(initt).getChainId()»;
- int next = executeTransitionChain(chain, null, null);
- next = enterHistory(next, false, false);
- setState(next);
- }
-
- /**
- * calls exit codes while exiting from the current state to one of its
- * parent states while remembering the history
- * @param current - the current state
- * @param to - the final parent state
- * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
- */
- private void exitTo(int current, int to, boolean handler) {
- while (current!=to) {
- switch (current) {
- «FOR state : xpac.stateMachine.getBaseStateList()»
- case «state.getStateId()»:
- «IF state.hasExitCode()»if (!handler) «state.getExitCodeOperationName()»();«ENDIF»
- history[«state.getParentStateId()»] = «state.getStateId()»;
- current = «state.getParentStateId()»;
- break;
- «ENDFOR»
- }
- }
- }
- /**
- * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
- * matching the trigger of this chain. The ID of the final state is returned
- * @param chain - the chain ID
- * @param generic_data - the generic data pointer
- * @return the ID of the final state
- */
- private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {
- switch (chain) {
- «var allchains = xpac.getTransitionChains()»
- «FOR tc : allchains»
- case «tc.getChainId()»:
- {
- «xpac.getExecuteChainCode(tc)»
- }
- «ENDFOR»
- }
- return NO_STATE;
- }
- /**
- * calls entry codes while entering a state's history. The ID of the final leaf state is returned
- * @param state - the state which is entered
- * @param handler - entry code is executed if not handler
- * @return - the ID of the final leaf state
- */
- private int enterHistory(int state, boolean handler, boolean skip_entry) {
- while (true) {
- switch (state) {
- «FOR state : xpac.stateMachine.getBaseStateList()»
- case «state.getStateId()»:
- «IF state.hasEntryCode()»if (!(skip_entry || handler)) «state.getEntryCodeOperationName()»();«ENDIF»
- «IF state.isLeaf()»
- // in leaf state: return state id
- return «state.getStateId()»;
- «ELSE»
- // state has a sub graph
- «IF state.subgraph.hasInitTransition()»
- // with init transition
- if (history[«state.getStateId()»]==NO_STATE) {
- «var sub_initt = state.subgraph.getInitTransition()»
- state = executeTransitionChain(«xpac.getChain(sub_initt).getChainId()», null, null);
- }
- else {
- state = history[«state.getStateId()»];
- }
- «ELSE»
- // without init transition
- state = history[«state.getStateId()»];
- «ENDIF»
- break;
- «ENDIF»
- «ENDFOR»
- case STATE_TOP:
- state = history[STATE_TOP];
- break;
- }
- skip_entry = false;
- }
- //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
- }
-
- //*** Entry and Exit Codes
- «FOR state : xpac.stateMachine.getStateList()»
- «IF xpac.isOwnObject(state)»
- «IF state.hasEntryCode()»
- protected void «state.getEntryCodeOperationName()»() {
- «xpac.getEntryCode(state)»
- }
- «ENDIF»
- «IF state.hasExitCode()»
- protected void «state.getExitCodeOperationName()»() {
- «xpac.getExitCode(state)»
- }
- «ENDIF»
- «ENDIF»
- «ENDFOR»
-
- //*** Action Codes
- «FOR tr : xpac.stateMachine.getTransitionList()»
- «IF xpac.isOwnObject(tr) && tr.hasActionCode()»
- protected void «tr.getActionCodeOperationName()»(«IF tr instanceof NonInitialTransition»InterfaceItemBase ifitem«languageGen.getArgumentList(xpac, tr)»«ENDIF») {
- «xpac.getActionCode(tr)»
- }
- «ENDIF»
- «ENDFOR»
-
- //******************************************
- // END of generated code for FSM
- //******************************************
- '''}
-
- def dispatch guard(TriggeredTransition tt, String trigger, ExpandedActorClass ac) {'''
- «var tr = tt.triggers.findFirst(e|ac.isMatching(e, trigger))»
- «IF tr.hasGuard()»
- if («ac.getCode(tr.guard.guard)»)
- «ENDIF»
- '''
- }
-
- def dispatch guard(Transition t, String trigger, ExpandedActorClass ac) {'''
- /* error */
- '''
- }
-}
+/*******************************************************************************
+ * 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.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.NonInitialTransition
+import org.eclipse.etrice.core.room.Transition
+import org.eclipse.etrice.core.room.TriggeredTransition
+import org.eclipse.etrice.generator.etricegen.ExpandedActorClass
+import org.eclipse.etrice.generator.etricegen.TransitionChain
+import static extension org.eclipse.etrice.generator.extensions.RoomNameProv.*
+import org.eclipse.etrice.generator.extensions.RoomExtensions
+import org.eclipse.etrice.generator.generic.LanguageGenerator
+
+
+@Singleton
+class StateMachineGen {
+
+ @Inject extension CExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject LanguageGenerator languageGen
+
+ def genStateMachine(ExpandedActorClass xpac, ActorClass ac) {'''
+ //******************************************
+ // START of generated code for FSM
+ //******************************************
+
+ // State IDs for FSM
+ «var offset = ac.getNumberOfInheritedBaseStates()»
+ «var baseStates = ac.stateMachine.getBaseStateList()»
+ «FOR state : baseStates»
+ protected static final int «state.getStateId()» = «baseStates.indexOf(state)+2+offset»;
+ «ENDFOR»
+ protected static final String stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStates() SEPARATOR ","»"«state.getStatePathName()»"
+ «ENDFOR»};
+
+ // history
+ // TODOHRR: history defined in ActorClassBase, init in constructor
+ // history = new int[5];
+ // for (int i = 0; i < history.length; i++) {
+ // history[i] = NO_STATE;
+ // }
+ protected int history[] = {NO_STATE,NO_STATE«FOR state : ac.getAllBaseStates()»,NO_STATE«ENDFOR»};
+
+ «var List<TransitionChain> chains = xpac.getOwnTransitionChains()»
+ «var offset_tc = xpac.getTransitionChains().size-chains.size»
+ // transition chains
+ «FOR tc : chains»
+ protected static final int «tc.getChainId()» = «chains.indexOf(tc)+1+offset_tc»;
+ «ENDFOR»
+
+ «var triggers = xpac.getOwnTriggers()»
+ // triggers for FSM
+ «FOR mif : triggers»protected static final int «xpac.getTriggerCodeName(mif)» = IFITEM_«mif.from.name» + EVT_SHIFT*«xpac.getMessageID(mif)»;
+ «ENDFOR»
+
+ // receiveEvent contains the main implementation of the FSM
+ @Override
+ public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {
+ int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;
+ int chain = NOT_CAUGHT;
+ int catching_state = NO_STATE;
+ boolean is_handler = false;
+ boolean skip_entry = false;
+
+ if (!handleSystemEvent(ifitem, evt, generic_data)) {
+ switch (state) {
+ «FOR state : xpac.stateMachine.getLeafStateList()»
+ case «state.getStateId()»:
+ «var atlist = xpac.getActiveTriggers(state)»
+ «IF !atlist.isEmpty»
+ switch(trigger) {
+ «FOR at : atlist»
+ case «xpac.getTriggerCodeName(at.trigger)»:
+ «var needData = xpac.hasGuard(at)»
+ «IF needData»{ «at.msg.getTypedDataDefinition()»«ENDIF»
+ «FOR tt : at.transitions SEPARATOR " else "»
+ «var chain = xpac.getChain(tt)»
+ «guard(chain.transition, at.trigger, xpac)»
+ {
+ chain = «chain.getChainId()»;
+ catching_state = «chain.getContextId()»;
+ «IF chain.isHandler()»is_handler = true;«ENDIF»
+ «IF chain.skipEntry»skip_entry = true;«ENDIF»
+ }
+ «ENDFOR»
+ «IF needData»}«ENDIF»
+ break;
+ «ENDFOR»
+ }
+ «ENDIF»
+ break;
+ «ENDFOR»
+ }
+ }
+ if (chain != NOT_CAUGHT) {
+ exitTo(state, catching_state, is_handler);
+ int next = executeTransitionChain(chain, ifitem, generic_data);
+ next = enterHistory(next, is_handler, skip_entry);
+ setState(next);
+ }
+ }
+
+ private void setState(int new_state) {
+ DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
+ if (stateStrings[new_state]!="Idle") {
+ // TODOTS: model switch for activation
+ System.out.println(getInstancePath() + " -> " + stateStrings[new_state]);
+ }
+ this.state = new_state;
+ }
+
+ @Override
+ public void executeInitTransition() {
+ «var initt = xpac.stateMachine.getInitTransition()»
+ int chain = «xpac.getChain(initt).getChainId()»;
+ int next = executeTransitionChain(chain, null, null);
+ next = enterHistory(next, false, false);
+ setState(next);
+ }
+
+ /**
+ * calls exit codes while exiting from the current state to one of its
+ * parent states while remembering the history
+ * @param current - the current state
+ * @param to - the final parent state
+ * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
+ */
+ private void exitTo(int current, int to, boolean handler) {
+ while (current!=to) {
+ switch (current) {
+ «FOR state : xpac.stateMachine.getBaseStateList()»
+ case «state.getStateId()»:
+ «IF state.hasExitCode()»if (!handler) «state.getExitCodeOperationName()»();«ENDIF»
+ history[«state.getParentStateId()»] = «state.getStateId()»;
+ current = «state.getParentStateId()»;
+ break;
+ «ENDFOR»
+ }
+ }
+ }
+ /**
+ * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
+ * matching the trigger of this chain. The ID of the final state is returned
+ * @param chain - the chain ID
+ * @param generic_data - the generic data pointer
+ * @return the ID of the final state
+ */
+ private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {
+ switch (chain) {
+ «var allchains = xpac.getTransitionChains()»
+ «FOR tc : allchains»
+ case «tc.getChainId()»:
+ {
+ «xpac.getExecuteChainCode(tc)»
+ }
+ «ENDFOR»
+ }
+ return NO_STATE;
+ }
+ /**
+ * calls entry codes while entering a state's history. The ID of the final leaf state is returned
+ * @param state - the state which is entered
+ * @param handler - entry code is executed if not handler
+ * @return - the ID of the final leaf state
+ */
+ private int enterHistory(int state, boolean handler, boolean skip_entry) {
+ while (true) {
+ switch (state) {
+ «FOR state : xpac.stateMachine.getBaseStateList()»
+ case «state.getStateId()»:
+ «IF state.hasEntryCode()»if (!(skip_entry || handler)) «state.getEntryCodeOperationName()»();«ENDIF»
+ «IF state.isLeaf()»
+ // in leaf state: return state id
+ return «state.getStateId()»;
+ «ELSE»
+ // state has a sub graph
+ «IF state.subgraph.hasInitTransition()»
+ // with init transition
+ if (history[«state.getStateId()»]==NO_STATE) {
+ «var sub_initt = state.subgraph.getInitTransition()»
+ state = executeTransitionChain(«xpac.getChain(sub_initt).getChainId()», null, null);
+ }
+ else {
+ state = history[«state.getStateId()»];
+ }
+ «ELSE»
+ // without init transition
+ state = history[«state.getStateId()»];
+ «ENDIF»
+ break;
+ «ENDIF»
+ «ENDFOR»
+ case STATE_TOP:
+ state = history[STATE_TOP];
+ break;
+ }
+ skip_entry = false;
+ }
+ //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
+ }
+
+ //*** Entry and Exit Codes
+ «FOR state : xpac.stateMachine.getStateList()»
+ «IF xpac.isOwnObject(state)»
+ «IF state.hasEntryCode()»
+ protected void «state.getEntryCodeOperationName()»() {
+ «xpac.getEntryCode(state)»
+ }
+ «ENDIF»
+ «IF state.hasExitCode()»
+ protected void «state.getExitCodeOperationName()»() {
+ «xpac.getExitCode(state)»
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+
+ //*** Action Codes
+ «FOR tr : xpac.stateMachine.getTransitionList()»
+ «IF xpac.isOwnObject(tr) && tr.hasActionCode()»
+ protected void «tr.getActionCodeOperationName()»(«IF tr instanceof NonInitialTransition»InterfaceItemBase ifitem«languageGen.getArgumentList(xpac, tr)»«ENDIF») {
+ «xpac.getActionCode(tr)»
+ }
+ «ENDIF»
+ «ENDFOR»
+
+ //******************************************
+ // END of generated code for FSM
+ //******************************************
+ '''}
+
+ def dispatch guard(TriggeredTransition tt, String trigger, ExpandedActorClass ac) {'''
+ «var tr = tt.triggers.findFirst(e|ac.isMatching(e, trigger))»
+ «IF tr.hasGuard()»
+ if («ac.getCode(tr.guard.guard)»)
+ «ENDIF»
+ '''
+ }
+
+ def dispatch guard(Transition t, String trigger, ExpandedActorClass ac) {'''
+ /* error */
+ '''
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
index 969211abc..fcbda3217 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
@@ -1,356 +1,356 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.SubSystemClass
-import org.eclipse.etrice.generator.base.ILogger
-import org.eclipse.etrice.generator.etricegen.Root
-import org.eclipse.etrice.generator.etricegen.ServiceImplInstance
-import org.eclipse.etrice.generator.etricegen.SubSystemInstance
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.extensions.RoomExtensions
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-
-import static extension org.eclipse.etrice.generator.base.Indexed.*
-
-
-@Singleton
-class SubSystemClassGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CExtensions stdExt
- @Inject extension RoomExtensions roomExt
- @Inject extension ProcedureHelpers helpers
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (ssi: root.subSystemInstances) {
- var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
- var file = ssi.subSystemClass.getCHeaderFileName
- logger.logInfo("generating SubSystemClass declaration: '"+file+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(file, root.generateHeaderFile(ssi, ssi.subSystemClass))
-
- file = ssi.subSystemClass.getCSourceFileName
- logger.logInfo("generating SubSystemClass implementation: '"+file+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(file, root.generateSourceFile(ssi, ssi.subSystemClass))
-
- file = ssi.subSystemClass.getInstSourceFileName
- logger.logInfo("generating SubSystemClass instance file: '"+file+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(file, root.generateInstanceFile(ssi, ssi.subSystemClass))
- }
- }
-
- def generateHeaderFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
- /**
- * @author generated by eTrice
- *
- * Header File of SubSystemClass «ssc.name»
- *
- */
-
- «generateIncludeGuardBegin(ssc.name)»
-
-
- /* lifecycle functions
- * init -> start -> run (loop) -> stop -> destroy
- */
-
- void «ssc.name»_init(void); /* lifecycle init */
- void «ssc.name»_start(void); /* lifecycle start */
-
- void «ssc.name»_run(void); /* lifecycle run */
-
- void «ssc.name»_stop(void); /* lifecycle stop */
- void «ssc.name»_destroy(void); /* lifecycle destroy */
-
-
- «generateIncludeGuardEnd(ssc.name)»
-
-
- '''
- }
-
- def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
- /**
- * @author generated by eTrice
- *
- * Source File of SubSystemClass «ssc.name»
- *
- */
-
- #include "«ssc.getCHeaderFileName»"
-
- /* include instances for all classes */
- #include "«ssc.getInstSourceFileName»"
-
- #include "etLogger.h"
- #include "etMSCLogger.h"
-
-
- /* data for SubSysten «ssc.name» */
- typedef struct «ssc.name» {
- char *name;
- } «ssc.name»;
-
- static «ssc.name» «ssc.name»Inst = {"«ssc.name»"};
-
- void «ssc.name»_initActorInstances(void);
-
- void «ssc.name»_init(void){
- ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "init")
- etLogger_logInfoF("%s_init", «ssc.name»Inst.name);
-
- /* initialization of all message services */
- etMessageService_init(&msgService_Thread1, msgBuffer_Thread1, MESSAGE_POOL_MAX, MESSAGE_BLOCK_SIZE);
-
- /* init all actors */
- «ssc.name»_initActorInstances();
-
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- void «ssc.name»_start(void){
- ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "start")
- etLogger_logInfoF("%s_start", «ssc.name»Inst.name);
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- void «ssc.name»_run(void){
- ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "run")
- int32 i;
- for (i=0; i<100; i++){
- etLogger_logInfoF("%s Scheduler tick %d", «ssc.name»Inst.name, i);
- etMessageService_execute(&msgService_Thread1);
- }
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- void «ssc.name»_stop(void){
- ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "stop")
- etLogger_logInfoF("%s_stop", «ssc.name»Inst.name);
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- void «ssc.name»_destroy(void){
- ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "destroy")
- etLogger_logInfoF("%s_destroy", «ssc.name»Inst.name);
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- void «ssc.name»_initActorInstances(void){
- ET_MSC_LOGGER_SYNC_ENTRY("«ssc.name»", "initActorInstances")
- «FOR ai : ssi.allContainedInstances»
- «ai.actorClass.name»_init(&«ai.path.getPathName()»);
- «ENDFOR»
- ET_MSC_LOGGER_SYNC_EXIT
- }
-
- '''
- }
-
- def generateInstanceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
- /**
- * @author generated by eTrice
- *
- * Instance File of SubSystemClass «ssc.name»
- * - instantiation of all actor instances and port instances
- * - configuration of data and connection of ports
- */
-
- #include "etMessageService.h"
-
- /* instantiation of message services */
- #define MESSAGE_POOL_MAX 10
- #define MESSAGE_BLOCK_SIZE 32
- /* MessageService for Thread1 */
- uint8 msgBuffer_Thread1[MESSAGE_POOL_MAX*MESSAGE_BLOCK_SIZE];
- etMessageService msgService_Thread1;
-
-
- /* include all used ActorClasses */
- /* TODO: only include used Actor Classes for current SubSystem */
- «FOR actorClass : root.getUsedActorClasses()»#include "«actorClass.name».h"
- «ENDFOR»
-
- /* include all used ProtcolClasses */
- «FOR protocolClass : root.getUsedProtocolClasses()»#include "«protocolClass.name».h"
- «ENDFOR»
-
-
- /* declarations of all ActorClass instances (const and variable structs) */
-
- /* forward declaration of varible actor structs */
- «FOR ai : ssi.allContainedInstances»
- static «ai.actorClass.name» «ai.path.getPathName()»;
- «ENDFOR»
-
- «FOR ai : ssi.allContainedInstances»
-
- /* instance «ai.path.getPathName()» */
- static const «ai.actorClass.name»_const «ai.path.getPathName()»_const = {
- &«ai.path.getPathName()»,
- /* Ports: {myActor, etReceiveMessage, msgService, peerAddress, localId} */
- «FOR port : ai.actorClass.endPorts»
- {&«ai.path.getPathName()», «ai.actorClass.name»_ReceiveMessage, &msgService_Thread1, 1, 123} /* Port «port.name» */
- «ENDFOR»
-
- };
- static «ai.actorClass.name» «ai.path.getPathName()» = {&«ai.path.getPathName()»_const};
- «ENDFOR»
-
-
-««« «FOR ai : ssi.allContainedInstances»
-««« // actor instance «ai.path» itself => Systemport Address
-««« // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
-««« Address addr_item_«ai.path.getPathName()» = new Address(0,«ai.threadId»,«ai.objId»);
-««« // interface items of «ai.path»
-««« «FOR pi : ai.orderedIfItemInstances»
-««« «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
-««« «FOR peer : pi.peers»
-««« «var i = pi.peers.indexOf(peer)»
-««« Address addr_item_«pi.path.getPathName()»_«i» = new Address(0,«pi.threadId»,«pi.objId+i»);
-««« «ENDFOR»
-««« «ELSE»
-««« Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
-««« «ENDIF»
-««« «ENDFOR»
-««« «ENDFOR»
-
- '''
- }
-
-
-// «var models = root.getReferencedModels(ssc)»
-// «FOR model : models»import «model.name».*;«ENDFOR»
-//
-//
-// «helpers.UserCode(ssc.userCode1)»
-//
-// public class «ssi.name» extends SubSystemClassBase{
-//
-// «helpers.UserCode(ssc.userCode2)»
-//
-// public «ssi.name»(IRTObject parent, String name) {
-// super(parent, name);
-// }
-//
-// @Override
-// public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){
-// }
-//
-// @Override
-// public void instantiateMessageServices(){
-//
-// RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 0, 0),"MessageService_Main"));
-// «FOR thread : ssc.threads»
-// RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, «ssc.threads.indexOf(thread)+1», 0),"MessageService_«thread.name»", «thread.prio»));
-// «ENDFOR»
-// }
-//
-// @Override
-// public void instantiateActors(){
-// // all addresses
-// // Addresses for the Subsystem Systemport
-// «FOR ai : ssi.allContainedInstances.indexed(ssi.maxObjId)»
-// Address addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai.value)» = new Address(0,0,«ai.index1»);
-// «ENDFOR»
-//
-// «FOR ai : ssi.allContainedInstances»
-// // actor instance «ai.path» itself => Systemport Address
-// // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
-// Address addr_item_«ai.path.getPathName()» = new Address(0,«ai.threadId»,«ai.objId»);
-// // interface items of «ai.path»
-// «FOR pi : ai.orderedIfItemInstances»
-// «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
-// «FOR peer : pi.peers»
-// «var i = pi.peers.indexOf(peer)»
-// Address addr_item_«pi.path.getPathName()»_«i» = new Address(0,«pi.threadId»,«pi.objId+i»);
-// «ENDFOR»
-// «ELSE»
-// Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
-// «ENDIF»
-// «ENDFOR»
-// «ENDFOR»
-//
-// // instantiate all actor instances
-// instances = new ActorClassBase[«ssi.allContainedInstances.size»];
-// «FOR ai : ssi.allContainedInstances»
-// instances[«ssi.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
-// «IF ai.eContainer instanceof SubSystemInstance»
-// this,
-// «ELSE»
-// instances[«ssi.allContainedInstances.indexOf(ai.eContainer)»],
-// «ENDIF»
-// "«ai.name»",
-// // own interface item addresses
-// new Address[][] {{addr_item_«ai.path.getPathName()»}«IF !ai.orderedIfItemInstances.empty»,«ENDIF»
-// «FOR pi : ai.orderedIfItemInstances SEPARATOR ","»
-// {
-// «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
-// «FOR peer : pi.peers SEPARATOR ","»
-// addr_item_«pi.path.getPathName()»_«pi.peers.indexOf(peer)»
-// «ENDFOR»
-// «ELSE»
-// addr_item_«pi.path.getPathName()»
-// «ENDIF»
-// }
-// «ENDFOR»
-// },
-// // peer interface item addresses
-// new Address[][] {{addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai)»}«IF !ai.orderedIfItemInstances.empty»,«ENDIF»
-// «FOR pi : ai.orderedIfItemInstances SEPARATOR ","»
-// {
-// «IF !(pi instanceof ServiceImplInstance) && pi.peers.isEmpty»
-// null
-// «ELSE»
-// «FOR pp : pi.peers SEPARATOR ","»
-// «IF pp instanceof ServiceImplInstance || pp.peers.size>1»
-// addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»
-// «ELSE»
-// addr_item_«pp.path.getPathName()»
-// «ENDIF»
-// «ENDFOR»
-// «ENDIF»
-// }
-// «ENDFOR»
-// }
-// );
-// «ENDFOR»
-//
-// // create the subsystem system port
-// RTSystemPort = new RTSystemServicesProtocolConjPortRepl(this, "RTSystemPort",
-// 0, //local ID
-// // own addresses
-// new Address[]{
-// «FOR ai : ssi.allContainedInstances SEPARATOR ","»
-// addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai)»
-// «ENDFOR»
-// },
-// // peer addresses
-// new Address[]{
-// «FOR ai : ssi.allContainedInstances SEPARATOR ","»
-// addr_item_«ai.path.getPathName()»
-// «ENDFOR»
-// });
-//
-// }
-// };
-
-
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.generator.base.ILogger
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.etrice.generator.etricegen.ServiceImplInstance
+import org.eclipse.etrice.generator.etricegen.SubSystemInstance
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.extensions.RoomExtensions
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+
+import static extension org.eclipse.etrice.generator.base.Indexed.*
+
+
+@Singleton
+class SubSystemClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (ssi: root.subSystemInstances) {
+ var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
+ var file = ssi.subSystemClass.getCHeaderFileName
+ logger.logInfo("generating SubSystemClass declaration: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateHeaderFile(ssi, ssi.subSystemClass))
+
+ file = ssi.subSystemClass.getCSourceFileName
+ logger.logInfo("generating SubSystemClass implementation: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateSourceFile(ssi, ssi.subSystemClass))
+
+ file = ssi.subSystemClass.getInstSourceFileName
+ logger.logInfo("generating SubSystemClass instance file: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateInstanceFile(ssi, ssi.subSystemClass))
+ }
+ }
+
+ def generateHeaderFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of SubSystemClass «ssc.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(ssc.name)»
+
+
+ /* lifecycle functions
+ * init -> start -> run (loop) -> stop -> destroy
+ */
+
+ void «ssc.name»_init(void); /* lifecycle init */
+ void «ssc.name»_start(void); /* lifecycle start */
+
+ void «ssc.name»_run(void); /* lifecycle run */
+
+ void «ssc.name»_stop(void); /* lifecycle stop */
+ void «ssc.name»_destroy(void); /* lifecycle destroy */
+
+
+ «generateIncludeGuardEnd(ssc.name)»
+
+
+ '''
+ }
+
+ def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of SubSystemClass «ssc.name»
+ *
+ */
+
+ #include "«ssc.getCHeaderFileName»"
+
+ /* include instances for all classes */
+ #include "«ssc.getInstSourceFileName»"
+
+ #include "etLogger.h"
+ #include "etMSCLogger.h"
+
+
+ /* data for SubSysten «ssc.name» */
+ typedef struct «ssc.name» {
+ char *name;
+ } «ssc.name»;
+
+ static «ssc.name» «ssc.name»Inst = {"«ssc.name»"};
+
+ void «ssc.name»_initActorInstances(void);
+
+ void «ssc.name»_init(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "init")
+ etLogger_logInfoF("%s_init", «ssc.name»Inst.name);
+
+ /* initialization of all message services */
+ etMessageService_init(&msgService_Thread1, msgBuffer_Thread1, MESSAGE_POOL_MAX, MESSAGE_BLOCK_SIZE);
+
+ /* init all actors */
+ «ssc.name»_initActorInstances();
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ void «ssc.name»_start(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "start")
+ etLogger_logInfoF("%s_start", «ssc.name»Inst.name);
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ void «ssc.name»_run(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "run")
+ int32 i;
+ for (i=0; i<100; i++){
+ etLogger_logInfoF("%s Scheduler tick %d", «ssc.name»Inst.name, i);
+ etMessageService_execute(&msgService_Thread1);
+ }
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ void «ssc.name»_stop(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "stop")
+ etLogger_logInfoF("%s_stop", «ssc.name»Inst.name);
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ void «ssc.name»_destroy(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("SubSys", "destroy")
+ etLogger_logInfoF("%s_destroy", «ssc.name»Inst.name);
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ void «ssc.name»_initActorInstances(void){
+ ET_MSC_LOGGER_SYNC_ENTRY("«ssc.name»", "initActorInstances")
+ «FOR ai : ssi.allContainedInstances»
+ «ai.actorClass.name»_init(&«ai.path.getPathName()»);
+ «ENDFOR»
+ ET_MSC_LOGGER_SYNC_EXIT
+ }
+
+ '''
+ }
+
+ def generateInstanceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Instance File of SubSystemClass «ssc.name»
+ * - instantiation of all actor instances and port instances
+ * - configuration of data and connection of ports
+ */
+
+ #include "etMessageService.h"
+
+ /* instantiation of message services */
+ #define MESSAGE_POOL_MAX 10
+ #define MESSAGE_BLOCK_SIZE 32
+ /* MessageService for Thread1 */
+ uint8 msgBuffer_Thread1[MESSAGE_POOL_MAX*MESSAGE_BLOCK_SIZE];
+ etMessageService msgService_Thread1;
+
+
+ /* include all used ActorClasses */
+ /* TODO: only include used Actor Classes for current SubSystem */
+ «FOR actorClass : root.getUsedActorClasses()»#include "«actorClass.name».h"
+ «ENDFOR»
+
+ /* include all used ProtcolClasses */
+ «FOR protocolClass : root.getUsedProtocolClasses()»#include "«protocolClass.name».h"
+ «ENDFOR»
+
+
+ /* declarations of all ActorClass instances (const and variable structs) */
+
+ /* forward declaration of varible actor structs */
+ «FOR ai : ssi.allContainedInstances»
+ static «ai.actorClass.name» «ai.path.getPathName()»;
+ «ENDFOR»
+
+ «FOR ai : ssi.allContainedInstances»
+
+ /* instance «ai.path.getPathName()» */
+ static const «ai.actorClass.name»_const «ai.path.getPathName()»_const = {
+ &«ai.path.getPathName()»,
+ /* Ports: {myActor, etReceiveMessage, msgService, peerAddress, localId} */
+ «FOR port : ai.actorClass.endPorts»
+ {&«ai.path.getPathName()», «ai.actorClass.name»_ReceiveMessage, &msgService_Thread1, 1, 123} /* Port «port.name» */
+ «ENDFOR»
+
+ };
+ static «ai.actorClass.name» «ai.path.getPathName()» = {&«ai.path.getPathName()»_const};
+ «ENDFOR»
+
+
+««« «FOR ai : ssi.allContainedInstances»
+««« // actor instance «ai.path» itself => Systemport Address
+««« // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
+««« Address addr_item_«ai.path.getPathName()» = new Address(0,«ai.threadId»,«ai.objId»);
+««« // interface items of «ai.path»
+««« «FOR pi : ai.orderedIfItemInstances»
+««« «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
+««« «FOR peer : pi.peers»
+««« «var i = pi.peers.indexOf(peer)»
+««« Address addr_item_«pi.path.getPathName()»_«i» = new Address(0,«pi.threadId»,«pi.objId+i»);
+««« «ENDFOR»
+««« «ELSE»
+««« Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
+««« «ENDIF»
+««« «ENDFOR»
+««« «ENDFOR»
+
+ '''
+ }
+
+
+// «var models = root.getReferencedModels(ssc)»
+// «FOR model : models»import «model.name».*;«ENDFOR»
+//
+//
+// «helpers.UserCode(ssc.userCode1)»
+//
+// public class «ssi.name» extends SubSystemClassBase{
+//
+// «helpers.UserCode(ssc.userCode2)»
+//
+// public «ssi.name»(IRTObject parent, String name) {
+// super(parent, name);
+// }
+//
+// @Override
+// public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){
+// }
+//
+// @Override
+// public void instantiateMessageServices(){
+//
+// RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 0, 0),"MessageService_Main"));
+// «FOR thread : ssc.threads»
+// RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, «ssc.threads.indexOf(thread)+1», 0),"MessageService_«thread.name»", «thread.prio»));
+// «ENDFOR»
+// }
+//
+// @Override
+// public void instantiateActors(){
+// // all addresses
+// // Addresses for the Subsystem Systemport
+// «FOR ai : ssi.allContainedInstances.indexed(ssi.maxObjId)»
+// Address addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai.value)» = new Address(0,0,«ai.index1»);
+// «ENDFOR»
+//
+// «FOR ai : ssi.allContainedInstances»
+// // actor instance «ai.path» itself => Systemport Address
+// // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
+// Address addr_item_«ai.path.getPathName()» = new Address(0,«ai.threadId»,«ai.objId»);
+// // interface items of «ai.path»
+// «FOR pi : ai.orderedIfItemInstances»
+// «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
+// «FOR peer : pi.peers»
+// «var i = pi.peers.indexOf(peer)»
+// Address addr_item_«pi.path.getPathName()»_«i» = new Address(0,«pi.threadId»,«pi.objId+i»);
+// «ENDFOR»
+// «ELSE»
+// Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
+// «ENDIF»
+// «ENDFOR»
+// «ENDFOR»
+//
+// // instantiate all actor instances
+// instances = new ActorClassBase[«ssi.allContainedInstances.size»];
+// «FOR ai : ssi.allContainedInstances»
+// instances[«ssi.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
+// «IF ai.eContainer instanceof SubSystemInstance»
+// this,
+// «ELSE»
+// instances[«ssi.allContainedInstances.indexOf(ai.eContainer)»],
+// «ENDIF»
+// "«ai.name»",
+// // own interface item addresses
+// new Address[][] {{addr_item_«ai.path.getPathName()»}«IF !ai.orderedIfItemInstances.empty»,«ENDIF»
+// «FOR pi : ai.orderedIfItemInstances SEPARATOR ","»
+// {
+// «IF pi instanceof ServiceImplInstance || pi.peers.size>1»
+// «FOR peer : pi.peers SEPARATOR ","»
+// addr_item_«pi.path.getPathName()»_«pi.peers.indexOf(peer)»
+// «ENDFOR»
+// «ELSE»
+// addr_item_«pi.path.getPathName()»
+// «ENDIF»
+// }
+// «ENDFOR»
+// },
+// // peer interface item addresses
+// new Address[][] {{addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai)»}«IF !ai.orderedIfItemInstances.empty»,«ENDIF»
+// «FOR pi : ai.orderedIfItemInstances SEPARATOR ","»
+// {
+// «IF !(pi instanceof ServiceImplInstance) && pi.peers.isEmpty»
+// null
+// «ELSE»
+// «FOR pp : pi.peers SEPARATOR ","»
+// «IF pp instanceof ServiceImplInstance || pp.peers.size>1»
+// addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»
+// «ELSE»
+// addr_item_«pp.path.getPathName()»
+// «ENDIF»
+// «ENDFOR»
+// «ENDIF»
+// }
+// «ENDFOR»
+// }
+// );
+// «ENDFOR»
+//
+// // create the subsystem system port
+// RTSystemPort = new RTSystemServicesProtocolConjPortRepl(this, "RTSystemPort",
+// 0, //local ID
+// // own addresses
+// new Address[]{
+// «FOR ai : ssi.allContainedInstances SEPARATOR ","»
+// addr_item_SystemPort_«ssi.allContainedInstances.indexOf(ai)»
+// «ENDFOR»
+// },
+// // peer addresses
+// new Address[]{
+// «FOR ai : ssi.allContainedInstances SEPARATOR ","»
+// addr_item_«ai.path.getPathName()»
+// «ENDFOR»
+// });
+//
+// }
+// };
+
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend
index 347a45a62..740c0b0f9 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.xtend
@@ -1,81 +1,81 @@
-/*******************************************************************************
- * 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)
- * Thomas Schuetz (changed for C code generator)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.c.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.SubSystemClass
-import org.eclipse.etrice.generator.etricegen.Root
-import org.eclipse.etrice.generator.etricegen.SubSystemInstance
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.extensions.RoomExtensions
-
-@Singleton
-class SubSystemRunnerGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension RoomExtensions roomExt
-
- def doGenerate(Root root) {
- for (sc: root.subSystemInstances) {
- fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
- fileAccess.generateFile( sc.name+"_Runner.c", root.generateSourceFile(sc, sc.subSystemClass))
- }
- }
-
- def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
- /**
- * @author generated by eTrice
- *
- * this class contains the main function running component «ssi.name»
- * it instantiates «ssi.name» and starts and ends the lifecycle
- */
-
-
- #include "«ssi.name».h"
-
- #include "etLogger.h"
- #include "etMSCLogger.h"
-
-
- /**
- * main function
- * creates component and starts and stops the lifecycle
- */
-
- int main(void) {
-
- etLogger_logInfo("*** T H E B E G I N ***");
- ET_MSC_LOGGER_OPEN("main");
-
- /* startup sequence of lifecycle */
- «ssi.name»_init(); /* lifecycle init */
- «ssi.name»_start(); /* lifecycle start */
-
- /* run Scheduler */
- «ssi.name»_run();
-
- /* shutdown sequence of lifecycle */
- «ssi.name»_stop(); /* lifecycle stop */
- «ssi.name»_destroy(); /* lifecycle destroy */
-
- ET_MSC_LOGGER_CLOSE
- etLogger_logInfo("*** T H E E N D ***");
-
- return 0;
- }
-
- '''
- }
+/*******************************************************************************
+ * 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)
+ * Thomas Schuetz (changed for C code generator)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.generator.etricegen.Root
+import org.eclipse.etrice.generator.etricegen.SubSystemInstance
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.extensions.RoomExtensions
+
+@Singleton
+class SubSystemRunnerGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension RoomExtensions roomExt
+
+ def doGenerate(Root root) {
+ for (sc: root.subSystemInstances) {
+ fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
+ fileAccess.generateFile( sc.name+"_Runner.c", root.generateSourceFile(sc, sc.subSystemClass))
+ }
+ }
+
+ def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * this class contains the main function running component «ssi.name»
+ * it instantiates «ssi.name» and starts and ends the lifecycle
+ */
+
+
+ #include "«ssi.name».h"
+
+ #include "etLogger.h"
+ #include "etMSCLogger.h"
+
+
+ /**
+ * main function
+ * creates component and starts and stops the lifecycle
+ */
+
+ int main(void) {
+
+ etLogger_logInfo("*** T H E B E G I N ***");
+ ET_MSC_LOGGER_OPEN("main");
+
+ /* startup sequence of lifecycle */
+ «ssi.name»_init(); /* lifecycle init */
+ «ssi.name»_start(); /* lifecycle start */
+
+ /* run Scheduler */
+ «ssi.name»_run();
+
+ /* shutdown sequence of lifecycle */
+ «ssi.name»_stop(); /* lifecycle stop */
+ «ssi.name»_destroy(); /* lifecycle destroy */
+
+ ET_MSC_LOGGER_CLOSE
+ etLogger_logInfo("*** T H E E N D ***");
+
+ return 0;
+ }
+
+ '''
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Validator.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Validator.java
index 7b6b5d98e..e46f7c165 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Validator.java
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Validator.java
@@ -1,26 +1,26 @@
-/*******************************************************************************
- * 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.c.gen;
-
-import org.eclipse.etrice.generator.etricegen.Root;
-
-/**
- * @author Henrik Rentz-Reichert
- *
- */
-public class Validator {
-
- public boolean validate(Root genModel) {
- return true;
- }
-}
+/*******************************************************************************
+ * 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.c.gen;
+
+import org.eclipse.etrice.generator.etricegen.Root;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class Validator {
+
+ public boolean validate(Root genModel) {
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
index 1c87ef5dc..32deefc75 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
@@ -1,39 +1,39 @@
-/*******************************************************************************
- * 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.c.setup;
-
-import org.eclipse.etrice.generator.base.AbstractGenerator;
-import org.eclipse.etrice.generator.base.GeneratorBaseModule;
-import org.eclipse.etrice.generator.c.Main;
-import org.eclipse.etrice.generator.c.gen.MainGen;
-import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.xtext.generator.IGenerator;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-
-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(CExtensions.class);
-
- }
-
-}
+/*******************************************************************************
+ * 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.c.setup;
+
+import org.eclipse.etrice.generator.base.AbstractGenerator;
+import org.eclipse.etrice.generator.base.GeneratorBaseModule;
+import org.eclipse.etrice.generator.c.Main;
+import org.eclipse.etrice.generator.c.gen.MainGen;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.xtext.generator.IGenerator;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+
+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(CExtensions.class);
+
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java
deleted file mode 100644
index c9ddd6cea..000000000
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java
+++ /dev/null
@@ -1,414 +0,0 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.HashSet;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.Annotation;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.generator.base.ILogger;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-import org.eclipse.etrice.generator.c.gen.StateMachineGen;
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
-import org.eclipse.xtext.xbase.lib.BooleanExtensions;
-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 ActorClassGen {
- @Inject
- private JavaIoFileSystemAccess fileAccess;
-
- @Inject
- private CExtensions stdExt;
-
- @Inject
- private RoomExtensions roomExt;
-
- @Inject
- private ProcedureHelpers helpers;
-
- @Inject
- private TypeHelpers _typeHelpers;
-
- @Inject
- private StateMachineGen stateMachineGen;
-
- @Inject
- private ILogger logger;
-
- public void doGenerate(final Root root) {
- EList<ExpandedActorClass> _xpActorClasses = root.getXpActorClasses();
- for (final ExpandedActorClass xpac : _xpActorClasses) {
- {
- ActorClass _actorClass = xpac.getActorClass();
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(_actorClass);
- ActorClass _actorClass_1 = xpac.getActorClass();
- String _path = this.roomExt.getPath(_actorClass_1);
- String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
- String path = _operator_plus;
- ActorClass _actorClass_2 = xpac.getActorClass();
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(_actorClass_2);
- String _operator_plus_1 = StringExtensions.operator_plus("generating ActorClass header \'", _cHeaderFileName);
- 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);
- ActorClass _actorClass_3 = xpac.getActorClass();
- String _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(_actorClass_3);
- ActorClass _actorClass_4 = xpac.getActorClass();
- StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, xpac, _actorClass_4);
- this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
- boolean _hasBehaviorAnnotation = this.hasBehaviorAnnotation(xpac, "BehaviorManual");
- boolean _operator_equals = ObjectExtensions.operator_equals(((Boolean)_hasBehaviorAnnotation), ((Boolean)false));
- if (_operator_equals) {
- {
- ActorClass _actorClass_5 = xpac.getActorClass();
- String _cSourceFileName = this.stdExt.getCSourceFileName(_actorClass_5);
- String _operator_plus_5 = StringExtensions.operator_plus("generating ActorClass header \'", _cSourceFileName);
- 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);
- ActorClass _actorClass_6 = xpac.getActorClass();
- String _cSourceFileName_1 = this.stdExt.getCSourceFileName(_actorClass_6);
- ActorClass _actorClass_7 = xpac.getActorClass();
- StringConcatenation _generateSourceFile = this.generateSourceFile(root, xpac, _actorClass_7);
- this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
- }
- }
- }
- }
- }
-
- public boolean hasBehaviorAnnotation(final ExpandedActorClass xpac, final String annotation) {
- ActorClass _actorClass = xpac.getActorClass();
- EList<Annotation> _annotations = _actorClass.getAnnotations();
- boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_annotations, null);
- if (_operator_notEquals) {
- ActorClass _actorClass_1 = xpac.getActorClass();
- EList<Annotation> _annotations_1 = _actorClass_1.getAnnotations();
- final Function1<Annotation,Boolean> _function = new Function1<Annotation,Boolean>() {
- public Boolean apply(final Annotation e) {
- String _name = e.getName();
- boolean _operator_equals = ObjectExtensions.operator_equals(_name, annotation);
- return ((Boolean)_operator_equals);
- }
- };
- Annotation _findFirst = IterableExtensions.<Annotation>findFirst(_annotations_1, _function);
- boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_findFirst, null);
- if (_operator_notEquals_1) {
- return true;
- }
- }
- return false;
- }
-
- public StringConcatenation generateHeaderFile(final Root root, final ExpandedActorClass xpac, final ActorClass ac) {
- 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("* Header File of ActorClass ");
- String _name = xpac.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- String _name_1 = xpac.getName();
- StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
- _builder.append(_generateIncludeGuardBegin, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etDatatypes.h\"");
- _builder.newLine();
- _builder.newLine();
- {
- HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(ac);
- for(final DataClass dataClass : _referencedDataClasses) {
- _builder.append("#include \"");
- String _name_2 = dataClass.getName();
- _builder.append(_name_2, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- {
- EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac);
- for(final ProtocolClass pc : _referencedProtocolClasses) {
- _builder.append("#include \"");
- String _name_3 = pc.getName();
- _builder.append(_name_3, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- DetailCode _userCode1 = ac.getUserCode1();
- StringConcatenation _UserCode = this.helpers.UserCode(_userCode1);
- _builder.append(_UserCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("typedef struct ");
- String _name_4 = xpac.getName();
- _builder.append(_name_4, "");
- _builder.append(" ");
- String _name_5 = xpac.getName();
- _builder.append(_name_5, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/* const part of ActorClass (ROM) */");
- _builder.newLine();
- _builder.append("typedef struct ");
- String _name_6 = xpac.getName();
- _builder.append(_name_6, "");
- _builder.append("_const {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("const ");
- String _name_7 = xpac.getName();
- _builder.append(_name_7, " ");
- _builder.append("* actor;");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("/* Ports */");
- _builder.newLine();
- {
- List<Port> _endPorts = this.roomExt.getEndPorts(ac);
- for(final Port ep : _endPorts) {
- _builder.append("\t");
- _builder.append("const ");
- String _portClassName = this.roomExt.getPortClassName(ep);
- _builder.append(_portClassName, " ");
- _builder.append(" ");
- String _name_8 = ep.getName();
- _builder.append(_name_8, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("} ");
- String _name_9 = xpac.getName();
- _builder.append(_name_9, "");
- _builder.append("_const;");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/* variable part of ActorClass (RAM) */");
- _builder.newLine();
- _builder.append("struct ");
- String _name_10 = xpac.getName();
- _builder.append(_name_10, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("const ");
- String _name_11 = xpac.getName();
- _builder.append(_name_11, " ");
- _builder.append("_const* constData;");
- _builder.newLineIfNotEmpty();
- _builder.append("};");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_12 = xpac.getName();
- _builder.append(_name_12, "");
- _builder.append("_init(");
- String _name_13 = xpac.getName();
- _builder.append(_name_13, "");
- _builder.append("* self);");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_14 = xpac.getName();
- _builder.append(_name_14, "");
- _builder.append("_ReceiveMessage(void* self, etInt16 localId, const etMessage* msg);");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- DetailCode _userCode2 = ac.getUserCode2();
- StringConcatenation _UserCode_1 = this.helpers.UserCode(_userCode2);
- _builder.append(_UserCode_1, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- String _name_15 = xpac.getName();
- StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_15);
- _builder.append(_generateIncludeGuardEnd, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation generateSourceFile(final Root root, final ExpandedActorClass xpac, final ActorClass ac) {
- 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 ActorClass ");
- String _name = xpac.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"");
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(xpac);
- _builder.append(_cHeaderFileName, "");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etLogger.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"etMSCLogger.h\"");
- _builder.newLine();
- _builder.newLine();
- DetailCode _userCode3 = xpac.getUserCode3();
- StringConcatenation _UserCode = this.helpers.UserCode(_userCode3);
- _builder.append(_UserCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_1 = xpac.getName();
- _builder.append(_name_1, "");
- _builder.append("_init(");
- String _name_2 = xpac.getName();
- _builder.append(_name_2, "");
- _builder.append("* self){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
- String _name_3 = xpac.getName();
- _builder.append(_name_3, " ");
- _builder.append("\", \"init\")");
- _builder.newLineIfNotEmpty();
- {
- ActorClass _actorClass = xpac.getActorClass();
- List<Port> _endPorts = this.roomExt.getEndPorts(_actorClass);
- final Function1<Port,Boolean> _function = new Function1<Port,Boolean>() {
- public Boolean apply(final Port e) {
- boolean _isConjugated = e.isConjugated();
- return ((Boolean)_isConjugated);
- }
- };
- Iterable<Port> _filter = IterableExtensions.<Port>filter(_endPorts, _function);
- for(final Port port : _filter) {
- {
- ProtocolClass _protocol = port.getProtocol();
- EList<Message> _incomingMessages = _protocol.getIncomingMessages();
- for(final Message message : _incomingMessages) {
- _builder.append("\t");
- String _portClassName = this.roomExt.getPortClassName(port);
- _builder.append(_portClassName, " ");
- _builder.append("_");
- String _name_4 = message.getName();
- _builder.append(_name_4, " ");
- _builder.append("(&self->constData->");
- String _name_5 = port.getName();
- _builder.append(_name_5, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- {
- ActorClass _actorClass_1 = xpac.getActorClass();
- List<Port> _endPorts_1 = this.roomExt.getEndPorts(_actorClass_1);
- final Function1<Port,Boolean> _function_1 = new Function1<Port,Boolean>() {
- public Boolean apply(final Port e) {
- boolean _isConjugated = e.isConjugated();
- boolean _operator_not = BooleanExtensions.operator_not(_isConjugated);
- return ((Boolean)_operator_not);
- }
- };
- Iterable<Port> _filter_1 = IterableExtensions.<Port>filter(_endPorts_1, _function_1);
- for(final Port port_1 : _filter_1) {
- {
- ProtocolClass _protocol_1 = port_1.getProtocol();
- EList<Message> _outgoingMessages = _protocol_1.getOutgoingMessages();
- for(final Message message_1 : _outgoingMessages) {
- _builder.append("\t");
- String _portClassName_1 = this.roomExt.getPortClassName(port_1);
- _builder.append(_portClassName_1, " ");
- _builder.append("_");
- String _name_6 = message_1.getName();
- _builder.append(_name_6, " ");
- _builder.append("(&self->constData->");
- String _name_7 = port_1.getName();
- _builder.append(_name_7, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_8 = xpac.getName();
- _builder.append(_name_8, "");
- _builder.append("_ReceiveMessage(void* self, etInt16 localId, const etMessage* msg){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
- String _name_9 = xpac.getName();
- _builder.append(_name_9, " ");
- _builder.append("\", \"ReceiveMessage\")");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
index dd59ed946..8c1a4e353 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
@@ -1,132 +1,132 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.core.room.RoomClass;
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.generator.etricegen.TransitionChain;
-import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.etrice.generator.generic.LanguageGenerator;
-import org.eclipse.xtext.xbase.lib.ComparableExtensions;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-import org.eclipse.xtext.xtend2.lib.StringConcatenation;
-
-@SuppressWarnings("all")
-@Singleton
-public class CExtensions implements ILanguageExtension {
- @Inject
- private LanguageGenerator languageGen;
-
- public String getTypedDataDefinition(final Message m) {
- String _typedData = this.languageGen.getTypedData(m);
- return _typedData;
- }
-
- public String accessLevelPrivate() {
- return "";
- }
-
- public String accessLevelProtected() {
- return "";
- }
-
- public String accessLevelPublic() {
- return "";
- }
-
- public String memberAccess() {
- return "self->";
- }
-
- public String selfPointer(final String classname, final int argumentCount) {
- String _xifexpression = null;
- boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)argumentCount), ((Integer)0));
- if (_operator_greaterThan) {
- String _operator_plus = StringExtensions.operator_plus(classname, "* self, ");
- _xifexpression = _operator_plus;
- } else {
- String _operator_plus_1 = StringExtensions.operator_plus(classname, "* self");
- _xifexpression = _operator_plus_1;
- }
- return _xifexpression;
- }
-
- public String operationScope(final String classname, final boolean isDeclaration) {
- String _operator_plus = StringExtensions.operator_plus(classname, "_");
- return _operator_plus;
- }
-
- /**
- * TODO: unify OUT and in an add for loop (also for Java)
- */
- public String outMessageId(final String classname, final String messagename) {
- String _operator_plus = StringExtensions.operator_plus(classname, "_OUT_");
- String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, messagename);
- return _operator_plus_1;
- }
-
- public String inMessageId(final String classname, final String messagename) {
- String _operator_plus = StringExtensions.operator_plus(classname, "_IN_");
- String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, messagename);
- return _operator_plus_1;
- }
-
- /**
- * TODO: move specific code elsewhere
- */
- public String getCHeaderFileName(final RoomClass rc) {
- String _name = rc.getName();
- String _operator_plus = StringExtensions.operator_plus(_name, ".h");
- return _operator_plus;
- }
-
- public String getCSourceFileName(final RoomClass rc) {
- String _name = rc.getName();
- String _operator_plus = StringExtensions.operator_plus(_name, ".c");
- return _operator_plus;
- }
-
- public String getInstSourceFileName(final RoomClass rc) {
- String _name = rc.getName();
- String _operator_plus = StringExtensions.operator_plus(_name, "_Inst.h");
- return _operator_plus;
- }
-
- 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;
- }
-
- public String getExecuteChainCode(final ExpandedActorClass ac, final TransitionChain tc) {
- String _executeChain = this.languageGen.getExecuteChain(ac, tc);
- return _executeChain;
- }
-}
+package org.eclipse.etrice.generator.c.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.RoomClass;
+import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.generator.etricegen.TransitionChain;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.LanguageGenerator;
+import org.eclipse.xtext.xbase.lib.ComparableExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class CExtensions implements ILanguageExtension {
+ @Inject
+ private LanguageGenerator languageGen;
+
+ public String getTypedDataDefinition(final Message m) {
+ String _typedData = this.languageGen.getTypedData(m);
+ return _typedData;
+ }
+
+ public String accessLevelPrivate() {
+ return "";
+ }
+
+ public String accessLevelProtected() {
+ return "";
+ }
+
+ public String accessLevelPublic() {
+ return "";
+ }
+
+ public String memberAccess() {
+ return "self->";
+ }
+
+ public String selfPointer(final String classname, final int argumentCount) {
+ String _xifexpression = null;
+ boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)argumentCount), ((Integer)0));
+ if (_operator_greaterThan) {
+ String _operator_plus = StringExtensions.operator_plus(classname, "* self, ");
+ _xifexpression = _operator_plus;
+ } else {
+ String _operator_plus_1 = StringExtensions.operator_plus(classname, "* self");
+ _xifexpression = _operator_plus_1;
+ }
+ return _xifexpression;
+ }
+
+ public String operationScope(final String classname, final boolean isDeclaration) {
+ String _operator_plus = StringExtensions.operator_plus(classname, "_");
+ return _operator_plus;
+ }
+
+ /**
+ * TODO: unify OUT and in an add for loop (also for Java)
+ */
+ public String outMessageId(final String classname, final String messagename) {
+ String _operator_plus = StringExtensions.operator_plus(classname, "_OUT_");
+ String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, messagename);
+ return _operator_plus_1;
+ }
+
+ public String inMessageId(final String classname, final String messagename) {
+ String _operator_plus = StringExtensions.operator_plus(classname, "_IN_");
+ String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, messagename);
+ return _operator_plus_1;
+ }
+
+ /**
+ * TODO: move specific code elsewhere
+ */
+ public String getCHeaderFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _operator_plus = StringExtensions.operator_plus(_name, ".h");
+ return _operator_plus;
+ }
+
+ public String getCSourceFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _operator_plus = StringExtensions.operator_plus(_name, ".c");
+ return _operator_plus;
+ }
+
+ public String getInstSourceFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ String _operator_plus = StringExtensions.operator_plus(_name, "_Inst.h");
+ return _operator_plus;
+ }
+
+ 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;
+ }
+
+ public String getExecuteChainCode(final ExpandedActorClass ac, final TransitionChain tc) {
+ String _executeChain = this.languageGen.getExecuteChain(ac, tc);
+ return _executeChain;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java
index fa7f4ee49..0dced56c4 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java
@@ -1,249 +1,249 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.HashSet;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.StandardOperation;
-import org.eclipse.etrice.generator.base.ILogger;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
-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 CExtensions stdExt;
-
- @Inject
- private RoomExtensions roomExt;
-
- @Inject
- private ProcedureHelpers helpers;
-
- @Inject
- private ILogger logger;
-
- public void doGenerate(final Root root) {
- 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 _cHeaderFileName = this.stdExt.getCHeaderFileName(dc);
- String _operator_plus_1 = StringExtensions.operator_plus("generating DataClass header \'", _cHeaderFileName);
- 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 _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(dc);
- StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, dc);
- this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
- String _cSourceFileName = this.stdExt.getCSourceFileName(dc);
- String _operator_plus_5 = StringExtensions.operator_plus("generating DataClass source \'", _cSourceFileName);
- 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 _cSourceFileName_1 = this.stdExt.getCSourceFileName(dc);
- StringConcatenation _generateSourceFile = this.generateSourceFile(root, dc);
- this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
- }
- }
- }
-
- public StringConcatenation generateHeaderFile(final Root root, final DataClass dc) {
- 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("* Header 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();
- String _name_1 = dc.getName();
- StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
- _builder.append(_generateIncludeGuardBegin, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etDatatypes.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* TODO: includes only for used DataClasses, also for other models */");
- _builder.newLine();
- {
- HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(dc);
- for(final DataClass dataClass : _referencedDataClasses) {
- _builder.append("#include \"");
- String _name_2 = dataClass.getName();
- _builder.append(_name_2, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- DetailCode _userCode1 = dc.getUserCode1();
- StringConcatenation _UserCode = this.helpers.UserCode(_userCode1);
- _builder.append(_UserCode, "");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("typedef struct {");
- _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");
- EList<Attribute> _attributes = dc.getAttributes();
- StringConcatenation _Attributes = this.helpers.Attributes(_attributes);
- _builder.append(_Attributes, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("} ");
- String _name_3 = dc.getName();
- _builder.append(_name_3, "");
- {
- DataClass _base = dc.getBase();
- boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
- if (_operator_notEquals) {
- _builder.append(" /* extends -> inheritance not implemented yet */ ");
- DataClass _base_1 = dc.getBase();
- String _name_4 = _base_1.getName();
- _builder.append(_name_4, "");
- }
- }
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("// TODO: do we need setters and getters for C and C++ ?");
- _builder.newLine();
- _builder.newLine();
- EList<StandardOperation> _operations = dc.getOperations();
- String _name_5 = dc.getName();
- StringConcatenation _OperationsDeclaration = this.helpers.OperationsDeclaration(_operations, _name_5);
- _builder.append(_OperationsDeclaration, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("// deep copy");
- _builder.newLine();
- _builder.append("void ");
- String _name_6 = dc.getName();
- _builder.append(_name_6, "");
- _builder.append("_deepCopy(");
- String _name_7 = dc.getName();
- _builder.append(_name_7, "");
- _builder.append("* source, ");
- String _name_8 = dc.getName();
- _builder.append(_name_8, "");
- _builder.append("* target);");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- String _name_9 = dc.getName();
- StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_9);
- _builder.append(_generateIncludeGuardEnd, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation generateSourceFile(final Root root, final DataClass dc) {
- 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 _cHeaderFileName = this.stdExt.getCHeaderFileName(dc);
- _builder.append(_cHeaderFileName, "");
- _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.append("// TODO: do we need setters and getters for C and C++ ?");
- _builder.newLine();
- _builder.newLine();
- EList<StandardOperation> _operations = dc.getOperations();
- String _name_1 = dc.getName();
- StringConcatenation _OperationsImplementation = this.helpers.OperationsImplementation(_operations, _name_1);
- _builder.append(_OperationsImplementation, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("// deep copy");
- _builder.newLine();
- _builder.append("void ");
- String _name_2 = dc.getName();
- _builder.append(_name_2, "");
- _builder.append("_deepCopy(");
- String _name_3 = dc.getName();
- _builder.append(_name_3, "");
- _builder.append("* source, ");
- String _name_4 = dc.getName();
- _builder.append(_name_4, "");
- _builder.append("* target) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("memcpy(target, source, sizeof(");
- String _name_5 = dc.getName();
- _builder.append(_name_5, " ");
- _builder.append("));");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-}
+package org.eclipse.etrice.generator.c.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.HashSet;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.StandardOperation;
+import org.eclipse.etrice.generator.base.ILogger;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.extensions.RoomExtensions;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+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 CExtensions stdExt;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ @Inject
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ 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 _cHeaderFileName = this.stdExt.getCHeaderFileName(dc);
+ String _operator_plus_1 = StringExtensions.operator_plus("generating DataClass header \'", _cHeaderFileName);
+ 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 _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(dc);
+ StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, dc);
+ this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
+ String _cSourceFileName = this.stdExt.getCSourceFileName(dc);
+ String _operator_plus_5 = StringExtensions.operator_plus("generating DataClass source \'", _cSourceFileName);
+ 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 _cSourceFileName_1 = this.stdExt.getCSourceFileName(dc);
+ StringConcatenation _generateSourceFile = this.generateSourceFile(root, dc);
+ this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
+ }
+ }
+ }
+
+ public StringConcatenation generateHeaderFile(final Root root, final DataClass dc) {
+ 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("* Header 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();
+ String _name_1 = dc.getName();
+ StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
+ _builder.append(_generateIncludeGuardBegin, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etDatatypes.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* TODO: includes only for used DataClasses, also for other models */");
+ _builder.newLine();
+ {
+ HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(dc);
+ for(final DataClass dataClass : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _name_2 = dataClass.getName();
+ _builder.append(_name_2, "");
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ DetailCode _userCode1 = dc.getUserCode1();
+ StringConcatenation _UserCode = this.helpers.UserCode(_userCode1);
+ _builder.append(_UserCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("typedef struct {");
+ _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");
+ EList<Attribute> _attributes = dc.getAttributes();
+ StringConcatenation _Attributes = this.helpers.Attributes(_attributes);
+ _builder.append(_Attributes, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("} ");
+ String _name_3 = dc.getName();
+ _builder.append(_name_3, "");
+ {
+ DataClass _base = dc.getBase();
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_base, null);
+ if (_operator_notEquals) {
+ _builder.append(" /* extends -> inheritance not implemented yet */ ");
+ DataClass _base_1 = dc.getBase();
+ String _name_4 = _base_1.getName();
+ _builder.append(_name_4, "");
+ }
+ }
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// TODO: do we need setters and getters for C and C++ ?");
+ _builder.newLine();
+ _builder.newLine();
+ EList<StandardOperation> _operations = dc.getOperations();
+ String _name_5 = dc.getName();
+ StringConcatenation _OperationsDeclaration = this.helpers.OperationsDeclaration(_operations, _name_5);
+ _builder.append(_OperationsDeclaration, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// deep copy");
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_6 = dc.getName();
+ _builder.append(_name_6, "");
+ _builder.append("_deepCopy(");
+ String _name_7 = dc.getName();
+ _builder.append(_name_7, "");
+ _builder.append("* source, ");
+ String _name_8 = dc.getName();
+ _builder.append(_name_8, "");
+ _builder.append("* target);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _name_9 = dc.getName();
+ StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_9);
+ _builder.append(_generateIncludeGuardEnd, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation generateSourceFile(final Root root, final DataClass dc) {
+ 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 _cHeaderFileName = this.stdExt.getCHeaderFileName(dc);
+ _builder.append(_cHeaderFileName, "");
+ _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.append("// TODO: do we need setters and getters for C and C++ ?");
+ _builder.newLine();
+ _builder.newLine();
+ EList<StandardOperation> _operations = dc.getOperations();
+ String _name_1 = dc.getName();
+ StringConcatenation _OperationsImplementation = this.helpers.OperationsImplementation(_operations, _name_1);
+ _builder.append(_OperationsImplementation, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// deep copy");
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_2 = dc.getName();
+ _builder.append(_name_2, "");
+ _builder.append("_deepCopy(");
+ String _name_3 = dc.getName();
+ _builder.append(_name_3, "");
+ _builder.append("* source, ");
+ String _name_4 = dc.getName();
+ _builder.append(_name_4, "");
+ _builder.append("* target) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("memcpy(target, source, sizeof(");
+ String _name_5 = dc.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/MainGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/MainGen.java
index ddbb7e3d4..e3a53f78b 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/MainGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/MainGen.java
@@ -1,61 +1,61 @@
-package org.eclipse.etrice.generator.c.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.c.gen.ActorClassGen;
-import org.eclipse.etrice.generator.c.gen.DataClassGen;
-import org.eclipse.etrice.generator.c.gen.ProtocolClassGen;
-import org.eclipse.etrice.generator.c.gen.SubSystemClassGen;
-import org.eclipse.etrice.generator.c.gen.SubSystemRunnerGen;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.extensions.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 ProtocolClassGen protocolClassGen;
-
- @Inject
- private ActorClassGen actorClassGen;
-
- @Inject
- private SubSystemClassGen subsystemClassGen;
-
- @Inject
- private SubSystemRunnerGen subsystemRunnerGen;
-
- @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);
- this.protocolClassGen.doGenerate(e);
- this.actorClassGen.doGenerate(e);
- this.subsystemClassGen.doGenerate(e);
- boolean _isLibrary = e.isLibrary();
- boolean _operator_not = BooleanExtensions.operator_not(_isLibrary);
- if (_operator_not) {
- this.subsystemRunnerGen.doGenerate(e);
- }
- }
-}
+package org.eclipse.etrice.generator.c.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.c.gen.ActorClassGen;
+import org.eclipse.etrice.generator.c.gen.DataClassGen;
+import org.eclipse.etrice.generator.c.gen.ProtocolClassGen;
+import org.eclipse.etrice.generator.c.gen.SubSystemClassGen;
+import org.eclipse.etrice.generator.c.gen.SubSystemRunnerGen;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.extensions.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 ProtocolClassGen protocolClassGen;
+
+ @Inject
+ private ActorClassGen actorClassGen;
+
+ @Inject
+ private SubSystemClassGen subsystemClassGen;
+
+ @Inject
+ private SubSystemRunnerGen subsystemRunnerGen;
+
+ @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);
+ this.protocolClassGen.doGenerate(e);
+ this.actorClassGen.doGenerate(e);
+ this.subsystemClassGen.doGenerate(e);
+ boolean _isLibrary = e.isLibrary();
+ boolean _operator_not = BooleanExtensions.operator_not(_isLibrary);
+ if (_operator_not) {
+ this.subsystemRunnerGen.doGenerate(e);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java
index c317c877c..a31787853 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java
@@ -1,572 +1,572 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.util.HashSet;
-import java.util.List;
-import org.eclipse.emf.common.util.EList;
-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.Message;
-import org.eclipse.etrice.core.room.PortClass;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.base.ILogger;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
-import org.eclipse.xtext.xbase.lib.BooleanExtensions;
-import org.eclipse.xtext.xbase.lib.IntegerExtensions;
-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 ProtocolClassGen {
- @Inject
- private JavaIoFileSystemAccess fileAccess;
-
- @Inject
- private CExtensions stdExt;
-
- @Inject
- private RoomExtensions roomExt;
-
- @Inject
- private ProcedureHelpers helpers;
-
- @Inject
- private ILogger logger;
-
- public void doGenerate(final Root root) {
- EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
- for (final ProtocolClass pc : _usedProtocolClasses) {
- {
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(pc);
- String _path = this.roomExt.getPath(pc);
- String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
- String path = _operator_plus;
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
- String _operator_plus_1 = StringExtensions.operator_plus("generating ProtocolClass header \'", _cHeaderFileName);
- 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 _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(pc);
- StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, pc);
- this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
- String _cSourceFileName = this.stdExt.getCSourceFileName(pc);
- String _operator_plus_5 = StringExtensions.operator_plus("generating ProtocolClass source \'", _cSourceFileName);
- 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 _cSourceFileName_1 = this.stdExt.getCSourceFileName(pc);
- StringConcatenation _generateSourceFile = this.generateSourceFile(root, pc);
- this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
- }
- }
- }
-
- public StringConcatenation generateHeaderFile(final Root root, final ProtocolClass pc) {
- 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("* Header File of ProtocolClass ");
- String _name = pc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- String _name_1 = pc.getName();
- StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
- _builder.append(_generateIncludeGuardBegin, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etDatatypes.h\"");
- _builder.newLine();
- _builder.append("#include \"etPort.h\"");
- _builder.newLine();
- _builder.newLine();
- DetailCode _userCode1 = pc.getUserCode1();
- StringConcatenation _UserCode = this.helpers.UserCode(_userCode1);
- _builder.append(_UserCode, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc);
- for(final DataClass dataClass : _referencedDataClasses) {
- _builder.append("#include \"");
- String _name_2 = dataClass.getName();
- _builder.append(_name_2, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("/* message IDs */");
- _builder.newLine();
- _builder.append("enum {");
- _builder.newLine();
- _builder.append("\t");
- String _name_3 = pc.getName();
- _builder.append(_name_3, " ");
- _builder.append("_MSG_MIN = 0, ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("/* IDs for outgoing messages */");
- _builder.newLine();
- {
- List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
- for(final Message message : _allOutgoingMessages) {
- _builder.append("\t");
- String _name_4 = pc.getName();
- String _name_5 = message.getName();
- String _outMessageId = this.stdExt.outMessageId(_name_4, _name_5);
- _builder.append(_outMessageId, " ");
- _builder.append(" = ");
- List<Message> _allOutgoingMessages_1 = this.roomExt.getAllOutgoingMessages(pc);
- int _indexOf = _allOutgoingMessages_1.indexOf(message);
- int _operator_plus = IntegerExtensions.operator_plus(((Integer)_indexOf), ((Integer)1));
- _builder.append(_operator_plus, " ");
- _builder.append(",");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("/* IDs for incoming messages */");
- _builder.newLine();
- {
- List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
- for(final Message message_1 : _allIncomingMessages) {
- _builder.append("\t");
- String _name_6 = pc.getName();
- String _name_7 = message_1.getName();
- String _inMessageId = this.stdExt.inMessageId(_name_6, _name_7);
- _builder.append(_inMessageId, " ");
- _builder.append(" = ");
- List<Message> _allIncomingMessages_1 = this.roomExt.getAllIncomingMessages(pc);
- int _indexOf_1 = _allIncomingMessages_1.indexOf(message_1);
- List<Message> _allOutgoingMessages_2 = this.roomExt.getAllOutgoingMessages(pc);
- int _size = _allOutgoingMessages_2.size();
- int _operator_plus_1 = IntegerExtensions.operator_plus(((Integer)_indexOf_1), ((Integer)_size));
- int _operator_plus_2 = IntegerExtensions.operator_plus(((Integer)_operator_plus_1), ((Integer)1));
- _builder.append(_operator_plus_2, " ");
- _builder.append(",");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("/* error if msgID >= MSG_MAX */");
- _builder.newLine();
- _builder.append("\t");
- String _name_8 = pc.getName();
- _builder.append(_name_8, " ");
- _builder.append("_MSG_MAX = ");
- List<Message> _allOutgoingMessages_3 = this.roomExt.getAllOutgoingMessages(pc);
- int _size_1 = _allOutgoingMessages_3.size();
- List<Message> _allIncomingMessages_2 = this.roomExt.getAllIncomingMessages(pc);
- int _size_2 = _allIncomingMessages_2.size();
- int _operator_plus_3 = IntegerExtensions.operator_plus(((Integer)_size_1), ((Integer)_size_2));
- int _operator_plus_4 = IntegerExtensions.operator_plus(((Integer)_operator_plus_3), ((Integer)1));
- _builder.append(_operator_plus_4, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("};");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/*--------------------- port classes */");
- _builder.newLine();
- StringConcatenation _portClassHeader = this.portClassHeader(pc, ((Boolean)false));
- _builder.append(_portClassHeader, "");
- _builder.newLineIfNotEmpty();
- StringConcatenation _portClassHeader_1 = this.portClassHeader(pc, ((Boolean)true));
- _builder.append(_portClassHeader_1, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/*--------------------- debug helpers */");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* get message string for message id */");
- _builder.newLine();
- _builder.append("const char* ");
- String _name_9 = pc.getName();
- _builder.append(_name_9, "");
- _builder.append("_getMessageString(int msg_id);");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- DetailCode _userCode2 = pc.getUserCode2();
- StringConcatenation _UserCode_1 = this.helpers.UserCode(_userCode2);
- _builder.append(_UserCode_1, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- String _name_10 = pc.getName();
- StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_10);
- _builder.append(_generateIncludeGuardEnd, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation generateSourceFile(final Root root, final ProtocolClass pc) {
- 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 ProtocolClass ");
- String _name = pc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"");
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
- _builder.append(_cHeaderFileName, "");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etMSCLogger.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/*--------------------- port classes */");
- _builder.newLine();
- StringConcatenation _portClassSource = this.portClassSource(pc, ((Boolean)false));
- _builder.append(_portClassSource, "");
- _builder.newLineIfNotEmpty();
- StringConcatenation _portClassSource_1 = this.portClassSource(pc, ((Boolean)true));
- _builder.append(_portClassSource_1, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/*--------------------- debug helpers */");
- _builder.newLine();
- StringConcatenation _generateDebugHelpersImplementation = this.generateDebugHelpersImplementation(root, pc);
- _builder.append(_generateDebugHelpersImplementation, "");
- _builder.newLineIfNotEmpty();
- return _builder;
- }
-
- public StringConcatenation portClass(final ProtocolClass pc, final Boolean conj) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation portClassHeader(final ProtocolClass pc, final Boolean conj) {
- StringConcatenation _builder = new StringConcatenation();
- String _portClassName = this.roomExt.getPortClassName(pc, conj);
- String portClassName = _portClassName;
- _builder.newLineIfNotEmpty();
- PortClass _portClass = this.roomExt.getPortClass(pc, conj);
- PortClass pClass = _portClass;
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("typedef etPort ");
- _builder.append(portClassName, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- boolean _operator_not = BooleanExtensions.operator_not(conj);
- if (_operator_not) {
- {
- List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
- for(final Message message : _allOutgoingMessages) {
- _builder.append("void ");
- _builder.append(portClassName, "");
- _builder.append("_");
- String _name = message.getName();
- _builder.append(_name, "");
- _builder.append("(const ");
- _builder.append(portClassName, "");
- _builder.append("* self);");
- _builder.newLineIfNotEmpty();
- }
- }
- } else {
- {
- List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
- for(final Message message_1 : _allIncomingMessages) {
- _builder.append("void ");
- _builder.append(portClassName, "");
- _builder.append("_");
- String _name_1 = message_1.getName();
- _builder.append(_name_1, "");
- _builder.append("(const ");
- _builder.append(portClassName, "");
- _builder.append("* self);");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation portClassSource(final ProtocolClass pc, final Boolean conj) {
- StringConcatenation _builder = new StringConcatenation();
- String _portClassName = this.roomExt.getPortClassName(pc, conj);
- String portClassName = _portClassName;
- _builder.newLineIfNotEmpty();
- PortClass _portClass = this.roomExt.getPortClass(pc, conj);
- PortClass pClass = _portClass;
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- boolean _operator_not = BooleanExtensions.operator_not(conj);
- if (_operator_not) {
- {
- List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
- for(final Message message : _allOutgoingMessages) {
- _builder.append("void ");
- _builder.append(portClassName, "");
- _builder.append("_");
- String _name = message.getName();
- _builder.append(_name, "");
- _builder.append("(const ");
- _builder.append(portClassName, "");
- _builder.append("* self){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
- _builder.append(portClassName, " ");
- _builder.append("\", \"");
- String _name_1 = message.getName();
- _builder.append(_name_1, " ");
- _builder.append("\")");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("msg->address = self->peerAddress;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("msg->evtID = ");
- String _name_2 = pc.getName();
- String _name_3 = message.getName();
- String _outMessageId = this.stdExt.outMessageId(_name_2, _name_3);
- _builder.append(_outMessageId, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("etMessageService_pushMessage(self->msgService, msg);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- }
- }
- } else {
- {
- List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
- for(final Message message_1 : _allIncomingMessages) {
- _builder.append("void ");
- _builder.append(portClassName, "");
- _builder.append("_");
- String _name_4 = message_1.getName();
- _builder.append(_name_4, "");
- _builder.append("(const ");
- _builder.append(portClassName, "");
- _builder.append("* self){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
- _builder.append(portClassName, " ");
- _builder.append("\", \"");
- String _name_5 = message_1.getName();
- _builder.append(_name_5, " ");
- _builder.append("\")");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("msg->address = self->peerAddress;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("msg->evtID = ");
- String _name_6 = pc.getName();
- String _name_7 = message_1.getName();
- String _inMessageId = this.stdExt.inMessageId(_name_6, _name_7);
- _builder.append(_inMessageId, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("etMessageService_pushMessage(self->msgService, msg);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation messageSignature(final ProtocolClass pc, final Message m) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("void ");
- String _name = pc.getName();
- _builder.append(_name, "");
- _builder.append("_");
- String _name_1 = m.getName();
- _builder.append(_name_1, "");
- _builder.append(" (");
- {
- VarDecl _data = m.getData();
- boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
- if (_operator_notEquals) {
- VarDecl _data_1 = m.getData();
- RefableType _refType = _data_1.getRefType();
- DataType _type = _refType.getType();
- String _name_2 = _type.getName();
- _builder.append(_name_2, "");
- _builder.append(" ");
- VarDecl _data_2 = m.getData();
- String _name_3 = _data_2.getName();
- _builder.append(_name_3, "");
- }
- }
- _builder.append(")");
- _builder.newLineIfNotEmpty();
- return _builder;
- }
-
- public StringConcatenation messageCall(final Message m) {
- StringConcatenation _builder = new StringConcatenation();
- String _name = m.getName();
- _builder.append(_name, "");
- _builder.append("(");
- {
- VarDecl _data = m.getData();
- boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
- if (_operator_notEquals) {
- _builder.append(" ");
- VarDecl _data_1 = m.getData();
- String _name_1 = _data_1.getName();
- _builder.append(_name_1, "");
- }
- }
- _builder.append(")");
- _builder.newLineIfNotEmpty();
- return _builder;
- }
-
- public StringConcatenation generateDebugHelpersImplementation(final Root root, final ProtocolClass pc) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.newLine();
- _builder.append("/* TODO: make this optional or different for smaller footprint */");
- _builder.newLine();
- _builder.append("/* message names as strings for debugging (generate MSC) */");
- _builder.newLine();
- _builder.append("static const char* ");
- String _name = pc.getName();
- _builder.append(_name, "");
- _builder.append("_messageStrings[] = {\"MIN\", ");
- {
- List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
- for(final Message m : _allOutgoingMessages) {
- _builder.append("\"");
- String _name_1 = m.getName();
- _builder.append(_name_1, "");
- _builder.append("\",");
- }
- }
- {
- List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
- for(final Message m_1 : _allIncomingMessages) {
- _builder.append("\"");
- String _name_2 = m_1.getName();
- _builder.append(_name_2, "");
- _builder.append("\", ");
- }
- }
- _builder.append("\"MAX\"};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("const char* ");
- String _name_3 = pc.getName();
- _builder.append(_name_3, "");
- _builder.append("_getMessageString(int msg_id) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("if (msg_id<");
- String _name_4 = pc.getName();
- _builder.append(_name_4, " ");
- _builder.append("_MSG_MIN || msg_id>");
- String _name_5 = pc.getName();
- _builder.append(_name_5, " ");
- _builder.append("_MSG_MAX+1){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("/* id out of range */");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return \"Message ID out of range\";");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("else{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("return ");
- String _name_6 = pc.getName();
- _builder.append(_name_6, " ");
- _builder.append("_messageStrings[msg_id];");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- return _builder;
- }
-}
+package org.eclipse.etrice.generator.c.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.HashSet;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+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.Message;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.generator.base.ILogger;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.extensions.RoomExtensions;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.xbase.lib.BooleanExtensions;
+import org.eclipse.xtext.xbase.lib.IntegerExtensions;
+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 ProtocolClassGen {
+ @Inject
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ private CExtensions stdExt;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ @Inject
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
+ for (final ProtocolClass pc : _usedProtocolClasses) {
+ {
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(pc);
+ String _path = this.roomExt.getPath(pc);
+ String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
+ String path = _operator_plus;
+ String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
+ String _operator_plus_1 = StringExtensions.operator_plus("generating ProtocolClass header \'", _cHeaderFileName);
+ 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 _cHeaderFileName_1 = this.stdExt.getCHeaderFileName(pc);
+ StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, pc);
+ this.fileAccess.generateFile(_cHeaderFileName_1, _generateHeaderFile);
+ String _cSourceFileName = this.stdExt.getCSourceFileName(pc);
+ String _operator_plus_5 = StringExtensions.operator_plus("generating ProtocolClass source \'", _cSourceFileName);
+ 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 _cSourceFileName_1 = this.stdExt.getCSourceFileName(pc);
+ StringConcatenation _generateSourceFile = this.generateSourceFile(root, pc);
+ this.fileAccess.generateFile(_cSourceFileName_1, _generateSourceFile);
+ }
+ }
+ }
+
+ public StringConcatenation generateHeaderFile(final Root root, final ProtocolClass pc) {
+ 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("* Header File of ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* ");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ String _name_1 = pc.getName();
+ StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
+ _builder.append(_generateIncludeGuardBegin, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etDatatypes.h\"");
+ _builder.newLine();
+ _builder.append("#include \"etPort.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ DetailCode _userCode1 = pc.getUserCode1();
+ StringConcatenation _UserCode = this.helpers.UserCode(_userCode1);
+ _builder.append(_UserCode, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ HashSet<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc);
+ for(final DataClass dataClass : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _name_2 = dataClass.getName();
+ _builder.append(_name_2, "");
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("/* message IDs */");
+ _builder.newLine();
+ _builder.append("enum {");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_3 = pc.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("_MSG_MIN = 0, ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("/* IDs for outgoing messages */");
+ _builder.newLine();
+ {
+ List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
+ for(final Message message : _allOutgoingMessages) {
+ _builder.append("\t");
+ String _name_4 = pc.getName();
+ String _name_5 = message.getName();
+ String _outMessageId = this.stdExt.outMessageId(_name_4, _name_5);
+ _builder.append(_outMessageId, " ");
+ _builder.append(" = ");
+ List<Message> _allOutgoingMessages_1 = this.roomExt.getAllOutgoingMessages(pc);
+ int _indexOf = _allOutgoingMessages_1.indexOf(message);
+ int _operator_plus = IntegerExtensions.operator_plus(((Integer)_indexOf), ((Integer)1));
+ _builder.append(_operator_plus, " ");
+ _builder.append(",");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("/* IDs for incoming messages */");
+ _builder.newLine();
+ {
+ List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
+ for(final Message message_1 : _allIncomingMessages) {
+ _builder.append("\t");
+ String _name_6 = pc.getName();
+ String _name_7 = message_1.getName();
+ String _inMessageId = this.stdExt.inMessageId(_name_6, _name_7);
+ _builder.append(_inMessageId, " ");
+ _builder.append(" = ");
+ List<Message> _allIncomingMessages_1 = this.roomExt.getAllIncomingMessages(pc);
+ int _indexOf_1 = _allIncomingMessages_1.indexOf(message_1);
+ List<Message> _allOutgoingMessages_2 = this.roomExt.getAllOutgoingMessages(pc);
+ int _size = _allOutgoingMessages_2.size();
+ int _operator_plus_1 = IntegerExtensions.operator_plus(((Integer)_indexOf_1), ((Integer)_size));
+ int _operator_plus_2 = IntegerExtensions.operator_plus(((Integer)_operator_plus_1), ((Integer)1));
+ _builder.append(_operator_plus_2, " ");
+ _builder.append(",");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("/* error if msgID >= MSG_MAX */");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_8 = pc.getName();
+ _builder.append(_name_8, " ");
+ _builder.append("_MSG_MAX = ");
+ List<Message> _allOutgoingMessages_3 = this.roomExt.getAllOutgoingMessages(pc);
+ int _size_1 = _allOutgoingMessages_3.size();
+ List<Message> _allIncomingMessages_2 = this.roomExt.getAllIncomingMessages(pc);
+ int _size_2 = _allIncomingMessages_2.size();
+ int _operator_plus_3 = IntegerExtensions.operator_plus(((Integer)_size_1), ((Integer)_size_2));
+ int _operator_plus_4 = IntegerExtensions.operator_plus(((Integer)_operator_plus_3), ((Integer)1));
+ _builder.append(_operator_plus_4, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/*--------------------- port classes */");
+ _builder.newLine();
+ StringConcatenation _portClassHeader = this.portClassHeader(pc, ((Boolean)false));
+ _builder.append(_portClassHeader, "");
+ _builder.newLineIfNotEmpty();
+ StringConcatenation _portClassHeader_1 = this.portClassHeader(pc, ((Boolean)true));
+ _builder.append(_portClassHeader_1, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/*--------------------- debug helpers */");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* get message string for message id */");
+ _builder.newLine();
+ _builder.append("const char* ");
+ String _name_9 = pc.getName();
+ _builder.append(_name_9, "");
+ _builder.append("_getMessageString(int msg_id);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ DetailCode _userCode2 = pc.getUserCode2();
+ StringConcatenation _UserCode_1 = this.helpers.UserCode(_userCode2);
+ _builder.append(_UserCode_1, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ String _name_10 = pc.getName();
+ StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_10);
+ _builder.append(_generateIncludeGuardEnd, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation generateSourceFile(final Root root, final ProtocolClass pc) {
+ 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 ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* ");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cHeaderFileName = this.stdExt.getCHeaderFileName(pc);
+ _builder.append(_cHeaderFileName, "");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etMSCLogger.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/*--------------------- port classes */");
+ _builder.newLine();
+ StringConcatenation _portClassSource = this.portClassSource(pc, ((Boolean)false));
+ _builder.append(_portClassSource, "");
+ _builder.newLineIfNotEmpty();
+ StringConcatenation _portClassSource_1 = this.portClassSource(pc, ((Boolean)true));
+ _builder.append(_portClassSource_1, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/*--------------------- debug helpers */");
+ _builder.newLine();
+ StringConcatenation _generateDebugHelpersImplementation = this.generateDebugHelpersImplementation(root, pc);
+ _builder.append(_generateDebugHelpersImplementation, "");
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ public StringConcatenation portClass(final ProtocolClass pc, final Boolean conj) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation portClassHeader(final ProtocolClass pc, final Boolean conj) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _portClassName = this.roomExt.getPortClassName(pc, conj);
+ String portClassName = _portClassName;
+ _builder.newLineIfNotEmpty();
+ PortClass _portClass = this.roomExt.getPortClass(pc, conj);
+ PortClass pClass = _portClass;
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("typedef etPort ");
+ _builder.append(portClassName, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ boolean _operator_not = BooleanExtensions.operator_not(conj);
+ if (_operator_not) {
+ {
+ List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
+ for(final Message message : _allOutgoingMessages) {
+ _builder.append("void ");
+ _builder.append(portClassName, "");
+ _builder.append("_");
+ String _name = message.getName();
+ _builder.append(_name, "");
+ _builder.append("(const ");
+ _builder.append(portClassName, "");
+ _builder.append("* self);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ } else {
+ {
+ List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
+ for(final Message message_1 : _allIncomingMessages) {
+ _builder.append("void ");
+ _builder.append(portClassName, "");
+ _builder.append("_");
+ String _name_1 = message_1.getName();
+ _builder.append(_name_1, "");
+ _builder.append("(const ");
+ _builder.append(portClassName, "");
+ _builder.append("* self);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation portClassSource(final ProtocolClass pc, final Boolean conj) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _portClassName = this.roomExt.getPortClassName(pc, conj);
+ String portClassName = _portClassName;
+ _builder.newLineIfNotEmpty();
+ PortClass _portClass = this.roomExt.getPortClass(pc, conj);
+ PortClass pClass = _portClass;
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ boolean _operator_not = BooleanExtensions.operator_not(conj);
+ if (_operator_not) {
+ {
+ List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
+ for(final Message message : _allOutgoingMessages) {
+ _builder.append("void ");
+ _builder.append(portClassName, "");
+ _builder.append("_");
+ String _name = message.getName();
+ _builder.append(_name, "");
+ _builder.append("(const ");
+ _builder.append(portClassName, "");
+ _builder.append("* self){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
+ _builder.append(portClassName, " ");
+ _builder.append("\", \"");
+ String _name_1 = message.getName();
+ _builder.append(_name_1, " ");
+ _builder.append("\")");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("msg->address = self->peerAddress;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("msg->evtID = ");
+ String _name_2 = pc.getName();
+ String _name_3 = message.getName();
+ String _outMessageId = this.stdExt.outMessageId(_name_2, _name_3);
+ _builder.append(_outMessageId, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("etMessageService_pushMessage(self->msgService, msg);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ } else {
+ {
+ List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
+ for(final Message message_1 : _allIncomingMessages) {
+ _builder.append("void ");
+ _builder.append(portClassName, "");
+ _builder.append("_");
+ String _name_4 = message_1.getName();
+ _builder.append(_name_4, "");
+ _builder.append("(const ");
+ _builder.append(portClassName, "");
+ _builder.append("* self){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
+ _builder.append(portClassName, " ");
+ _builder.append("\", \"");
+ String _name_5 = message_1.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("\")");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("etMessage* msg = etMessageService_getMessageBuffer(self->msgService, sizeof(etMessage));");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("msg->address = self->peerAddress;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("msg->evtID = ");
+ String _name_6 = pc.getName();
+ String _name_7 = message_1.getName();
+ String _inMessageId = this.stdExt.inMessageId(_name_6, _name_7);
+ _builder.append(_inMessageId, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("etMessageService_pushMessage(self->msgService, msg);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation messageSignature(final ProtocolClass pc, final Message m) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("void ");
+ String _name = pc.getName();
+ _builder.append(_name, "");
+ _builder.append("_");
+ String _name_1 = m.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" (");
+ {
+ VarDecl _data = m.getData();
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
+ if (_operator_notEquals) {
+ VarDecl _data_1 = m.getData();
+ RefableType _refType = _data_1.getRefType();
+ DataType _type = _refType.getType();
+ String _name_2 = _type.getName();
+ _builder.append(_name_2, "");
+ _builder.append(" ");
+ VarDecl _data_2 = m.getData();
+ String _name_3 = _data_2.getName();
+ _builder.append(_name_3, "");
+ }
+ }
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ public StringConcatenation messageCall(final Message m) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name = m.getName();
+ _builder.append(_name, "");
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_data, null);
+ if (_operator_notEquals) {
+ _builder.append(" ");
+ VarDecl _data_1 = m.getData();
+ String _name_1 = _data_1.getName();
+ _builder.append(_name_1, "");
+ }
+ }
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ public StringConcatenation generateDebugHelpersImplementation(final Root root, final ProtocolClass pc) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.newLine();
+ _builder.append("/* TODO: make this optional or different for smaller footprint */");
+ _builder.newLine();
+ _builder.append("/* message names as strings for debugging (generate MSC) */");
+ _builder.newLine();
+ _builder.append("static const char* ");
+ String _name = pc.getName();
+ _builder.append(_name, "");
+ _builder.append("_messageStrings[] = {\"MIN\", ");
+ {
+ List<Message> _allOutgoingMessages = this.roomExt.getAllOutgoingMessages(pc);
+ for(final Message m : _allOutgoingMessages) {
+ _builder.append("\"");
+ String _name_1 = m.getName();
+ _builder.append(_name_1, "");
+ _builder.append("\",");
+ }
+ }
+ {
+ List<Message> _allIncomingMessages = this.roomExt.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ _builder.append("\"");
+ String _name_2 = m_1.getName();
+ _builder.append(_name_2, "");
+ _builder.append("\", ");
+ }
+ }
+ _builder.append("\"MAX\"};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("const char* ");
+ String _name_3 = pc.getName();
+ _builder.append(_name_3, "");
+ _builder.append("_getMessageString(int msg_id) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if (msg_id<");
+ String _name_4 = pc.getName();
+ _builder.append(_name_4, " ");
+ _builder.append("_MSG_MIN || msg_id>");
+ String _name_5 = pc.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("_MSG_MAX+1){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("/* id out of range */");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return \"Message ID out of range\";");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("else{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return ");
+ String _name_6 = pc.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("_messageStrings[msg_id];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java
index 66e8c245c..65863e4ca 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java
@@ -1,868 +1,867 @@
-package org.eclipse.etrice.generator.c.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.ActorClass;
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.Guard;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.core.room.MessageFromIf;
-import org.eclipse.etrice.core.room.NonInitialTransition;
-import org.eclipse.etrice.core.room.State;
-import org.eclipse.etrice.core.room.StateGraph;
-import org.eclipse.etrice.core.room.StateMachine;
-import org.eclipse.etrice.core.room.Transition;
-import org.eclipse.etrice.core.room.Trigger;
-import org.eclipse.etrice.core.room.TriggeredTransition;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-import org.eclipse.etrice.generator.etricegen.ActiveTrigger;
-import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
-import org.eclipse.etrice.generator.etricegen.TransitionChain;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.etrice.generator.extensions.RoomNameProv;
-import org.eclipse.etrice.generator.generic.LanguageGenerator;
-import org.eclipse.xtext.xbase.lib.BooleanExtensions;
-import org.eclipse.xtext.xbase.lib.Functions.Function1;
-import org.eclipse.xtext.xbase.lib.IntegerExtensions;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-import org.eclipse.xtext.xtend2.lib.StringConcatenation;
-
-@SuppressWarnings("all")
-@Singleton
-public class StateMachineGen {
- @Inject
- private CExtensions stdExt;
-
- @Inject
- private RoomExtensions roomExt;
-
- @Inject
- private LanguageGenerator languageGen;
-
- public StringConcatenation genStateMachine(final ExpandedActorClass xpac, final ActorClass ac) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("//******************************************");
- _builder.newLine();
- _builder.append("// START of generated code for FSM");
- _builder.newLine();
- _builder.append("//******************************************");
- _builder.newLine();
- _builder.newLine();
- _builder.append("// State IDs for FSM");
- _builder.newLine();
- int _numberOfInheritedBaseStates = this.roomExt.getNumberOfInheritedBaseStates(ac);
- int offset = _numberOfInheritedBaseStates;
- _builder.newLineIfNotEmpty();
- StateMachine _stateMachine = ac.getStateMachine();
- List<State> _baseStateList = this.roomExt.getBaseStateList(_stateMachine);
- List<State> baseStates = _baseStateList;
- _builder.newLineIfNotEmpty();
- {
- for(final State state : baseStates) {
- _builder.append("protected static final int ");
- String _stateId = this.roomExt.getStateId(state);
- _builder.append(_stateId, "");
- _builder.append(" = ");
- int _indexOf = baseStates.indexOf(state);
- int _operator_plus = IntegerExtensions.operator_plus(((Integer)_indexOf), ((Integer)2));
- int _operator_plus_1 = IntegerExtensions.operator_plus(((Integer)_operator_plus), ((Integer)offset));
- _builder.append(_operator_plus_1, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("protected static final String stateStrings[] = {\"<no state>\",\"<top>\",");
- {
- List<State> _allBaseStates = this.roomExt.getAllBaseStates(ac);
- boolean hasAnyElements = false;
- for(final State state_1 : _allBaseStates) {
- if (!hasAnyElements) {
- hasAnyElements = true;
- } else {
- _builder.appendImmediate(",", " ");
- }
- _builder.append("\"");
- String _statePathName = this.roomExt.getStatePathName(state_1);
- _builder.append(_statePathName, " ");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- }
- }
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("// history");
- _builder.newLine();
- _builder.append("// TODOHRR: history defined in ActorClassBase, init in constructor");
- _builder.newLine();
- _builder.append("//\t\thistory = new int[5];");
- _builder.newLine();
- _builder.append("//\t\tfor (int i = 0; i < history.length; i++) {");
- _builder.newLine();
- _builder.append("//\t\t\thistory[i] = NO_STATE;");
- _builder.newLine();
- _builder.append("//\t\t}");
- _builder.newLine();
- _builder.append("protected int history[] = {NO_STATE,NO_STATE");
- {
- List<State> _allBaseStates_1 = this.roomExt.getAllBaseStates(ac);
- for(final State state_2 : _allBaseStates_1) {
- _builder.append(",NO_STATE");
- }
- }
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- EList<TransitionChain> _ownTransitionChains = xpac.getOwnTransitionChains();
- List<TransitionChain> chains = _ownTransitionChains;
- _builder.newLineIfNotEmpty();
- EList<TransitionChain> _transitionChains = xpac.getTransitionChains();
- int _size = _transitionChains.size();
- int _size_1 = chains.size();
- int _operator_minus = IntegerExtensions.operator_minus(((Integer)_size), ((Integer)_size_1));
- int offset_tc = _operator_minus;
- _builder.newLineIfNotEmpty();
- _builder.append("// transition chains");
- _builder.newLine();
- {
- for(final TransitionChain tc : chains) {
- _builder.append("protected static final int ");
- String _chainId = this.roomExt.getChainId(tc);
- _builder.append(_chainId, "");
- _builder.append(" = ");
- int _indexOf_1 = chains.indexOf(tc);
- int _operator_plus_2 = IntegerExtensions.operator_plus(((Integer)_indexOf_1), ((Integer)1));
- int _operator_plus_3 = IntegerExtensions.operator_plus(((Integer)_operator_plus_2), ((Integer)offset_tc));
- _builder.append(_operator_plus_3, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- EList<MessageFromIf> _ownTriggers = xpac.getOwnTriggers();
- EList<MessageFromIf> triggers = _ownTriggers;
- _builder.newLineIfNotEmpty();
- _builder.append("// triggers for FSM");
- _builder.newLine();
- {
- for(final MessageFromIf mif : triggers) {
- _builder.append("protected static final int ");
- String _triggerCodeName = xpac.getTriggerCodeName(mif);
- _builder.append(_triggerCodeName, "");
- _builder.append(" = IFITEM_");
- InterfaceItem _from = mif.getFrom();
- String _name = _from.getName();
- _builder.append(_name, "");
- _builder.append(" + EVT_SHIFT*");
- String _messageID = xpac.getMessageID(mif);
- _builder.append(_messageID, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("// receiveEvent contains the main implementation of the FSM");
- _builder.newLine();
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("int chain = NOT_CAUGHT;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("int catching_state = NO_STATE;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("boolean is_handler = false;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("boolean skip_entry = false;");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("if (!handleSystemEvent(ifitem, evt, generic_data)) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("switch (state) {");
- _builder.newLine();
- {
- StateMachine _stateMachine_1 = xpac.getStateMachine();
- List<State> _leafStateList = this.roomExt.getLeafStateList(_stateMachine_1);
- for(final State state_3 : _leafStateList) {
- _builder.append("\t\t\t");
- _builder.append("case ");
- String _stateId_1 = this.roomExt.getStateId(state_3);
- _builder.append(_stateId_1, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- EList<ActiveTrigger> _activeTriggers = xpac.getActiveTriggers(state_3);
- EList<ActiveTrigger> atlist = _activeTriggers;
- _builder.newLineIfNotEmpty();
- {
- boolean _isEmpty = atlist.isEmpty();
- boolean _operator_not = BooleanExtensions.operator_not(_isEmpty);
- if (_operator_not) {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("switch(trigger) {");
- _builder.newLine();
- {
- for(final ActiveTrigger at : atlist) {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("case ");
- String _trigger = at.getTrigger();
- String _triggerCodeName_1 = xpac.getTriggerCodeName(_trigger);
- _builder.append(_triggerCodeName_1, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- boolean _hasGuard = this.roomExt.hasGuard(xpac, at);
- boolean needData = _hasGuard;
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- {
- if (needData) {
- _builder.append("{ ");
- Message _msg = at.getMsg();
- String _typedDataDefinition = this.stdExt.getTypedDataDefinition(_msg);
- _builder.append(_typedDataDefinition, " ");
- }
- }
- _builder.newLineIfNotEmpty();
- {
- EList<TriggeredTransition> _transitions = at.getTransitions();
- boolean hasAnyElements_1 = false;
- for(final TriggeredTransition tt : _transitions) {
- if (!hasAnyElements_1) {
- hasAnyElements_1 = true;
- } else {
- _builder.appendImmediate(" else ", " ");
- }
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- TransitionChain _chain = xpac.getChain(tt);
- TransitionChain chain = _chain;
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- Transition _transition = chain.getTransition();
- String _trigger_1 = at.getTrigger();
- StringConcatenation _guard = this.guard(_transition, _trigger_1, xpac);
- _builder.append(_guard, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("chain = ");
- String _chainId_1 = this.roomExt.getChainId(chain);
- _builder.append(_chainId_1, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("catching_state = ");
- String _contextId = this.roomExt.getContextId(chain);
- _builder.append(_contextId, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("\t");
- {
- boolean _isHandler = chain.isHandler();
- if (_isHandler) {
- _builder.append("is_handler = true;");
- }
- }
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("\t");
- {
- boolean _isSkipEntry = chain.isSkipEntry();
- if (_isSkipEntry) {
- _builder.append("skip_entry = true;");
- }
- }
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- {
- if (needData) {
- _builder.append("}");
- }
- }
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("break;");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("break;");
- _builder.newLine();
- }
- }
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("if (chain != NOT_CAUGHT) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("exitTo(state, catching_state, is_handler);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("int next = executeTransitionChain(chain, ifitem, generic_data);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("next = enterHistory(next, is_handler, skip_entry);");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("setState(next);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("private void setState(int new_state) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("if (stateStrings[new_state]!=\"Idle\") {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("// TODOTS: model switch for activation");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("System.out.println(getInstancePath() + \" -> \" + stateStrings[new_state]);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("this.state = new_state;");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("@Override");
- _builder.newLine();
- _builder.append("public void executeInitTransition() {");
- _builder.newLine();
- _builder.append("\t");
- StateMachine _stateMachine_2 = xpac.getStateMachine();
- Transition _initTransition = this.roomExt.getInitTransition(_stateMachine_2);
- Transition initt = _initTransition;
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("int chain = ");
- TransitionChain _chain_1 = xpac.getChain(initt);
- String _chainId_2 = this.roomExt.getChainId(_chain_1);
- _builder.append(_chainId_2, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("int next = executeTransitionChain(chain, null, null);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("next = enterHistory(next, false, false);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("setState(next);");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* calls exit codes while exiting from the current state to one of its");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* parent states while remembering the history");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param current - the current state");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param to - the final parent state");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.append("private void exitTo(int current, int to, boolean handler) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("while (current!=to) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("switch (current) {");
- _builder.newLine();
- {
- StateMachine _stateMachine_3 = xpac.getStateMachine();
- List<State> _baseStateList_1 = this.roomExt.getBaseStateList(_stateMachine_3);
- for(final State state_4 : _baseStateList_1) {
- _builder.append("\t\t\t");
- _builder.append("case ");
- String _stateId_2 = this.roomExt.getStateId(state_4);
- _builder.append(_stateId_2, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- {
- boolean _hasExitCode = this.roomExt.hasExitCode(state_4);
- if (_hasExitCode) {
- _builder.append("if (!handler) ");
- String _exitCodeOperationName = RoomNameProv.getExitCodeOperationName(state_4);
- _builder.append(_exitCodeOperationName, " ");
- _builder.append("();");
- }
- }
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("history[");
- String _parentStateId = RoomNameProv.getParentStateId(state_4);
- _builder.append(_parentStateId, " ");
- _builder.append("] = ");
- String _stateId_3 = this.roomExt.getStateId(state_4);
- _builder.append(_stateId_3, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("current = ");
- String _parentStateId_1 = RoomNameProv.getParentStateId(state_4);
- _builder.append(_parentStateId_1, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("break;");
- _builder.newLine();
- }
- }
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* calls action, entry and exit codes along a transition chain. The generic data are cast to typed data");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* matching the trigger of this chain. The ID of the final state is returned");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param chain - the chain ID");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param generic_data - the generic data pointer");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @return the ID of the final state");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.append("private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("switch (chain) {");
- _builder.newLine();
- _builder.append("\t\t");
- EList<TransitionChain> _transitionChains_1 = xpac.getTransitionChains();
- EList<TransitionChain> allchains = _transitionChains_1;
- _builder.newLineIfNotEmpty();
- {
- for(final TransitionChain tc_1 : allchains) {
- _builder.append("\t\t");
- _builder.append("case ");
- String _chainId_3 = this.roomExt.getChainId(tc_1);
- _builder.append(_chainId_3, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("{");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("\t");
- String _executeChainCode = this.stdExt.getExecuteChainCode(xpac, tc_1);
- _builder.append(_executeChainCode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- }
- }
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("return NO_STATE;");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* calls entry codes while entering a state\'s history. The ID of the final leaf state is returned");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param state - the state which is entered");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @param handler - entry code is executed if not handler");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* @return - the ID of the final leaf state");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.append("private int enterHistory(int state, boolean handler, boolean skip_entry) {");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("while (true) {");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("switch (state) {");
- _builder.newLine();
- {
- StateMachine _stateMachine_4 = xpac.getStateMachine();
- List<State> _baseStateList_2 = this.roomExt.getBaseStateList(_stateMachine_4);
- for(final State state_5 : _baseStateList_2) {
- _builder.append("\t\t\t");
- _builder.append("case ");
- String _stateId_4 = this.roomExt.getStateId(state_5);
- _builder.append(_stateId_4, " ");
- _builder.append(":");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- {
- boolean _hasEntryCode = this.roomExt.hasEntryCode(state_5);
- if (_hasEntryCode) {
- _builder.append("if (!(skip_entry || handler)) ");
- String _entryCodeOperationName = RoomNameProv.getEntryCodeOperationName(state_5);
- _builder.append(_entryCodeOperationName, " ");
- _builder.append("();");
- }
- }
- _builder.newLineIfNotEmpty();
- {
- boolean _isLeaf = this.roomExt.isLeaf(state_5);
- if (_isLeaf) {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("// in leaf state: return state id");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("return ");
- String _stateId_5 = this.roomExt.getStateId(state_5);
- _builder.append(_stateId_5, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("// state has a sub graph");
- _builder.newLine();
- {
- StateGraph _subgraph = state_5.getSubgraph();
- boolean _hasInitTransition = this.roomExt.hasInitTransition(_subgraph);
- if (_hasInitTransition) {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("// with init transition");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("if (history[");
- String _stateId_6 = this.roomExt.getStateId(state_5);
- _builder.append(_stateId_6, " ");
- _builder.append("]==NO_STATE) {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- StateGraph _subgraph_1 = state_5.getSubgraph();
- Transition _initTransition_1 = this.roomExt.getInitTransition(_subgraph_1);
- Transition sub_initt = _initTransition_1;
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("state = executeTransitionChain(");
- TransitionChain _chain_2 = xpac.getChain(sub_initt);
- String _chainId_4 = this.roomExt.getChainId(_chain_2);
- _builder.append(_chainId_4, " ");
- _builder.append(", null, null);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("else {");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("\t");
- _builder.append("state = history[");
- String _stateId_7 = this.roomExt.getStateId(state_5);
- _builder.append(_stateId_7, " ");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- } else {
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("// without init transition");
- _builder.newLine();
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("state = history[");
- String _stateId_8 = this.roomExt.getStateId(state_5);
- _builder.append(_stateId_8, " ");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t\t\t");
- _builder.append("\t");
- _builder.append("break;");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("\t\t\t");
- _builder.append("case STATE_TOP:");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("state = history[STATE_TOP];");
- _builder.newLine();
- _builder.append("\t\t\t\t");
- _builder.append("break;");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("skip_entry = false;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("//return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("//*** Entry and Exit Codes");
- _builder.newLine();
- {
- StateMachine _stateMachine_5 = xpac.getStateMachine();
- List<State> _stateList = this.roomExt.getStateList(_stateMachine_5);
- for(final State state_6 : _stateList) {
- {
- boolean _isOwnObject = xpac.isOwnObject(state_6);
- if (_isOwnObject) {
- {
- boolean _hasEntryCode_1 = this.roomExt.hasEntryCode(state_6);
- if (_hasEntryCode_1) {
- _builder.append("protected void ");
- String _entryCodeOperationName_1 = RoomNameProv.getEntryCodeOperationName(state_6);
- _builder.append(_entryCodeOperationName_1, "");
- _builder.append("() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _entryCode = this.roomExt.getEntryCode(xpac, state_6);
- _builder.append(_entryCode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- {
- boolean _hasExitCode_1 = this.roomExt.hasExitCode(state_6);
- if (_hasExitCode_1) {
- _builder.append("protected void ");
- String _exitCodeOperationName_1 = RoomNameProv.getExitCodeOperationName(state_6);
- _builder.append(_exitCodeOperationName_1, "");
- _builder.append("() {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _exitCode = this.roomExt.getExitCode(xpac, state_6);
- _builder.append(_exitCode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- }
- }
- _builder.newLine();
- _builder.append("//*** Action Codes");
- _builder.newLine();
- {
- StateMachine _stateMachine_6 = xpac.getStateMachine();
- List<Transition> _transitionList = this.roomExt.getTransitionList(_stateMachine_6);
- for(final Transition tr : _transitionList) {
- {
- boolean _operator_and = false;
- boolean _isOwnObject_1 = xpac.isOwnObject(tr);
- if (!_isOwnObject_1) {
- _operator_and = false;
- } else {
- boolean _hasActionCode = this.roomExt.hasActionCode(tr);
- _operator_and = BooleanExtensions.operator_and(_isOwnObject_1, _hasActionCode);
- }
- if (_operator_and) {
- _builder.append("protected void ");
- String _actionCodeOperationName = RoomNameProv.getActionCodeOperationName(tr);
- _builder.append(_actionCodeOperationName, "");
- _builder.append("(");
- {
- if ((tr instanceof NonInitialTransition)) {
- _builder.append("InterfaceItemBase ifitem");
- String _argumentList = this.languageGen.getArgumentList(xpac, tr);
- _builder.append(_argumentList, "");
- }
- }
- _builder.append(") {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _actionCode = this.roomExt.getActionCode(xpac, tr);
- _builder.append(_actionCode, " ");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- _builder.append("\t ");
- _builder.newLine();
- _builder.append("//******************************************");
- _builder.newLine();
- _builder.append("// END of generated code for FSM");
- _builder.newLine();
- _builder.append("//******************************************");
- _builder.newLine();
- return _builder;
- }
-
- protected StringConcatenation _guard(final TriggeredTransition tt, final String trigger, final ExpandedActorClass ac) {
- StringConcatenation _builder = new StringConcatenation();
- EList<Trigger> _triggers = tt.getTriggers();
- final Function1<Trigger,Boolean> _function = new Function1<Trigger,Boolean>() {
- public Boolean apply(final Trigger e) {
- boolean _isMatching = ac.isMatching(e, trigger);
- return ((Boolean)_isMatching);
- }
- };
- Trigger _findFirst = IterableExtensions.<Trigger>findFirst(_triggers, _function);
- Trigger tr = _findFirst;
- _builder.newLineIfNotEmpty();
- {
- boolean _hasGuard = this.roomExt.hasGuard(tr);
- if (_hasGuard) {
- _builder.append("if (");
- Guard _guard = tr.getGuard();
- DetailCode _guard_1 = _guard.getGuard();
- String _code = ac.getCode(_guard_1);
- _builder.append(_code, "");
- _builder.append(")");
- _builder.newLineIfNotEmpty();
- }
- }
- return _builder;
- }
-
- protected StringConcatenation _guard(final Transition t, final String trigger, final ExpandedActorClass ac) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("/* error */");
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation guard(final Transition tt, final String trigger, final ExpandedActorClass ac) {
- if (tt instanceof TriggeredTransition) {
- return _guard((TriggeredTransition)tt, trigger, ac);
- } else {
- return _guard(tt, trigger, ac);
- }
- }
-}
+package org.eclipse.etrice.generator.c.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.ActorClass;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.Guard;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.MessageFromIf;
+import org.eclipse.etrice.core.room.NonInitialTransition;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.core.room.Trigger;
+import org.eclipse.etrice.core.room.TriggeredTransition;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.etricegen.ActiveTrigger;
+import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.generator.etricegen.TransitionChain;
+import org.eclipse.etrice.generator.extensions.RoomExtensions;
+import org.eclipse.etrice.generator.extensions.RoomNameProv;
+import org.eclipse.etrice.generator.generic.LanguageGenerator;
+import org.eclipse.xtext.xbase.lib.BooleanExtensions;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IntegerExtensions;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class StateMachineGen {
+ @Inject
+ private CExtensions stdExt;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ @Inject
+ private LanguageGenerator languageGen;
+
+ public StringConcatenation genStateMachine(final ExpandedActorClass xpac, final ActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("//******************************************");
+ _builder.newLine();
+ _builder.append("// START of generated code for FSM");
+ _builder.newLine();
+ _builder.append("//******************************************");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// State IDs for FSM");
+ _builder.newLine();
+ int _numberOfInheritedBaseStates = this.roomExt.getNumberOfInheritedBaseStates(ac);
+ int offset = _numberOfInheritedBaseStates;
+ _builder.newLineIfNotEmpty();
+ StateGraph _stateMachine = ac.getStateMachine();
+ List<State> _baseStateList = this.roomExt.getBaseStateList(_stateMachine);
+ List<State> baseStates = _baseStateList;
+ _builder.newLineIfNotEmpty();
+ {
+ for(final State state : baseStates) {
+ _builder.append("protected static final int ");
+ String _stateId = this.roomExt.getStateId(state);
+ _builder.append(_stateId, "");
+ _builder.append(" = ");
+ int _indexOf = baseStates.indexOf(state);
+ int _operator_plus = IntegerExtensions.operator_plus(((Integer)_indexOf), ((Integer)2));
+ int _operator_plus_1 = IntegerExtensions.operator_plus(((Integer)_operator_plus), ((Integer)offset));
+ _builder.append(_operator_plus_1, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("protected static final String stateStrings[] = {\"<no state>\",\"<top>\",");
+ {
+ List<State> _allBaseStates = this.roomExt.getAllBaseStates(ac);
+ boolean hasAnyElements = false;
+ for(final State state_1 : _allBaseStates) {
+ if (!hasAnyElements) {
+ hasAnyElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
+ }
+ _builder.append("\"");
+ String _statePathName = this.roomExt.getStatePathName(state_1);
+ _builder.append(_statePathName, " ");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ }
+ }
+ _builder.append("};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// history");
+ _builder.newLine();
+ _builder.append("// TODOHRR: history defined in ActorClassBase, init in constructor");
+ _builder.newLine();
+ _builder.append("//\t\thistory = new int[5];");
+ _builder.newLine();
+ _builder.append("//\t\tfor (int i = 0; i < history.length; i++) {");
+ _builder.newLine();
+ _builder.append("//\t\t\thistory[i] = NO_STATE;");
+ _builder.newLine();
+ _builder.append("//\t\t}");
+ _builder.newLine();
+ _builder.append("protected int history[] = {NO_STATE,NO_STATE");
+ {
+ List<State> _allBaseStates_1 = this.roomExt.getAllBaseStates(ac);
+ for(final State state_2 : _allBaseStates_1) {
+ _builder.append(",NO_STATE");
+ }
+ }
+ _builder.append("};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ EList<TransitionChain> _ownTransitionChains = xpac.getOwnTransitionChains();
+ List<TransitionChain> chains = _ownTransitionChains;
+ _builder.newLineIfNotEmpty();
+ EList<TransitionChain> _transitionChains = xpac.getTransitionChains();
+ int _size = _transitionChains.size();
+ int _size_1 = chains.size();
+ int _operator_minus = IntegerExtensions.operator_minus(((Integer)_size), ((Integer)_size_1));
+ int offset_tc = _operator_minus;
+ _builder.newLineIfNotEmpty();
+ _builder.append("// transition chains");
+ _builder.newLine();
+ {
+ for(final TransitionChain tc : chains) {
+ _builder.append("protected static final int ");
+ String _chainId = this.roomExt.getChainId(tc);
+ _builder.append(_chainId, "");
+ _builder.append(" = ");
+ int _indexOf_1 = chains.indexOf(tc);
+ int _operator_plus_2 = IntegerExtensions.operator_plus(((Integer)_indexOf_1), ((Integer)1));
+ int _operator_plus_3 = IntegerExtensions.operator_plus(((Integer)_operator_plus_2), ((Integer)offset_tc));
+ _builder.append(_operator_plus_3, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ EList<MessageFromIf> _ownTriggers = xpac.getOwnTriggers();
+ EList<MessageFromIf> triggers = _ownTriggers;
+ _builder.newLineIfNotEmpty();
+ _builder.append("// triggers for FSM");
+ _builder.newLine();
+ {
+ for(final MessageFromIf mif : triggers) {
+ _builder.append("protected static final int ");
+ String _triggerCodeName = xpac.getTriggerCodeName(mif);
+ _builder.append(_triggerCodeName, "");
+ _builder.append(" = IFITEM_");
+ InterfaceItem _from = mif.getFrom();
+ String _name = _from.getName();
+ _builder.append(_name, "");
+ _builder.append(" + EVT_SHIFT*");
+ String _messageID = xpac.getMessageID(mif);
+ _builder.append(_messageID, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("// receiveEvent contains the main implementation of the FSM");
+ _builder.newLine();
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int chain = NOT_CAUGHT;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int catching_state = NO_STATE;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("boolean is_handler = false;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("boolean skip_entry = false;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if (!handleSystemEvent(ifitem, evt, generic_data)) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("switch (state) {");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_1 = xpac.getStateMachine();
+ List<State> _leafStateList = this.roomExt.getLeafStateList(_stateMachine_1);
+ for(final State state_3 : _leafStateList) {
+ _builder.append("\t\t\t");
+ _builder.append("case ");
+ String _stateId_1 = this.roomExt.getStateId(state_3);
+ _builder.append(_stateId_1, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ EList<ActiveTrigger> _activeTriggers = xpac.getActiveTriggers(state_3);
+ EList<ActiveTrigger> atlist = _activeTriggers;
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isEmpty = atlist.isEmpty();
+ boolean _operator_not = BooleanExtensions.operator_not(_isEmpty);
+ if (_operator_not) {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("switch(trigger) {");
+ _builder.newLine();
+ {
+ for(final ActiveTrigger at : atlist) {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("case ");
+ String _trigger = at.getTrigger();
+ String _triggerCodeName_1 = xpac.getTriggerCodeName(_trigger);
+ _builder.append(_triggerCodeName_1, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ boolean _hasGuard = this.roomExt.hasGuard(xpac, at);
+ boolean needData = _hasGuard;
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ {
+ if (needData) {
+ _builder.append("{ ");
+ Message _msg = at.getMsg();
+ String _typedDataDefinition = this.stdExt.getTypedDataDefinition(_msg);
+ _builder.append(_typedDataDefinition, " ");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ {
+ EList<TriggeredTransition> _transitions = at.getTransitions();
+ boolean hasAnyElements_1 = false;
+ for(final TriggeredTransition tt : _transitions) {
+ if (!hasAnyElements_1) {
+ hasAnyElements_1 = true;
+ } else {
+ _builder.appendImmediate(" else ", " ");
+ }
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ TransitionChain _chain = xpac.getChain(tt);
+ TransitionChain chain = _chain;
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ Transition _transition = chain.getTransition();
+ String _trigger_1 = at.getTrigger();
+ StringConcatenation _guard = this.guard(_transition, _trigger_1, xpac);
+ _builder.append(_guard, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("chain = ");
+ String _chainId_1 = this.roomExt.getChainId(chain);
+ _builder.append(_chainId_1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("catching_state = ");
+ String _contextId = this.roomExt.getContextId(chain);
+ _builder.append(_contextId, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ {
+ boolean _isHandler = chain.isHandler();
+ if (_isHandler) {
+ _builder.append("is_handler = true;");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ {
+ boolean _isSkipEntry = chain.isSkipEntry();
+ if (_isSkipEntry) {
+ _builder.append("skip_entry = true;");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ {
+ if (needData) {
+ _builder.append("}");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if (chain != NOT_CAUGHT) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("exitTo(state, catching_state, is_handler);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("int next = executeTransitionChain(chain, ifitem, generic_data);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("next = enterHistory(next, is_handler, skip_entry);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("setState(next);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("private void setState(int new_state) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if (stateStrings[new_state]!=\"Idle\") {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// TODOTS: model switch for activation");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("System.out.println(getInstancePath() + \" -> \" + stateStrings[new_state]);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("this.state = new_state;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("@Override");
+ _builder.newLine();
+ _builder.append("public void executeInitTransition() {");
+ _builder.newLine();
+ _builder.append("\t");
+ StateGraph _stateMachine_2 = xpac.getStateMachine();
+ Transition _initTransition = this.roomExt.getInitTransition(_stateMachine_2);
+ Transition initt = _initTransition;
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("int chain = ");
+ TransitionChain _chain_1 = xpac.getChain(initt);
+ String _chainId_2 = this.roomExt.getChainId(_chain_1);
+ _builder.append(_chainId_2, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("int next = executeTransitionChain(chain, null, null);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("next = enterHistory(next, false, false);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("setState(next);");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* calls exit codes while exiting from the current state to one of its");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* parent states while remembering the history");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param current - the current state");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param to - the final parent state");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("private void exitTo(int current, int to, boolean handler) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("while (current!=to) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("switch (current) {");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_3 = xpac.getStateMachine();
+ List<State> _baseStateList_1 = this.roomExt.getBaseStateList(_stateMachine_3);
+ for(final State state_4 : _baseStateList_1) {
+ _builder.append("\t\t\t");
+ _builder.append("case ");
+ String _stateId_2 = this.roomExt.getStateId(state_4);
+ _builder.append(_stateId_2, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ {
+ boolean _hasExitCode = this.roomExt.hasExitCode(state_4);
+ if (_hasExitCode) {
+ _builder.append("if (!handler) ");
+ String _exitCodeOperationName = RoomNameProv.getExitCodeOperationName(state_4);
+ _builder.append(_exitCodeOperationName, " ");
+ _builder.append("();");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("history[");
+ String _parentStateId = RoomNameProv.getParentStateId(state_4);
+ _builder.append(_parentStateId, " ");
+ _builder.append("] = ");
+ String _stateId_3 = this.roomExt.getStateId(state_4);
+ _builder.append(_stateId_3, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("current = ");
+ String _parentStateId_1 = RoomNameProv.getParentStateId(state_4);
+ _builder.append(_parentStateId_1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* calls action, entry and exit codes along a transition chain. The generic data are cast to typed data");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* matching the trigger of this chain. The ID of the final state is returned");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param chain - the chain ID");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param generic_data - the generic data pointer");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @return the ID of the final state");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("switch (chain) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ EList<TransitionChain> _transitionChains_1 = xpac.getTransitionChains();
+ EList<TransitionChain> allchains = _transitionChains_1;
+ _builder.newLineIfNotEmpty();
+ {
+ for(final TransitionChain tc_1 : allchains) {
+ _builder.append("\t\t");
+ _builder.append("case ");
+ String _chainId_3 = this.roomExt.getChainId(tc_1);
+ _builder.append(_chainId_3, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("\t");
+ String _executeChainCode = this.stdExt.getExecuteChainCode(xpac, tc_1);
+ _builder.append(_executeChainCode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("return NO_STATE;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* calls entry codes while entering a state\'s history. The ID of the final leaf state is returned");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param state - the state which is entered");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @param handler - entry code is executed if not handler");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @return - the ID of the final leaf state");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.append("private int enterHistory(int state, boolean handler, boolean skip_entry) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("while (true) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("switch (state) {");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_4 = xpac.getStateMachine();
+ List<State> _baseStateList_2 = this.roomExt.getBaseStateList(_stateMachine_4);
+ for(final State state_5 : _baseStateList_2) {
+ _builder.append("\t\t\t");
+ _builder.append("case ");
+ String _stateId_4 = this.roomExt.getStateId(state_5);
+ _builder.append(_stateId_4, " ");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ {
+ boolean _hasEntryCode = this.roomExt.hasEntryCode(state_5);
+ if (_hasEntryCode) {
+ _builder.append("if (!(skip_entry || handler)) ");
+ String _entryCodeOperationName = RoomNameProv.getEntryCodeOperationName(state_5);
+ _builder.append(_entryCodeOperationName, " ");
+ _builder.append("();");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isLeaf = this.roomExt.isLeaf(state_5);
+ if (_isLeaf) {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("// in leaf state: return state id");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("return ");
+ String _stateId_5 = this.roomExt.getStateId(state_5);
+ _builder.append(_stateId_5, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("// state has a sub graph");
+ _builder.newLine();
+ {
+ StateGraph _subgraph = state_5.getSubgraph();
+ boolean _hasInitTransition = this.roomExt.hasInitTransition(_subgraph);
+ if (_hasInitTransition) {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("// with init transition");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("if (history[");
+ String _stateId_6 = this.roomExt.getStateId(state_5);
+ _builder.append(_stateId_6, " ");
+ _builder.append("]==NO_STATE) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ StateGraph _subgraph_1 = state_5.getSubgraph();
+ Transition _initTransition_1 = this.roomExt.getInitTransition(_subgraph_1);
+ Transition sub_initt = _initTransition_1;
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("state = executeTransitionChain(");
+ TransitionChain _chain_2 = xpac.getChain(sub_initt);
+ String _chainId_4 = this.roomExt.getChainId(_chain_2);
+ _builder.append(_chainId_4, " ");
+ _builder.append(", null, null);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("else {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("state = history[");
+ String _stateId_7 = this.roomExt.getStateId(state_5);
+ _builder.append(_stateId_7, " ");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("// without init transition");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("state = history[");
+ String _stateId_8 = this.roomExt.getStateId(state_5);
+ _builder.append(_stateId_8, " ");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("\t\t\t");
+ _builder.append("case STATE_TOP:");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("state = history[STATE_TOP];");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("break;");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("skip_entry = false;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("//*** Entry and Exit Codes");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_5 = xpac.getStateMachine();
+ List<State> _stateList = this.roomExt.getStateList(_stateMachine_5);
+ for(final State state_6 : _stateList) {
+ {
+ boolean _isOwnObject = xpac.isOwnObject(state_6);
+ if (_isOwnObject) {
+ {
+ boolean _hasEntryCode_1 = this.roomExt.hasEntryCode(state_6);
+ if (_hasEntryCode_1) {
+ _builder.append("protected void ");
+ String _entryCodeOperationName_1 = RoomNameProv.getEntryCodeOperationName(state_6);
+ _builder.append(_entryCodeOperationName_1, "");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _entryCode = this.roomExt.getEntryCode(xpac, state_6);
+ _builder.append(_entryCode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ {
+ boolean _hasExitCode_1 = this.roomExt.hasExitCode(state_6);
+ if (_hasExitCode_1) {
+ _builder.append("protected void ");
+ String _exitCodeOperationName_1 = RoomNameProv.getExitCodeOperationName(state_6);
+ _builder.append(_exitCodeOperationName_1, "");
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _exitCode = this.roomExt.getExitCode(xpac, state_6);
+ _builder.append(_exitCode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("//*** Action Codes");
+ _builder.newLine();
+ {
+ StateGraph _stateMachine_6 = xpac.getStateMachine();
+ List<Transition> _transitionList = this.roomExt.getTransitionList(_stateMachine_6);
+ for(final Transition tr : _transitionList) {
+ {
+ boolean _operator_and = false;
+ boolean _isOwnObject_1 = xpac.isOwnObject(tr);
+ if (!_isOwnObject_1) {
+ _operator_and = false;
+ } else {
+ boolean _hasActionCode = this.roomExt.hasActionCode(tr);
+ _operator_and = BooleanExtensions.operator_and(_isOwnObject_1, _hasActionCode);
+ }
+ if (_operator_and) {
+ _builder.append("protected void ");
+ String _actionCodeOperationName = RoomNameProv.getActionCodeOperationName(tr);
+ _builder.append(_actionCodeOperationName, "");
+ _builder.append("(");
+ {
+ if ((tr instanceof NonInitialTransition)) {
+ _builder.append("InterfaceItemBase ifitem");
+ String _argumentList = this.languageGen.getArgumentList(xpac, tr);
+ _builder.append(_argumentList, "");
+ }
+ }
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _actionCode = this.roomExt.getActionCode(xpac, tr);
+ _builder.append(_actionCode, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _builder.append("\t ");
+ _builder.newLine();
+ _builder.append("//******************************************");
+ _builder.newLine();
+ _builder.append("// END of generated code for FSM");
+ _builder.newLine();
+ _builder.append("//******************************************");
+ _builder.newLine();
+ return _builder;
+ }
+
+ protected StringConcatenation _guard(final TriggeredTransition tt, final String trigger, final ExpandedActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ EList<Trigger> _triggers = tt.getTriggers();
+ final Function1<Trigger,Boolean> _function = new Function1<Trigger,Boolean>() {
+ public Boolean apply(final Trigger e) {
+ boolean _isMatching = ac.isMatching(e, trigger);
+ return ((Boolean)_isMatching);
+ }
+ };
+ Trigger _findFirst = IterableExtensions.<Trigger>findFirst(_triggers, _function);
+ Trigger tr = _findFirst;
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _hasGuard = this.roomExt.hasGuard(tr);
+ if (_hasGuard) {
+ _builder.append("if (");
+ Guard _guard = tr.getGuard();
+ DetailCode _guard_1 = _guard.getGuard();
+ String _code = ac.getCode(_guard_1);
+ _builder.append(_code, "");
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ return _builder;
+ }
+
+ protected StringConcatenation _guard(final Transition t, final String trigger, final ExpandedActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/* error */");
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation guard(final Transition tt, final String trigger, final ExpandedActorClass ac) {
+ if (tt instanceof TriggeredTransition) {
+ return _guard((TriggeredTransition)tt, trigger, ac);
+ } else {
+ return _guard(tt, trigger, ac);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
index 5338f91ea..7fdcd826c 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
@@ -1,578 +1,578 @@
-package org.eclipse.etrice.generator.c.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.ActorClass;
-import org.eclipse.etrice.core.room.Port;
-import org.eclipse.etrice.core.room.ProtocolClass;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.generator.base.ILogger;
-import org.eclipse.etrice.generator.c.gen.CExtensions;
-import org.eclipse.etrice.generator.etricegen.ActorInstance;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.etricegen.SubSystemInstance;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.etrice.generator.generic.ProcedureHelpers;
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-import org.eclipse.xtext.xtend2.lib.StringConcatenation;
-
-@SuppressWarnings("all")
-@Singleton
-public class SubSystemClassGen {
- @Inject
- private JavaIoFileSystemAccess fileAccess;
-
- @Inject
- private CExtensions stdExt;
-
- @Inject
- private RoomExtensions roomExt;
-
- @Inject
- private ProcedureHelpers helpers;
-
- @Inject
- private ILogger logger;
-
- public void doGenerate(final Root root) {
- EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
- for (final SubSystemInstance ssi : _subSystemInstances) {
- {
- SubSystemClass _subSystemClass = ssi.getSubSystemClass();
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
- SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
- String _path = this.roomExt.getPath(_subSystemClass_1);
- String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
- String path = _operator_plus;
- SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(_subSystemClass_2);
- String file = _cHeaderFileName;
- String _operator_plus_1 = StringExtensions.operator_plus("generating SubSystemClass declaration: \'", file);
- 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);
- SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
- StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, ssi, _subSystemClass_3);
- this.fileAccess.generateFile(file, _generateHeaderFile);
- SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
- String _cSourceFileName = this.stdExt.getCSourceFileName(_subSystemClass_4);
- file = _cSourceFileName;
- String _operator_plus_5 = StringExtensions.operator_plus("generating SubSystemClass implementation: \'", file);
- 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);
- SubSystemClass _subSystemClass_5 = ssi.getSubSystemClass();
- StringConcatenation _generateSourceFile = this.generateSourceFile(root, ssi, _subSystemClass_5);
- this.fileAccess.generateFile(file, _generateSourceFile);
- SubSystemClass _subSystemClass_6 = ssi.getSubSystemClass();
- String _instSourceFileName = this.stdExt.getInstSourceFileName(_subSystemClass_6);
- file = _instSourceFileName;
- String _operator_plus_9 = StringExtensions.operator_plus("generating SubSystemClass instance file: \'", file);
- String _operator_plus_10 = StringExtensions.operator_plus(_operator_plus_9, "\' in \'");
- String _operator_plus_11 = StringExtensions.operator_plus(_operator_plus_10, path);
- String _operator_plus_12 = StringExtensions.operator_plus(_operator_plus_11, "\'");
- this.logger.logInfo(_operator_plus_12);
- this.fileAccess.setOutputPath(path);
- SubSystemClass _subSystemClass_7 = ssi.getSubSystemClass();
- StringConcatenation _generateInstanceFile = this.generateInstanceFile(root, ssi, _subSystemClass_7);
- this.fileAccess.generateFile(file, _generateInstanceFile);
- }
- }
- }
-
- public StringConcatenation generateHeaderFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
- 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("* Header File of SubSystemClass ");
- String _name = ssc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- String _name_1 = ssc.getName();
- StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
- _builder.append(_generateIncludeGuardBegin, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* lifecycle functions");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* init -> start -> run (loop) -> stop -> destroy");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_2 = ssc.getName();
- _builder.append(_name_2, "");
- _builder.append("_init(void);\t\t/* lifecycle init \t */");
- _builder.newLineIfNotEmpty();
- _builder.append("void ");
- String _name_3 = ssc.getName();
- _builder.append(_name_3, "");
- _builder.append("_start(void);\t/* lifecycle start \t */");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_4 = ssc.getName();
- _builder.append(_name_4, "");
- _builder.append("_run(void);\t\t/* lifecycle run \t */");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_5 = ssc.getName();
- _builder.append(_name_5, "");
- _builder.append("_stop(void); \t/* lifecycle stop\t */");
- _builder.newLineIfNotEmpty();
- _builder.append("void ");
- String _name_6 = ssc.getName();
- _builder.append(_name_6, "");
- _builder.append("_destroy(void); \t/* lifecycle destroy */");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- String _name_7 = ssc.getName();
- StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_7);
- _builder.append(_generateIncludeGuardEnd, "");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation generateSourceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
- 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 SubSystemClass ");
- String _name = ssc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* ");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"");
- String _cHeaderFileName = this.stdExt.getCHeaderFileName(ssc);
- _builder.append(_cHeaderFileName, "");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("/* include instances for all classes */");
- _builder.newLine();
- _builder.append("#include \"");
- String _instSourceFileName = this.stdExt.getInstSourceFileName(ssc);
- _builder.append(_instSourceFileName, "");
- _builder.append("\"");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etLogger.h\"");
- _builder.newLine();
- _builder.append("#include \"etMSCLogger.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* data for SubSysten ");
- String _name_1 = ssc.getName();
- _builder.append(_name_1, "");
- _builder.append(" */");
- _builder.newLineIfNotEmpty();
- _builder.append("typedef struct ");
- String _name_2 = ssc.getName();
- _builder.append(_name_2, "");
- _builder.append(" {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("char *name;");
- _builder.newLine();
- _builder.append("} ");
- String _name_3 = ssc.getName();
- _builder.append(_name_3, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("static ");
- String _name_4 = ssc.getName();
- _builder.append(_name_4, "");
- _builder.append(" ");
- String _name_5 = ssc.getName();
- _builder.append(_name_5, "");
- _builder.append("Inst = {\"");
- String _name_6 = ssc.getName();
- _builder.append(_name_6, "");
- _builder.append("\"};");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_7 = ssc.getName();
- _builder.append(_name_7, "");
- _builder.append("_initActorInstances(void);");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("void ");
- String _name_8 = ssc.getName();
- _builder.append(_name_8, "");
- _builder.append("_init(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"init\")");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfoF(\"%s_init\", ");
- String _name_9 = ssc.getName();
- _builder.append(_name_9, " ");
- _builder.append("Inst.name);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/* initialization of all message services */");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etMessageService_init(&msgService_Thread1, msgBuffer_Thread1, MESSAGE_POOL_MAX, MESSAGE_BLOCK_SIZE);");
- _builder.newLine();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/* init all actors */");
- _builder.newLine();
- _builder.append("\t");
- String _name_10 = ssc.getName();
- _builder.append(_name_10, " ");
- _builder.append("_initActorInstances();");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_11 = ssc.getName();
- _builder.append(_name_11, "");
- _builder.append("_start(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"start\")");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfoF(\"%s_start\", ");
- String _name_12 = ssc.getName();
- _builder.append(_name_12, " ");
- _builder.append("Inst.name);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_13 = ssc.getName();
- _builder.append(_name_13, "");
- _builder.append("_run(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"run\")");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("int32 i;");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("for (i=0; i<100; i++){");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("etLogger_logInfoF(\"%s Scheduler tick %d\", ");
- String _name_14 = ssc.getName();
- _builder.append(_name_14, " ");
- _builder.append("Inst.name, i);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.append("etMessageService_execute(&msgService_Thread1);");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("}");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_15 = ssc.getName();
- _builder.append(_name_15, "");
- _builder.append("_stop(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"stop\")");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfoF(\"%s_stop\", ");
- String _name_16 = ssc.getName();
- _builder.append(_name_16, " ");
- _builder.append("Inst.name);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_17 = ssc.getName();
- _builder.append(_name_17, "");
- _builder.append("_destroy(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"destroy\")");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfoF(\"%s_destroy\", ");
- String _name_18 = ssc.getName();
- _builder.append(_name_18, " ");
- _builder.append("Inst.name);");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- _builder.append("void ");
- String _name_19 = ssc.getName();
- _builder.append(_name_19, "");
- _builder.append("_initActorInstances(void){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
- String _name_20 = ssc.getName();
- _builder.append(_name_20, " ");
- _builder.append("\", \"initActorInstances\")");
- _builder.newLineIfNotEmpty();
- {
- EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances();
- for(final ActorInstance ai : _allContainedInstances) {
- _builder.append("\t");
- ActorClass _actorClass = ai.getActorClass();
- String _name_21 = _actorClass.getName();
- _builder.append(_name_21, " ");
- _builder.append("_init(&");
- String _path = ai.getPath();
- String _pathName = this.roomExt.getPathName(_path);
- _builder.append(_pathName, " ");
- _builder.append(");");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-
- public StringConcatenation generateInstanceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
- 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("* Instance File of SubSystemClass ");
- String _name = ssc.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* - instantiation of all actor instances and port instances");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* - configuration of data and connection of ports");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"etMessageService.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* instantiation of message services */");
- _builder.newLine();
- _builder.append("#define MESSAGE_POOL_MAX 10");
- _builder.newLine();
- _builder.append("#define MESSAGE_BLOCK_SIZE 32");
- _builder.newLine();
- _builder.append("/* MessageService for Thread1 */");
- _builder.newLine();
- _builder.append("uint8 msgBuffer_Thread1[MESSAGE_POOL_MAX*MESSAGE_BLOCK_SIZE];");
- _builder.newLine();
- _builder.append("etMessageService msgService_Thread1;");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* include all used ActorClasses */");
- _builder.newLine();
- _builder.append("/* TODO: only include used Actor Classes for current SubSystem */");
- _builder.newLine();
- {
- EList<ActorClass> _usedActorClasses = root.getUsedActorClasses();
- for(final ActorClass actorClass : _usedActorClasses) {
- _builder.append("#include \"");
- String _name_1 = actorClass.getName();
- _builder.append(_name_1, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.append("/* include all used ProtcolClasses */");
- _builder.newLine();
- {
- EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
- for(final ProtocolClass protocolClass : _usedProtocolClasses) {
- _builder.append("#include \"");
- String _name_2 = protocolClass.getName();
- _builder.append(_name_2, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* declarations of all ActorClass instances (const and variable structs) */");
- _builder.newLine();
- _builder.newLine();
- _builder.append("/* forward declaration of varible actor structs */");
- _builder.newLine();
- {
- EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances();
- for(final ActorInstance ai : _allContainedInstances) {
- _builder.append("static ");
- ActorClass _actorClass = ai.getActorClass();
- String _name_3 = _actorClass.getName();
- _builder.append(_name_3, "");
- _builder.append(" ");
- String _path = ai.getPath();
- String _pathName = this.roomExt.getPathName(_path);
- _builder.append(_pathName, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- {
- EList<ActorInstance> _allContainedInstances_1 = ssi.getAllContainedInstances();
- for(final ActorInstance ai_1 : _allContainedInstances_1) {
- _builder.newLine();
- _builder.append("/* instance ");
- String _path_1 = ai_1.getPath();
- String _pathName_1 = this.roomExt.getPathName(_path_1);
- _builder.append(_pathName_1, "");
- _builder.append(" */");
- _builder.newLineIfNotEmpty();
- _builder.append("static const ");
- ActorClass _actorClass_1 = ai_1.getActorClass();
- String _name_4 = _actorClass_1.getName();
- _builder.append(_name_4, "");
- _builder.append("_const ");
- String _path_2 = ai_1.getPath();
- String _pathName_2 = this.roomExt.getPathName(_path_2);
- _builder.append(_pathName_2, "");
- _builder.append("_const = {");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("&");
- String _path_3 = ai_1.getPath();
- String _pathName_3 = this.roomExt.getPathName(_path_3);
- _builder.append(_pathName_3, " ");
- _builder.append(",");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- _builder.append("/* Ports: {myActor, etReceiveMessage, msgService, peerAddress, localId} */");
- _builder.newLine();
- {
- ActorClass _actorClass_2 = ai_1.getActorClass();
- List<Port> _endPorts = this.roomExt.getEndPorts(_actorClass_2);
- for(final Port port : _endPorts) {
- _builder.append("\t");
- _builder.append("{&");
- String _path_4 = ai_1.getPath();
- String _pathName_4 = this.roomExt.getPathName(_path_4);
- _builder.append(_pathName_4, " ");
- _builder.append(", ");
- ActorClass _actorClass_3 = ai_1.getActorClass();
- String _name_5 = _actorClass_3.getName();
- _builder.append(_name_5, " ");
- _builder.append("_ReceiveMessage, &msgService_Thread1, 1, 123} /* Port ");
- String _name_6 = port.getName();
- _builder.append(_name_6, " ");
- _builder.append(" */");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.append("\t");
- _builder.newLine();
- _builder.append("};");
- _builder.newLine();
- _builder.append("static ");
- ActorClass _actorClass_4 = ai_1.getActorClass();
- String _name_7 = _actorClass_4.getName();
- _builder.append(_name_7, "");
- _builder.append(" ");
- String _path_5 = ai_1.getPath();
- String _pathName_5 = this.roomExt.getPathName(_path_5);
- _builder.append(_pathName_5, "");
- _builder.append(" = {&");
- String _path_6 = ai_1.getPath();
- String _pathName_6 = this.roomExt.getPathName(_path_6);
- _builder.append(_pathName_6, "");
- _builder.append("_const};");
- _builder.newLineIfNotEmpty();
- }
- }
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-}
+package org.eclipse.etrice.generator.c.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.ActorClass;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.generator.base.ILogger;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.etricegen.ActorInstance;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.etricegen.SubSystemInstance;
+import org.eclipse.etrice.generator.extensions.RoomExtensions;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class SubSystemClassGen {
+ @Inject
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ private CExtensions stdExt;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ @Inject
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
+ for (final SubSystemInstance ssi : _subSystemInstances) {
+ {
+ SubSystemClass _subSystemClass = ssi.getSubSystemClass();
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
+ SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass();
+ String _path = this.roomExt.getPath(_subSystemClass_1);
+ String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
+ String path = _operator_plus;
+ SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass();
+ String _cHeaderFileName = this.stdExt.getCHeaderFileName(_subSystemClass_2);
+ String file = _cHeaderFileName;
+ String _operator_plus_1 = StringExtensions.operator_plus("generating SubSystemClass declaration: \'", file);
+ 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);
+ SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass();
+ StringConcatenation _generateHeaderFile = this.generateHeaderFile(root, ssi, _subSystemClass_3);
+ this.fileAccess.generateFile(file, _generateHeaderFile);
+ SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass();
+ String _cSourceFileName = this.stdExt.getCSourceFileName(_subSystemClass_4);
+ file = _cSourceFileName;
+ String _operator_plus_5 = StringExtensions.operator_plus("generating SubSystemClass implementation: \'", file);
+ 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);
+ SubSystemClass _subSystemClass_5 = ssi.getSubSystemClass();
+ StringConcatenation _generateSourceFile = this.generateSourceFile(root, ssi, _subSystemClass_5);
+ this.fileAccess.generateFile(file, _generateSourceFile);
+ SubSystemClass _subSystemClass_6 = ssi.getSubSystemClass();
+ String _instSourceFileName = this.stdExt.getInstSourceFileName(_subSystemClass_6);
+ file = _instSourceFileName;
+ String _operator_plus_9 = StringExtensions.operator_plus("generating SubSystemClass instance file: \'", file);
+ String _operator_plus_10 = StringExtensions.operator_plus(_operator_plus_9, "\' in \'");
+ String _operator_plus_11 = StringExtensions.operator_plus(_operator_plus_10, path);
+ String _operator_plus_12 = StringExtensions.operator_plus(_operator_plus_11, "\'");
+ this.logger.logInfo(_operator_plus_12);
+ this.fileAccess.setOutputPath(path);
+ SubSystemClass _subSystemClass_7 = ssi.getSubSystemClass();
+ StringConcatenation _generateInstanceFile = this.generateInstanceFile(root, ssi, _subSystemClass_7);
+ this.fileAccess.generateFile(file, _generateInstanceFile);
+ }
+ }
+ }
+
+ public StringConcatenation generateHeaderFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
+ 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("* Header File of SubSystemClass ");
+ String _name = ssc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* ");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ String _name_1 = ssc.getName();
+ StringConcatenation _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(_name_1);
+ _builder.append(_generateIncludeGuardBegin, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* lifecycle functions");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* init -> start -> run (loop) -> stop -> destroy");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_2 = ssc.getName();
+ _builder.append(_name_2, "");
+ _builder.append("_init(void);\t\t/* lifecycle init \t */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("void ");
+ String _name_3 = ssc.getName();
+ _builder.append(_name_3, "");
+ _builder.append("_start(void);\t/* lifecycle start \t */");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_4 = ssc.getName();
+ _builder.append(_name_4, "");
+ _builder.append("_run(void);\t\t/* lifecycle run \t */");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_5 = ssc.getName();
+ _builder.append(_name_5, "");
+ _builder.append("_stop(void); \t/* lifecycle stop\t */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("void ");
+ String _name_6 = ssc.getName();
+ _builder.append(_name_6, "");
+ _builder.append("_destroy(void); \t/* lifecycle destroy */");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ String _name_7 = ssc.getName();
+ StringConcatenation _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_7);
+ _builder.append(_generateIncludeGuardEnd, "");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation generateSourceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
+ 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 SubSystemClass ");
+ String _name = ssc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* ");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cHeaderFileName = this.stdExt.getCHeaderFileName(ssc);
+ _builder.append(_cHeaderFileName, "");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* include instances for all classes */");
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _instSourceFileName = this.stdExt.getInstSourceFileName(ssc);
+ _builder.append(_instSourceFileName, "");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etLogger.h\"");
+ _builder.newLine();
+ _builder.append("#include \"etMSCLogger.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* data for SubSysten ");
+ String _name_1 = ssc.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("typedef struct ");
+ String _name_2 = ssc.getName();
+ _builder.append(_name_2, "");
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("char *name;");
+ _builder.newLine();
+ _builder.append("} ");
+ String _name_3 = ssc.getName();
+ _builder.append(_name_3, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("static ");
+ String _name_4 = ssc.getName();
+ _builder.append(_name_4, "");
+ _builder.append(" ");
+ String _name_5 = ssc.getName();
+ _builder.append(_name_5, "");
+ _builder.append("Inst = {\"");
+ String _name_6 = ssc.getName();
+ _builder.append(_name_6, "");
+ _builder.append("\"};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_7 = ssc.getName();
+ _builder.append(_name_7, "");
+ _builder.append("_initActorInstances(void);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_8 = ssc.getName();
+ _builder.append(_name_8, "");
+ _builder.append("_init(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"init\")");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfoF(\"%s_init\", ");
+ String _name_9 = ssc.getName();
+ _builder.append(_name_9, " ");
+ _builder.append("Inst.name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* initialization of all message services */");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etMessageService_init(&msgService_Thread1, msgBuffer_Thread1, MESSAGE_POOL_MAX, MESSAGE_BLOCK_SIZE);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* init all actors */");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_10 = ssc.getName();
+ _builder.append(_name_10, " ");
+ _builder.append("_initActorInstances();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_11 = ssc.getName();
+ _builder.append(_name_11, "");
+ _builder.append("_start(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"start\")");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfoF(\"%s_start\", ");
+ String _name_12 = ssc.getName();
+ _builder.append(_name_12, " ");
+ _builder.append("Inst.name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_13 = ssc.getName();
+ _builder.append(_name_13, "");
+ _builder.append("_run(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"run\")");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("int32 i;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("for (i=0; i<100; i++){");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("etLogger_logInfoF(\"%s Scheduler tick %d\", ");
+ String _name_14 = ssc.getName();
+ _builder.append(_name_14, " ");
+ _builder.append("Inst.name, i);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("etMessageService_execute(&msgService_Thread1);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_15 = ssc.getName();
+ _builder.append(_name_15, "");
+ _builder.append("_stop(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"stop\")");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfoF(\"%s_stop\", ");
+ String _name_16 = ssc.getName();
+ _builder.append(_name_16, " ");
+ _builder.append("Inst.name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_17 = ssc.getName();
+ _builder.append(_name_17, "");
+ _builder.append("_destroy(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"SubSys\", \"destroy\")");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfoF(\"%s_destroy\", ");
+ String _name_18 = ssc.getName();
+ _builder.append(_name_18, " ");
+ _builder.append("Inst.name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_19 = ssc.getName();
+ _builder.append(_name_19, "");
+ _builder.append("_initActorInstances(void){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"");
+ String _name_20 = ssc.getName();
+ _builder.append(_name_20, " ");
+ _builder.append("\", \"initActorInstances\")");
+ _builder.newLineIfNotEmpty();
+ {
+ EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances();
+ for(final ActorInstance ai : _allContainedInstances) {
+ _builder.append("\t");
+ ActorClass _actorClass = ai.getActorClass();
+ String _name_21 = _actorClass.getName();
+ _builder.append(_name_21, " ");
+ _builder.append("_init(&");
+ String _path = ai.getPath();
+ String _pathName = this.roomExt.getPathName(_path);
+ _builder.append(_pathName, " ");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_SYNC_EXIT");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public StringConcatenation generateInstanceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
+ 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("* Instance File of SubSystemClass ");
+ String _name = ssc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* - instantiation of all actor instances and port instances");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* - configuration of data and connection of ports");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"etMessageService.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* instantiation of message services */");
+ _builder.newLine();
+ _builder.append("#define MESSAGE_POOL_MAX 10");
+ _builder.newLine();
+ _builder.append("#define MESSAGE_BLOCK_SIZE 32");
+ _builder.newLine();
+ _builder.append("/* MessageService for Thread1 */");
+ _builder.newLine();
+ _builder.append("uint8 msgBuffer_Thread1[MESSAGE_POOL_MAX*MESSAGE_BLOCK_SIZE];");
+ _builder.newLine();
+ _builder.append("etMessageService msgService_Thread1;");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* include all used ActorClasses */");
+ _builder.newLine();
+ _builder.append("/* TODO: only include used Actor Classes for current SubSystem */");
+ _builder.newLine();
+ {
+ EList<ActorClass> _usedActorClasses = root.getUsedActorClasses();
+ for(final ActorClass actorClass : _usedActorClasses) {
+ _builder.append("#include \"");
+ String _name_1 = actorClass.getName();
+ _builder.append(_name_1, "");
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("/* include all used ProtcolClasses */");
+ _builder.newLine();
+ {
+ EList<ProtocolClass> _usedProtocolClasses = root.getUsedProtocolClasses();
+ for(final ProtocolClass protocolClass : _usedProtocolClasses) {
+ _builder.append("#include \"");
+ String _name_2 = protocolClass.getName();
+ _builder.append(_name_2, "");
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* declarations of all ActorClass instances (const and variable structs) */");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/* forward declaration of varible actor structs */");
+ _builder.newLine();
+ {
+ EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances();
+ for(final ActorInstance ai : _allContainedInstances) {
+ _builder.append("static ");
+ ActorClass _actorClass = ai.getActorClass();
+ String _name_3 = _actorClass.getName();
+ _builder.append(_name_3, "");
+ _builder.append(" ");
+ String _path = ai.getPath();
+ String _pathName = this.roomExt.getPathName(_path);
+ _builder.append(_pathName, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ {
+ EList<ActorInstance> _allContainedInstances_1 = ssi.getAllContainedInstances();
+ for(final ActorInstance ai_1 : _allContainedInstances_1) {
+ _builder.newLine();
+ _builder.append("/* instance ");
+ String _path_1 = ai_1.getPath();
+ String _pathName_1 = this.roomExt.getPathName(_path_1);
+ _builder.append(_pathName_1, "");
+ _builder.append(" */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("static const ");
+ ActorClass _actorClass_1 = ai_1.getActorClass();
+ String _name_4 = _actorClass_1.getName();
+ _builder.append(_name_4, "");
+ _builder.append("_const ");
+ String _path_2 = ai_1.getPath();
+ String _pathName_2 = this.roomExt.getPathName(_path_2);
+ _builder.append(_pathName_2, "");
+ _builder.append("_const = {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("&");
+ String _path_3 = ai_1.getPath();
+ String _pathName_3 = this.roomExt.getPathName(_path_3);
+ _builder.append(_pathName_3, " ");
+ _builder.append(",");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("/* Ports: {myActor, etReceiveMessage, msgService, peerAddress, localId} */");
+ _builder.newLine();
+ {
+ ActorClass _actorClass_2 = ai_1.getActorClass();
+ List<Port> _endPorts = this.roomExt.getEndPorts(_actorClass_2);
+ for(final Port port : _endPorts) {
+ _builder.append("\t");
+ _builder.append("{&");
+ String _path_4 = ai_1.getPath();
+ String _pathName_4 = this.roomExt.getPathName(_path_4);
+ _builder.append(_pathName_4, " ");
+ _builder.append(", ");
+ ActorClass _actorClass_3 = ai_1.getActorClass();
+ String _name_5 = _actorClass_3.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("_ReceiveMessage, &msgService_Thread1, 1, 123} /* Port ");
+ String _name_6 = port.getName();
+ _builder.append(_name_6, " ");
+ _builder.append(" */");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.append("static ");
+ ActorClass _actorClass_4 = ai_1.getActorClass();
+ String _name_7 = _actorClass_4.getName();
+ _builder.append(_name_7, "");
+ _builder.append(" ");
+ String _path_5 = ai_1.getPath();
+ String _pathName_5 = this.roomExt.getPathName(_path_5);
+ _builder.append(_pathName_5, "");
+ _builder.append(" = {&");
+ String _path_6 = ai_1.getPath();
+ String _pathName_6 = this.roomExt.getPathName(_path_6);
+ _builder.append(_pathName_6, "");
+ _builder.append("_const};");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java
index fb976ba44..125f76155 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemRunnerGen.java
@@ -1,154 +1,154 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.etrice.core.room.SubSystemClass;
-import org.eclipse.etrice.generator.etricegen.Root;
-import org.eclipse.etrice.generator.etricegen.SubSystemInstance;
-import org.eclipse.etrice.generator.extensions.RoomExtensions;
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
-import org.eclipse.xtext.xbase.lib.StringExtensions;
-import org.eclipse.xtext.xtend2.lib.StringConcatenation;
-
-@SuppressWarnings("all")
-@Singleton
-public class SubSystemRunnerGen {
- @Inject
- private JavaIoFileSystemAccess fileAccess;
-
- @Inject
- private RoomExtensions roomExt;
-
- public void doGenerate(final Root root) {
- EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
- for (final SubSystemInstance sc : _subSystemInstances) {
- {
- SubSystemClass _subSystemClass = sc.getSubSystemClass();
- String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
- SubSystemClass _subSystemClass_1 = sc.getSubSystemClass();
- String _path = this.roomExt.getPath(_subSystemClass_1);
- String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
- this.fileAccess.setOutputPath(_operator_plus);
- String _name = sc.getName();
- String _operator_plus_1 = StringExtensions.operator_plus(_name, "_Runner.c");
- SubSystemClass _subSystemClass_2 = sc.getSubSystemClass();
- StringConcatenation _generateSourceFile = this.generateSourceFile(root, sc, _subSystemClass_2);
- this.fileAccess.generateFile(_operator_plus_1, _generateSourceFile);
- }
- }
- }
-
- public StringConcatenation generateSourceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
- 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("* this class contains the main function running component ");
- String _name = ssi.getName();
- _builder.append(_name, " ");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("* it instantiates ");
- String _name_1 = ssi.getName();
- _builder.append(_name_1, " ");
- _builder.append(" and starts and ends the lifecycle");
- _builder.newLineIfNotEmpty();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.append("#include \"");
- String _name_2 = ssi.getName();
- _builder.append(_name_2, "");
- _builder.append(".h\"");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("#include \"etLogger.h\"");
- _builder.newLine();
- _builder.append("#include \"etMSCLogger.h\"");
- _builder.newLine();
- _builder.newLine();
- _builder.newLine();
- _builder.append("/**");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* main function");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("* creates component and starts and stops the lifecycle");
- _builder.newLine();
- _builder.append(" ");
- _builder.append("*/");
- _builder.newLine();
- _builder.newLine();
- _builder.append("int main(void) {");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfo(\"*** T H E B E G I N ***\");");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_OPEN(\"main\");");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/* startup sequence of lifecycle */");
- _builder.newLine();
- _builder.append("\t");
- String _name_3 = ssi.getName();
- _builder.append(_name_3, " ");
- _builder.append("_init(); \t\t/* lifecycle init */");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_4 = ssi.getName();
- _builder.append(_name_4, " ");
- _builder.append("_start(); \t/* lifecycle start */");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/* run Scheduler */");
- _builder.newLine();
- _builder.append("\t");
- String _name_5 = ssi.getName();
- _builder.append(_name_5, " ");
- _builder.append("_run();");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("/* shutdown sequence of lifecycle */");
- _builder.newLine();
- _builder.append("\t");
- String _name_6 = ssi.getName();
- _builder.append(_name_6, " ");
- _builder.append("_stop(); \t\t/* lifecycle stop */");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_7 = ssi.getName();
- _builder.append(_name_7, " ");
- _builder.append("_destroy(); \t/* lifecycle destroy */");
- _builder.newLineIfNotEmpty();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("ET_MSC_LOGGER_CLOSE");
- _builder.newLine();
- _builder.append("\t");
- _builder.append("etLogger_logInfo(\"*** T H E E N D ***\");");
- _builder.newLine();
- _builder.newLine();
- _builder.append("\t");
- _builder.append("return 0;");
- _builder.newLine();
- _builder.append("}");
- _builder.newLine();
- _builder.newLine();
- return _builder;
- }
-}
+package org.eclipse.etrice.generator.c.gen;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.generator.etricegen.Root;
+import org.eclipse.etrice.generator.etricegen.SubSystemInstance;
+import org.eclipse.etrice.generator.extensions.RoomExtensions;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+
+@SuppressWarnings("all")
+@Singleton
+public class SubSystemRunnerGen {
+ @Inject
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ private RoomExtensions roomExt;
+
+ public void doGenerate(final Root root) {
+ EList<SubSystemInstance> _subSystemInstances = root.getSubSystemInstances();
+ for (final SubSystemInstance sc : _subSystemInstances) {
+ {
+ SubSystemClass _subSystemClass = sc.getSubSystemClass();
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass);
+ SubSystemClass _subSystemClass_1 = sc.getSubSystemClass();
+ String _path = this.roomExt.getPath(_subSystemClass_1);
+ String _operator_plus = StringExtensions.operator_plus(_generationTargetPath, _path);
+ this.fileAccess.setOutputPath(_operator_plus);
+ String _name = sc.getName();
+ String _operator_plus_1 = StringExtensions.operator_plus(_name, "_Runner.c");
+ SubSystemClass _subSystemClass_2 = sc.getSubSystemClass();
+ StringConcatenation _generateSourceFile = this.generateSourceFile(root, sc, _subSystemClass_2);
+ this.fileAccess.generateFile(_operator_plus_1, _generateSourceFile);
+ }
+ }
+ }
+
+ public StringConcatenation generateSourceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) {
+ 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("* this class contains the main function running component ");
+ String _name = ssi.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("* it instantiates ");
+ String _name_1 = ssi.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" and starts and ends the lifecycle");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _name_2 = ssi.getName();
+ _builder.append(_name_2, "");
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etLogger.h\"");
+ _builder.newLine();
+ _builder.append("#include \"etMSCLogger.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* main function");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* creates component and starts and stops the lifecycle");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("int main(void) {");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfo(\"*** T H E B E G I N ***\");");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_OPEN(\"main\");");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* startup sequence of lifecycle */");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_3 = ssi.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("_init(); \t\t/* lifecycle init */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_4 = ssi.getName();
+ _builder.append(_name_4, " ");
+ _builder.append("_start(); \t/* lifecycle start */");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* run Scheduler */");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_5 = ssi.getName();
+ _builder.append(_name_5, " ");
+ _builder.append("_run();");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* shutdown sequence of lifecycle */");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_6 = ssi.getName();
+ _builder.append(_name_6, " ");
+ _builder.append("_stop(); \t\t/* lifecycle stop */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_7 = ssi.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("_destroy(); \t/* lifecycle destroy */");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ET_MSC_LOGGER_CLOSE");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("etLogger_logInfo(\"*** T H E E N D ***\");");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("return 0;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ return _builder;
+ }
+}

Back to the top