diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c/src/org/eclipse')
5 files changed, 56 insertions, 41 deletions
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 4ae2535af..c5e7c9e6c 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 @@ -95,7 +95,7 @@ class ActorClassGen { «ENDFOR» «helpers.Attributes(ac.attributes)» - «helpers.Operations(ac.operations)» + «helpers.OperationsDeclaration(ac.operations, ac.name)» //--------------------- construction public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){ 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 af43028a6..459e848c7 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 @@ -86,6 +86,23 @@ class CExtensions implements ILanguageExtension { 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+"_"} + //**** C-Specific // used diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend index c8e57cb72..d9d0938a9 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/DataClassGen.xtend @@ -52,57 +52,55 @@ class DataClassGen { } def generateHeaderFile(Root root, DataClass dc) {''' - TODO: includes for C-Headers instead of Java imports + #ifndef _«dc.name»_H_ + #define _«dc.name»_H_ - «var models = root.getReferencedModels(dc)» - «FOR model : models»//import «model.name».*; + #include "../../src/datatypes.h" + + /* TODO: includes only for used DataClasses, also for other models */ + «FOR dataClass : root.getReferencedDataClasses(dc)»«IF dataClass.name != dc.name»#include "«dataClass.name».h"«ENDIF» «ENDFOR» «helpers.UserCode(dc.userCode1)» + typedef struct { - typedef struct «dc.name»«IF dc.base!=null» /* extends -> inheritance not implemented yet */ «dc.base.name»«ENDIF» { - - «helpers.UserCode(dc.userCode2)» - + «helpers.UserCode(dc.userCode2)» + «helpers.Attributes(dc.attributes)» - «helpers.AttributeSettersGetters(dc.attributes)» - «helpers.Operations(dc.operations)» - - // default constructor - public «dc.name»() { - «FOR a : dc.attributes» - «IF a.defaultValueLiteral!=null» - «IF a.size==0»«a.name» = «a.defaultValueLiteral»;«ENDIF» - «ELSEIF a.type.type!=null» - «a.name» = new «a.type.type.name»(); - «ENDIF» - «ENDFOR» - } - // deep copy - public «dc.name» deepCopy() { - «dc.name» copy = new «dc.name»(); - «FOR a : dc.attributes» - «IF a.type.type!=null» - copy.«a.name» = «a.name».deepCopy(); - «ELSE» - «IF a.size==0»copy.«a.name» = «a.name»;«ELSE»for (int i=0;i<«a.size»;i++){copy.«a.name»[i]=«a.name»[i];}«ENDIF» - «ENDIF» - «ENDFOR» - return copy; - } - }; + } «dc.name»«IF dc.base!=null» /* extends -> inheritance not implemented yet */ «dc.base.name»«ENDIF»; + + // TODO: do we need setters and getters for C and C++ ? + + «helpers.OperationsDeclaration(dc.operations, dc.name)» + + // deep copy + void «dc.name»_deepCopy(«dc.name»* source, «dc.name»* target); + + #endif /* _«dc.name»_H_ */ + ''' } def generateSourceFile(Root root, DataClass dc) {''' - #include "«dc.getCHeaderFileName»"; + #include "«dc.getCHeaderFileName»" «helpers.UserCode(dc.userCode3)» - // TODO + // TODO: do we need setters and getters for C and C++ ? + + «helpers.OperationsImplementation(dc.operations, dc.name)» + + #include <string.h> + + // deep copy + void «dc.name»_deepCopy(«dc.name»* source, «dc.name»* target) { + memcpy(target, source, sizeof(«dc.name»)); + } + + '''} 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 8ae420117..6dae1889d 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 @@ -41,12 +41,12 @@ class MainGen implements IGenerator { def void doGenerate(Root e) { dataClassGen.doGenerate(e); - protocolClassGen.doGenerate(e); - actorClassGen.doGenerate(e); - subsystemClassGen.doGenerate(e); + //protocolClassGen.doGenerate(e); + //actorClassGen.doGenerate(e); + //subsystemClassGen.doGenerate(e); if (!e.library) { - subsystemRunnerGen.doGenerate(e); + //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 69fdbeeb8..c2d2041ee 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 @@ -151,7 +151,7 @@ class ProtocolClassGen { «IF pclass!=null» «helpers.Attributes(pclass.attributes)» - «helpers.Operations(pclass.operations)» + «helpers.OperationsDeclaration(pclass.operations, name)» «ENDIF» // sent messages |