diff options
author | Henrik Rentz-Reichert | 2017-11-10 10:22:25 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2017-11-10 19:57:25 +0000 |
commit | b5b1401f30884bdc6c160f8500e3f29b6566c481 (patch) | |
tree | e4c3f9027ac047ac2e25922801a1bb6eb7d5bbd9 /plugins/org.eclipse.etrice.generator.c | |
parent | 2e9666c1b52cef7d82be927d14e6dc8b57587a81 (diff) | |
download | org.eclipse.etrice-b5b1401f30884bdc6c160f8500e3f29b6566c481.tar.gz org.eclipse.etrice-b5b1401f30884bdc6c160f8500e3f29b6566c481.tar.xz org.eclipse.etrice-b5b1401f30884bdc6c160f8500e3f29b6566c481.zip |
Bug 511330 - [core.genmodel.fsm] introduce simplified generator model
for state machines
* bug fix in ui.behavior tests
Change-Id: I0ee471ae6b0e7502ba2dbf63f9ec46b33d0610e6
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c')
6 files changed, 0 insertions, 6535 deletions
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 8e8605f0e..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java +++ /dev/null @@ -1,1218 +0,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.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType; -import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass; -import org.eclipse.etrice.core.genmodel.etricegen.Root; -import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions; -import org.eclipse.etrice.core.genmodel.fsm.ILogger; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.CommunicationType; -import org.eclipse.etrice.core.room.DataClass; -import org.eclipse.etrice.core.room.DataType; -import org.eclipse.etrice.core.room.EnumerationType; -import org.eclipse.etrice.core.room.GeneralProtocolClass; -import org.eclipse.etrice.core.room.InterfaceItem; -import org.eclipse.etrice.core.room.Message; -import org.eclipse.etrice.core.room.Operation; -import org.eclipse.etrice.core.room.Port; -import org.eclipse.etrice.core.room.PortOperation; -import org.eclipse.etrice.core.room.ProtocolClass; -import org.eclipse.etrice.core.room.RoomClass; -import org.eclipse.etrice.core.room.RoomModel; -import org.eclipse.etrice.core.room.SAP; -import org.eclipse.etrice.core.room.ServiceImplementation; -import org.eclipse.etrice.core.room.StandardOperation; -import org.eclipse.etrice.core.room.VarDecl; -import org.eclipse.etrice.generator.c.Main; -import org.eclipse.etrice.generator.c.gen.CExtensions; -import org.eclipse.etrice.generator.c.gen.StateMachineGen; -import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo; -import org.eclipse.etrice.generator.generic.GenericActorClassGenerator; -import org.eclipse.etrice.generator.generic.ILanguageExtension; -import org.eclipse.etrice.generator.generic.ProcedureHelpers; -import org.eclipse.etrice.generator.generic.RoomExtensions; -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") -public class ActorClassGen extends GenericActorClassGenerator { - @Inject - @Extension - protected RoomExtensions _roomExtensions; - - @Inject - @Extension - protected CExtensions _cExtensions; - - @Inject - @Extension - protected ProcedureHelpers _procedureHelpers; - - @Inject - @Extension - protected StateMachineGen _stateMachineGen; - - @Inject - protected ILanguageExtension langExt; - - @Inject - protected IGeneratorFileIo fileIO; - - @Inject - protected ILogger logger; - - public void doGenerate(final Root root) { - final Function1<ActorClass, ExpandedActorClass> _function = (ActorClass it) -> { - return root.getExpandedActorClass(it); - }; - List<ExpandedActorClass> _map = ListExtensions.<ActorClass, ExpandedActorClass>map(root.getActorClasses(), _function); - for (final ExpandedActorClass xpac : _map) { - { - String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(xpac.getActorClass()); - String _path = this._roomExtensions.getPath(xpac.getActorClass()); - final String path = (_generationTargetPath + _path); - String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(xpac.getActorClass()); - String _path_1 = this._roomExtensions.getPath(xpac.getActorClass()); - final String infopath = (_generationInfoPath + _path_1); - String file = this._cExtensions.getCHeaderFileName(xpac.getActorClass()); - this.fileIO.generateFile("generating ActorClass header", path, infopath, file, this.generateHeaderFile(root, xpac)); - file = this._cExtensions.getCUtilsFileName(xpac.getActorClass()); - this.fileIO.generateFile("generating ActorClass utils", path, infopath, file, this.generateUtilsFile(root, xpac)); - boolean _isBehaviorAnnotationPresent = this._roomHelpers.isBehaviorAnnotationPresent(xpac.getActorClass(), "BehaviorManual"); - if (_isBehaviorAnnotationPresent) { - String _name = xpac.getActorClass().getName(); - String _plus = ("omitting ActorClass source for \'" + _name); - String _plus_1 = (_plus + "\' since @BehaviorManual is specified"); - this.logger.logInfo(_plus_1); - } else { - file = this._cExtensions.getCSourceFileName(xpac.getActorClass()); - this.fileIO.generateFile("generating ActorClass source", path, infopath, file, this.generateSourceFile(root, xpac)); - } - } - } - } - - protected CharSequence generateHeaderFile(final Root root, final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - final Function1<Port, Boolean> _function = (Port p) -> { - GeneralProtocolClass _protocol = p.getProtocol(); - CommunicationType _commType = ((ProtocolClass) _protocol).getCommType(); - return Boolean.valueOf(Objects.equal(_commType, CommunicationType.EVENT_DRIVEN)); - }; - final Iterable<Port> eventPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function); - final Function1<Port, Boolean> _function_1 = (Port p) -> { - return Boolean.valueOf((Objects.equal(((ProtocolClass) p.getProtocol()).getCommType(), CommunicationType.DATA_DRIVEN) && p.isConjugated())); - }; - final Iterable<Port> sendPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function_1); - final Function1<Port, Boolean> _function_2 = (Port p) -> { - return Boolean.valueOf((Objects.equal(((ProtocolClass) p.getProtocol()).getCommType(), CommunicationType.DATA_DRIVEN) && (!p.isConjugated()))); - }; - final Iterable<Port> recvPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function_2); - ComponentCommunicationType _commType = ac.getCommType(); - final boolean dataDriven = Objects.equal(_commType, ComponentCommunicationType.DATA_DRIVEN); - ComponentCommunicationType _commType_1 = ac.getCommType(); - final boolean async = Objects.equal(_commType_1, ComponentCommunicationType.ASYNCHRONOUS); - final boolean hasConstData = ((!(((IterableExtensions.isEmpty(eventPorts) && IterableExtensions.isEmpty(recvPorts)) && this._roomHelpers.getAllSAPs(ac).isEmpty()) && this._roomHelpers.getAllServiceImplementations(ac).isEmpty())) || Main.getSettings().isGenerateMSCInstrumentation()); - final boolean isEmptyStateGraph = FsmGenExtensions.isEmpty(xpac.getGraphContainer().getGraph()); - final boolean hasVarData = (!(((IterableExtensions.isEmpty(sendPorts) && this._roomHelpers.getAllAttributes(ac).isEmpty()) && isEmptyStateGraph) && (!hasConstData))); - 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 = ac.getName(); - _builder.append(_name, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(ac); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"etDatatypes.h\""); - _builder.newLine(); - _builder.append("#include \"messaging/etMessage.h\""); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* include all referenced room classes */"); - _builder.newLine(); - { - EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(ac); - EList<EnumerationType> _referencedEnumClasses = root.getReferencedEnumClasses(ac); - Iterable<DataType> _plus = Iterables.<DataType>concat(_referencedDataClasses, _referencedEnumClasses); - EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac); - final Function1<RoomClass, String> _function_3 = (RoomClass it) -> { - return it.getName(); - }; - List<RoomClass> _sortBy = IterableExtensions.<RoomClass, String>sortBy(Iterables.<RoomClass>concat(_plus, _referencedProtocolClasses), _function_3); - for(final RoomClass rc : _sortBy) { - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(rc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(ac, 1, true); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("typedef struct "); - String _name_1 = ac.getName(); - _builder.append(_name_1); - _builder.append(" "); - String _name_2 = ac.getName(); - _builder.append(_name_2); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* const part of ActorClass (ROM) */"); - _builder.newLine(); - { - if (hasConstData) { - _builder.append("typedef struct "); - String _name_3 = ac.getName(); - _builder.append(_name_3); - _builder.append("_const {"); - _builder.newLineIfNotEmpty(); - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("\t"); - _builder.append("const char* instName;"); - _builder.newLine(); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("/* simple ports */"); - _builder.newLine(); - { - for(final Port ep : eventPorts) { - { - int _multiplicity = ep.getMultiplicity(); - boolean _equals = (_multiplicity == 1); - if (_equals) { - _builder.append("\t"); - _builder.append("const "); - String _portClassName = this._roomExtensions.getPortClassName(ep); - _builder.append(_portClassName, "\t"); - _builder.append(" "); - String _name_4 = ep.getName(); - _builder.append(_name_4, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* data receive ports */"); - _builder.newLine(); - { - for(final Port ep_1 : recvPorts) { - { - int _multiplicity_1 = ep_1.getMultiplicity(); - boolean _equals_1 = (_multiplicity_1 == 1); - if (_equals_1) { - _builder.append("\t"); - _builder.append("const "); - String _portClassName_1 = this._roomExtensions.getPortClassName(ep_1); - _builder.append(_portClassName_1, "\t"); - _builder.append(" "); - String _name_5 = ep_1.getName(); - _builder.append(_name_5, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* saps */"); - _builder.newLine(); - { - List<SAP> _allSAPs = this._roomHelpers.getAllSAPs(ac); - for(final SAP sap : _allSAPs) { - _builder.append("\t"); - _builder.append("const "); - String _portClassName_2 = this._roomExtensions.getPortClassName(sap); - _builder.append(_portClassName_2, "\t"); - _builder.append(" "); - String _name_6 = sap.getName(); - _builder.append(_name_6, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* replicated ports */"); - _builder.newLine(); - { - List<Port> _allEndPorts = this._roomHelpers.getAllEndPorts(ac); - for(final Port ep_2 : _allEndPorts) { - { - int _multiplicity_2 = ep_2.getMultiplicity(); - boolean _notEquals = (_multiplicity_2 != 1); - if (_notEquals) { - _builder.append("\t"); - _builder.append("const etReplPort "); - String _name_7 = ep_2.getName(); - _builder.append(_name_7, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* services */"); - _builder.newLine(); - { - List<ServiceImplementation> _allServiceImplementations = this._roomHelpers.getAllServiceImplementations(ac); - for(final ServiceImplementation svc : _allServiceImplementations) { - _builder.append("\t"); - _builder.append("const etReplPort "); - String _name_8 = svc.getSpp().getName(); - _builder.append(_name_8, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("} "); - String _name_9 = ac.getName(); - _builder.append(_name_9); - _builder.append("_const;"); - _builder.newLineIfNotEmpty(); - } else { - _builder.append("/* this actor class has no ports and thus no constant data */"); - _builder.newLine(); - } - } - _builder.newLine(); - { - if ((!isEmptyStateGraph)) { - _builder.newLine(); - CharSequence _genHeaderConstants = this._stateMachineGen.genHeaderConstants(xpac); - _builder.append(_genHeaderConstants); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* variable part of ActorClass (RAM) */"); - _builder.newLine(); - { - if (hasVarData) { - _builder.append("struct "); - String _name_10 = ac.getName(); - _builder.append(_name_10); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - if (hasConstData) { - _builder.append("\t"); - _builder.append("const "); - String _name_11 = ac.getName(); - _builder.append(_name_11, "\t"); - _builder.append("_const* const constData;"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("/* data send ports */"); - _builder.newLine(); - { - for(final Port ep_3 : sendPorts) { - { - int _multiplicity_3 = ep_3.getMultiplicity(); - boolean _equals_2 = (_multiplicity_3 == 1); - if (_equals_2) { - _builder.append("\t"); - String _portClassName_3 = this._roomExtensions.getPortClassName(ep_3); - _builder.append(_portClassName_3, "\t"); - _builder.append(" "); - String _name_12 = ep_3.getName(); - _builder.append(_name_12, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - CharSequence _attributes = this._procedureHelpers.attributes(this._roomHelpers.getAllAttributes(ac)); - _builder.append(_attributes, "\t"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - if ((!isEmptyStateGraph)) { - _builder.newLine(); - _builder.append("\t"); - CharSequence _genDataMembers = this._stateMachineGen.genDataMembers(xpac); - _builder.append(_genDataMembers, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("};"); - _builder.newLine(); - } else { - _builder.append("struct "); - String _name_13 = ac.getName(); - _builder.append(_name_13); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("/* This actor class has no data at all."); - _builder.newLine(); - _builder.append("\t "); - _builder.append("But the private actor instance data is passed to all life cycle functions."); - _builder.newLine(); - _builder.append("\t "); - _builder.append("By introducing the dummy data we keep this case simple"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("*/"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("int dummy;"); - _builder.newLine(); - _builder.append("};"); - _builder.newLine(); - } - } - _builder.newLine(); - _builder.append("void "); - String _name_14 = ac.getName(); - _builder.append(_name_14); - _builder.append("_init("); - String _name_15 = ac.getName(); - _builder.append(_name_15); - _builder.append("* self);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("void "); - String _name_16 = ac.getName(); - _builder.append(_name_16); - _builder.append("_receiveMessage(void* self, const void* ifitem, const etMessage* msg);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - if ((dataDriven || async)) { - _builder.append("void "); - String _name_17 = ac.getName(); - _builder.append(_name_17); - _builder.append("_execute("); - String _name_18 = ac.getName(); - _builder.append(_name_18); - _builder.append("* self);"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - String _userStructorsDeclaration = this._procedureHelpers.userStructorsDeclaration(ac); - _builder.append(_userStructorsDeclaration); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(this._roomHelpers.getLatestOperations(ac), ac.getName()); - _builder.append(_operationsDeclaration); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode_1 = this._procedureHelpers.userCode(ac, 2, true); - _builder.append(_userCode_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(ac); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - protected CharSequence generateUtilsFile(final Root root, final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - final Function1<Port, Boolean> _function = (Port p) -> { - GeneralProtocolClass _protocol = p.getProtocol(); - CommunicationType _commType = ((ProtocolClass) _protocol).getCommType(); - return Boolean.valueOf(Objects.equal(_commType, CommunicationType.EVENT_DRIVEN)); - }; - final Iterable<Port> eventPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function); - final Function1<Port, Boolean> _function_1 = (Port it) -> { - int _multiplicity = it.getMultiplicity(); - return Boolean.valueOf((_multiplicity != 1)); - }; - final Iterable<Port> replEventPorts = IterableExtensions.<Port>filter(eventPorts, _function_1); - final Function1<Port, Boolean> _function_2 = (Port p) -> { - return Boolean.valueOf(((Objects.equal(((ProtocolClass) p.getProtocol()).getCommType(), CommunicationType.DATA_DRIVEN) && p.isConjugated()) && (p.getMultiplicity() == 1))); - }; - final Iterable<Port> sendPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function_2); - final Function1<Port, Boolean> _function_3 = (Port p) -> { - return Boolean.valueOf(((Objects.equal(((ProtocolClass) p.getProtocol()).getCommType(), CommunicationType.DATA_DRIVEN) && (!p.isConjugated())) && (p.getMultiplicity() == 1))); - }; - final Iterable<Port> recvPorts = IterableExtensions.<Port>filter(this._roomHelpers.getAllEndPorts(ac), _function_3); - final Function1<InterfaceItem, Boolean> _function_4 = (InterfaceItem p) -> { - return Boolean.valueOf(((!Objects.equal(this._roomHelpers.getPortClass(p), null)) && (this._roomHelpers.getPortClass(p).getOperations().size() > 0))); - }; - final Iterable<InterfaceItem> portsWithOperations = IterableExtensions.<InterfaceItem>filter(this._roomHelpers.getAllInterfaceItems(ac), _function_4); - EObject _eContainer = ac.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "_"); - String _plus = (_replaceAll + "_"); - String _name = ac.getName(); - String _plus_1 = (_plus + _name); - final String filename = (_plus_1 + "_Utils"); - 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("* Utils File of ActorClass "); - String _name_1 = ac.getName(); - _builder.append(_name_1, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(filename); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(ac); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("* access macros for ports, operations and attributes"); - _builder.newLine(); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* simple event ports */"); - _builder.newLine(); - { - final Function1<Port, Boolean> _function_5 = (Port it) -> { - int _multiplicity = it.getMultiplicity(); - return Boolean.valueOf((_multiplicity == 1)); - }; - Iterable<Port> _filter = IterableExtensions.<Port>filter(eventPorts, _function_5); - for(final Port ep : _filter) { - { - List<Message> _outgoing = this._roomHelpers.getOutgoing(ep); - for(final Message msg : _outgoing) { - String _xifexpression = null; - VarDecl _data = msg.getData(); - boolean _notEquals = (!Objects.equal(_data, null)); - if (_notEquals) { - _xifexpression = "data"; - } else { - _xifexpression = ""; - } - final String data1 = _xifexpression; - _builder.newLineIfNotEmpty(); - String _xifexpression_1 = null; - VarDecl _data_1 = msg.getData(); - boolean _notEquals_1 = (!Objects.equal(_data_1, null)); - if (_notEquals_1) { - _xifexpression_1 = ", data"; - } else { - _xifexpression_1 = ""; - } - final String data2 = _xifexpression_1; - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_2 = ep.getName(); - _builder.append(_name_2); - _builder.append("_"); - String _name_3 = msg.getName(); - _builder.append(_name_3); - _builder.append("("); - _builder.append(data1); - _builder.append(") "); - String _portClassName = this._roomExtensions.getPortClassName(ep); - _builder.append(_portClassName); - _builder.append("_"); - String _name_4 = msg.getName(); - _builder.append(_name_4); - _builder.append("(&self->constData->"); - String _name_5 = ep.getName(); - _builder.append(_name_5); - _builder.append(data2); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* data receive ports */"); - _builder.newLine(); - { - for(final Port ep_1 : recvPorts) { - { - List<Message> _incoming = this._roomHelpers.getIncoming(ep_1); - for(final Message msg_1 : _incoming) { - _builder.append("#define "); - String _name_6 = ep_1.getName(); - _builder.append(_name_6); - _builder.append("_"); - String _name_7 = msg_1.getName(); - _builder.append(_name_7); - _builder.append(" "); - String _portClassName_1 = this._roomExtensions.getPortClassName(ep_1); - _builder.append(_portClassName_1); - _builder.append("_"); - String _name_8 = msg_1.getName(); - _builder.append(_name_8); - _builder.append("_get(&self->constData->"); - String _name_9 = ep_1.getName(); - _builder.append(_name_9); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* data send ports */"); - _builder.newLine(); - { - for(final Port ep_2 : sendPorts) { - { - List<Message> _outgoing_1 = this._roomHelpers.getOutgoing(ep_2); - for(final Message msg_2 : _outgoing_1) { - String _xifexpression_2 = null; - VarDecl _data_2 = msg_2.getData(); - boolean _notEquals_2 = (!Objects.equal(_data_2, null)); - if (_notEquals_2) { - _xifexpression_2 = "data"; - } else { - _xifexpression_2 = ""; - } - final String data1_1 = _xifexpression_2; - _builder.newLineIfNotEmpty(); - String _xifexpression_3 = null; - VarDecl _data_3 = msg_2.getData(); - boolean _notEquals_3 = (!Objects.equal(_data_3, null)); - if (_notEquals_3) { - _xifexpression_3 = ", data"; - } else { - _xifexpression_3 = ""; - } - final String data2_1 = _xifexpression_3; - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_10 = ep_2.getName(); - _builder.append(_name_10); - _builder.append("_"); - String _name_11 = msg_2.getName(); - _builder.append(_name_11); - _builder.append("("); - _builder.append(data1_1); - _builder.append(") "); - String _portClassName_2 = this._roomExtensions.getPortClassName(ep_2); - _builder.append(_portClassName_2); - _builder.append("_"); - String _name_12 = msg_2.getName(); - _builder.append(_name_12); - _builder.append("_set(&self->"); - String _name_13 = ep_2.getName(); - _builder.append(_name_13); - _builder.append(data2_1); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* saps */"); - _builder.newLine(); - { - List<SAP> _allSAPs = this._roomHelpers.getAllSAPs(ac); - for(final SAP sap : _allSAPs) { - { - List<Message> _outgoing_2 = this._roomHelpers.getOutgoing(sap); - for(final Message msg_3 : _outgoing_2) { - String _xifexpression_4 = null; - VarDecl _data_4 = msg_3.getData(); - boolean _notEquals_4 = (!Objects.equal(_data_4, null)); - if (_notEquals_4) { - _xifexpression_4 = "data"; - } else { - _xifexpression_4 = ""; - } - final String data1_2 = _xifexpression_4; - _builder.newLineIfNotEmpty(); - String _xifexpression_5 = null; - VarDecl _data_5 = msg_3.getData(); - boolean _notEquals_5 = (!Objects.equal(_data_5, null)); - if (_notEquals_5) { - _xifexpression_5 = ", data"; - } else { - _xifexpression_5 = ""; - } - final String data2_2 = _xifexpression_5; - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_14 = sap.getName(); - _builder.append(_name_14); - _builder.append("_"); - String _name_15 = msg_3.getName(); - _builder.append(_name_15); - _builder.append("("); - _builder.append(data1_2); - _builder.append(") "); - String _portClassName_3 = this._roomExtensions.getPortClassName(sap); - _builder.append(_portClassName_3); - _builder.append("_"); - String _name_16 = msg_3.getName(); - _builder.append(_name_16); - _builder.append("(&self->constData->"); - String _name_17 = sap.getName(); - _builder.append(_name_17); - _builder.append(data2_2); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* replicated event ports */"); - _builder.newLine(); - { - boolean _isEmpty = IterableExtensions.isEmpty(replEventPorts); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("#define ifitem_index (((etReplSubPort*)ifitem)->index)"); - _builder.newLine(); - } - } - { - for(final Port ep_3 : replEventPorts) { - { - List<Message> _outgoing_3 = this._roomHelpers.getOutgoing(ep_3); - for(final Message msg_4 : _outgoing_3) { - String _xifexpression_6 = null; - VarDecl _data_6 = msg_4.getData(); - boolean _notEquals_6 = (!Objects.equal(_data_6, null)); - if (_notEquals_6) { - _xifexpression_6 = "data"; - } else { - _xifexpression_6 = ""; - } - final String data1_3 = _xifexpression_6; - _builder.newLineIfNotEmpty(); - String _xifexpression_7 = null; - VarDecl _data_7 = msg_4.getData(); - boolean _notEquals_7 = (!Objects.equal(_data_7, null)); - if (_notEquals_7) { - _xifexpression_7 = ", data"; - } else { - _xifexpression_7 = ""; - } - final String data2_3 = _xifexpression_7; - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_18 = ep_3.getName(); - _builder.append(_name_18); - _builder.append("_"); - String _name_19 = msg_4.getName(); - _builder.append(_name_19); - _builder.append("_broadcast("); - _builder.append(data1_3); - _builder.append(") "); - String _portClassName_4 = this._roomExtensions.getPortClassName(ep_3); - _builder.append(_portClassName_4); - _builder.append("_"); - String _name_20 = msg_4.getName(); - _builder.append(_name_20); - _builder.append("_broadcast(&self->constData->"); - String _name_21 = ep_3.getName(); - _builder.append(_name_21); - _builder.append(data2_3); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_22 = ep_3.getName(); - _builder.append(_name_22); - _builder.append("_"); - String _name_23 = msg_4.getName(); - _builder.append(_name_23); - _builder.append("(idx"); - _builder.append(data2_3); - _builder.append(") "); - String _portClassName_5 = this._roomExtensions.getPortClassName(ep_3); - _builder.append(_portClassName_5); - _builder.append("_"); - String _name_24 = msg_4.getName(); - _builder.append(_name_24); - _builder.append("(&self->constData->"); - String _name_25 = ep_3.getName(); - _builder.append(_name_25); - _builder.append(", idx"); - _builder.append(data2_3); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* services */"); - _builder.newLine(); - { - List<ServiceImplementation> _allServiceImplementations = this._roomHelpers.getAllServiceImplementations(ac); - for(final ServiceImplementation svc : _allServiceImplementations) { - { - List<Message> _outgoing_4 = this._roomHelpers.getOutgoing(svc.getSpp()); - for(final Message msg_5 : _outgoing_4) { - String _xifexpression_8 = null; - VarDecl _data_8 = msg_5.getData(); - boolean _notEquals_8 = (!Objects.equal(_data_8, null)); - if (_notEquals_8) { - _xifexpression_8 = "data"; - } else { - _xifexpression_8 = ""; - } - final String data1_4 = _xifexpression_8; - _builder.newLineIfNotEmpty(); - String _xifexpression_9 = null; - VarDecl _data_9 = msg_5.getData(); - boolean _notEquals_9 = (!Objects.equal(_data_9, null)); - if (_notEquals_9) { - _xifexpression_9 = ", data"; - } else { - _xifexpression_9 = ""; - } - final String data2_4 = _xifexpression_9; - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_26 = svc.getSpp().getName(); - _builder.append(_name_26); - _builder.append("_"); - String _name_27 = msg_5.getName(); - _builder.append(_name_27); - _builder.append("_broadcast("); - _builder.append(data1_4); - _builder.append(") "); - String _portClassName_6 = this._roomExtensions.getPortClassName(svc.getSpp()); - _builder.append(_portClassName_6); - _builder.append("_"); - String _name_28 = msg_5.getName(); - _builder.append(_name_28); - _builder.append("_broadcast(&self->constData->"); - String _name_29 = svc.getSpp().getName(); - _builder.append(_name_29); - _builder.append(data2_4); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_30 = svc.getSpp().getName(); - _builder.append(_name_30); - _builder.append("_"); - String _name_31 = msg_5.getName(); - _builder.append(_name_31); - _builder.append("(idx"); - _builder.append(data2_4); - _builder.append(") "); - String _portClassName_7 = this._roomExtensions.getPortClassName(svc.getSpp()); - _builder.append(_portClassName_7); - _builder.append("_"); - String _name_32 = msg_5.getName(); - _builder.append(_name_32); - _builder.append("(&self->constData->"); - String _name_33 = svc.getSpp().getName(); - _builder.append(_name_33); - _builder.append(", idx"); - _builder.append(data2_4); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("/* operations */"); - _builder.newLine(); - { - List<StandardOperation> _latestOperations = this._roomHelpers.getLatestOperations(ac); - for(final StandardOperation op : _latestOperations) { - final CharSequence args = this.argList(op); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_34 = op.getName(); - _builder.append(_name_34); - _builder.append("("); - _builder.append(args); - _builder.append(") "); - String _name_35 = ac.getName(); - _builder.append(_name_35); - _builder.append("_"); - String _name_36 = op.getName(); - _builder.append(_name_36); - _builder.append("(self"); - { - boolean _isEmpty_1 = op.getArguments().isEmpty(); - boolean _not_1 = (!_isEmpty_1); - if (_not_1) { - _builder.append(", "); - _builder.append(args); - } - } - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* attributes */"); - _builder.newLine(); - { - List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(ac); - for(final Attribute a : _allAttributes) { - _builder.append("#define "); - String _name_37 = a.getName(); - _builder.append(_name_37); - _builder.append(" (self->"); - String _name_38 = a.getName(); - _builder.append(_name_38); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* port operations */"); - _builder.newLine(); - { - for(final InterfaceItem p : portsWithOperations) { - { - EList<PortOperation> _operations = this._roomHelpers.getPortClass(p).getOperations(); - for(final PortOperation op_1 : _operations) { - final CharSequence args_1 = this.argList(op_1); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_39 = p.getName(); - _builder.append(_name_39); - _builder.append("_"); - String _name_40 = op_1.getName(); - _builder.append(_name_40); - _builder.append("("); - _builder.append(args_1); - _builder.append(") "); - String _portClassName_8 = this._roomExtensions.getPortClassName(p); - _builder.append(_portClassName_8); - _builder.append("_"); - String _name_41 = op_1.getName(); - _builder.append(_name_41); - _builder.append("(("); - String _portClassName_9 = this._roomExtensions.getPortClassName(p); - _builder.append(_portClassName_9); - _builder.append("*)&self->constData->"); - String _name_42 = p.getName(); - _builder.append(_name_42); - { - boolean _isEmpty_2 = op_1.getArguments().isEmpty(); - boolean _not_2 = (!_isEmpty_2); - if (_not_2) { - _builder.append(", "); - _builder.append(args_1); - } - } - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(filename); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence argList(final Operation op) { - StringConcatenation _builder = new StringConcatenation(); - { - EList<VarDecl> _arguments = op.getArguments(); - boolean _hasElements = false; - for(final VarDecl a : _arguments) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", ""); - } - String _name = a.getName(); - _builder.append(_name); - } - } - return _builder; - } - - protected CharSequence generateSourceFile(final Root root, final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - ComponentCommunicationType _commType = ac.getCommType(); - final boolean async = Objects.equal(_commType, ComponentCommunicationType.ASYNCHRONOUS); - ComponentCommunicationType _commType_1 = ac.getCommType(); - final boolean eventDriven = Objects.equal(_commType_1, ComponentCommunicationType.EVENT_DRIVEN); - ComponentCommunicationType _commType_2 = ac.getCommType(); - final boolean dataDriven = Objects.equal(_commType_2, ComponentCommunicationType.DATA_DRIVEN); - final boolean handleEvents = (async || eventDriven); - final boolean isEmptyStateGraph = FsmGenExtensions.isEmpty(xpac.getGraphContainer().getGraph()); - 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 = ac.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._cExtensions.getCHeaderFileName(ac); - _builder.append(_cHeaderFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"modelbase/etActor.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etLogger.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etMSCLogger.h\""); - _builder.newLine(); - _builder.append("#include \"etUnit/etUnit.h\""); - _builder.newLine(); - _builder.append("#include \"base/etMemory.h\""); - _builder.newLine(); - _builder.newLine(); - { - EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac); - for(final ProtocolClass pc : _referencedProtocolClasses) { - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(pc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("#include \""); - String _cUtilsFileName = this._cExtensions.getCUtilsFileName(ac); - _builder.append(_cUtilsFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(ac, 3, true); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* interface item IDs */"); - _builder.newLine(); - String _genInterfaceItemConstants = this.genInterfaceItemConstants(xpac); - _builder.append(_genInterfaceItemConstants); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - if ((!isEmptyStateGraph)) { - CharSequence _genStateMachine = this._stateMachineGen.genStateMachine(xpac.getGraphContainer()); - _builder.append(_genStateMachine); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("void "); - String _name_1 = ac.getName(); - _builder.append(_name_1); - _builder.append("_init("); - String _name_2 = ac.getName(); - _builder.append(_name_2); - _builder.append("* self){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - String _name_3 = ac.getName(); - _builder.append(_name_3, "\t"); - _builder.append("\", \"init\")"); - _builder.newLineIfNotEmpty(); - { - if ((!isEmptyStateGraph)) { - _builder.append("\t"); - CharSequence _genInitialization = this._stateMachineGen.genInitialization(xpac); - _builder.append(_genInitialization, "\t"); - _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_4 = ac.getName(); - _builder.append(_name_4); - _builder.append("_receiveMessage(void* self, const void* ifitem, const etMessage* msg){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - String _name_5 = ac.getName(); - _builder.append(_name_5, "\t"); - _builder.append("\", \"_receiveMessage\")"); - _builder.newLineIfNotEmpty(); - { - if ((!isEmptyStateGraph)) { - { - if (handleEvents) { - _builder.append("\t"); - String _operationScope = this.langExt.operationScope(ac.getName(), false); - _builder.append(_operationScope, "\t"); - _builder.append("receiveEvent(self, (etPort*)ifitem, msg->evtID, (void*)(((char*)msg)+MEM_CEIL(sizeof(etMessage))));"); - _builder.newLineIfNotEmpty(); - } else { - _builder.append("\t"); - String _operationScope_1 = this.langExt.operationScope(ac.getName(), false); - _builder.append(_operationScope_1, "\t"); - _builder.append("receiveEventInternal(self);"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - { - if ((dataDriven || async)) { - _builder.append("void "); - String _name_6 = ac.getName(); - _builder.append(_name_6); - _builder.append("_execute("); - String _name_7 = ac.getName(); - _builder.append(_name_7); - _builder.append("* self) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - String _name_8 = ac.getName(); - _builder.append(_name_8, "\t"); - _builder.append("\", \"_execute\")"); - _builder.newLineIfNotEmpty(); - { - if ((!isEmptyStateGraph)) { - _builder.newLine(); - { - if (handleEvents) { - _builder.append("\t"); - String _operationScope_2 = this.langExt.operationScope(ac.getName(), false); - _builder.append(_operationScope_2, "\t"); - _builder.append("receiveEvent(self, NULL, 0, NULL);"); - _builder.newLineIfNotEmpty(); - } else { - _builder.append("\t"); - String _operationScope_3 = this.langExt.operationScope(ac.getName(), false); - _builder.append(_operationScope_3, "\t"); - _builder.append("receiveEventInternal(self);"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - } - } - _builder.newLine(); - String _userStructorsImplementation = this._procedureHelpers.userStructorsImplementation(ac); - _builder.append(_userStructorsImplementation); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(this._roomHelpers.getLatestOperations(ac), ac.getName()); - _builder.append(_operationsImplementation); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } -} 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 deleted file mode 100644 index 23e59b4b8..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java +++ /dev/null @@ -1,760 +0,0 @@ -/** - * 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) - */ -package org.eclipse.etrice.generator.c.gen; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.common.base.LiteralType; -import org.eclipse.etrice.core.etphys.eTPhys.NodeRef; -import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance; -import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.DataClass; -import org.eclipse.etrice.core.room.DataType; -import org.eclipse.etrice.core.room.EnumLiteral; -import org.eclipse.etrice.core.room.EnumerationType; -import org.eclipse.etrice.core.room.ExternalType; -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.RoomModel; -import org.eclipse.etrice.core.room.VarDecl; -import org.eclipse.etrice.core.room.util.RoomHelpers; -import org.eclipse.etrice.generator.fsm.generic.ILanguageExtensionBase; -import org.eclipse.etrice.generator.generic.ILanguageExtension; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.util.Pair; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Extension; - -@Singleton -@SuppressWarnings("all") -public class CExtensions implements ILanguageExtension { - @Inject - protected IDiagnostician diagnostician; - - @Inject - @Extension - protected RoomHelpers _roomHelpers; - - @Override - public String getTypedDataDefinition(final EObject msg) { - String _xifexpression = null; - if ((msg instanceof Message)) { - _xifexpression = this.generateArglistAndTypedData(((Message) msg).getData())[ILanguageExtensionBase.TypedDataKind.DECLARATION_AND_INITIALIZATION.ordinal()]; - } else { - _xifexpression = ""; - } - return _xifexpression; - } - - @Override - public String accessLevelPrivate() { - return "static "; - } - - @Override - public String accessLevelProtected() { - return "static "; - } - - @Override - public String accessLevelPublic() { - return ""; - } - - @Override - public String memberAccess() { - return "self->"; - } - - @Override - public String selfPointer(final String classname, final boolean hasArgs) { - String _xifexpression = null; - if (hasArgs) { - _xifexpression = "* self, "; - } else { - _xifexpression = "* self"; - } - return (classname + _xifexpression); - } - - @Override - public String selfPointer(final boolean hasArgs) { - String _xifexpression = null; - if (hasArgs) { - _xifexpression = "self, "; - } else { - _xifexpression = "self"; - } - return _xifexpression; - } - - @Override - public String scopeSeparator() { - return ""; - } - - @Override - public String operationScope(final String classname, final boolean isDeclaration) { - return (classname + "_"); - } - - @Override - public String memberInDeclaration(final String namespace, final String member) { - return ((namespace + "_") + member); - } - - @Override - public String memberInUse(final String namespace, final String member) { - return ((namespace + "_") + member); - } - - /** - * TODO: move specific code elsewhere - */ - public String getCHeaderFileName(final RoomClass rc) { - String _name = rc.getName(); - return (_name + ".h"); - } - - public String getCSourceFileName(final RoomClass rc) { - String _name = rc.getName(); - return (_name + ".c"); - } - - public String getCUtilsFileName(final RoomClass rc) { - String _name = rc.getName(); - return (_name + "_Utils.h"); - } - - public String getInstSourceFileName(final RoomClass rc) { - String _name = rc.getName(); - return (_name + "_Inst.h"); - } - - public String getDispSourceFileName(final RoomClass rc) { - String _name = rc.getName(); - return (_name + "_Disp.h"); - } - - public String getCHeaderFileName(final NodeRef nr, final SubSystemInstance ssi) { - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - String _plus_1 = (_plus + _name_1); - return (_plus_1 + ".h"); - } - - public String getCSourceFileName(final NodeRef nr, final SubSystemInstance ssi) { - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - String _plus_1 = (_plus + _name_1); - return (_plus_1 + ".c"); - } - - public String getInstSourceFileName(final NodeRef nr, final SubSystemInstance ssi) { - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - String _plus_1 = (_plus + _name_1); - return (_plus_1 + "_Inst.h"); - } - - public String getDispSourceFileName(final NodeRef nr, final SubSystemInstance ssi) { - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - String _plus_1 = (_plus + _name_1); - return (_plus_1 + "_Disp.h"); - } - - public CharSequence getIncludeGuardString(final String filename) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("_"); - String _upperCase = filename.toUpperCase(); - _builder.append(_upperCase); - _builder.append("_H_"); - return _builder; - } - - public CharSequence generateIncludeGuardBegin(final RoomClass rc) { - CharSequence _xblockexpression = null; - { - EObject _eContainer = rc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "_"); - String _plus = (_replaceAll + "_"); - String _name = rc.getName(); - final String filename = (_plus + _name); - _xblockexpression = this.generateIncludeGuardBegin(filename); - } - return _xblockexpression; - } - - public CharSequence generateIncludeGuardEnd(final RoomClass rc) { - CharSequence _xblockexpression = null; - { - EObject _eContainer = rc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "_"); - String _plus = (_replaceAll + "_"); - String _name = rc.getName(); - final String filename = (_plus + _name); - _xblockexpression = this.generateIncludeGuardEnd(filename); - } - return _xblockexpression; - } - - public CharSequence generateIncludeGuardBegin(final String filename) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("#ifndef "); - CharSequence _includeGuardString = this.getIncludeGuardString(filename); - _builder.append(_includeGuardString); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - CharSequence _includeGuardString_1 = this.getIncludeGuardString(filename); - _builder.append(_includeGuardString_1); - _builder.newLineIfNotEmpty(); - return _builder; - } - - public CharSequence generateIncludeGuardEnd(final String filename) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("#endif /* "); - CharSequence _includeGuardString = this.getIncludeGuardString(filename); - _builder.append(_includeGuardString); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - return _builder; - } - - @Override - public boolean usesInheritance() { - return false; - } - - @Override - public boolean usesPointers() { - return true; - } - - @Override - public String genEnumeration(final String name, final List<Pair<String, String>> entries) { - String _xblockexpression = null; - { - boolean _isEmpty = entries.isEmpty(); - if (_isEmpty) { - return "/* empty enum not generated */"; - } - StringConcatenation _builder = new StringConcatenation(); - _builder.append("enum "); - _builder.append(name); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - boolean _hasElements = false; - for(final Pair<String, String> entry : entries) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(",", "\t"); - } - _builder.append("\t"); - String _first = entry.getFirst(); - _builder.append(_first, "\t"); - _builder.append(" = "); - String _second = entry.getSecond(); - _builder.append(_second, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("};"); - _builder.newLine(); - _xblockexpression = _builder.toString(); - } - return _xblockexpression; - } - - @Override - public String booleanConstant(final boolean b) { - String _xifexpression = null; - if (b) { - _xifexpression = "ET_TRUE"; - } else { - _xifexpression = "ET_FALSE"; - } - return _xifexpression; - } - - @Override - public String pointerLiteral() { - return "*"; - } - - @Override - public String nullPointer() { - return "NULL"; - } - - @Override - public String voidPointer() { - return "void*"; - } - - @Override - public String arrayType(final String type, final int size, final boolean isRef) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(type); - { - if (isRef) { - _builder.append("*"); - } - } - _builder.newLineIfNotEmpty(); - return _builder.toString(); - } - - @Override - public String arrayDeclaration(final String type, final int size, final boolean isRef, final String name) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(type); - { - if (isRef) { - _builder.append("*"); - } - } - _builder.append(" "); - _builder.append(name); - _builder.append("["); - _builder.append(size); - _builder.append("]"); - _builder.newLineIfNotEmpty(); - return _builder.toString(); - } - - @Override - public String superCall(final String baseClassName, final String method, final String args) { - return ""; - } - - @Override - public String toValueLiteral(final PrimitiveType type, final String value) { - String _switchResult = null; - String _targetName = type.getTargetName(); - boolean _matched = false; - if ((type.getTargetName().equals("char") && (value.length() == 1))) { - _matched=true; - _switchResult = (("\'" + value) + "\'"); - } - if (!_matched) { - LiteralType _type = type.getType(); - boolean _equals = Objects.equal(_type, LiteralType.CHAR); - if (_equals) { - _matched=true; - _switchResult = (("\"" + value) + "\""); - } - } - if (!_matched) { - if ((value.contains(",") || value.contains("{"))) { - _matched=true; - String _xblockexpression = null; - { - String[] singleValues = value.replace("{", "").replace("}", "").trim().split(","); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("{ "); - { - boolean _hasElements = false; - for(final String v : singleValues) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", ""); - } - String _valueLiteral = this.toValueLiteral(type, v.trim()); - _builder.append(_valueLiteral); - } - } - _builder.append(" }"); - _xblockexpression = _builder.toString(); - } - _switchResult = _xblockexpression; - } - } - if (!_matched) { - if (Objects.equal(_targetName, "boolean")) { - _matched=true; - String _xifexpression = null; - boolean _equals_1 = value.equals("true"); - if (_equals_1) { - _xifexpression = "ET_TRUE"; - } else { - _xifexpression = "ET_FALSE"; - } - _switchResult = _xifexpression; - } - } - if (!_matched) { - _switchResult = value; - } - return _switchResult; - } - - @Override - public String toEnumLiteral(final EnumerationType type, final String value) { - String _xifexpression = null; - if ((value.contains(",") || value.contains("{"))) { - String _xblockexpression = null; - { - String[] singleValues = value.replace("{", "").replace("}", "").trim().split(","); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("{ "); - { - boolean _hasElements = false; - for(final String v : singleValues) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", ""); - } - String _convertStringEnumLiteral = this.convertStringEnumLiteral(type, v.trim()); - _builder.append(_convertStringEnumLiteral); - } - } - _builder.append(" }"); - _xblockexpression = _builder.toString(); - } - _xifexpression = _xblockexpression; - } else { - _xifexpression = this.convertStringEnumLiteral(type, value); - } - return _xifexpression; - } - - private String convertStringEnumLiteral(final EnumerationType type, final String value) { - String v = value; - boolean _startsWith = v.startsWith(type.getName()); - if (_startsWith) { - int _length = type.getName().length(); - int _plus = (_length + 1); - v = v.substring(_plus); - } - EList<EnumLiteral> _literals = type.getLiterals(); - for (final EnumLiteral l : _literals) { - boolean _equals = l.getName().equals(v); - if (_equals) { - String _name = type.getName(); - String _plus_1 = (_name + "_"); - String _name_1 = l.getName(); - return (_plus_1 + _name_1); - } - } - return null; - } - - @Override - public String defaultValue(final DataType dt) { - String _switchResult = null; - boolean _matched = false; - if (dt instanceof PrimitiveType) { - _matched=true; - _switchResult = this.toValueLiteral(((PrimitiveType)dt), ((PrimitiveType)dt).getDefaultValueLiteral()); - } - if (!_matched) { - if (dt instanceof EnumerationType) { - _matched=true; - _switchResult = this.getDefaultValue(((EnumerationType)dt)); - } - } - if (!_matched) { - if (dt instanceof ExternalType) { - _matched=true; - String _xblockexpression = null; - { - String _defaultValueLiteral = ((ExternalType)dt).getDefaultValueLiteral(); - boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null)); - if (_notEquals) { - return ((ExternalType)dt).getDefaultValueLiteral(); - } - String _name = ((ExternalType)dt).getName(); - String _plus = ("external type " + _name); - String _plus_1 = (_plus + "has no default initialization"); - this.diagnostician.error(_plus_1, ((ExternalType)dt).eContainer(), ((ExternalType)dt).eContainingFeature()); - _xblockexpression = ""; - } - _switchResult = _xblockexpression; - } - } - if (!_matched) { - if (dt instanceof DataClass) { - _matched=true; - StringConcatenation _builder = new StringConcatenation(); - _builder.append("{"); - _builder.newLine(); - { - List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(((DataClass)dt)); - boolean _hasElements = false; - for(final Attribute att : _allAttributes) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(",", "\t"); - } - _builder.append("\t"); - String _initializationWithDefaultValues = this.initializationWithDefaultValues(att); - _builder.append(_initializationWithDefaultValues, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("}"); - _builder.newLine(); - _switchResult = _builder.toString(); - } - } - return _switchResult; - } - - public String getDefaultValue(final EnumerationType type) { - String _xifexpression = null; - boolean _isEmpty = type.getLiterals().isEmpty(); - if (_isEmpty) { - _xifexpression = ""; - } else { - _xifexpression = this.getCastedValue(type.getLiterals().get(0)); - } - return _xifexpression; - } - - @Override - public String initializationWithDefaultValues(final DataType dt, final int size) { - String _xblockexpression = null; - { - final String dv = this.defaultValue(dt); - _xblockexpression = this.initializer(dv, size); - } - return _xblockexpression; - } - - private String initializer(final String dv, final int size) { - String _xifexpression = null; - if ((size > 1)) { - String _xblockexpression = null; - { - String res = "{"; - int i = 0; - while ((i < size)) { - { - res = (res + dv); - i = (i + 1); - if ((i < size)) { - res = (res + ","); - } - } - } - _xblockexpression = (res + "}"); - } - _xifexpression = _xblockexpression; - } else { - _xifexpression = dv; - } - return _xifexpression; - } - - public String initializationWithDefaultValues(final Attribute att) { - String _xblockexpression = null; - { - final String dv = att.getDefaultValueLiteral(); - String _xifexpression = null; - boolean _notEquals = (!Objects.equal(dv, null)); - if (_notEquals) { - String _xifexpression_1 = null; - boolean _startsWith = dv.startsWith("{"); - if (_startsWith) { - _xifexpression_1 = dv; - } else { - _xifexpression_1 = this.initializer(dv, att.getSize()); - } - _xifexpression = _xifexpression_1; - } else { - String _xifexpression_2 = null; - boolean _isRef = att.getType().isRef(); - if (_isRef) { - _xifexpression_2 = this.initializer("NULL", att.getSize()); - } else { - _xifexpression_2 = this.initializationWithDefaultValues(att.getType().getType(), att.getSize()); - } - _xifexpression = _xifexpression_2; - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - - @Override - public String[] generateArglistAndTypedData(final EObject d) { - if ((Objects.equal(d, null) || (!(d instanceof VarDecl)))) { - return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class)); - } - final VarDecl data = ((VarDecl) d); - boolean _equals = Objects.equal(data, null); - if (_equals) { - return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class)); - } - String _xifexpression = null; - DataType _type = data.getRefType().getType(); - if ((_type instanceof PrimitiveType)) { - DataType _type_1 = data.getRefType().getType(); - _xifexpression = ((PrimitiveType) _type_1).getTargetName(); - } else { - String _xifexpression_1 = null; - DataType _type_2 = data.getRefType().getType(); - if ((_type_2 instanceof EnumerationType)) { - DataType _type_3 = data.getRefType().getType(); - _xifexpression_1 = this.getTargetType(((EnumerationType) _type_3)); - } else { - String _xifexpression_2 = null; - DataType _type_4 = data.getRefType().getType(); - if ((_type_4 instanceof ExternalType)) { - DataType _type_5 = data.getRefType().getType(); - _xifexpression_2 = ((ExternalType) _type_5).getTargetName(); - } else { - _xifexpression_2 = data.getRefType().getType().getName(); - } - _xifexpression_1 = _xifexpression_2; - } - _xifexpression = _xifexpression_1; - } - String typeName = _xifexpression; - String _xifexpression_3 = null; - DataType _type_6 = data.getRefType().getType(); - if ((_type_6 instanceof PrimitiveType)) { - String _xblockexpression = null; - { - DataType _type_7 = data.getRefType().getType(); - final String ct = ((PrimitiveType) _type_7).getCastName(); - String _xifexpression_4 = null; - if (((!Objects.equal(ct, null)) && (!ct.isEmpty()))) { - _xifexpression_4 = ct; - } else { - _xifexpression_4 = typeName; - } - _xblockexpression = _xifexpression_4; - } - _xifexpression_3 = _xblockexpression; - } else { - String _xifexpression_4 = null; - DataType _type_7 = data.getRefType().getType(); - if ((_type_7 instanceof EnumerationType)) { - DataType _type_8 = data.getRefType().getType(); - _xifexpression_4 = this.getCastType(((EnumerationType) _type_8)); - } else { - _xifexpression_4 = typeName; - } - _xifexpression_3 = _xifexpression_4; - } - String castTypeName = _xifexpression_3; - castTypeName = (castTypeName + "*"); - String deRef = "*"; - final boolean isRef = data.getRefType().isRef(); - final boolean isPrim = ((data.getRefType().getType() instanceof PrimitiveType) || (data.getRefType().getType() instanceof EnumerationType)); - if (isRef) { - typeName = (typeName + "*"); - castTypeName = (castTypeName + "*"); - } else { - if ((!isPrim)) { - typeName = (typeName + "*"); - deRef = ""; - } - } - final String dataArg = (", " + ILanguageExtension.GENERIC_DATA_NAME); - final String typedData = (((((((typeName + " ") + ILanguageExtension.GENERIC_DATA_NAME) + " = ") + deRef) + "((") + castTypeName) + ") generic_data__et);\n"); - final String typedArgList = (((", " + typeName) + " ") + ILanguageExtension.GENERIC_DATA_NAME); - return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class)); - } - - public String getIncludePath(final RoomClass rc) { - EObject _eContainer = rc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "/"); - String _plus = ("\"" + _replaceAll); - String _plus_1 = (_plus + "/"); - String _cHeaderFileName = this.getCHeaderFileName(rc); - String _plus_2 = (_plus_1 + _cHeaderFileName); - return (_plus_2 + "\""); - } - - public String getUtilsIncludePath(final RoomClass rc) { - EObject _eContainer = rc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().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; - PrimitiveType _primitiveType = type.getPrimitiveType(); - boolean _notEquals = (!Objects.equal(_primitiveType, null)); - if (_notEquals) { - _xifexpression = type.getPrimitiveType().getTargetName(); - } else { - _xifexpression = type.getName(); - } - return _xifexpression; - } - - @Override - public String getCastedValue(final EnumLiteral literal) { - String _xblockexpression = null; - { - EObject _eContainer = literal.eContainer(); - final EnumerationType type = ((EnumerationType) _eContainer); - final String cast = this.getTargetType(type); - String _xifexpression = null; - PrimitiveType _primitiveType = type.getPrimitiveType(); - boolean _equals = Objects.equal(_primitiveType, null); - if (_equals) { - _xifexpression = Long.toString(literal.getLiteralValue()); - } else { - String _string = Long.toString(literal.getLiteralValue()); - String _plus = ((("((" + cast) + ")") + _string); - _xifexpression = (_plus + ")"); - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - - @Override - public String getCastType(final EnumerationType type) { - String _xifexpression = null; - PrimitiveType _primitiveType = type.getPrimitiveType(); - boolean _notEquals = (!Objects.equal(_primitiveType, null)); - if (_notEquals) { - _xifexpression = type.getPrimitiveType().getCastName(); - } else { - _xifexpression = type.getName(); - } - return _xifexpression; - } - - @Override - public String makeOverridable() { - return ""; - } -} 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 deleted file mode 100644 index 2dc2a444b..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/DataClassGen.java +++ /dev/null @@ -1,388 +0,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.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.genmodel.etricegen.Root; -import org.eclipse.etrice.core.genmodel.fsm.ILogger; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.DataClass; -import org.eclipse.etrice.core.room.DataType; -import org.eclipse.etrice.core.room.EnumerationType; -import org.eclipse.etrice.core.room.Operation; -import org.eclipse.etrice.core.room.RoomModel; -import org.eclipse.etrice.core.room.StandardOperation; -import org.eclipse.etrice.core.room.VarDecl; -import org.eclipse.etrice.core.room.util.RoomHelpers; -import org.eclipse.etrice.generator.c.gen.CExtensions; -import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo; -import org.eclipse.etrice.generator.generic.ProcedureHelpers; -import org.eclipse.etrice.generator.generic.RoomExtensions; -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; - -@Singleton -@SuppressWarnings("all") -public class DataClassGen { - @Inject - private IGeneratorFileIo fileIO; - - @Inject - @Extension - private RoomHelpers _roomHelpers; - - @Inject - @Extension - private CExtensions _cExtensions; - - @Inject - @Extension - private RoomExtensions _roomExtensions; - - @Inject - @Extension - private ProcedureHelpers _procedureHelpers; - - @Inject - private ILogger logger; - - public void doGenerate(final Root root) { - EList<DataClass> _dataClasses = root.getDataClasses(); - for (final DataClass dc : _dataClasses) { - { - String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(dc); - String _path = this._roomExtensions.getPath(dc); - final String path = (_generationTargetPath + _path); - String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(dc); - String _path_1 = this._roomExtensions.getPath(dc); - final String infopath = (_generationInfoPath + _path_1); - String file = this._cExtensions.getCHeaderFileName(dc); - this.fileIO.generateFile("generating DataClass header", path, infopath, file, this.generateHeaderFile(root, dc)); - file = this._cExtensions.getCUtilsFileName(dc); - this.fileIO.generateFile("generating ProtocolClass utils", path, infopath, file, this.generateUtilsFile(root, dc)); - file = this._cExtensions.getCSourceFileName(dc); - this.fileIO.generateFile("generating DataClass source", path, infopath, file, this.generateSourceFile(root, dc)); - } - } - } - - public CharSequence 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(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(dc); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"etDatatypes.h\""); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* include all referenced room classes */"); - _builder.newLine(); - { - EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(dc); - EList<EnumerationType> _referencedEnumClasses = root.getReferencedEnumClasses(dc); - final Function1<DataType, String> _function = (DataType it) -> { - return it.getName(); - }; - List<DataType> _sortBy = IterableExtensions.<DataType, String>sortBy(Iterables.<DataType>concat(_referencedDataClasses, _referencedEnumClasses), _function); - for(final DataType rc : _sortBy) { - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(rc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(dc, 1); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.newLine(); - _builder.append("typedef struct {"); - _builder.newLine(); - _builder.append("\t"); - CharSequence _attributes = this._procedureHelpers.attributes(this._roomHelpers.getAllAttributes(dc)); - _builder.append(_attributes, "\t"); - _builder.newLineIfNotEmpty(); - _builder.append("} "); - String _name_1 = dc.getName(); - _builder.append(_name_1); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(dc); - for(final Attribute a : _allAttributes) { - { - String _defaultValueLiteral = a.getDefaultValueLiteral(); - boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null)); - if (_notEquals) { - String _name_2 = dc.getName(); - String _plus = (_name_2 + " "); - String _name_3 = a.getName(); - String _plus_1 = (_plus + _name_3); - String _plus_2 = (_plus_1 + ": Attribute initialization not supported in C"); - this.logger.logInfo(_plus_2); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.newLine(); - CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(dc.getOperations(), dc.getName()); - _builder.append(_operationsDeclaration); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* deep copy */"); - _builder.newLine(); - _builder.append("void "); - String _name_4 = dc.getName(); - _builder.append(_name_4); - _builder.append("_deepCopy("); - String _name_5 = dc.getName(); - _builder.append(_name_5); - _builder.append("* source, "); - String _name_6 = dc.getName(); - _builder.append(_name_6); - _builder.append("* target);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode_1 = this._procedureHelpers.userCode(dc, 2); - _builder.append(_userCode_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(dc); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - return _builder; - } - - private CharSequence generateUtilsFile(final Root root, final DataClass dc) { - CharSequence _xblockexpression = null; - { - EObject _eContainer = dc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "_"); - String _plus = (_replaceAll + "_"); - String _name = dc.getName(); - String _plus_1 = (_plus + _name); - final String filename = (_plus_1 + "_Utils"); - 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("* Utils File of DataClass "); - String _name_1 = dc.getName(); - _builder.append(_name_1, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("* "); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(filename); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(dc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("* access macros for operations and attributes"); - _builder.newLine(); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* operations */"); - _builder.newLine(); - { - List<StandardOperation> _allOperations = this._roomHelpers.getAllOperations(dc); - for(final StandardOperation op : _allOperations) { - final CharSequence args = this.argList(op); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name_2 = op.getName(); - _builder.append(_name_2); - _builder.append("("); - _builder.append(args); - _builder.append(") "); - String _name_3 = dc.getName(); - _builder.append(_name_3); - _builder.append("_"); - String _name_4 = op.getName(); - _builder.append(_name_4); - _builder.append("(self"); - { - boolean _isEmpty = op.getArguments().isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append(", "); - _builder.append(args); - } - } - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* attributes */"); - _builder.newLine(); - { - List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(dc); - for(final Attribute a : _allAttributes) { - _builder.append("#define "); - String _name_5 = a.getName(); - _builder.append(_name_5); - _builder.append(" (self->"); - String _name_6 = a.getName(); - _builder.append(_name_6); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(filename); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence argList(final Operation op) { - StringConcatenation _builder = new StringConcatenation(); - { - EList<VarDecl> _arguments = op.getArguments(); - boolean _hasElements = false; - for(final VarDecl a : _arguments) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", ""); - } - String _name = a.getName(); - _builder.append(_name); - } - } - return _builder; - } - - public CharSequence 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.h>"); - _builder.newLine(); - _builder.newLine(); - _builder.append("#include \""); - String _cHeaderFileName = this._cExtensions.getCHeaderFileName(dc); - _builder.append(_cHeaderFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.append("#include \""); - String _cUtilsFileName = this._cExtensions.getCUtilsFileName(dc); - _builder.append(_cUtilsFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(dc, 3); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.newLine(); - CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(dc.getOperations(), dc.getName()); - _builder.append(_operationsImplementation); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("void "); - String _name_1 = dc.getName(); - _builder.append(_name_1); - _builder.append("_deepCopy("); - String _name_2 = dc.getName(); - _builder.append(_name_2); - _builder.append("* source, "); - String _name_3 = dc.getName(); - _builder.append(_name_3); - _builder.append("* target) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("memcpy(target, source, sizeof("); - String _name_4 = dc.getName(); - _builder.append(_name_4, "\t"); - _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/NodeGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java deleted file mode 100644 index 9a4e24a41..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java +++ /dev/null @@ -1,2516 +0,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.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.common.base.LiteralType; -import org.eclipse.etrice.core.common.converter.TimeConverter; -import org.eclipse.etrice.core.etmap.util.ETMapUtil; -import org.eclipse.etrice.core.etphys.eTPhys.ExecMode; -import org.eclipse.etrice.core.etphys.eTPhys.NodeRef; -import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread; -import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType; -import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance; -import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance; -import org.eclipse.etrice.core.genmodel.etricegen.PortInstance; -import org.eclipse.etrice.core.genmodel.etricegen.Root; -import org.eclipse.etrice.core.genmodel.etricegen.StructureInstance; -import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance; -import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician; -import org.eclipse.etrice.core.genmodel.fsm.ILogger; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.CommunicationType; -import org.eclipse.etrice.core.room.DataType; -import org.eclipse.etrice.core.room.EnumerationType; -import org.eclipse.etrice.core.room.GeneralProtocolClass; -import org.eclipse.etrice.core.room.InterfaceItem; -import org.eclipse.etrice.core.room.Message; -import org.eclipse.etrice.core.room.MessageHandler; -import org.eclipse.etrice.core.room.Port; -import org.eclipse.etrice.core.room.PortClass; -import org.eclipse.etrice.core.room.PrimitiveType; -import org.eclipse.etrice.core.room.ProtocolClass; -import org.eclipse.etrice.core.room.RoomClass; -import org.eclipse.etrice.core.room.SAP; -import org.eclipse.etrice.core.room.SPP; -import org.eclipse.etrice.core.room.SubSystemClass; -import org.eclipse.etrice.core.room.VarDecl; -import org.eclipse.etrice.core.room.util.RoomHelpers; -import org.eclipse.etrice.generator.c.Main; -import org.eclipse.etrice.generator.c.gen.CExtensions; -import org.eclipse.etrice.generator.c.gen.Initialization; -import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo; -import org.eclipse.etrice.generator.fsm.base.IntelligentSeparator; -import org.eclipse.etrice.generator.generic.ProcedureHelpers; -import org.eclipse.etrice.generator.generic.RoomExtensions; -import org.eclipse.etrice.generator.generic.TypeHelpers; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IntegerRange; -import org.eclipse.xtext.xbase.lib.IterableExtensions; - -@Singleton -@SuppressWarnings("all") -public class NodeGen { - @Inject - @Extension - private RoomHelpers _roomHelpers; - - @Inject - @Extension - private CExtensions _cExtensions; - - @Inject - @Extension - private RoomExtensions _roomExtensions; - - @Inject - @Extension - private TypeHelpers _typeHelpers; - - @Inject - @Extension - private ProcedureHelpers helpers; - - @Inject - private IGeneratorFileIo fileIO; - - @Inject - private Initialization attrInitGenAddon; - - @Inject - private IDiagnostician diagnostician; - - @Inject - private ILogger logger; - - public void doGenerate(final Root root) { - Collection<NodeRef> _nodeRefs = ETMapUtil.getNodeRefs(); - for (final NodeRef nr : _nodeRefs) { - List<String> _subSystemInstancePaths = ETMapUtil.getSubSystemInstancePaths(nr); - for (final String instpath : _subSystemInstancePaths) { - { - StructureInstance _instance = root.getInstance(instpath); - final SubSystemInstance ssi = ((SubSystemInstance) _instance); - boolean _notEquals = (!Objects.equal(ssi, null)); - if (_notEquals) { - String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(ssi.getSubSystemClass()); - String _path = this._roomExtensions.getPath(ssi.getSubSystemClass()); - final String filepath = (_generationTargetPath + _path); - String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(ssi.getSubSystemClass()); - String _path_1 = this._roomExtensions.getPath(ssi.getSubSystemClass()); - final String infopath = (_generationInfoPath + _path_1); - String file = this._cExtensions.getCHeaderFileName(nr, ssi); - this.checkDataPorts(ssi); - final Set<PhysicalThread> usedThreads = ETMapUtil.getUsedThreads(nr, ssi); - this.fileIO.generateFile("generating Node declaration", filepath, infopath, file, this.generateHeaderFile(root, ssi)); - file = this._cExtensions.getCSourceFileName(nr, ssi); - this.fileIO.generateFile("generating Node implementation", filepath, infopath, file, this.generateSourceFile(root, ssi, usedThreads)); - file = this._cExtensions.getInstSourceFileName(nr, ssi); - this.fileIO.generateFile("generating Node instance file", filepath, infopath, file, this.generateInstanceFile(root, ssi, usedThreads)); - file = this._cExtensions.getDispSourceFileName(nr, ssi); - this.fileIO.generateFile("generating Node dispatcher file", filepath, infopath, file, this.generateDispatcherFile(root, ssi, usedThreads)); - } - } - } - } - } - - private CharSequence generateHeaderFile(final Root root, final SubSystemInstance ssi) { - CharSequence _xblockexpression = null; - { - final NodeRef nr = ETMapUtil.getNodeRef(ssi); - final SubSystemClass ssc = ssi.getSubSystemClass(); - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - final String clsname = (_plus + _name_1); - 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 Node "); - String _name_2 = nr.getName(); - _builder.append(_name_2, " "); - _builder.append(" with SubSystem "); - String _name_3 = ssi.getName(); - _builder.append(_name_3, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(clsname); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"etDatatypes.h\""); - _builder.newLine(); - _builder.newLine(); - CharSequence _userCode = this.helpers.userCode(ssc.getUserCode1()); - _builder.append(_userCode); - _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 "); - _builder.append(clsname); - _builder.append("_init(void);\t\t/* lifecycle init \t */"); - _builder.newLineIfNotEmpty(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_start(void);\t/* lifecycle start \t */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_run(etBool runAsTest);\t\t/* lifecycle run \t */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_stop(void); \t/* lifecycle stop\t */"); - _builder.newLineIfNotEmpty(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_destroy(void); \t/* lifecycle destroy */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_shutdown(void); /* shutdown the dispatcher loop */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode_1 = this.helpers.userCode(ssc.getUserCode2()); - _builder.append(_userCode_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(clsname); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence generateSourceFile(final Root root, final SubSystemInstance ssi, final Collection<PhysicalThread> usedThreads) { - CharSequence _xblockexpression = null; - { - final NodeRef nr = ETMapUtil.getNodeRef(ssi); - final SubSystemClass ssc = ssi.getSubSystemClass(); - String _name = nr.getName(); - String _plus = (_name + "_"); - String _name_1 = ssi.getName(); - final String clsname = (_plus + _name_1); - final Function1<PhysicalThread, Boolean> _function = (PhysicalThread t) -> { - return Boolean.valueOf(usedThreads.contains(t)); - }; - final Iterable<PhysicalThread> threads = IterableExtensions.<PhysicalThread>filter(nr.getType().getThreads(), _function); - final boolean logData = (Main.getSettings().isGenerateDataInstrumentation() && this._roomHelpers.isAnnotationPresent(ssc.getAnnotations(), "DataLogging")); - 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 Node "); - String _name_2 = nr.getName(); - _builder.append(_name_2, " "); - _builder.append(" with SubSystem "); - String _name_3 = ssi.getName(); - _builder.append(_name_3, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - _builder.append("#include <stdio.h>"); - _builder.newLine(); - _builder.append("#include <string.h>"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("#include \""); - String _cHeaderFileName = this._cExtensions.getCHeaderFileName(nr, ssi); - _builder.append(_cHeaderFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"debugging/etLogger.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etMSCLogger.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etDataLogger.h\""); - _builder.newLine(); - _builder.append("#include \"messaging/etSystemProtocol.h\""); - _builder.newLine(); - _builder.append("#include \"osal/etTimer.h\""); - _builder.newLine(); - _builder.append("#include \"osal/etSema.h\""); - _builder.newLine(); - _builder.append("#include \"runtime/etRuntime.h\""); - _builder.newLine(); - _builder.append("#include \"etRuntimeConfig.h\""); - _builder.newLine(); - _builder.newLine(); - CharSequence _userCode = this.helpers.userCode(ssc.getUserCode3()); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* data for Node "); - String _name_4 = nr.getName(); - _builder.append(_name_4); - _builder.append(" with SubSystem "); - String _name_5 = ssi.getName(); - _builder.append(_name_5); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - _builder.append("typedef struct "); - _builder.append(clsname); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("char *name;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("volatile int shutdownRequest;"); - _builder.newLine(); - _builder.append("} "); - _builder.append(clsname); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("static "); - _builder.append(clsname); - _builder.append(" "); - _builder.append(clsname); - _builder.append("Inst = {\""); - _builder.append(clsname); - _builder.append("\", 0};"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_initActorInstances(void);"); - _builder.newLineIfNotEmpty(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_constructActorInstances(void);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* include instances for all classes */"); - _builder.newLine(); - _builder.append("#include \""); - String _instSourceFileName = this._cExtensions.getInstSourceFileName(nr, ssi); - _builder.append(_instSourceFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.append("#include \""); - String _dispSourceFileName = this._cExtensions.getDispSourceFileName(nr, ssi); - _builder.append(_dispSourceFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_initMessageServices(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"initMessageServices\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("etTime interval;"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("/* initialization of all message services */"); - _builder.newLine(); - { - final Function1<PhysicalThread, Long> _function_1 = (PhysicalThread it) -> { - long _prio = it.getPrio(); - return Long.valueOf((-_prio)); - }; - List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1); - for(final PhysicalThread thread : _sortBy) { - { - if ((Objects.equal(thread.getExecmode(), ExecMode.POLLED) || Objects.equal(thread.getExecmode(), ExecMode.MIXED))) { - _builder.append("\t\t"); - _builder.append("interval.sec = "); - long _split = TimeConverter.split(thread.getTime(), TimeConverter.SEC, true); - _builder.append(_split, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("interval.nSec = "); - long _split_1 = TimeConverter.split(thread.getTime(), TimeConverter.MILLI_SEC, false); - _builder.append(_split_1, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t\t"); - _builder.append("etMessageService_init("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("&msgService_"); - String _name_6 = thread.getName(); - _builder.append(_name_6, "\t\t\t"); - _builder.append(","); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("msgBuffer_"); - String _name_7 = thread.getName(); - _builder.append(_name_7, "\t\t\t"); - _builder.append(","); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - String _upperCase = thread.getName().toUpperCase(); - _builder.append(_upperCase, "\t\t\t"); - _builder.append("_POOL_SIZE,"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - String _upperCase_1 = thread.getName().toUpperCase(); - _builder.append(_upperCase_1, "\t\t\t"); - _builder.append("_BLOCK_SIZE,"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - int _stacksize = thread.getStacksize(); - _builder.append(_stacksize, "\t\t\t"); - _builder.append(","); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - long _prio = thread.getPrio(); - _builder.append(_prio, "\t\t\t"); - _builder.append(","); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("interval,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("MsgDispatcher_"); - String _name_8 = thread.getName(); - _builder.append(_name_8, "\t\t\t"); - _builder.append("_receiveMessage,"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("EXECMODE_"); - String _upperCase_2 = thread.getExecmode().toString().toUpperCase(); - _builder.append(_upperCase_2, "\t\t\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_startMessageServices(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"startMessageServices\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - final Function1<PhysicalThread, Long> _function_2 = (PhysicalThread it) -> { - long _prio_1 = it.getPrio(); - return Long.valueOf((-_prio_1)); - }; - List<PhysicalThread> _sortBy_1 = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_2); - for(final PhysicalThread thread_1 : _sortBy_1) { - _builder.append("\t"); - _builder.append("etMessageService_start(&msgService_"); - String _name_9 = thread_1.getName(); - _builder.append(_name_9, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_stopMessageServices(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"stopMessageServices\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - for(final PhysicalThread thread_2 : threads) { - _builder.append("\t"); - _builder.append("etMessageService_stop(&msgService_"); - String _name_10 = thread_2.getName(); - _builder.append(_name_10, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_destroyMessageServices(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"destroyMessageServices\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - for(final PhysicalThread thread_3 : threads) { - _builder.append("\t"); - _builder.append("etMessageService_destroy(&msgService_"); - String _name_11 = thread_3.getName(); - _builder.append(_name_11, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_init(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"init\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("etLogger_logInfoF(\"%s_init\", "); - _builder.append(clsname, "\t"); - _builder.append("Inst.name);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* construct all actors */"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_constructActorInstances();"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* initialization of all message services */"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_initMessageServices();"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* init all actors */"); - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_initActorInstances();"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - if (logData) { - { - for(final PhysicalThread thread_4 : threads) { - _builder.append("\t"); - _builder.append("MsgDispatcher_"); - String _name_12 = thread_4.getName(); - _builder.append(_name_12, "\t"); - _builder.append("_logDataHeaders();"); - _builder.newLineIfNotEmpty(); - } - } - { - for(final PhysicalThread thread_5 : threads) { - _builder.append("\t"); - _builder.append("MsgDispatcher_"); - String _name_13 = thread_5.getName(); - _builder.append(_name_13, "\t"); - _builder.append("_logData();"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_start(void) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"start\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("etLogger_logInfoF(\"%s_start\", "); - _builder.append(clsname, "\t"); - _builder.append("Inst.name);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_startMessageServices();"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_run(etBool runAsTest) {"); - _builder.newLineIfNotEmpty(); - _builder.append("#ifdef ET_RUNNER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"run\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("if (runAsTest) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("etSema_waitForWakeup(etRuntime_getTerminateSemaphore());"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("else {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("printf(\"type quit to exit\\n\");"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("fflush(stdout);"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("while (ET_TRUE) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("char line[64];"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("if (fgets(line, 64, stdin) != NULL) {"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("if (strncmp(line, \"quit\", 4)==0)"); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("break;"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("#endif"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_stop(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"stop\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("etLogger_logInfoF(\"%s_stop\", "); - _builder.append(clsname, "\t"); - _builder.append("Inst.name);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_stopMessageServices();"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_destroy(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"destroy\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("etLogger_logInfoF(\"%s_destroy\", "); - _builder.append(clsname, "\t"); - _builder.append("Inst.name);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances(); - for(final ActorInstance ai : _allContainedInstances) { - _builder.append("\t"); - ActorClass _actorClass = ai.getActorClass(); - String _pathName = this._roomExtensions.getPathName(ai.getPath()); - String _plus_1 = ("&" + _pathName); - String _invokeUserStructor = this.helpers.invokeUserStructor(_actorClass, _plus_1, false); - _builder.append(_invokeUserStructor, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("_destroyMessageServices();"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("void "); - _builder.append(clsname); - _builder.append("_shutdown(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"shutdown\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("etLogger_logInfoF(\"%s_shutdown\", "); - _builder.append(clsname, "\t"); - _builder.append("Inst.name);"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append(clsname, "\t"); - _builder.append("Inst.shutdownRequest = 1;"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_constructActorInstances(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"constructActorInstances\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances_1 = ssi.getAllContainedInstances(); - for(final ActorInstance ai_1 : _allContainedInstances_1) { - _builder.append("\t"); - ActorClass _actorClass_1 = ai_1.getActorClass(); - String _pathName_1 = this._roomExtensions.getPathName(ai_1.getPath()); - String _plus_2 = ("&" + _pathName_1); - String _invokeUserStructor_1 = this.helpers.invokeUserStructor(_actorClass_1, _plus_2, true); - _builder.append(_invokeUserStructor_1, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("static void "); - _builder.append(clsname); - _builder.append("_initActorInstances(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(clsname, "\t"); - _builder.append("\", \"initActorInstances\")"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances_2 = ssi.getAllContainedInstances(); - for(final ActorInstance ai_2 : _allContainedInstances_2) { - _builder.append("\t"); - String _name_14 = ai_2.getActorClass().getName(); - _builder.append(_name_14, "\t"); - _builder.append("_init(&"); - String _pathName_2 = this._roomExtensions.getPathName(ai_2.getPath()); - _builder.append(_pathName_2, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence generateInstanceFile(final Root root, final SubSystemInstance ssi, final Collection<PhysicalThread> usedThreads) { - CharSequence _xblockexpression = null; - { - final NodeRef nr = ETMapUtil.getNodeRef(ssi); - 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 Node "); - String _name = nr.getName(); - _builder.append(_name, " "); - _builder.append(" with SubSystem "); - String _name_1 = ssi.getName(); - _builder.append(_name_1, " "); - _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 \"messaging/etMessageService.h\""); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* include all referenced room classes */"); - _builder.newLine(); - { - EList<ActorClass> _referencedActorClasses = root.getReferencedActorClasses(ssi.getSubSystemClass()); - EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ssi.getSubSystemClass()); - final Function1<RoomClass, String> _function = (RoomClass it) -> { - return it.getName(); - }; - List<RoomClass> _sortBy = IterableExtensions.<RoomClass, String>sortBy(Iterables.<RoomClass>concat(_referencedActorClasses, _referencedProtocolClasses), _function); - for(final RoomClass dc : _sortBy) { - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(dc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* instantiation of message services and message buffers */"); - _builder.newLine(); - { - final Function1<PhysicalThread, Boolean> _function_1 = (PhysicalThread t) -> { - return Boolean.valueOf(usedThreads.contains(t)); - }; - Iterable<PhysicalThread> _filter = IterableExtensions.<PhysicalThread>filter(nr.getType().getThreads(), _function_1); - for(final PhysicalThread thread : _filter) { - _builder.append("/* "); - String _name_2 = thread.getName(); - _builder.append(_name_2); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _upperCase = thread.getName().toUpperCase(); - _builder.append(_upperCase); - _builder.append("_POOL_SIZE\t\t"); - int _msgpoolsize = thread.getMsgpoolsize(); - _builder.append(_msgpoolsize); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _upperCase_1 = thread.getName().toUpperCase(); - _builder.append(_upperCase_1); - _builder.append("_BLOCK_SIZE\t"); - int _msgblocksize = thread.getMsgblocksize(); - _builder.append(_msgblocksize); - _builder.newLineIfNotEmpty(); - _builder.append("static uint8 msgBuffer_"); - String _name_3 = thread.getName(); - _builder.append(_name_3); - _builder.append("["); - String _upperCase_2 = thread.getName().toUpperCase(); - _builder.append(_upperCase_2); - _builder.append("_POOL_SIZE * "); - String _upperCase_3 = thread.getName().toUpperCase(); - _builder.append(_upperCase_3); - _builder.append("_BLOCK_SIZE];"); - _builder.newLineIfNotEmpty(); - _builder.append("static etMessageService msgService_"); - String _name_4 = thread.getName(); - _builder.append(_name_4); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* declarations of all ActorClass instances (const and variable structs) */"); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* forward declaration of variable actor structs */"); - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances = ssi.getAllContainedInstances(); - for(final ActorInstance ai : _allContainedInstances) { - _builder.append("static "); - String _name_5 = ai.getActorClass().getName(); - _builder.append(_name_5); - _builder.append(" "); - String _pathName = this._roomExtensions.getPathName(ai.getPath()); - _builder.append(_pathName); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* forward declaration of variable port structs */"); - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances_1 = ssi.getAllContainedInstances(); - for(final ActorInstance ai_1 : _allContainedInstances_1) { - { - boolean _isEmpty = ai_1.getOrderedIfItemInstances().isEmpty(); - if (_isEmpty) { - _builder.append("/* nothing to do */"); - _builder.newLine(); - } else { - { - EList<InterfaceItemInstance> _orderedIfItemInstances = ai_1.getOrderedIfItemInstances(); - for(final InterfaceItemInstance pi : _orderedIfItemInstances) { - { - PortClass _portClass = this._roomExtensions.getPortClass(pi.getProtocol(), this._roomExtensions.isConjugated(pi)); - EList<Attribute> _attributes = null; - if (_portClass!=null) { - _attributes=_portClass.getAttributes(); - } - int _size = 0; - if (_attributes!=null) { - _size=_attributes.size(); - } - boolean _greaterThan = (_size > 0); - if (_greaterThan) { - _builder.append("static "); - String _portClassName = this._roomExtensions.getPortClassName(pi.getProtocol(), this._roomExtensions.isConjugated(pi)); - _builder.append(_portClassName); - _builder.append("_var "); - String _pathName_1 = this._roomExtensions.getPathName(pi.getPath()); - _builder.append(_pathName_1); - _builder.append("_var"); - { - boolean _isReplicated = pi.isReplicated(); - if (_isReplicated) { - _builder.append("["); - int _size_1 = pi.getPeers().size(); - _builder.append(_size_1); - _builder.append("]"); - } - } - _builder.append("={"); - _builder.newLineIfNotEmpty(); - { - int _xifexpression = (int) 0; - int _size_2 = pi.getPeers().size(); - boolean _equals = (_size_2 == 0); - if (_equals) { - _xifexpression = 1; - } else { - _xifexpression = pi.getPeers().size(); - } - IntegerRange _upTo = new IntegerRange(1, _xifexpression); - boolean _hasElements = false; - for(final Integer i : _upTo) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", "\t"); - } - _builder.append("\t"); - CharSequence _generateAttributeInit = this.attrInitGenAddon.generateAttributeInit(pi, this._roomHelpers.getPortClass(pi.getInterfaceItem()).getAttributes()); - _builder.append(_generateAttributeInit, "\t"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t\t\t"); - } - } - _builder.append("};"); - _builder.newLineIfNotEmpty(); - } - } - } - } - } - } - } - } - _builder.newLine(); - { - EList<ActorInstance> _allContainedInstances_2 = ssi.getAllContainedInstances(); - for(final ActorInstance ai_2 : _allContainedInstances_2) { - _builder.newLine(); - _builder.append("/* instance "); - String _pathName_2 = this._roomExtensions.getPathName(ai_2.getPath()); - _builder.append(_pathName_2); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - { - if (((!Main.getSettings().isGenerateMSCInstrumentation()) && ai_2.getOrderedIfItemInstances().isEmpty())) { - _builder.append("/* no ports/saps/services - nothing to initialize statically */"); - _builder.newLine(); - } else { - CharSequence _genActorInstanceInitializer = this.genActorInstanceInitializer(root, ai_2); - _builder.append(_genActorInstanceInitializer); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence genActorInstanceInitializer(final Root root, final ActorInstance ai) { - CharSequence _xblockexpression = null; - { - final String instName = this._roomExtensions.getPathName(ai.getPath()); - final ArrayList<InterfaceItemInstance> replEventItems = new ArrayList<InterfaceItemInstance>(); - final Function1<InterfaceItemInstance, Boolean> _function = (InterfaceItemInstance e) -> { - return Boolean.valueOf(e.isReplicated()); - }; - Iterables.<InterfaceItemInstance>addAll(replEventItems, IterableExtensions.<InterfaceItemInstance>filter(ai.getOrderedIfItemInstances(), _function)); - final Function1<InterfaceItemInstance, Boolean> _function_1 = (InterfaceItemInstance e) -> { - boolean _isEmpty = e.getPeers().isEmpty(); - return Boolean.valueOf((!_isEmpty)); - }; - InterfaceItemInstance _findFirst = IterableExtensions.<InterfaceItemInstance>findFirst(replEventItems, _function_1); - final boolean haveReplSubItems = (!Objects.equal(_findFirst, null)); - final Function1<InterfaceItemInstance, Boolean> _function_2 = (InterfaceItemInstance i) -> { - InterfaceItem _interfaceItem = i.getInterfaceItem(); - return Boolean.valueOf((_interfaceItem instanceof Port)); - }; - final Iterable<InterfaceItemInstance> replEventPorts = IterableExtensions.<InterfaceItemInstance>filter(replEventItems, _function_2); - final Function1<InterfaceItemInstance, Boolean> _function_3 = (InterfaceItemInstance i) -> { - InterfaceItem _interfaceItem = i.getInterfaceItem(); - return Boolean.valueOf((_interfaceItem instanceof SPP)); - }; - final Iterable<InterfaceItemInstance> replEventSPPs = IterableExtensions.<InterfaceItemInstance>filter(replEventItems, _function_3); - final Function1<InterfaceItemInstance, Boolean> _function_4 = (InterfaceItemInstance e) -> { - return Boolean.valueOf(e.isSimple()); - }; - final Iterable<InterfaceItemInstance> simplePorts = IterableExtensions.<InterfaceItemInstance>filter(ai.getOrderedIfItemInstances(), _function_4); - final ArrayList<InterfaceItemInstance> simpleEventItems = new ArrayList<InterfaceItemInstance>(); - final Function1<InterfaceItemInstance, Boolean> _function_5 = (InterfaceItemInstance p) -> { - CommunicationType _commType = p.getProtocol().getCommType(); - return Boolean.valueOf(Objects.equal(_commType, CommunicationType.EVENT_DRIVEN)); - }; - Iterables.<InterfaceItemInstance>addAll(simpleEventItems, IterableExtensions.<InterfaceItemInstance>filter(simplePorts, _function_5)); - final Function1<InterfaceItemInstance, Boolean> _function_6 = (InterfaceItemInstance i) -> { - InterfaceItem _interfaceItem = i.getInterfaceItem(); - return Boolean.valueOf((_interfaceItem instanceof Port)); - }; - final Iterable<InterfaceItemInstance> simpleEventPorts = IterableExtensions.<InterfaceItemInstance>filter(simpleEventItems, _function_6); - final Function1<InterfaceItemInstance, Boolean> _function_7 = (InterfaceItemInstance i) -> { - InterfaceItem _interfaceItem = i.getInterfaceItem(); - return Boolean.valueOf((_interfaceItem instanceof SAP)); - }; - final Iterable<InterfaceItemInstance> simpleEventSAPs = IterableExtensions.<InterfaceItemInstance>filter(simpleEventItems, _function_7); - final Function1<InterfaceItemInstance, Boolean> _function_8 = (InterfaceItemInstance p) -> { - CommunicationType _commType = p.getProtocol().getCommType(); - return Boolean.valueOf(Objects.equal(_commType, CommunicationType.DATA_DRIVEN)); - }; - final Iterable<InterfaceItemInstance> dataPorts = IterableExtensions.<InterfaceItemInstance>filter(simplePorts, _function_8); - final Function1<InterfaceItemInstance, Boolean> _function_9 = (InterfaceItemInstance p) -> { - return Boolean.valueOf(((p instanceof PortInstance) && (!((PortInstance) p).getPort().isConjugated()))); - }; - final Iterable<InterfaceItemInstance> recvPorts = IterableExtensions.<InterfaceItemInstance>filter(dataPorts, _function_9); - final Function1<InterfaceItemInstance, Boolean> _function_10 = (InterfaceItemInstance p) -> { - return Boolean.valueOf(((p instanceof PortInstance) && ((PortInstance) p).getPort().isConjugated())); - }; - final Iterable<InterfaceItemInstance> sendPorts = IterableExtensions.<InterfaceItemInstance>filter(dataPorts, _function_10); - final HashMap<InterfaceItemInstance, Integer> offsets = new HashMap<InterfaceItemInstance, Integer>(); - int offset = 0; - for (final InterfaceItemInstance p : replEventItems) { - { - offsets.put(p, Integer.valueOf(offset)); - int _size = p.getPeers().size(); - int _plus = (offset + _size); - offset = _plus; - } - } - String _xifexpression = null; - if (haveReplSubItems) { - _xifexpression = (instName + "_repl_sub_ports"); - } else { - _xifexpression = "NULL"; - } - String replSubPortsArray = _xifexpression; - final boolean haveConstData = ((((!simpleEventItems.isEmpty()) || (!IterableExtensions.isEmpty(recvPorts))) || (!replEventItems.isEmpty())) || Main.getSettings().isGenerateMSCInstrumentation()); - final IntelligentSeparator sep = new IntelligentSeparator(","); - String _xifexpression_1 = null; - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _xifexpression_1 = "/*const*/"; - } else { - _xifexpression_1 = "const"; - } - final String const_ = _xifexpression_1; - StringConcatenation _builder = new StringConcatenation(); - { - boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_1) { - CharSequence _genPeerPortArrays = this.genPeerPortArrays(root, ai); - _builder.append(_genPeerPortArrays); - _builder.newLineIfNotEmpty(); - } - } - { - if (haveReplSubItems) { - _builder.append("static const etReplSubPort "); - _builder.append(replSubPortsArray); - _builder.append("["); - _builder.append(offset); - _builder.append("] = {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("/* Replicated Sub Ports: {varData, msgService, peerAddress, localId, index} */"); - _builder.newLine(); - { - final Function1<InterfaceItemInstance, Boolean> _function_11 = (InterfaceItemInstance e) -> { - boolean _isEmpty = e.getPeers().isEmpty(); - return Boolean.valueOf((!_isEmpty)); - }; - Iterable<InterfaceItemInstance> _filter = IterableExtensions.<InterfaceItemInstance>filter(replEventItems, _function_11); - boolean _hasElements = false; - for(final InterfaceItemInstance pi : _filter) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(",", "\t"); - } - _builder.append("\t"); - String _genReplSubPortInitializers = this.genReplSubPortInitializers(root, ai, pi); - _builder.append(_genReplSubPortInitializers, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("};"); - _builder.newLine(); - } - } - { - if (haveConstData) { - _builder.append("static "); - _builder.append(const_); - _builder.append(" "); - String _name = ai.getActorClass().getName(); - _builder.append(_name); - _builder.append("_const "); - _builder.append(instName); - _builder.append("_const = {"); - _builder.newLineIfNotEmpty(); - { - boolean _isGenerateMSCInstrumentation_2 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_2) { - _builder.append("\t"); - _builder.append(sep, "\t"); - _builder.append("\""); - String _path = ai.getPath(); - _builder.append(_path, "\t"); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("/* Ports: {varData, msgService, peerAddress, localId} */"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* simple ports */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_1 : simpleEventPorts) { - _builder.append("\t"); - _builder.append(sep, "\t"); - String _genPortInitializer = this.genPortInitializer(root, ai, pi_1); - _builder.append(_genPortInitializer, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* data receive ports */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_2 : recvPorts) { - _builder.append("\t"); - _builder.append(sep, "\t"); - String _genRecvPortInitializer = this.genRecvPortInitializer(root, ai, pi_2); - _builder.append(_genRecvPortInitializer, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* saps */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_3 : simpleEventSAPs) { - _builder.append("\t"); - _builder.append(sep, "\t"); - String _genPortInitializer_1 = this.genPortInitializer(root, ai, pi_3); - _builder.append(_genPortInitializer_1, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* replicated ports */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_4 : replEventPorts) { - _builder.append("\t"); - _builder.append(sep, "\t"); - _builder.append("{"); - int _size = pi_4.getPeers().size(); - _builder.append(_size, "\t"); - _builder.append(", "); - _builder.append(replSubPortsArray, "\t"); - _builder.append("+"); - Integer _get = offsets.get(pi_4); - _builder.append(_get, "\t"); - _builder.append("}"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* services */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_5 : replEventSPPs) { - _builder.append("\t"); - _builder.append(sep, "\t"); - _builder.append("{"); - int _size_1 = pi_5.getPeers().size(); - _builder.append(_size_1, "\t"); - _builder.append(", "); - _builder.append(replSubPortsArray, "\t"); - _builder.append("+"); - Integer _get_1 = offsets.get(pi_5); - _builder.append(_get_1, "\t"); - _builder.append("}"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("};"); - _builder.newLine(); - } - } - _builder.append("static "); - String _name_1 = ai.getActorClass().getName(); - _builder.append(_name_1); - _builder.append(" "); - _builder.append(instName); - _builder.append(" = {"); - _builder.newLineIfNotEmpty(); - { - if (haveConstData) { - _builder.append("\t"); - _builder.append("&"); - _builder.append(instName, "\t"); - _builder.append("_const,"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("/* data send ports */"); - _builder.newLine(); - { - for(final InterfaceItemInstance pi_6 : sendPorts) { - _builder.append("\t"); - CharSequence _genSendPortInitializer = this.genSendPortInitializer(pi_6); - _builder.append(_genSendPortInitializer, "\t"); - _builder.append(","); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* attributes */"); - _builder.newLine(); - _builder.append("\t"); - CharSequence _generateAttributeInit = this.attrInitGenAddon.generateAttributeInit(ai, this._roomHelpers.getAllAttributes(ai.getActorClass())); - _builder.append(_generateAttributeInit, "\t"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* state and history are initialized in init function */"); - _builder.newLine(); - _builder.append("};"); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence genPeerPortArrays(final Root root, final ActorInstance ai) { - CharSequence _xblockexpression = null; - { - final Function1<InterfaceItemInstance, Boolean> _function = (InterfaceItemInstance e) -> { - return Boolean.valueOf((e.isSimple() && (e instanceof PortInstance))); - }; - final Function1<InterfaceItemInstance, PortInstance> _function_1 = (InterfaceItemInstance inst) -> { - return ((PortInstance) inst); - }; - final Iterable<PortInstance> simplePorts = IterableExtensions.<InterfaceItemInstance, PortInstance>map(IterableExtensions.<InterfaceItemInstance>filter(ai.getOrderedIfItemInstances(), _function), _function_1); - final Function1<PortInstance, Boolean> _function_2 = (PortInstance p) -> { - return Boolean.valueOf((p.getPort().isConjugated() && Objects.equal(p.getProtocol().getCommType(), CommunicationType.DATA_DRIVEN))); - }; - final Iterable<PortInstance> sendPorts = IterableExtensions.<PortInstance>filter(simplePorts, _function_2); - final Function1<PortInstance, Boolean> _function_3 = (PortInstance p) -> { - final Function1<Message, Boolean> _function_4 = (Message m) -> { - return Boolean.valueOf((this._typeHelpers.isEnumeration(m.getData().getRefType().getType()) || this._typeHelpers.isBoolean(m.getData().getRefType().getType()))); - }; - boolean _isEmpty = IterableExtensions.isEmpty(IterableExtensions.<Message>filter(this._roomHelpers.getOutgoing(p.getPort()), _function_4)); - return Boolean.valueOf((!_isEmpty)); - }; - final Iterable<PortInstance> loggedPorts = IterableExtensions.<PortInstance>filter(sendPorts, _function_3); - StringConcatenation _builder = new StringConcatenation(); - { - boolean _isEmpty = IterableExtensions.isEmpty(loggedPorts); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - { - for(final PortInstance pi : loggedPorts) { - _builder.append("static const char* "); - String _pathName = this._roomExtensions.getPathName(pi.getPath()); - _builder.append(_pathName); - _builder.append("_peers["); - int _size = pi.getPeers().size(); - int _plus = (_size + 1); - _builder.append(_plus); - _builder.append("] = {"); - _builder.newLineIfNotEmpty(); - { - EList<InterfaceItemInstance> _peers = pi.getPeers(); - for(final InterfaceItemInstance peer : _peers) { - _builder.append("\t"); - _builder.append("\""); - EObject _eContainer = peer.eContainer(); - String _path = ((ActorInstance) _eContainer).getPath(); - _builder.append(_path, "\t"); - _builder.append("\","); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t"); - _builder.append("NULL"); - _builder.newLine(); - _builder.append("};"); - _builder.newLine(); - } - } - _builder.append("#endif"); - _builder.newLine(); - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private String genPortInitializer(final Root root, final ActorInstance ai, final InterfaceItemInstance pi) { - String _xblockexpression = null; - { - int _xifexpression = (int) 0; - boolean _isEmpty = pi.getPeers().isEmpty(); - if (_isEmpty) { - _xifexpression = 0; - } else { - _xifexpression = pi.getPeers().get(0).getObjId(); - } - final int objId = _xifexpression; - int _xifexpression_1 = (int) 0; - boolean _isEmpty_1 = pi.getPeers().isEmpty(); - if (_isEmpty_1) { - _xifexpression_1 = 0; - } else { - _xifexpression_1 = pi.getPeers().get(0).getPeers().indexOf(pi); - } - final int idx = _xifexpression_1; - String _xifexpression_2 = null; - boolean _isEmpty_2 = pi.getPeers().isEmpty(); - if (_isEmpty_2) { - _xifexpression_2 = "NULL"; - } else { - EObject _eContainer = pi.getPeers().get(0).eContainer(); - String _name = ETMapUtil.getMappedThread(((ActorInstance) _eContainer)).getThread().getName(); - _xifexpression_2 = ("&msgService_" + _name); - } - final String msgSvc = _xifexpression_2; - String myInst = ""; - String peerInst = ""; - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - EObject _eContainer_1 = pi.eContainer(); - String _path = ((ActorInstance) _eContainer_1).getPath(); - String _plus = ("\n#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE\n,\"" + _path); - String _plus_1 = (_plus + "\","); - myInst = _plus_1; - String _xifexpression_3 = null; - boolean _isEmpty_3 = pi.getPeers().isEmpty(); - boolean _not = (!_isEmpty_3); - if (_not) { - EObject _eContainer_2 = pi.getPeers().get(0).eContainer(); - String _path_1 = ((ActorInstance) _eContainer_2).getPath(); - String _plus_2 = ("\"" + _path_1); - _xifexpression_3 = (_plus_2 + "\"\n#endif\n"); - } else { - _xifexpression_3 = "\n#endif\n"; - } - peerInst = _xifexpression_3; - } - String _interfaceItemInstanceData = this.getInterfaceItemInstanceData(pi); - String _plus_3 = ("{" + _interfaceItemInstanceData); - String _plus_4 = (_plus_3 + ", "); - String _plus_5 = (_plus_4 + msgSvc); - String _plus_6 = (_plus_5 + ", "); - String _plus_7 = (_plus_6 + Integer.valueOf((objId + idx))); - String _plus_8 = (_plus_7 + "+BASE_ADDRESS, "); - int _interfaceItemLocalId = root.getExpandedActorClass(ai).getInterfaceItemLocalId(pi.getInterfaceItem()); - int _plus_9 = (_interfaceItemLocalId + 1); - String _plus_10 = (_plus_8 + Integer.valueOf(_plus_9)); - String _plus_11 = (_plus_10 + myInst); - String _plus_12 = (_plus_11 + peerInst); - String _plus_13 = (_plus_12 + "} /* Port "); - String _name_1 = pi.getName(); - String _plus_14 = (_plus_13 + _name_1); - _xblockexpression = (_plus_14 + " */"); - } - return _xblockexpression; - } - - private CharSequence genSendPortInitializer(final InterfaceItemInstance pi) { - CharSequence _xblockexpression = null; - { - GeneralProtocolClass _protocol = ((PortInstance) pi).getPort().getProtocol(); - final ProtocolClass pc = ((ProtocolClass) _protocol); - final Function1<Message, Boolean> _function = (Message m) -> { - VarDecl _data = m.getData(); - return Boolean.valueOf((!Objects.equal(_data, null))); - }; - Iterable<Message> messages = IterableExtensions.<Message>filter(this._roomHelpers.getAllIncomingMessages(pc), _function); - final Function1<Message, Boolean> _function_1 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isEnumeration(m.getData().getRefType().getType())); - }; - final Iterable<Message> enumMsgs = IterableExtensions.<Message>filter(messages, _function_1); - final Function1<Message, Boolean> _function_2 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isBoolean(m.getData().getRefType().getType())); - }; - final Iterable<Message> boolMsgs = IterableExtensions.<Message>filter(messages, _function_2); - final boolean usesMSC = (Main.getSettings().isGenerateMSCInstrumentation() && (!(IterableExtensions.isEmpty(enumMsgs) && IterableExtensions.isEmpty(boolMsgs)))); - EObject _eContainer = pi.eContainer(); - final String instName = ((ActorInstance) _eContainer).getPath(); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("{"); - _builder.newLine(); - { - EList<Message> _incomingMessages = pc.getIncomingMessages(); - boolean _hasElements = false; - for(final Message m : _incomingMessages) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(",", "\t"); - } - _builder.append("\t"); - String _defaultValue = this._cExtensions.defaultValue(m.getData().getRefType().getType()); - _builder.append(_defaultValue, "\t"); - _builder.newLineIfNotEmpty(); - } - } - { - if (usesMSC) { - _builder.append("\t"); - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(", \""); - _builder.append(instName, "\t\t"); - _builder.append("\","); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - String _pathName = this._roomExtensions.getPathName(pi.getPath()); - _builder.append(_pathName, "\t\t"); - _builder.append("_peers"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("#endif"); - _builder.newLine(); - } - } - _builder.append("} /* send port "); - String _name = pi.getName(); - _builder.append(_name); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private String getInterfaceItemInstanceData(final InterfaceItemInstance pi) { - PortClass _portClass = this._roomExtensions.getPortClass(pi.getProtocol(), this._roomExtensions.isConjugated(pi)); - boolean _equals = Objects.equal(_portClass, null); - if (_equals) { - return "NULL"; - } - boolean _isEmpty = this._roomExtensions.getPortClass(pi.getProtocol(), this._roomExtensions.isConjugated(pi)).getAttributes().isEmpty(); - if (_isEmpty) { - return "NULL"; - } else { - String _pathName = this._roomExtensions.getPathName(pi.getPath()); - String _plus = ("&" + _pathName); - return (_plus + "_var"); - } - } - - private String genRecvPortInitializer(final Root root, final ActorInstance ai, final InterfaceItemInstance pi) { - String _xblockexpression = null; - { - final Function1<Message, Boolean> _function = (Message m) -> { - VarDecl _data = m.getData(); - return Boolean.valueOf((!Objects.equal(_data, null))); - }; - Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(this._roomHelpers.getIncoming(pi.getInterfaceItem()), _function); - final Function1<Message, Boolean> _function_1 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isEnumeration(m.getData().getRefType().getType())); - }; - final Iterable<Message> enumMsgs = IterableExtensions.<Message>filter(sentMsgs, _function_1); - final Function1<Message, Boolean> _function_2 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isBoolean(m.getData().getRefType().getType())); - }; - final Iterable<Message> boolMsgs = IterableExtensions.<Message>filter(sentMsgs, _function_2); - final boolean usesMSC = (Main.getSettings().isGenerateMSCInstrumentation() && (!(IterableExtensions.isEmpty(enumMsgs) && IterableExtensions.isEmpty(boolMsgs)))); - String enumVal = ""; - if (usesMSC) { - String _path = ai.getPath(); - String _plus = ("\n, \"" + _path); - String _plus_1 = (_plus + "\""); - enumVal = _plus_1; - for (final Message msg : enumMsgs) { - String _defaultValue = this._cExtensions.defaultValue(msg.getData().getRefType().getType()); - String _plus_2 = ((enumVal + "\n, ") + _defaultValue); - enumVal = _plus_2; - } - for (final Message msg_1 : boolMsgs) { - String _defaultValue_1 = this._cExtensions.defaultValue(msg_1.getData().getRefType().getType()); - String _plus_3 = ((enumVal + "\n, ") + _defaultValue_1); - enumVal = _plus_3; - } - enumVal = (("\n#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE" + enumVal) + "\n#endif\n"); - } - boolean _isEmpty = pi.getPeers().isEmpty(); - if (_isEmpty) { - return (("{NULL" + enumVal) + "}"); - } - InterfaceItemInstance peer = pi.getPeers().get(0); - EObject _eContainer = pi.getPeers().get(0).eContainer(); - ActorInstance peerInst = ((ActorInstance) _eContainer); - String instName = this._roomExtensions.getPathName(peerInst.getPath()); - String _name = peer.getName(); - String _plus_4 = ((("{&" + instName) + ".") + _name); - String _plus_5 = (_plus_4 + enumVal); - _xblockexpression = (_plus_5 + "}"); - } - return _xblockexpression; - } - - private String genReplSubPortInitializers(final Root root, final ActorInstance ai, final InterfaceItemInstance pi) { - String result = ""; - String _xifexpression = null; - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - EObject _eContainer = pi.eContainer(); - String _path = ((ActorInstance) _eContainer).getPath(); - String _plus = ("\n#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE\n,\"" + _path); - _xifexpression = (_plus + "\"\n"); - } else { - _xifexpression = ""; - } - final String myInst = _xifexpression; - EList<InterfaceItemInstance> _peers = pi.getPeers(); - for (final InterfaceItemInstance p : _peers) { - { - final int idx = pi.getPeers().indexOf(p); - String _xifexpression_1 = null; - int _size = pi.getPeers().size(); - int _minus = (_size - 1); - boolean _lessThan = (idx < _minus); - if (_lessThan) { - _xifexpression_1 = ","; - } else { - _xifexpression_1 = ""; - } - final String comma = _xifexpression_1; - EObject _eContainer_1 = p.eContainer(); - final String thread = ETMapUtil.getMappedThread(((ActorInstance) _eContainer_1)).getThread().getName(); - String iiiD = this.getInterfaceItemInstanceData(pi); - String _xifexpression_2 = null; - boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_1) { - EObject _eContainer_2 = p.eContainer(); - String _path_1 = ((ActorInstance) _eContainer_2).getPath(); - String _plus_1 = (",\"" + _path_1); - _xifexpression_2 = (_plus_1 + "\"\n#endif\n"); - } else { - _xifexpression_2 = ""; - } - final String peerInst = _xifexpression_2; - String _xifexpression_3 = null; - boolean _equals = iiiD.equals("NULL"); - if (_equals) { - _xifexpression_3 = (iiiD + ","); - } else { - _xifexpression_3 = (((iiiD + "[") + Integer.valueOf(idx)) + "],"); - } - iiiD = _xifexpression_3; - int _objId = p.getObjId(); - String _plus_2 = ((((((result + - "{{") + iiiD) + "&msgService_") + thread) + ", ") + Integer.valueOf(_objId)); - String _plus_3 = (_plus_2 + "+BASE_ADDRESS, "); - int _interfaceItemLocalId = root.getExpandedActorClass(ai).getInterfaceItemLocalId(pi.getInterfaceItem()); - int _plus_4 = (_interfaceItemLocalId + 1); - String _plus_5 = (_plus_3 + Integer.valueOf(_plus_4)); - String _plus_6 = (_plus_5 + myInst); - String _plus_7 = (_plus_6 + peerInst); - String _plus_8 = (_plus_7 + "},"); - String _plus_9 = (_plus_8 + Integer.valueOf(idx)); - String _plus_10 = (_plus_9 + "}"); - String _plus_11 = (_plus_10 + comma); - String _plus_12 = (_plus_11 + " /* Repl Sub Port "); - String _name = pi.getName(); - String _plus_13 = (_plus_12 + _name); - String _plus_14 = (_plus_13 + " idx +"); - String _plus_15 = (_plus_14 + Integer.valueOf(idx)); - String _plus_16 = (_plus_15 + "*/\n"); - result = _plus_16; - } - } - return result; - } - - private CharSequence generateDispatcherFile(final Root root, final SubSystemInstance ssi, final Collection<PhysicalThread> usedThreads) { - CharSequence _xblockexpression = null; - { - final NodeRef nr = ETMapUtil.getNodeRef(ssi); - final boolean logData = (Main.getSettings().isGenerateDataInstrumentation() && this._roomHelpers.isAnnotationPresent(ssi.getSubSystemClass().getAnnotations(), "DataLogging")); - ArrayList<PortInstance> _xifexpression = null; - if (logData) { - _xifexpression = this.loggedPorts(ssi); - } else { - _xifexpression = CollectionLiterals.<PortInstance>newArrayList(); - } - final ArrayList<PortInstance> loggedPorts = _xifexpression; - 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("* Dispatcher File of Node "); - String _name = nr.getName(); - _builder.append(_name, " "); - _builder.append(" with SubSystem "); - String _name_1 = ssi.getName(); - _builder.append(_name_1, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("* contains a generated message dispatcher (receiveMessage) for each MessageService (Thread)"); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - _builder.append("#include \"messaging/etMessageReceiver.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etLogger.h\""); - _builder.newLine(); - _builder.append("#include \"debugging/etMSCLogger.h\""); - _builder.newLine(); - _builder.newLine(); - { - final Function1<PhysicalThread, Boolean> _function = (PhysicalThread t) -> { - return Boolean.valueOf(usedThreads.contains(t)); - }; - Iterable<PhysicalThread> _filter = IterableExtensions.<PhysicalThread>filter(nr.getType().getThreads(), _function); - boolean _hasElements = false; - for(final PhysicalThread thread : _filter) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate("\n", ""); - } - final Function1<ActorInstance, Boolean> _function_1 = (ActorInstance ai) -> { - PhysicalThread _thread = ETMapUtil.getMappedThread(ai).getThread(); - return Boolean.valueOf(Objects.equal(_thread, thread)); - }; - final Iterable<ActorInstance> instancesOnThread = IterableExtensions.<ActorInstance>filter(ssi.getAllContainedInstances(), _function_1); - _builder.newLineIfNotEmpty(); - final Function1<ActorInstance, Boolean> _function_2 = (ActorInstance ai) -> { - return Boolean.valueOf((Objects.equal(ai.getActorClass().getCommType(), ComponentCommunicationType.EVENT_DRIVEN) || Objects.equal(ai.getActorClass().getCommType(), ComponentCommunicationType.ASYNCHRONOUS))); - }; - final Iterable<ActorInstance> dispatchedInstances = IterableExtensions.<ActorInstance>filter(instancesOnThread, _function_2); - _builder.newLineIfNotEmpty(); - final Function1<ActorInstance, Boolean> _function_3 = (ActorInstance ai) -> { - return Boolean.valueOf((Objects.equal(ai.getActorClass().getCommType(), ComponentCommunicationType.DATA_DRIVEN) || Objects.equal(ai.getActorClass().getCommType(), ComponentCommunicationType.ASYNCHRONOUS))); - }; - final Iterable<ActorInstance> executedInstances = IterableExtensions.<ActorInstance>filter(instancesOnThread, _function_3); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - int _size = IterableExtensions.size(executedInstances); - boolean _greaterThan = (_size > 0); - if (_greaterThan) { - _builder.append("/**"); - _builder.newLine(); - _builder.append(" "); - _builder.append("* generated execute function for all cyclic execute calls for the async or datadriven actor instances of thread \""); - String _name_2 = thread.getName(); - _builder.append(_name_2, " "); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.append("static void MsgDispatcher_"); - String _name_3 = thread.getName(); - _builder.append(_name_3); - _builder.append("_poll(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"MsgDispatcher_"); - String _name_4 = thread.getName(); - _builder.append(_name_4, "\t"); - _builder.append("\", \"execute\")"); - _builder.newLineIfNotEmpty(); - { - for(final ActorInstance ai : executedInstances) { - _builder.append("\t"); - String _name_5 = ai.getActorClass().getName(); - _builder.append(_name_5, "\t"); - _builder.append("_execute((void*)&"); - String _pathName = this._roomExtensions.getPathName(ai.getPath()); - _builder.append(_pathName, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - { - if (logData) { - _builder.append("static void MsgDispatcher_"); - String _name_6 = thread.getName(); - _builder.append(_name_6); - _builder.append("_logDataHeaders(void){"); - _builder.newLineIfNotEmpty(); - { - for(final PortInstance pi : loggedPorts) { - _builder.append("\t"); - _builder.append("ET_DATA_LOGGER_LOG_STRING(\""); - String _path = pi.getPath(); - _builder.append(_path, "\t"); - _builder.append("\")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("}"); - _builder.newLine(); - _builder.append("static void MsgDispatcher_"); - String _name_7 = thread.getName(); - _builder.append(_name_7); - _builder.append("_logData(void){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_DATA_LOGGER_NEW_ROW"); - _builder.newLine(); - { - for(final PortInstance pi_1 : loggedPorts) { - _builder.append("\t"); - String _createLoggerCall = this.createLoggerCall(pi_1); - _builder.append(_createLoggerCall, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("}"); - _builder.newLine(); - } - } - } - } - _builder.newLine(); - _builder.append("/**"); - _builder.newLine(); - _builder.append(" "); - _builder.append("* generated dispatch function for all messages for the thread \""); - String _name_8 = thread.getName(); - _builder.append(_name_8, " "); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.append("static etBool MsgDispatcher_"); - String _name_9 = thread.getName(); - _builder.append(_name_9); - _builder.append("_receiveMessage(const etMessage* msg){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\"MsgDispatcher_"); - String _name_10 = thread.getName(); - _builder.append(_name_10, "\t"); - _builder.append("\", \"receiveMessage\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("switch(msg->address){"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("case MESSAGESERVICE_ADDRESS:"); - _builder.newLine(); - { - boolean _isEmpty = IterableExtensions.isEmpty(executedInstances); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("\t\t\t"); - _builder.append("if (msg->evtID == etSystemProtocol_IN_poll) {"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("\t"); - _builder.append("MsgDispatcher_"); - String _name_11 = thread.getName(); - _builder.append(_name_11, "\t\t\t\t"); - _builder.append("_poll();"); - _builder.newLineIfNotEmpty(); - { - if (logData) { - _builder.append("\t\t\t"); - _builder.append("\t"); - _builder.append("MsgDispatcher_"); - String _name_12 = thread.getName(); - _builder.append(_name_12, "\t\t\t\t"); - _builder.append("_logData();"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("else"); - _builder.newLine(); - } - } - _builder.append("\t\t\t"); - _builder.append("if (msg->evtID == etSystemProtocol_IN_terminate)"); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("return ET_FALSE;"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("break;"); - _builder.newLine(); - { - for(final ActorInstance ai_1 : dispatchedInstances) { - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("/* interface items of "); - String _path_1 = ai_1.getPath(); - _builder.append(_path_1, "\t\t"); - _builder.append(" */"); - _builder.newLineIfNotEmpty(); - { - final Function1<InterfaceItemInstance, Boolean> _function_4 = (InterfaceItemInstance p) -> { - CommunicationType _commType = p.getProtocol().getCommType(); - return Boolean.valueOf(Objects.equal(_commType, CommunicationType.EVENT_DRIVEN)); - }; - Iterable<InterfaceItemInstance> _filter_1 = IterableExtensions.<InterfaceItemInstance>filter(ai_1.getOrderedIfItemInstances(), _function_4); - for(final InterfaceItemInstance pi_2 : _filter_1) { - { - boolean _isReplicated = pi_2.isReplicated(); - if (_isReplicated) { - { - EList<InterfaceItemInstance> _peers = pi_2.getPeers(); - for(final InterfaceItemInstance peer : _peers) { - _builder.append("\t\t"); - _builder.append("case "); - int _objId = pi_2.getObjId(); - int _indexOf = pi_2.getPeers().indexOf(peer); - int _plus = (_objId + _indexOf); - _builder.append(_plus, "\t\t"); - _builder.append("+BASE_ADDRESS:"); - _builder.newLineIfNotEmpty(); - { - boolean _handlesReceive = this._roomExtensions.handlesReceive(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - if (_handlesReceive) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("switch (msg->evtID){"); - _builder.newLine(); - { - List<MessageHandler> _receiveHandlers = this._roomExtensions.getReceiveHandlers(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - for(final MessageHandler h : _receiveHandlers) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("case "); - String _name_13 = pi_2.getProtocol().getName(); - _builder.append(_name_13, "\t\t\t\t"); - _builder.append("_"); - String _codeName = this._roomExtensions.getCodeName(h.getMsg()); - _builder.append(_codeName, "\t\t\t\t"); - _builder.append(":"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("\t"); - String _portClassName = this._roomExtensions.getPortClassName(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - _builder.append(_portClassName, "\t\t\t\t\t"); - _builder.append("_"); - String _name_14 = h.getMsg().getName(); - _builder.append(_name_14, "\t\t\t\t\t"); - _builder.append("_receiveHandler((etPort *)&"); - String _pathName_1 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_1, "\t\t\t\t\t"); - _builder.append("_const."); - String _name_15 = pi_2.getName(); - _builder.append(_name_15, "\t\t\t\t\t"); - _builder.append(".ports["); - int _indexOf_1 = pi_2.getPeers().indexOf(peer); - _builder.append(_indexOf_1, "\t\t\t\t\t"); - _builder.append("],msg,(void*)&"); - String _pathName_2 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_2, "\t\t\t\t\t"); - _builder.append(","); - String _name_16 = ai_1.getActorClass().getName(); - _builder.append(_name_16, "\t\t\t\t\t"); - _builder.append("_receiveMessage);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("break;"); - _builder.newLine(); - } - } - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("default: "); - String _name_17 = ai_1.getActorClass().getName(); - _builder.append(_name_17, "\t\t\t\t"); - _builder.append("_receiveMessage((void*)&"); - String _pathName_3 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_3, "\t\t\t\t"); - _builder.append(",(etPort*)&"); - String _pathName_4 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_4, "\t\t\t\t"); - _builder.append("_const."); - String _name_18 = pi_2.getName(); - _builder.append(_name_18, "\t\t\t\t"); - _builder.append(".ports["); - int _indexOf_2 = pi_2.getPeers().indexOf(peer); - _builder.append(_indexOf_2, "\t\t\t\t"); - _builder.append("], msg);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("break;"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - } else { - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_IN("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - String _pathName_5 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_5, "\t\t\t\t"); - _builder.append("_const."); - String _name_19 = pi_2.getName(); - _builder.append(_name_19, "\t\t\t\t"); - _builder.append(".ports["); - int _indexOf_3 = pi_2.getPeers().indexOf(peer); - _builder.append(_indexOf_3, "\t\t\t\t"); - _builder.append("].port.peerInstName,"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - String _name_20 = pi_2.getProtocol().getName(); - _builder.append(_name_20, "\t\t\t\t"); - _builder.append("_getMessageString(msg->evtID),"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - String _pathName_6 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_6, "\t\t\t\t"); - _builder.append("_const."); - String _name_21 = pi_2.getName(); - _builder.append(_name_21, "\t\t\t\t"); - _builder.append(".ports["); - int _indexOf_4 = pi_2.getPeers().indexOf(peer); - _builder.append(_indexOf_4, "\t\t\t\t"); - _builder.append("].port.myInstName"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(")"); - _builder.newLine(); - } - } - _builder.append("\t\t"); - _builder.append("\t"); - String _name_22 = ai_1.getActorClass().getName(); - _builder.append(_name_22, "\t\t\t"); - _builder.append("_receiveMessage((void*)&"); - String _pathName_7 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_7, "\t\t\t"); - _builder.append(",&"); - String _pathName_8 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_8, "\t\t\t"); - _builder.append("_const."); - String _name_23 = pi_2.getName(); - _builder.append(_name_23, "\t\t\t"); - _builder.append(".ports["); - int _indexOf_5 = pi_2.getPeers().indexOf(peer); - _builder.append(_indexOf_5, "\t\t\t"); - _builder.append("].port, msg);"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t\t"); - _builder.append("break;"); - _builder.newLine(); - } - } - } else { - _builder.append("\t\t"); - _builder.append("case "); - int _objId_1 = pi_2.getObjId(); - _builder.append(_objId_1, "\t\t"); - _builder.append("+BASE_ADDRESS:"); - _builder.newLineIfNotEmpty(); - { - boolean _handlesReceive_1 = this._roomExtensions.handlesReceive(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - if (_handlesReceive_1) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("switch (msg->evtID){"); - _builder.newLine(); - { - List<MessageHandler> _receiveHandlers_1 = this._roomExtensions.getReceiveHandlers(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - for(final MessageHandler h_1 : _receiveHandlers_1) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("case "); - String _name_24 = pi_2.getProtocol().getName(); - _builder.append(_name_24, "\t\t\t\t"); - _builder.append("_"); - String _codeName_1 = this._roomExtensions.getCodeName(h_1.getMsg()); - _builder.append(_codeName_1, "\t\t\t\t"); - _builder.append(":"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("\t"); - String _portClassName_1 = this._roomExtensions.getPortClassName(pi_2.getProtocol(), this._roomExtensions.isConjugated(pi_2)); - _builder.append(_portClassName_1, "\t\t\t\t\t"); - _builder.append("_"); - String _name_25 = h_1.getMsg().getName(); - _builder.append(_name_25, "\t\t\t\t\t"); - _builder.append("_receiveHandler((etPort *)&"); - String _pathName_9 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_9, "\t\t\t\t\t"); - _builder.append("_const."); - String _name_26 = pi_2.getName(); - _builder.append(_name_26, "\t\t\t\t\t"); - _builder.append(",msg,(void*)&"); - String _pathName_10 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_10, "\t\t\t\t\t"); - _builder.append(","); - String _name_27 = ai_1.getActorClass().getName(); - _builder.append(_name_27, "\t\t\t\t\t"); - _builder.append("_receiveMessage);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("break;"); - _builder.newLine(); - } - } - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("default: "); - String _name_28 = ai_1.getActorClass().getName(); - _builder.append(_name_28, "\t\t\t\t"); - _builder.append("_receiveMessage((void*)&"); - String _pathName_11 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_11, "\t\t\t\t"); - _builder.append(",(etPort*)&"); - String _pathName_12 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_12, "\t\t\t\t"); - _builder.append("_const."); - String _name_29 = pi_2.getName(); - _builder.append(_name_29, "\t\t\t\t"); - _builder.append(", msg);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("break;"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - } else { - { - boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_1) { - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_IN("); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("((etPort*)&"); - String _pathName_13 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_13, "\t\t\t\t"); - _builder.append("_const."); - String _name_30 = pi_2.getName(); - _builder.append(_name_30, "\t\t\t\t"); - _builder.append(")->peerInstName,"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - String _name_31 = pi_2.getProtocol().getName(); - _builder.append(_name_31, "\t\t\t\t"); - _builder.append("_getMessageString(msg->evtID),"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("((etPort*)&"); - String _pathName_14 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_14, "\t\t\t\t"); - _builder.append("_const."); - String _name_32 = pi_2.getName(); - _builder.append(_name_32, "\t\t\t\t"); - _builder.append(")->myInstName"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(")"); - _builder.newLine(); - } - } - _builder.append("\t\t"); - _builder.append("\t"); - String _name_33 = ai_1.getActorClass().getName(); - _builder.append(_name_33, "\t\t\t"); - _builder.append("_receiveMessage((void*)&"); - String _pathName_15 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_15, "\t\t\t"); - _builder.append(",(etPort*)&"); - String _pathName_16 = this._roomExtensions.getPathName(ai_1.getPath()); - _builder.append(_pathName_16, "\t\t\t"); - _builder.append("_const."); - String _name_34 = pi_2.getName(); - _builder.append(_name_34, "\t\t\t"); - _builder.append(", msg);"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t\t"); - _builder.append("\t"); - _builder.append("break;"); - _builder.newLine(); - } - } - } - } - } - } - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("default:"); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("etLogger_logErrorF(\"MessageService_"); - String _name_35 = thread.getName(); - _builder.append(_name_35, "\t\t\t"); - _builder.append("_receiveMessage: address %d does not exist \", msg->address);"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t"); - _builder.append("break;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("return ET_TRUE;"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private String createLoggerCall(final PortInstance pi) { - String _xblockexpression = null; - { - final Function1<Message, Boolean> _function = (Message m) -> { - return Boolean.valueOf(((!Objects.equal(m.getData(), null)) && this._typeHelpers.isEnumerationOrPrimitive(m.getData().getRefType().getType()))); - }; - final Message msg = ((Message[])Conversions.unwrapArray(IterableExtensions.<Message>filter(pi.getProtocol().getIncomingMessages(), _function), Message.class))[0]; - EObject _eContainer = pi.eContainer(); - final ActorInstance ai = ((ActorInstance) _eContainer); - String _pathName = this._roomExtensions.getPathName(ai.getPath()); - String _plus = (_pathName + "."); - String _name = pi.getName(); - String _plus_1 = (_plus + _name); - String _plus_2 = (_plus_1 + "."); - String _name_1 = msg.getName(); - final String data = (_plus_2 + _name_1); - LiteralType _xifexpression = null; - DataType _type = msg.getData().getRefType().getType(); - if ((_type instanceof EnumerationType)) { - _xifexpression = LiteralType.INT; - } else { - DataType _type_1 = msg.getData().getRefType().getType(); - _xifexpression = ((PrimitiveType) _type_1).getType(); - } - final LiteralType type = _xifexpression; - String _switchResult = null; - if (type != null) { - switch (type) { - case BOOL: - _switchResult = (("ET_DATA_LOGGER_LOG_BOOL((int)" + data) + ")"); - break; - case CHAR: - _switchResult = (("ET_DATA_LOGGER_LOG_INT((int)" + data) + ")"); - break; - case INT: - _switchResult = (("ET_DATA_LOGGER_LOG_INT((int)" + data) + ")"); - break; - case REAL: - _switchResult = (("ET_DATA_LOGGER_LOG_DOUBLE((double)" + data) + ")"); - break; - default: - _switchResult = "internal error: unknown primitive type"; - break; - } - } else { - _switchResult = "internal error: unknown primitive type"; - } - _xblockexpression = _switchResult; - } - return _xblockexpression; - } - - private ArrayList<PortInstance> loggedPorts(final SubSystemInstance ssi) { - final ArrayList<PortInstance> result = CollectionLiterals.<PortInstance>newArrayList(); - boolean _isAnnotationPresent = this._roomHelpers.isAnnotationPresent(ssi.getSubSystemClass().getAnnotations(), "DataLogging"); - if (_isAnnotationPresent) { - this.logger.logInfo("Data Logging is configured by annotation"); - final String filters = this._roomHelpers.getAttribute(ssi.getSubSystemClass().getAnnotations(), "DataLogging", "pathlist"); - final String[] filterList = filters.split(","); - for (final String filter : filterList) { - this.logger.logInfo((" filter: " + filter)); - } - final ArrayList<String> notLogged = CollectionLiterals.<String>newArrayList(); - this.logger.logInfo(" logged ports:"); - TreeIterator<EObject> iter = ssi.eAllContents(); - while (iter.hasNext()) { - { - final EObject obj = iter.next(); - if ((obj instanceof PortInstance)) { - final PortInstance pi = ((PortInstance) obj); - boolean _isRelay = this._roomHelpers.isRelay(pi.getPort()); - boolean _not = (!_isRelay); - if (_not) { - CommunicationType _commType = pi.getProtocol().getCommType(); - boolean _equals = Objects.equal(_commType, CommunicationType.DATA_DRIVEN); - if (_equals) { - boolean _isConjugated = pi.getPort().isConjugated(); - if (_isConjugated) { - final String path = pi.getPath(); - boolean matched = false; - boolean primitive = false; - for (final String filter_1 : filterList) { - boolean _matches = path.matches(filter_1); - if (_matches) { - matched = true; - final Function1<Message, Boolean> _function = (Message m) -> { - return Boolean.valueOf(((!Objects.equal(m.getData(), null)) && this._typeHelpers.isEnumerationOrPrimitive(m.getData().getRefType().getType()))); - }; - boolean _isEmpty = IterableExtensions.isEmpty(IterableExtensions.<Message>filter(pi.getProtocol().getIncomingMessages(), _function)); - boolean _not_1 = (!_isEmpty); - if (_not_1) { - result.add(pi); - primitive = true; - String _path = pi.getPath(); - String _plus = (" data driven port " + _path); - String _plus_1 = (_plus + " (matched "); - String _plus_2 = (_plus_1 + filter_1); - String _plus_3 = (_plus_2 + ")"); - this.logger.logInfo(_plus_3); - } - } - } - if ((!primitive)) { - if (matched) { - String _path_1 = pi.getPath(); - String _plus_4 = (" data driven port " + _path_1); - String _plus_5 = (_plus_4 + " (matched but contains no primitive data)"); - notLogged.add(_plus_5); - } else { - String _path_2 = pi.getPath(); - String _plus_6 = (" data driven port " + _path_2); - String _plus_7 = (_plus_6 + " (no match found)"); - notLogged.add(_plus_7); - } - } - } else { - String _path_3 = pi.getPath(); - String _plus_8 = (" data driven port " + _path_3); - String _plus_9 = (_plus_8 + " (receive port)"); - notLogged.add(_plus_9); - } - } - } - } - } - } - this.logger.logInfo(" NOT logged ports:"); - for (final String nl : notLogged) { - this.logger.logInfo(nl); - } - } - return result; - } - - private void checkDataPorts(final SubSystemInstance comp) { - final HashSet<String> found = new HashSet<String>(); - EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances(); - for (final ActorInstance ai : _allContainedInstances) { - { - final int thread = ai.getThreadId(); - EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances(); - for (final InterfaceItemInstance pi : _orderedIfItemInstances) { - CommunicationType _commType = pi.getProtocol().getCommType(); - boolean _equals = Objects.equal(_commType, CommunicationType.DATA_DRIVEN); - if (_equals) { - EList<InterfaceItemInstance> _peers = pi.getPeers(); - for (final InterfaceItemInstance peer : _peers) { - { - EObject _eContainer = peer.eContainer(); - final ActorInstance peer_ai = ((ActorInstance) _eContainer); - final int peer_thread = peer_ai.getThreadId(); - if ((thread != peer_thread)) { - final String path = pi.getPath(); - final String ppath = peer.getPath(); - String _xifexpression = null; - int _compareTo = path.compareTo(ppath); - boolean _lessThan = (_compareTo < 0); - if (_lessThan) { - _xifexpression = ((path + " and ") + ppath); - } else { - _xifexpression = ((ppath + " and ") + path); - } - final String pair = _xifexpression; - boolean _contains = found.contains(pair); - boolean _not = (!_contains); - if (_not) { - found.add(pair); - this.diagnostician.error((pair + ": data ports placed on different threads (not supported yet)"), - pi.getInterfaceItem(), pi.getInterfaceItem().eContainingFeature()); - } - } - } - } - } - } - } - } - } -} 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 deleted file mode 100644 index ffe24c515..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ProtocolClassGen.java +++ /dev/null @@ -1,1428 +0,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.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.genmodel.etricegen.Root; -import org.eclipse.etrice.core.genmodel.fsm.ILogger; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.CommunicationType; -import org.eclipse.etrice.core.room.DataClass; -import org.eclipse.etrice.core.room.EnumerationType; -import org.eclipse.etrice.core.room.Message; -import org.eclipse.etrice.core.room.MessageHandler; -import org.eclipse.etrice.core.room.Operation; -import org.eclipse.etrice.core.room.PortClass; -import org.eclipse.etrice.core.room.PortOperation; -import org.eclipse.etrice.core.room.ProtocolClass; -import org.eclipse.etrice.core.room.RoomClass; -import org.eclipse.etrice.core.room.RoomModel; -import org.eclipse.etrice.core.room.VarDecl; -import org.eclipse.etrice.generator.base.AbstractGenerator; -import org.eclipse.etrice.generator.c.Main; -import org.eclipse.etrice.generator.c.gen.CExtensions; -import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo; -import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator; -import org.eclipse.etrice.generator.generic.ProcedureHelpers; -import org.eclipse.etrice.generator.generic.RoomExtensions; -import org.eclipse.etrice.generator.generic.TypeHelpers; -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") -public class ProtocolClassGen extends GenericProtocolClassGenerator { - @Inject - private IGeneratorFileIo fileIO; - - @Inject - @Extension - private CExtensions _cExtensions; - - @Inject - @Extension - private RoomExtensions _roomExtensions; - - @Inject - @Extension - private ProcedureHelpers _procedureHelpers; - - @Inject - @Extension - private TypeHelpers _typeHelpers; - - @Inject - private ILogger logger; - - public void doGenerate(final Root root) { - EList<ProtocolClass> _protocolClasses = root.getProtocolClasses(); - for (final ProtocolClass pc : _protocolClasses) { - { - String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(pc); - String _path = this._roomExtensions.getPath(pc); - final String path = (_generationTargetPath + _path); - String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(pc); - String _path_1 = this._roomExtensions.getPath(pc); - final String infopath = (_generationInfoPath + _path_1); - String file = this._cExtensions.getCHeaderFileName(pc); - this.fileIO.generateFile("generating ProtocolClass header", path, infopath, file, this.generateHeaderFile(root, pc)); - file = this._cExtensions.getCUtilsFileName(pc); - this.fileIO.generateFile("generating ProtocolClass utils", path, infopath, file, this.generateUtilsFile(root, pc)); - file = this._cExtensions.getCSourceFileName(pc); - this.fileIO.generateFile("generating ProtocolClass source", path, infopath, file, this.generateSourceFile(root, pc)); - } - } - } - - private CharSequence 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(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(pc); - _builder.append(_generateIncludeGuardBegin); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("#include \"etDatatypes.h\""); - _builder.newLine(); - _builder.append("#include \"modelbase/etPort.h\""); - _builder.newLine(); - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(pc, 1); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* include all referenced room classes */"); - _builder.newLine(); - { - EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(pc); - EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc); - Iterable<RoomClass> _plus = Iterables.<RoomClass>concat(_referencedProtocolClasses, _referencedDataClasses); - EList<EnumerationType> _referencedEnumClasses = root.getReferencedEnumClasses(pc); - final Function1<RoomClass, String> _function = (RoomClass it) -> { - return it.getName(); - }; - List<RoomClass> _sortBy = IterableExtensions.<RoomClass, String>sortBy(Iterables.<RoomClass>concat(_plus, _referencedEnumClasses), _function); - for(final RoomClass dc : _sortBy) { - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(dc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - { - CommunicationType _commType = pc.getCommType(); - boolean _equals = Objects.equal(_commType, CommunicationType.EVENT_DRIVEN); - if (_equals) { - _builder.newLine(); - _builder.append("/* message IDs */"); - _builder.newLine(); - String _genMessageIDs = this.genMessageIDs(pc); - _builder.append(_genMessageIDs); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/*--------------------- port structs and methods */"); - _builder.newLine(); - CharSequence _portClassHeader = this.portClassHeader(pc, Boolean.valueOf(false)); - _builder.append(_portClassHeader); - _builder.newLineIfNotEmpty(); - CharSequence _portClassHeader_1 = this.portClassHeader(pc, Boolean.valueOf(true)); - _builder.append(_portClassHeader_1); - _builder.newLineIfNotEmpty(); - } else { - CommunicationType _commType_1 = pc.getCommType(); - boolean _equals_1 = Objects.equal(_commType_1, CommunicationType.DATA_DRIVEN); - if (_equals_1) { - _builder.append("/*--------------------- port structs and methods */"); - _builder.newLine(); - CharSequence _genDataDrivenPortHeaders = this.genDataDrivenPortHeaders(pc); - _builder.append(_genDataDrivenPortHeaders); - _builder.newLineIfNotEmpty(); - } else { - CommunicationType _commType_2 = pc.getCommType(); - boolean _equals_2 = Objects.equal(_commType_2, CommunicationType.SYNCHRONOUS); - if (_equals_2) { - _builder.append("#error \"synchronoue protocols not implemented yet\""); - _builder.newLine(); - } - } - } - } - _builder.newLine(); - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("/*--------------------- debug helpers */"); - _builder.newLine(); - _builder.newLine(); - _builder.append("/* get message string for message id */"); - _builder.newLine(); - _builder.append("const char* "); - String _name_1 = pc.getName(); - _builder.append(_name_1); - _builder.append("_getMessageString(int msg_id);"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - CharSequence _userCode_1 = this._procedureHelpers.userCode(pc, 2); - _builder.append(_userCode_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(pc); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - return _builder; - } - - private CharSequence generateUtilsFile(final Root root, final ProtocolClass pc) { - CharSequence _xblockexpression = null; - { - EObject _eContainer = pc.eContainer(); - String _replaceAll = ((RoomModel) _eContainer).getName().replaceAll("\\.", "_"); - String _plus = (_replaceAll + "_"); - String _name = pc.getName(); - String _plus_1 = (_plus + _name); - final String filename = (_plus_1 + "_Utils"); - 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("* Utils File of ProtocolClass "); - String _name_1 = pc.getName(); - _builder.append(_name_1, " "); - _builder.newLineIfNotEmpty(); - _builder.append(" "); - _builder.append("* "); - _builder.newLine(); - _builder.append(" "); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateIncludeGuardBegin = this._cExtensions.generateIncludeGuardBegin(filename); - _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 "); - String _utilsIncludePath = this._cExtensions.getUtilsIncludePath(pc.getBase()); - _builder.append(_utilsIncludePath); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("#include "); - String _includePath = this._cExtensions.getIncludePath(pc); - _builder.append(_includePath); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/*"); - _builder.newLine(); - _builder.append(" "); - _builder.append("* access macros for operations and attributes"); - _builder.newLine(); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - CharSequence _generateUtilsFile = this.generateUtilsFile(pc, false); - _builder.append(_generateUtilsFile); - _builder.newLineIfNotEmpty(); - CharSequence _generateUtilsFile_1 = this.generateUtilsFile(pc, true); - _builder.append(_generateUtilsFile_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(filename); - _builder.append(_generateIncludeGuardEnd); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence generateUtilsFile(final ProtocolClass pc, final boolean conj) { - CharSequence _xblockexpression = null; - { - final PortClass portClass = this._roomExtensions.getPortClass(pc, conj); - final String portClassName = this._roomExtensions.getPortClassName(pc, conj); - StringConcatenation _builder = new StringConcatenation(); - { - boolean _notEquals = (!Objects.equal(portClass, null)); - if (_notEquals) { - _builder.append("/* "); - { - if (conj) { - _builder.append("conjugate"); - } else { - _builder.append("regular"); - } - } - _builder.append(" port class */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* operations */"); - _builder.newLine(); - { - EList<PortOperation> _operations = portClass.getOperations(); - for(final PortOperation op : _operations) { - final CharSequence args = this.argList(op); - _builder.newLineIfNotEmpty(); - _builder.append("#define "); - String _name = op.getName(); - _builder.append(_name); - _builder.append("("); - _builder.append(args); - _builder.append(") "); - _builder.append(portClassName); - _builder.append("_"); - String _name_1 = op.getName(); - _builder.append(_name_1); - _builder.append("(self"); - { - boolean _isEmpty = op.getArguments().isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append(", "); - _builder.append(args); - } - } - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _builder.append("/* attributes */"); - _builder.newLine(); - { - EList<Attribute> _attributes = portClass.getAttributes(); - for(final Attribute a : _attributes) { - _builder.append("#define "); - String _name_2 = a.getName(); - _builder.append(_name_2); - _builder.append(" ((("); - _builder.append(portClassName); - _builder.append("_var*)(self->varData))->"); - String _name_3 = a.getName(); - _builder.append(_name_3); - _builder.append(")"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence argList(final Operation op) { - StringConcatenation _builder = new StringConcatenation(); - { - EList<VarDecl> _arguments = op.getArguments(); - boolean _hasElements = false; - for(final VarDecl a : _arguments) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(", ", ""); - } - String _name = a.getName(); - _builder.append(_name); - } - } - return _builder; - } - - private CharSequence 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._cExtensions.getCHeaderFileName(pc); - _builder.append(_cHeaderFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.append("#include \"debugging/etMSCLogger.h\""); - _builder.newLine(); - _builder.append("#include \""); - String _cUtilsFileName = this._cExtensions.getCUtilsFileName(pc); - _builder.append(_cUtilsFileName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - CharSequence _userCode = this._procedureHelpers.userCode(pc, 3); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/*--------------------- port methods */"); - _builder.newLine(); - { - CommunicationType _commType = pc.getCommType(); - boolean _equals = Objects.equal(_commType, CommunicationType.EVENT_DRIVEN); - if (_equals) { - CharSequence _portClassSource = this.portClassSource(pc, Boolean.valueOf(false)); - _builder.append(_portClassSource); - _builder.newLineIfNotEmpty(); - CharSequence _portClassSource_1 = this.portClassSource(pc, Boolean.valueOf(true)); - _builder.append(_portClassSource_1); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("/*--------------------- debug helpers */"); - _builder.newLine(); - CharSequence _generateDebugHelpersImplementation = this.generateDebugHelpersImplementation(root, pc); - _builder.append(_generateDebugHelpersImplementation); - _builder.newLineIfNotEmpty(); - } - } - } else { - CommunicationType _commType_1 = pc.getCommType(); - boolean _equals_1 = Objects.equal(_commType_1, CommunicationType.DATA_DRIVEN); - if (_equals_1) { - CharSequence _genDataDrivenPortSources = this.genDataDrivenPortSources(pc); - _builder.append(_genDataDrivenPortSources); - _builder.newLineIfNotEmpty(); - } else { - CommunicationType _commType_2 = pc.getCommType(); - boolean _equals_2 = Objects.equal(_commType_2, CommunicationType.SYNCHRONOUS); - if (_equals_2) { - _builder.append("#error \"synchronous protocols not implemented yet\""); - _builder.newLine(); - } - } - } - } - return _builder; - } - - private CharSequence portClassHeader(final ProtocolClass pc, final Boolean conj) { - CharSequence _xblockexpression = null; - { - String portClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue()); - String replPortClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue(), true); - List<Message> _xifexpression = null; - if ((conj).booleanValue()) { - _xifexpression = this._roomHelpers.getAllIncomingMessages(pc); - } else { - _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 = (PortClass p) -> { - return p.getAttributes(); - }; - final List<Attribute> allAttributes = IterableExtensions.<Attribute>toList(Iterables.<Attribute>concat(ListExtensions.<PortClass, EList<Attribute>>map(allPortClasses, _function))); - final Function1<PortClass, EList<PortOperation>> _function_1 = (PortClass p) -> { - return p.getOperations(); - }; - final List<PortOperation> allOperations = IterableExtensions.<PortOperation>toList(Iterables.<PortOperation>concat(ListExtensions.<PortClass, EList<PortOperation>>map(allPortClasses, _function_1))); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("typedef etPort "); - _builder.append(portClassName); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("typedef etReplPort "); - _builder.append(replPortClassName); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - 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(); - { - for(final Attribute a : allAttributes) { - { - 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(); - } - } - } - } - } - } - _builder.newLine(); - { - for(final Message message : messages) { - VarDecl _data = message.getData(); - boolean hasData = (!Objects.equal(_data, null)); - _builder.newLineIfNotEmpty(); - String _xifexpression_1 = null; - if (hasData) { - _xifexpression_1 = this._typeHelpers.typeName(message.getData().getRefType().getType()); - } else { - _xifexpression_1 = ""; - } - String typeName = _xifexpression_1; - _builder.newLineIfNotEmpty(); - String _xifexpression_2 = null; - if ((hasData && ((!this._typeHelpers.isEnumerationOrPrimitive(message.getData().getRefType().getType())) || message.getData().getRefType().isRef()))) { - _xifexpression_2 = "*"; - } else { - _xifexpression_2 = ""; - } - String refp = _xifexpression_2; - _builder.newLineIfNotEmpty(); - String _xifexpression_3 = null; - if (hasData) { - _xifexpression_3 = (((", " + typeName) + refp) + " data"); - } else { - _xifexpression_3 = ""; - } - String data = _xifexpression_3; - _builder.newLineIfNotEmpty(); - String _messageSignature = this.messageSignature(portClassName, message.getName(), "", data); - _builder.append(_messageSignature); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - String _messageSignature_1 = this.messageSignature(replPortClassName, message.getName(), "_broadcast", data); - _builder.append(_messageSignature_1); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - String _messageSignature_2 = this.messageSignature(replPortClassName, message.getName(), "", (", int idx" + data)); - _builder.append(_messageSignature_2); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - { - 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 _handlesReceiveIncludingSuper = this._roomExtensions.handlesReceiveIncludingSuper(pc, (conj).booleanValue()); - if (_handlesReceiveIncludingSuper) { - { - List<MessageHandler> _receiveHandlersIncludingSuper = this._roomExtensions.getReceiveHandlersIncludingSuper(pc, (conj).booleanValue()); - for(final MessageHandler h : _receiveHandlersIncludingSuper) { - _builder.append("void "); - _builder.append(portClassName); - _builder.append("_"); - String _name_1 = h.getMsg().getName(); - _builder.append(_name_1); - _builder.append("_receiveHandler("); - _builder.append(portClassName); - _builder.append("* self, const etMessage* msg, void * actor, etActorReceiveMessage receiveMessageFunc);"); - _builder.newLineIfNotEmpty(); - } - } - } - } - _builder.append("etInt32 "); - _builder.append(replPortClassName); - _builder.append("_getReplication(const "); - _builder.append(replPortClassName); - _builder.append("* self);"); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence genDataDrivenPortHeaders(final ProtocolClass pc) { - CharSequence _xblockexpression = null; - { - final Function1<Message, Boolean> _function = (Message m) -> { - VarDecl _data = m.getData(); - return Boolean.valueOf((!Objects.equal(_data, null))); - }; - Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(this._roomHelpers.getAllIncomingMessages(pc), _function); - final Function1<Message, Boolean> _function_1 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isEnumeration(m.getData().getRefType().getType())); - }; - final Iterable<Message> enumMsgs = IterableExtensions.<Message>filter(sentMsgs, _function_1); - final Function1<Message, Boolean> _function_2 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isBoolean(m.getData().getRefType().getType())); - }; - final Iterable<Message> boolMsgs = IterableExtensions.<Message>filter(sentMsgs, _function_2); - final boolean usesMSC = (Main.getSettings().isGenerateMSCInstrumentation() && (!(IterableExtensions.isEmpty(enumMsgs) && IterableExtensions.isEmpty(boolMsgs)))); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("/* data driven send port (conjugated) */"); - _builder.newLine(); - _builder.append("typedef struct "); - String _portClassName = this._roomExtensions.getPortClassName(pc, true); - _builder.append(_portClassName); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - for(final Message msg : sentMsgs) { - _builder.append("\t"); - String typeName = this._typeHelpers.typeName(msg.getData().getRefType().getType()); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - String _xifexpression = null; - boolean _isRef = msg.getData().getRefType().isRef(); - if (_isRef) { - _xifexpression = "*"; - } else { - _xifexpression = ""; - } - String refp = _xifexpression; - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append(typeName, "\t"); - _builder.append(refp, "\t"); - _builder.append(" "); - String _name = msg.getName(); - _builder.append(_name, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - { - if (usesMSC) { - _builder.append("\t"); - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("const char* instName;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("const char** peerNames;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("#endif"); - _builder.newLine(); - } - } - _builder.append("}"); - _builder.newLine(); - String _portClassName_1 = this._roomExtensions.getPortClassName(pc, true); - _builder.append(_portClassName_1); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - _builder.append("/* data driven receive port (regular) */"); - _builder.newLine(); - _builder.append("typedef struct "); - String _portClassName_2 = this._roomExtensions.getPortClassName(pc, false); - _builder.append(_portClassName_2); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("const "); - String _portClassName_3 = this._roomExtensions.getPortClassName(pc, true); - _builder.append(_portClassName_3, "\t"); - _builder.append("* peer;"); - _builder.newLineIfNotEmpty(); - { - if (usesMSC) { - _builder.append("\t"); - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("const char* instName;"); - _builder.newLine(); - { - for(final Message msg_1 : enumMsgs) { - _builder.append("\t"); - _builder.append("\t"); - String typeName_1 = this._typeHelpers.typeName(msg_1.getData().getRefType().getType()); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - String _xifexpression_1 = null; - boolean _isRef_1 = msg_1.getData().getRefType().isRef(); - if (_isRef_1) { - _xifexpression_1 = "*"; - } else { - _xifexpression_1 = ""; - } - String refp_1 = _xifexpression_1; - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(typeName_1, "\t\t"); - _builder.append(refp_1, "\t\t"); - _builder.append(" "); - String _name_1 = msg_1.getName(); - _builder.append(_name_1, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - { - for(final Message msg_2 : boolMsgs) { - _builder.append("\t"); - _builder.append("\t"); - String typeName_2 = this._typeHelpers.typeName(msg_2.getData().getRefType().getType()); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - String _xifexpression_2 = null; - boolean _isRef_2 = msg_2.getData().getRefType().isRef(); - if (_isRef_2) { - _xifexpression_2 = "*"; - } else { - _xifexpression_2 = ""; - } - String refp_2 = _xifexpression_2; - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(typeName_2, "\t\t"); - _builder.append(refp_2, "\t\t"); - _builder.append(" "); - String _name_2 = msg_2.getName(); - _builder.append(_name_2, "\t\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t"); - _builder.append("#endif"); - _builder.newLine(); - } - } - _builder.append("}"); - _builder.newLine(); - String _portClassName_4 = this._roomExtensions.getPortClassName(pc, false); - _builder.append(_portClassName_4); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - { - for(final Message message : sentMsgs) { - VarDecl _data = message.getData(); - boolean hasData = (!Objects.equal(_data, null)); - _builder.newLineIfNotEmpty(); - String _xifexpression_3 = null; - if (hasData) { - _xifexpression_3 = this._typeHelpers.typeName(message.getData().getRefType().getType()); - } else { - _xifexpression_3 = ""; - } - String typeName_3 = _xifexpression_3; - _builder.newLineIfNotEmpty(); - String _xifexpression_4 = null; - if ((hasData && (!this._typeHelpers.isEnumerationOrPrimitive(message.getData().getRefType().getType())))) { - _xifexpression_4 = "*"; - } else { - _xifexpression_4 = ""; - } - String refp_3 = _xifexpression_4; - _builder.newLineIfNotEmpty(); - String _xifexpression_5 = null; - if (hasData) { - _xifexpression_5 = (((", " + typeName_3) + refp_3) + " data"); - } else { - _xifexpression_5 = ""; - } - String data = _xifexpression_5; - _builder.newLineIfNotEmpty(); - String _messageSetterSignature = this.messageSetterSignature(this._roomExtensions.getPortClassName(pc, true), message.getName(), data); - _builder.append(_messageSetterSignature); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - String _messageGetterSignature = this.messageGetterSignature(this._roomExtensions.getPortClassName(pc, false), message.getName(), typeName_3); - _builder.append(_messageGetterSignature); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence genDataDrivenPortSources(final ProtocolClass pc) { - CharSequence _xblockexpression = null; - { - final Function1<Message, Boolean> _function = (Message m) -> { - VarDecl _data = m.getData(); - return Boolean.valueOf((!Objects.equal(_data, null))); - }; - Iterable<Message> messages = IterableExtensions.<Message>filter(this._roomHelpers.getAllIncomingMessages(pc), _function); - final Function1<Message, Boolean> _function_1 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isEnumeration(m.getData().getRefType().getType())); - }; - final Iterable<Message> enumMsgs = IterableExtensions.<Message>filter(messages, _function_1); - final Function1<Message, Boolean> _function_2 = (Message m) -> { - return Boolean.valueOf(this._typeHelpers.isBoolean(m.getData().getRefType().getType())); - }; - final Iterable<Message> boolMsgs = IterableExtensions.<Message>filter(messages, _function_2); - final boolean usesMSC = (Main.getSettings().isGenerateMSCInstrumentation() && (!(IterableExtensions.isEmpty(enumMsgs) && IterableExtensions.isEmpty(boolMsgs)))); - StringConcatenation _builder = new StringConcatenation(); - { - for(final Message message : messages) { - String typeName = this._typeHelpers.typeName(message.getData().getRefType().getType()); - _builder.newLineIfNotEmpty(); - String _xifexpression = null; - boolean _isEnumerationOrPrimitive = this._typeHelpers.isEnumerationOrPrimitive(message.getData().getRefType().getType()); - boolean _not = (!_isEnumerationOrPrimitive); - if (_not) { - _xifexpression = "*"; - } else { - _xifexpression = ""; - } - String refp = _xifexpression; - _builder.newLineIfNotEmpty(); - String data = (((", " + typeName) + refp) + " data"); - _builder.newLineIfNotEmpty(); - String _messageSetterSignature = this.messageSetterSignature(this._roomExtensions.getPortClassName(pc, true), message.getName(), data); - _builder.append(_messageSetterSignature); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - if ((usesMSC && IterableExtensions.<Message>exists(enumMsgs, ((Function1<Message, Boolean>) (Message m) -> { - return Boolean.valueOf(Objects.equal(m, message)); - })))) { - _builder.append("\t"); - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("const char** peerName;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("for (peerName=self->peerNames; *peerName!=NULL; ++peerName) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_OUT(self->instName, "); - String _name = message.getData().getRefType().getType().getName(); - _builder.append(_name, "\t\t\t\t"); - _builder.append("_getLiteralName(data), *peerName)"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t\t\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_IN(self->instName, "); - String _name_1 = message.getData().getRefType().getType().getName(); - _builder.append(_name_1, "\t\t\t\t"); - _builder.append("_getLiteralName(data), *peerName)"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("#endif"); - _builder.newLine(); - } - } - { - if ((usesMSC && IterableExtensions.<Message>exists(boolMsgs, ((Function1<Message, Boolean>) (Message m) -> { - return Boolean.valueOf(Objects.equal(m, message)); - })))) { - _builder.append("\t"); - _builder.append("#ifdef ET_ASYNC_MSC_LOGGER_ACTIVATE"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("const char** peerName;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("for (peerName=self->peerNames; *peerName!=NULL; ++peerName) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_OUT(self->instName, data?\"true\":\"false\", *peerName)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_IN(self->instName, data?\"true\":\"false\", *peerName)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("#endif"); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append("self->"); - String _name_2 = message.getName(); - _builder.append(_name_2, "\t"); - _builder.append(" = "); - _builder.append(refp, "\t"); - _builder.append("data;"); - _builder.newLineIfNotEmpty(); - _builder.append("}"); - _builder.newLine(); - String _messageGetterSignature = this.messageGetterSignature(this._roomExtensions.getPortClassName(pc, false), message.getName(), typeName); - _builder.append(_messageGetterSignature); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("return self->peer->"); - String _name_3 = message.getName(); - _builder.append(_name_3, "\t"); - _builder.append(";"); - _builder.newLineIfNotEmpty(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence portClassSource(final ProtocolClass pc, final Boolean conj) { - CharSequence _xblockexpression = null; - { - 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; - if ((conj).booleanValue()) { - _xifexpression = this._roomHelpers.getAllIncomingMessages(pc); - } else { - _xifexpression = this._roomHelpers.getAllOutgoingMessages(pc); - } - final List<Message> messages = _xifexpression; - String _xifexpression_1 = null; - if ((conj).booleanValue()) { - _xifexpression_1 = "IN_"; - } else { - _xifexpression_1 = "OUT_"; - } - final String dir = _xifexpression_1; - StringConcatenation _builder = new StringConcatenation(); - { - for(final Message message : messages) { - VarDecl _data = message.getData(); - boolean hasData = (!Objects.equal(_data, null)); - _builder.newLineIfNotEmpty(); - String _xifexpression_2 = null; - if (hasData) { - _xifexpression_2 = this._typeHelpers.typeName(message.getData().getRefType().getType()); - } else { - _xifexpression_2 = ""; - } - String typeName = _xifexpression_2; - _builder.newLineIfNotEmpty(); - String _xifexpression_3 = null; - if ((hasData && message.getData().getRefType().isRef())) { - _xifexpression_3 = "*"; - } else { - _xifexpression_3 = ""; - } - String refp = _xifexpression_3; - _builder.newLineIfNotEmpty(); - String _xifexpression_4 = null; - if ((hasData && ((!this._typeHelpers.isEnumerationOrPrimitive(message.getData().getRefType().getType())) || message.getData().getRefType().isRef()))) { - _xifexpression_4 = "*"; - } else { - _xifexpression_4 = ""; - } - String refpd = _xifexpression_4; - _builder.newLineIfNotEmpty(); - String _xifexpression_5 = null; - if (((hasData && (!this._typeHelpers.isEnumerationOrPrimitive(message.getData().getRefType().getType()))) && (!message.getData().getRefType().isRef()))) { - _xifexpression_5 = ""; - } else { - _xifexpression_5 = "&"; - } - String refa = _xifexpression_5; - _builder.newLineIfNotEmpty(); - String _xifexpression_6 = null; - if (hasData) { - _xifexpression_6 = (((", " + typeName) + refpd) + " data__et"); - } else { - _xifexpression_6 = ""; - } - String data = _xifexpression_6; - _builder.newLineIfNotEmpty(); - String _xifexpression_7 = null; - if (hasData) { - _xifexpression_7 = ", data__et"; - } else { - _xifexpression_7 = ""; - } - String dataCall = _xifexpression_7; - _builder.newLineIfNotEmpty(); - MessageHandler hdlr = this._roomExtensions.getSendHandler(message, (conj).booleanValue()); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - String _messageSignature = this.messageSignature(portClassName, message.getName(), "", data); - _builder.append(_messageSignature); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - boolean _notEquals = (!Objects.equal(hdlr, null)); - if (_notEquals) { - _builder.append("\t"); - String _translatedCode = AbstractGenerator.getInstance().getTranslatedCode(hdlr.getDetailCode()); - _builder.append(_translatedCode, "\t"); - _builder.newLineIfNotEmpty(); - } else { - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(portClassName, "\t"); - _builder.append("\", \""); - String _name = message.getName(); - _builder.append(_name, "\t"); - _builder.append("\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("\t"); - String _name_1 = pc.getName(); - String _name_2 = message.getName(); - String _plus = (dir + _name_2); - String _sendMessageCall = this.sendMessageCall(hasData, "self", this._cExtensions.memberInUse(_name_1, _plus), (typeName + refp), (refa + "data__et")); - _builder.append(_sendMessageCall, "\t\t"); - _builder.newLineIfNotEmpty(); - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("\t"); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_OUT(self->myInstName, \""); - String _name_3 = message.getName(); - _builder.append(_name_3, "\t\t"); - _builder.append("\", self->peerInstName)"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_EXIT"); - _builder.newLine(); - } - } - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - String _messageSignature_1 = this.messageSignature(replPortClassName, message.getName(), "_broadcast", data); - _builder.append(_messageSignature_1); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - boolean _notEquals_1 = (!Objects.equal(hdlr, null)); - if (_notEquals_1) { - _builder.append("\t"); - _builder.append("int i;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("for (i=0; i<((etReplPort*)self)->size; ++i) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - _builder.append(portClassName, "\t\t"); - _builder.append("_"); - String _name_4 = message.getName(); - _builder.append(_name_4, "\t\t"); - _builder.append("(&((etReplPort*)self)->ports[i].port"); - _builder.append(dataCall, "\t\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("}\t\t\t\t\t"); - _builder.newLine(); - } else { - _builder.append("\t"); - _builder.append("int i;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(replPortClassName, "\t"); - _builder.append("\", \""); - String _name_5 = message.getName(); - _builder.append(_name_5, "\t"); - _builder.append("\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("for (i=0; i<((etReplPort*)self)->size; ++i) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - String _name_6 = pc.getName(); - String _name_7 = message.getName(); - String _plus_1 = (dir + _name_7); - String _sendMessageCall_1 = this.sendMessageCall(hasData, "(&((etReplPort*)self)->ports[i].port)", this._cExtensions.memberInUse(_name_6, _plus_1), (typeName + refp), (refa + "data__et")); - _builder.append(_sendMessageCall_1, "\t\t"); - _builder.newLineIfNotEmpty(); - { - boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_1) { - _builder.append("\t"); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_OUT(((etReplPort*)self)->ports[i].port.myInstName, \""); - String _name_8 = message.getName(); - _builder.append(_name_8, "\t\t"); - _builder.append("\", ((etReplPort*)self)->ports[i].port.peerInstName)"); - _builder.newLineIfNotEmpty(); - } - } - _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(); - String _messageSignature_2 = this.messageSignature(replPortClassName, message.getName(), "", (", int idx__et" + data)); - _builder.append(_messageSignature_2); - _builder.append(" {"); - _builder.newLineIfNotEmpty(); - { - boolean _notEquals_2 = (!Objects.equal(hdlr, null)); - if (_notEquals_2) { - _builder.append("\t"); - _builder.append(portClassName, "\t"); - _builder.append("_"); - String _name_9 = message.getName(); - _builder.append(_name_9, "\t"); - _builder.append("(&((etReplPort*)self)->ports[idx__et].port"); - _builder.append(dataCall, "\t"); - _builder.append(");"); - _builder.newLineIfNotEmpty(); - } else { - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_SYNC_ENTRY(\""); - _builder.append(replPortClassName, "\t"); - _builder.append("\", \""); - String _name_10 = message.getName(); - _builder.append(_name_10, "\t"); - _builder.append("\")"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("if (0<=idx__et && idx__et<((etReplPort*)self)->size) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\t"); - String _name_11 = pc.getName(); - String _name_12 = message.getName(); - String _plus_2 = (dir + _name_12); - String _sendMessageCall_2 = this.sendMessageCall(hasData, "(&((etReplPort*)self)->ports[idx__et].port)", this._cExtensions.memberInUse(_name_11, _plus_2), (typeName + refp), (refa + "data__et")); - _builder.append(_sendMessageCall_2, "\t\t"); - _builder.newLineIfNotEmpty(); - { - boolean _isGenerateMSCInstrumentation_2 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_2) { - _builder.append("\t"); - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_ASYNC_OUT(((etReplPort*)self)->ports[idx__et].port.myInstName, \""); - String _name_13 = message.getName(); - _builder.append(_name_13, "\t\t"); - _builder.append("\", ((etReplPort*)self)->ports[idx__et].port.peerInstName)"); - _builder.newLineIfNotEmpty(); - } - } - _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(); - } - } - { - boolean _isEmpty = allPortClasses.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("/* begin "); - _builder.append(portClassName); - _builder.append(" specific (including base classes) */"); - _builder.newLineIfNotEmpty(); - { - for(final PortClass p : allPortClasses) { - CharSequence _userCode = this._procedureHelpers.userCode(p.getUserCode()); - _builder.append(_userCode); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - { - for(final PortClass p_1 : allPortClasses) { - CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(p_1.getOperations(), portClassName); - _builder.append(_operationsImplementation); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("/* end "); - _builder.append(portClassName); - _builder.append(" specific (including base classes) */"); - _builder.newLineIfNotEmpty(); - _builder.newLine(); - } - } - _builder.append("etInt32 "); - _builder.append(replPortClassName); - _builder.append("_getReplication(const "); - _builder.append(replPortClassName); - _builder.append("* self) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("return ((etReplPort*)self)->size;"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - { - boolean _handlesReceive = this._roomExtensions.handlesReceive(pc, (conj).booleanValue()); - if (_handlesReceive) { - CharSequence _genReceiveHandlers = this.genReceiveHandlers(pc, conj); - _builder.append(_genReceiveHandlers); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private String sendMessageCall(final boolean hasData, final String selfPtr, final String msg, final String typeName, final String data) { - String _xifexpression = null; - if (hasData) { - _xifexpression = (((((((("etPort_sendMessage(" + selfPtr) + ", ") + msg) + ", sizeof(") + typeName) + "), ") + data) + ");"); - } else { - _xifexpression = (((("etPort_sendMessage(" + selfPtr) + ", ") + msg) + ", 0, NULL);"); - } - return _xifexpression; - } - - private String messageSignature(final String className, final String messageName, final String methodSuffix, final String data) { - return ((((((((("void " + className) + "_") + messageName) + methodSuffix) + "(const ") + className) + "* self") + data) + ")"); - } - - private String messageSetterSignature(final String className, final String messageName, final String data) { - return (((((((("void " + className) + "_") + messageName) + "_set(") + className) + "* self") + data) + ")"); - } - - private String messageGetterSignature(final String className, final String messageName, final String type) { - return (((((((type + " ") + className) + "_") + messageName) + "_get(const ") + className) + "* const self)"); - } - - private CharSequence genReceiveHandlers(final ProtocolClass pc, final Boolean conj) { - CharSequence _xblockexpression = null; - { - String portClassName = this._roomExtensions.getPortClassName(pc, (conj).booleanValue()); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("/* receiver handlers */"); - _builder.newLine(); - { - List<MessageHandler> _receiveHandlers = this._roomExtensions.getReceiveHandlers(pc, (conj).booleanValue()); - for(final MessageHandler h : _receiveHandlers) { - _builder.append("void "); - _builder.append(portClassName); - _builder.append("_"); - String _name = h.getMsg().getName(); - _builder.append(_name); - _builder.append("_receiveHandler("); - _builder.append(portClassName); - _builder.append("* self, const etMessage* msg, void * actor, etActorReceiveMessage receiveMessageFunc){"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - String _translatedCode = AbstractGenerator.getInstance().getTranslatedCode(h.getDetailCode()); - _builder.append(_translatedCode, "\t"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("/* hand over the message to the actor: */"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("/* (*receiveMessageFunc)(actor, self, msg); */"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - } - } - _xblockexpression = _builder; - } - return _xblockexpression; - } - - private CharSequence generateDebugHelpersImplementation(final Root root, final ProtocolClass pc) { - StringConcatenation _builder = new StringConcatenation(); - _builder.newLine(); - _builder.append("/* message names as strings for debugging (generate MSC) */"); - _builder.newLine(); - _builder.append("static const char* const "); - String _name = pc.getName(); - _builder.append(_name); - _builder.append("_messageStrings[] = {\"MIN\", "); - { - List<Message> _allOutgoingMessages = this._roomHelpers.getAllOutgoingMessages(pc); - for(final Message m : _allOutgoingMessages) { - _builder.append("\""); - String _name_1 = m.getName(); - _builder.append(_name_1); - _builder.append("\","); - } - } - { - List<Message> _allIncomingMessages = this._roomHelpers.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, "\t"); - _builder.append("_MSG_MIN || msg_id>"); - String _name_5 = pc.getName(); - _builder.append(_name_5, "\t"); - _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, "\t\t"); - _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 deleted file mode 100644 index ab2ca76cf..000000000 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/StateMachineGen.java +++ /dev/null @@ -1,225 +0,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) - */ -package org.eclipse.etrice.generator.c.gen; - -import com.google.common.collect.Iterators; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.List; -import org.eclipse.etrice.core.fsm.fSM.ModelComponent; -import org.eclipse.etrice.core.fsm.fSM.State; -import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; -import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass; -import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions; -import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer; -import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.generator.c.Main; -import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator; -import org.eclipse.etrice.generator.generic.RoomExtensions; -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.IteratorExtensions; - -@Singleton -@SuppressWarnings("all") -public class StateMachineGen extends GenericStateMachineGenerator { - @Inject - @Extension - private RoomExtensions _roomExtensions; - - public CharSequence genHeaderConstants(final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - final Function1<Node, Boolean> _function = (Node it) -> { - boolean _isInherited = it.isInherited(); - return Boolean.valueOf((!_isInherited)); - }; - int _size = IteratorExtensions.size(IteratorExtensions.<Node>filter(FsmGenExtensions.getAllStateNodes(xpac.getGraphContainer().getGraph()), _function)); - final Function1<Node, Boolean> _function_1 = (Node it) -> { - return Boolean.valueOf(FsmGenExtensions.isLeaf(it)); - }; - int _size_1 = IteratorExtensions.size(IteratorExtensions.<Node>filter(FsmGenExtensions.getAllStateNodes(xpac.getGraphContainer().getGraph()), _function_1)); - int _minus = (_size - _size_1); - final int historySize = (_minus + 2); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("/* constant for state machine data */"); - _builder.newLine(); - _builder.append("#define "); - String _upperCase = ac.getName().toUpperCase(); - _builder.append(_upperCase); - _builder.append("_HISTORY_SIZE "); - _builder.append(historySize); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - public CharSequence genDataMembers(final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("/* state machine variables */"); - _builder.newLine(); - _builder.append("etInt16 state;"); - _builder.newLine(); - _builder.append("etInt16 history["); - String _upperCase = ac.getName().toUpperCase(); - _builder.append(_upperCase); - _builder.append("_HISTORY_SIZE];"); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - public CharSequence genInitialization(final ExpandedActorClass xpac) { - CharSequence _xblockexpression = null; - { - final ActorClass ac = xpac.getActorClass(); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("self->state = STATE_TOP;"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("int i;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("for (i=0; i<"); - String _upperCase = ac.getName().toUpperCase(); - _builder.append(_upperCase, "\t"); - _builder.append("_HISTORY_SIZE; ++i)"); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t"); - _builder.append("self->history[i] = NO_STATE;"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - String _operationScope = this.langExt.operationScope(ac.getName(), false); - _builder.append(_operationScope); - _builder.append("executeInitTransition(self);"); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - /** - * @param generateImplementation NOT used - */ - @Override - public CharSequence genExtra(final GraphContainer gc, final boolean generateImplementation) { - CharSequence _xblockexpression = null; - { - final ModelComponent mc = gc.getComponent(); - final Function1<Node, StateGraphNode> _function = (Node it) -> { - return it.getStateGraphNode(); - }; - final List<State> allStates = IteratorExtensions.<State>toList(Iterators.<State>filter(IteratorExtensions.<Node, StateGraphNode>map(FsmGenExtensions.getAllStateNodes(gc.getGraph()), _function), State.class)); - final Iterable<State> states = this._roomExtensions.getLeafStatesLast(allStates); - StringConcatenation _builder = new StringConcatenation(); - { - boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation) { - _builder.append("/* state names */"); - _builder.newLine(); - _builder.append("static char* stateStrings[] = {\"<no state>\",\"<top>\","); - { - boolean _hasElements = false; - for(final State state : states) { - if (!_hasElements) { - _hasElements = true; - } else { - _builder.appendImmediate(",", ""); - } - _builder.append("\""); - String _genStatePathName = this._codegenHelpers.getGenStatePathName(state); - _builder.append(_genStatePathName); - _builder.append("\""); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("};"); - _builder.newLineIfNotEmpty(); - } - } - _builder.newLine(); - String _accessLevelPrivate = this.langExt.accessLevelPrivate(); - _builder.append(_accessLevelPrivate); - _builder.append("void setState("); - String _componentName = mc.getComponentName(); - _builder.append(_componentName); - _builder.append("* self, "); - String _stateType = this.stateType(); - _builder.append(_stateType); - _builder.append(" new_state) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("self->state = new_state;"); - _builder.newLine(); - { - boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation(); - if (_isGenerateMSCInstrumentation_1) { - _builder.append("\t"); - _builder.append("ET_MSC_LOGGER_CHANGE_STATE(self->constData->instName, stateStrings[new_state])"); - _builder.newLine(); - } - } - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - String _accessLevelPrivate_1 = this.langExt.accessLevelPrivate(); - _builder.append(_accessLevelPrivate_1); - String _stateType_1 = this.stateType(); - _builder.append(_stateType_1); - _builder.append(" getState("); - String _componentName_1 = mc.getComponentName(); - _builder.append(_componentName_1); - _builder.append("* self) {"); - _builder.newLineIfNotEmpty(); - _builder.append("\t"); - _builder.append("return self->state;"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - @Override - public String stateType() { - return "etInt16"; - } - - @Override - public String boolType() { - return "etBool"; - } - - @Override - public CharSequence markVariableUsed(final String varname) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("((void)trigger__et);\t/* avoids unused warning */"); - _builder.newLine(); - return _builder; - } - - @Override - public String unreachableReturn() { - return "/* return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) */"; - } -} |