Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend11
-rw-r--r--runtime/org.eclipse.etrice.modellib.c/model/Annotations.room8
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/build.gradle3
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/models/SubSystemUserCodeTest.room32
4 files changed, 53 insertions, 1 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
index 3edaff61e..185b0eb8a 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
@@ -22,6 +22,7 @@ import java.util.Collection
import java.util.HashMap
import java.util.HashSet
import org.eclipse.etrice.core.common.base.LiteralType
+import org.eclipse.etrice.core.common.base.StringLiteral
import org.eclipse.etrice.core.common.converter.TimeConverter
import org.eclipse.etrice.core.etmap.util.ETMapUtil
import org.eclipse.etrice.core.etphys.eTPhys.ExecMode
@@ -407,7 +408,9 @@ class NodeGen {
«genActorInstanceInitializer(root, ai)»
«ENDIF»
«ENDFOR»
-
+
+ /* special user codes from annotation SubSystemUserCode */
+ «ssi.generateSubSystemUserCodes»
'''
}
@@ -890,4 +893,10 @@ class NodeGen {
}
}
}
+
+ private def generateSubSystemUserCodes(SubSystemInstance ssi) {
+ val acs = ssi.allContainedInstances.map[actorClass].toSet
+ val annotations = acs.map[annotations.filter[type.name == 'SubSystemUserCode']].flatten
+ annotations.map[attributes].flatten.map[value].filter(StringLiteral).map[value].join(NEWLINE)
+ }
}
diff --git a/runtime/org.eclipse.etrice.modellib.c/model/Annotations.room b/runtime/org.eclipse.etrice.modellib.c/model/Annotations.room
index dbdbb0a8d..064d7dd86 100644
--- a/runtime/org.eclipse.etrice.modellib.c/model/Annotations.room
+++ b/runtime/org.eclipse.etrice.modellib.c/model/Annotations.room
@@ -17,6 +17,14 @@ RoomModel room.basic.annotations {
optional attribute noGenerate: ptBoolean
}
+ /**
+ * Special user code which is generated to the sub system instance.
+ */
+ AnnotationType SubSystemUserCode {
+ target = ActorClass
+ mandatory attribute userCode: ptCharacter
+ }
+
AnnotationType DataLogging {
target = SubSystemClass
mandatory attribute pathlist: ptCharacter
diff --git a/tests/org.eclipse.etrice.generator.common.tests/build.gradle b/tests/org.eclipse.etrice.generator.common.tests/build.gradle
index 42d4d908d..5046158f5 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/build.gradle
+++ b/tests/org.eclipse.etrice.generator.common.tests/build.gradle
@@ -37,3 +37,6 @@ createTest('java', 'detailExpressionCompileTest', [genericPhysical, 'models/Deta
// VarargsTTest
createTest('c', 'varargsTest', [genericPhysical, 'models/VarargsTest.room'])
createTest('java', 'varargsTest', [genericPhysical, 'models/VarargsTest.room'])
+
+// SubSystemUserCodeTest
+createTest('c', 'subSystemUserCodeTest', ['models/SubSystemUserCodeTest.room', genericPhysical])
diff --git a/tests/org.eclipse.etrice.generator.common.tests/models/SubSystemUserCodeTest.room b/tests/org.eclipse.etrice.generator.common.tests/models/SubSystemUserCodeTest.room
new file mode 100644
index 000000000..d93962daa
--- /dev/null
+++ b/tests/org.eclipse.etrice.generator.common.tests/models/SubSystemUserCodeTest.room
@@ -0,0 +1,32 @@
+RoomModel SubSystemUserCodeTest {
+
+ import room.basic.annotations.* from "../../../runtime/org.eclipse.etrice.modellib.c/model/Annotations.room"
+ import room.basic.test.* from "../../../runtime/org.eclipse.etrice.modellib.c/model/Tests.room"
+ import room.basic.types.* from "../../../runtime/org.eclipse.etrice.modellib.c/model/Types.room"
+
+ ActorClass AGeneratedUserCode {
+ @TestInstance
+ @SubSystemUserCode(userCode="
+ int inSubSystemInstance(){ return 99; }
+ ")
+ Structure {
+ usercode3 '''
+ extern int inSubSystemInstance();
+ '''
+ }
+ Behavior {
+ ctor '''
+ etInt16 caseId = etUnit_openAll("log", "SubSystemUserCodeTest", "org.eclipse.etrice.generator.c.tests.SubSystemUserCodeTest", "SubSystemUserCodeTest_case");
+ EXPECT_EQUAL_INT32(caseId, "", 99, inSubSystemInstance());
+ etUnit_testFinished(caseId);
+ etUnit_closeAll(caseId);
+ '''
+
+ }
+ }
+
+ // no instance => no sub system user code
+ ActorClass ANotGenerated {
+ @SubSystemUserCode(userCode="int inSubSystemInstance(){ return 0; }")
+ }
+} \ No newline at end of file

Back to the top