Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2011-12-23 15:12:42 +0000
committerThomas Schuetz2011-12-23 15:12:42 +0000
commitf502cbe9485f647ecd273222bf53717fa00c5043 (patch)
treef7e19a27ecb36d9255ea8f7a5f22bcb98a625c78 /plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
parentf9975ec475dc447886695489cfafba8adb5b7860 (diff)
downloadorg.eclipse.etrice-f502cbe9485f647ecd273222bf53717fa00c5043.tar.gz
org.eclipse.etrice-f502cbe9485f647ecd273222bf53717fa00c5043.tar.xz
org.eclipse.etrice-f502cbe9485f647ecd273222bf53717fa00c5043.zip
[generator.c] added project for C-Generator, moved more language independent generator code to plugin generator
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend107
1 files changed, 107 insertions, 0 deletions
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
new file mode 100644
index 000000000..af43028a6
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+
+package org.eclipse.etrice.generator.c.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.FreeType
+import org.eclipse.etrice.core.room.Message
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.core.room.Type
+import org.eclipse.etrice.core.room.TypedID
+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
+
+
+
+ //-------------------------------------------------------
+ // Java types
+
+ // type names for Type class (distinguish Primitive and DataClass)
+ override String toType(PrimitiveType prim) {
+ prim.toString()
+ }
+
+ override String typeName(Type type) {
+ if (type.type!=null)
+ return type.type.name
+ else
+ type.prim.toType
+ }
+ override String freeTypeName(FreeType type) {
+ if (type.type!=null)
+ return type.type
+ else
+ type.prim.toType
+ }
+
+ // default values for data
+ override String defaultValue(PrimitiveType prim) {
+ return switch(prim.toString()) {
+ case 'uint8': '0'
+ case 'uint16': '0'
+ case 'uint32': '0'
+ case 'int8': '0'
+ case 'int16': '0'
+ case 'int32': '0'
+ case 'float32': '0.0'
+ case 'float64': '0.0'
+ case 'string': '""'
+ default: prim.toString()
+ };
+ }
+ override String defaultValue(TypedID a) {
+ if (a.type.type!=null)
+ return "new "+a.type.type.name+"()"
+ else
+ return a.type.prim.defaultValue
+ }
+
+ override String getTypedDataDefinition(Message m) {
+ return languageGen.getTypedData(m)
+ }
+
+ //**** C-Specific
+
+ // used
+ def String getCHeaderFileName(RoomClass rc) {
+ return rc.name+".h";
+ }
+
+ // used
+ def String getCSourceFileName(RoomClass rc) {
+ return rc.name+".c";
+ }
+
+ //-------------------------------------------------------
+ // transition chain visitor
+
+ def String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc) {
+ return languageGen.getExecuteChain(ac, tc)
+ }
+} \ No newline at end of file

Back to the top