diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c')
4 files changed, 145 insertions, 91 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 index e27d01a2f..4639c8f7e 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 @@ -353,6 +353,10 @@ class CExtensions implements ILanguageExtension { "\""+(rc.eContainer as RoomModel).name.replaceAll("\\.","/")+"/"+rc.getCHeaderFileName+"\"" } + def getUtilsIncludePath(RoomClass rc) { + "\""+(rc.eContainer as RoomModel).name.replaceAll("\\.","/")+"/"+rc.getCUtilsFileName+"\"" + } + override getTargetType(EnumerationType type) { if (type.getPrimitiveType()!=null) type.getPrimitiveType().getTargetName() 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 4cb4b94c7..f792caed0 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 @@ -124,7 +124,12 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { */ «generateIncludeGuardBegin(filename)» - + + «IF pc.base!=null» + // include base class utils + #include «pc.base.utilsIncludePath» + + «ENDIF» #include «pc.includePath» /* @@ -199,24 +204,25 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { var portClassName = pc.getPortClassName(conj) var replPortClassName = pc.getPortClassName(conj, true) var messages = if (conj) pc.allIncomingMessages else pc.allOutgoingMessages + val allPortClasses = pc.getAllPortClasses(conj) + val allAttributes = allPortClasses.map[p|p.attributes].flatten.toList + val allOperations = allPortClasses.map[p|p.operations].flatten.toList ''' typedef etPort «portClassName»; typedef etReplPort «replPortClassName»; - «IF pc.getPortClass(conj)!=null» - «IF !(pc.getPortClass(conj).attributes.empty)» - /* variable part of PortClass (RAM) */ - typedef struct «portClassName»_var «portClassName»_var; - struct «portClassName»_var { - «pc.getPortClass(conj).attributes.attributes» - }; - «FOR a:pc.getPortClass(conj).attributes» - «IF a.defaultValueLiteral!=null» - «logger.logInfo(portClassName+" "+a.name+": Attribute initialization not supported in C")» - «ENDIF» - «ENDFOR» - «ENDIF» + «IF !(allAttributes.empty)» + /* variable part of PortClass (RAM) */ + typedef struct «portClassName»_var «portClassName»_var; + struct «portClassName»_var { + «allAttributes.attributes» + }; + «FOR a:allAttributes» + «IF a.defaultValueLiteral!=null» + «logger.logInfo(portClassName+" "+a.name+": Attribute initialization not supported in C")» + «ENDIF» + «ENDFOR» «ENDIF» «FOR message : messages» @@ -229,12 +235,12 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { «messageSignature(replPortClassName, message.name, "", ", int idx"+data)»; «ENDFOR» - «IF (pc.getPortClass(conj) != null)» - «pc.getPortClass(conj).operations.operationsDeclaration(portClassName)» + «IF !(allOperations.empty)» + «allOperations.operationsDeclaration(portClassName)» «ENDIF» - «IF pc.handlesReceive(conj)» - «FOR h:getReceiveHandlers(pc,conj)» + «IF pc.handlesReceiveIncludingSuper(conj)» + «FOR h:pc.getReceiveHandlersIncludingSuper(conj)» void «portClassName»_«h.msg.name»_receiveHandler(«portClassName»* self, const etMessage* msg, void * actor, etActorReceiveMessage receiveMessageFunc); «ENDFOR» «ENDIF» @@ -349,7 +355,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { } def private portClassSource(ProtocolClass pc, Boolean conj) { - val pclass = pc.getPortClass(conj) + val allPortClasses = pc.getAllPortClasses(conj) val portClassName = pc.getPortClassName(conj) val replPortClassName = pc.getPortClassName(conj, true) val messages = if (conj) pc.allIncomingMessages else pc.allOutgoingMessages @@ -414,12 +420,16 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { } «ENDFOR» - «IF pclass!=null» - /* begin «portClassName» specific */ - «pclass.userCode.userCode» + «IF !allPortClasses.empty» + /* begin «portClassName» specific (including base classes) */ + «FOR p : allPortClasses» + «p.userCode.userCode» + «ENDFOR» - «pc.getPortClass(conj).operations.operationsImplementation(portClassName)» - /* end «portClassName» specific */ + «FOR p : allPortClasses» + «p.operations.operationsImplementation(portClassName)» + «ENDFOR» + /* end «portClassName» specific (including base classes) */ «ENDIF» etInt32 «replPortClassName»_getReplication(const «replPortClassName»* self) { @@ -470,7 +480,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { ''' /* receiver handlers */ - «FOR h:getReceiveHandlers(pc,conj)» + «FOR h:pc.getReceiveHandlers(conj)» void «portClassName»_«h.msg.name»_receiveHandler(«portClassName»* self, const etMessage* msg, void * actor, etActorReceiveMessage receiveMessageFunc){ «AbstractGenerator::getInstance().getTranslatedCode(h.detailCode)» /* hand over the message to the actor: */ 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 17987b6fb..bf0bb37e9 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 @@ -746,6 +746,17 @@ public class CExtensions implements ILanguageExtension { return (_plus_2 + "\""); } + public String getUtilsIncludePath(final RoomClass rc) { + EObject _eContainer = rc.eContainer(); + String _name = ((RoomModel) _eContainer).getName(); + String _replaceAll = _name.replaceAll("\\.", "/"); + String _plus = ("\"" + _replaceAll); + String _plus_1 = (_plus + "/"); + String _cUtilsFileName = this.getCUtilsFileName(rc); + String _plus_2 = (_plus_1 + _cUtilsFileName); + return (_plus_2 + "\""); + } + @Override public String getTargetType(final EnumerationType type) { String _xifexpression = null; 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 cb54e0a94..04f0106dc 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 @@ -12,6 +12,7 @@ package org.eclipse.etrice.generator.c.gen; import com.google.common.base.Objects; +import com.google.common.collect.Iterables; import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.List; @@ -47,6 +48,7 @@ import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.xbase.lib.Extension; import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; @Singleton @SuppressWarnings("all") @@ -263,6 +265,20 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append(_generateIncludeGuardBegin, ""); _builder.newLineIfNotEmpty(); _builder.newLine(); + { + ProtocolClass _base = pc.getBase(); + boolean _notEquals = (!Objects.equal(_base, null)); + if (_notEquals) { + _builder.append("// include base class utils"); + _builder.newLine(); + _builder.append("#include "); + ProtocolClass _base_1 = pc.getBase(); + String _utilsIncludePath = this._cExtensions.getUtilsIncludePath(_base_1); + _builder.append(_utilsIncludePath, ""); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + } + } _builder.append("#include "); String _includePath = this._cExtensions.getIncludePath(pc); _builder.append(_includePath, ""); @@ -481,6 +497,25 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _xifexpression = this._roomHelpers.getAllOutgoingMessages(pc); } List<Message> messages = _xifexpression; + final List<PortClass> allPortClasses = this._roomExtensions.getAllPortClasses(pc, (conj).booleanValue()); + final Function1<PortClass, EList<Attribute>> _function = new Function1<PortClass, EList<Attribute>>() { + @Override + public EList<Attribute> apply(final PortClass p) { + return p.getAttributes(); + } + }; + List<EList<Attribute>> _map = ListExtensions.<PortClass, EList<Attribute>>map(allPortClasses, _function); + Iterable<Attribute> _flatten = Iterables.<Attribute>concat(_map); + final List<Attribute> allAttributes = IterableExtensions.<Attribute>toList(_flatten); + final Function1<PortClass, EList<PortOperation>> _function_1 = new Function1<PortClass, EList<PortOperation>>() { + @Override + public EList<PortOperation> apply(final PortClass p) { + return p.getOperations(); + } + }; + List<EList<PortOperation>> _map_1 = ListExtensions.<PortClass, EList<PortOperation>>map(allPortClasses, _function_1); + Iterable<PortOperation> _flatten_1 = Iterables.<PortOperation>concat(_map_1); + final List<PortOperation> allOperations = IterableExtensions.<PortOperation>toList(_flatten_1); StringConcatenation _builder = new StringConcatenation(); _builder.append("typedef etPort "); _builder.append(portClassName, ""); @@ -492,50 +527,38 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.newLineIfNotEmpty(); _builder.newLine(); { - PortClass _portClass = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - boolean _notEquals = (!Objects.equal(_portClass, null)); - if (_notEquals) { + boolean _isEmpty = allAttributes.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + _builder.append("/* variable part of PortClass (RAM) */"); + _builder.newLine(); + _builder.append("typedef struct "); + _builder.append(portClassName, ""); + _builder.append("_var "); + _builder.append(portClassName, ""); + _builder.append("_var; "); + _builder.newLineIfNotEmpty(); + _builder.append("struct "); + _builder.append(portClassName, ""); + _builder.append("_var {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + CharSequence _attributes = this._procedureHelpers.attributes(allAttributes); + _builder.append(_attributes, "\t"); + _builder.newLineIfNotEmpty(); + _builder.append("};"); + _builder.newLine(); { - PortClass _portClass_1 = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - EList<Attribute> _attributes = _portClass_1.getAttributes(); - boolean _isEmpty = _attributes.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("/* variable part of PortClass (RAM) */"); - _builder.newLine(); - _builder.append("typedef struct "); - _builder.append(portClassName, ""); - _builder.append("_var "); - _builder.append(portClassName, ""); - _builder.append("_var; "); - _builder.newLineIfNotEmpty(); - _builder.append("struct "); - _builder.append(portClassName, ""); - _builder.append("_var {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - PortClass _portClass_2 = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - EList<Attribute> _attributes_1 = _portClass_2.getAttributes(); - CharSequence _attributes_2 = this._procedureHelpers.attributes(_attributes_1); - _builder.append(_attributes_2, "\t"); - _builder.newLineIfNotEmpty(); - _builder.append("};"); - _builder.newLine(); + for(final Attribute a : allAttributes) { { - PortClass _portClass_3 = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - EList<Attribute> _attributes_3 = _portClass_3.getAttributes(); - for(final Attribute a : _attributes_3) { - { - String _defaultValueLiteral = a.getDefaultValueLiteral(); - boolean _notEquals_1 = (!Objects.equal(_defaultValueLiteral, null)); - if (_notEquals_1) { - String _name = a.getName(); - String _plus = ((portClassName + " ") + _name); - String _plus_1 = (_plus + ": Attribute initialization not supported in C"); - this.logger.logInfo(_plus_1); - _builder.newLineIfNotEmpty(); - } - } + String _defaultValueLiteral = a.getDefaultValueLiteral(); + boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null)); + if (_notEquals) { + String _name = a.getName(); + String _plus = ((portClassName + " ") + _name); + String _plus_1 = (_plus + ": Attribute initialization not supported in C"); + this.logger.logInfo(_plus_1); + _builder.newLineIfNotEmpty(); } } } @@ -594,23 +617,21 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { } _builder.newLine(); { - PortClass _portClass_4 = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - boolean _notEquals_2 = (!Objects.equal(_portClass_4, null)); - if (_notEquals_2) { - PortClass _portClass_5 = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - EList<PortOperation> _operations = _portClass_5.getOperations(); - CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(_operations, portClassName); + boolean _isEmpty_1 = allOperations.isEmpty(); + boolean _not_1 = (!_isEmpty_1); + if (_not_1) { + CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(allOperations, portClassName); _builder.append(_operationsDeclaration, ""); _builder.newLineIfNotEmpty(); } } _builder.newLine(); { - boolean _handlesReceive = this._roomExtensions.handlesReceive(pc, (conj).booleanValue()); - if (_handlesReceive) { + boolean _handlesReceiveIncludingSuper = this._roomExtensions.handlesReceiveIncludingSuper(pc, (conj).booleanValue()); + if (_handlesReceiveIncludingSuper) { { - List<MessageHandler> _receiveHandlers = this._roomExtensions.getReceiveHandlers(pc, (conj).booleanValue()); - for(final MessageHandler h : _receiveHandlers) { + List<MessageHandler> _receiveHandlersIncludingSuper = this._roomExtensions.getReceiveHandlersIncludingSuper(pc, (conj).booleanValue()); + for(final MessageHandler h : _receiveHandlersIncludingSuper) { _builder.append("void "); _builder.append(portClassName, ""); _builder.append("_"); @@ -1079,7 +1100,7 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { private CharSequence portClassSource(final ProtocolClass pc, final Boolean conj) { CharSequence _xblockexpression = null; { - final PortClass pclass = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); + final List<PortClass> allPortClasses = this._roomExtensions.getAllPortClasses(pc, (conj).booleanValue()); final String portClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue()); final String replPortClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue(), true); List<Message> _xifexpression = null; @@ -1349,25 +1370,33 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { } } { - boolean _notEquals_3 = (!Objects.equal(pclass, null)); - if (_notEquals_3) { + boolean _isEmpty = allPortClasses.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { _builder.append("/* begin "); _builder.append(portClassName, ""); - _builder.append(" specific */"); - _builder.newLineIfNotEmpty(); - DetailCode _userCode = pclass.getUserCode(); - CharSequence _userCode_1 = this._procedureHelpers.userCode(_userCode); - _builder.append(_userCode_1, ""); + _builder.append(" specific (including base classes) */"); _builder.newLineIfNotEmpty(); + { + for(final PortClass p : allPortClasses) { + DetailCode _userCode = p.getUserCode(); + CharSequence _userCode_1 = this._procedureHelpers.userCode(_userCode); + _builder.append(_userCode_1, ""); + _builder.newLineIfNotEmpty(); + } + } _builder.newLine(); - PortClass _portClass = this._roomExtensions.getPortClass(pc, (conj).booleanValue()); - EList<PortOperation> _operations = _portClass.getOperations(); - CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations, portClassName); - _builder.append(_operationsImplementation, ""); - _builder.newLineIfNotEmpty(); + { + for(final PortClass p_1 : allPortClasses) { + EList<PortOperation> _operations = p_1.getOperations(); + CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(_operations, portClassName); + _builder.append(_operationsImplementation, ""); + _builder.newLineIfNotEmpty(); + } + } _builder.append("/* end "); _builder.append(portClassName, ""); - _builder.append(" specific */"); + _builder.append(" specific (including base classes) */"); _builder.newLineIfNotEmpty(); _builder.newLine(); } |