From c8fb83cda6ba0297d86272d914bf49e70bd4d2ed Mon Sep 17 00:00:00 2001 From: Juergen Haug Date: Wed, 12 Dec 2012 19:39:49 +0100 Subject: [generator,doc] update gen.cpp and doc Change-Id: I1e5c01dd57653119ab9eb8c320e39468c6330509 --- .../etrice/generator/cpp/gen/ConfigGenAddon.xtend | 56 +- .../etrice/generator/cpp/gen/ActorClassGen.java | 821 ++++++++++++++++++ .../etrice/generator/cpp/gen/ConfigGenAddon.java | 558 +++++++++++++ .../etrice/generator/cpp/gen/Initialization.java | 297 +++++++ .../etrice/generator/cpp/gen/StateMachineGen.java | 143 ++++ .../generator/cpp/gen/SubSystemClassGen.java | 930 +++++++++++++++++++++ .../generator/cpp/gen/SubSystemRunnerGen.java | 263 ++++++ .../generator/doc/gen/InstanceDiagramGen.java | 237 ++++++ 8 files changed, 3275 insertions(+), 30 deletions(-) create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/Initialization.java create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.java create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.java create mode 100644 plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.java diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend index adcb47143..25375c7e3 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend +++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend @@ -16,18 +16,17 @@ import com.google.inject.Inject import java.util.ArrayList import java.util.List import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance +import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase import org.eclipse.etrice.core.room.ActorClass import org.eclipse.etrice.core.room.Attribute import org.eclipse.etrice.core.room.DataClass -import org.eclipse.etrice.core.room.GeneralProtocolClass -import org.eclipse.etrice.core.room.InterfaceItem +import org.eclipse.etrice.core.room.ExternalType import org.eclipse.etrice.core.room.PrimitiveType -import org.eclipse.etrice.core.room.ProtocolClass +import org.eclipse.etrice.core.room.util.RoomHelpers import org.eclipse.etrice.generator.base.IDataConfiguration import org.eclipse.etrice.generator.generic.ProcedureHelpers import org.eclipse.etrice.generator.generic.RoomExtensions import org.eclipse.etrice.generator.generic.TypeHelpers -import org.eclipse.etrice.core.room.ExternalType class ConfigGenAddon { @@ -40,40 +39,37 @@ class ConfigGenAddon { // For SubSystemClassGen def public genActorInstanceConfig(ActorInstance ai, String aiVariableName){''' - «FOR a : ai.actorClass.attributes» - «applyInstanceConfig(ai, null, aiVariableName, new ArrayList().union(a))» + «FOR a : ai.actorClass.allAttributes» + «applyInstanceConfig(ai, aiVariableName, new ArrayList().union(a))» «ENDFOR» - «FOR p : ai.actorClass.allEndPorts» - «FOR a : getAttributes(p.protocol, !p.conjugated)» - «applyInstanceConfig(ai, p, aiVariableName+"."+invokeGetter(p.name, null), new ArrayList().union(a))» - «ENDFOR» - «ENDFOR» - «FOR sap : ai.actorClass.allSAPs» - «FOR a : getAttributes(sap.protocol, true)» - «applyInstanceConfig(ai, sap, aiVariableName+"."+invokeGetter(sap.name, null), new ArrayList().union(a))» - «ENDFOR» + «FOR pi : ai.orderedIfItemInstances» + «var attribs = RoomHelpers::getPortClass(pi.interfaceItem)?.attributes» + «IF attribs != null» + «FOR a : attribs» + «applyInstanceConfig(pi, aiVariableName+"."+invokeGetter(pi.name, null), new ArrayList().union(a))» + «ENDFOR» + «ENDIF» «ENDFOR» ''' } - def private List getAttributes(GeneralProtocolClass gpc, boolean regular){ - var result = new ArrayList - if(gpc instanceof ProtocolClass){ - var protocol = gpc as ProtocolClass - if(regular && protocol.regular?.attributes != null) - result.addAll(protocol.regular.attributes) - else if(!regular && protocol.conjugate?.attributes != null) - result.addAll(protocol.conjugate.attributes) - } - return result - } +// def private List getAttributes(GeneralProtocolClass gpc, boolean regular){ +// var result = new ArrayList +// if(gpc instanceof ProtocolClass){ +// var protocol = gpc as ProtocolClass +// if(regular && protocol.regular?.attributes != null) +// result.addAll(protocol.regular.attributes) +// else if(!regular && protocol.conjugate?.attributes != null) +// result.addAll(protocol.conjugate.attributes) +// } +// return result +// } - def private applyInstanceConfig(ActorInstance ai, InterfaceItem port, String invokes, List path){ + def private applyInstanceConfig(InstanceBase instance, String invokes, List path){ var a = path.last var aType = a.refType.type if(aType.primitive){ - var value = if(port==null)dataConfigExt.getAttrInstanceConfigValue(ai, path) - else dataConfigExt.getAttrInstanceConfigValue(ai, port, path) + var value = typeHelpers.getAttrInstanceConfigValue(path, instance) if(value == null) '''''' else if(a.size == 0 || aType.characterType) @@ -90,7 +86,7 @@ class ConfigGenAddon { } else if (aType.dataClass)''' «FOR e : (aType as DataClass).attributes» - «applyInstanceConfig(ai, port, invokes+"."+a.name.invokeGetter(null), path.union(e))» + «applyInstanceConfig(instance, invokes+"."+a.name.invokeGetter(null), path.union(e))» «ENDFOR» ''' } diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java new file mode 100644 index 000000000..65bf46776 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java @@ -0,0 +1,821 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.etrice.core.genmodel.base.ILogger; +import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass; +import org.eclipse.etrice.core.genmodel.etricegen.Root; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.room.ActorCommunicationType; +import org.eclipse.etrice.core.room.Attribute; +import org.eclipse.etrice.core.room.DataClass; +import org.eclipse.etrice.core.room.DetailCode; +import org.eclipse.etrice.core.room.Port; +import org.eclipse.etrice.core.room.ProtocolClass; +import org.eclipse.etrice.core.room.RoomModel; +import org.eclipse.etrice.core.room.SAPRef; +import org.eclipse.etrice.core.room.SPPRef; +import org.eclipse.etrice.core.room.ServiceImplementation; +import org.eclipse.etrice.core.room.StandardOperation; +import org.eclipse.etrice.core.room.util.RoomHelpers; +import org.eclipse.etrice.generator.base.AbstractGenerator; +import org.eclipse.etrice.generator.cpp.GeneratorOptions; +import org.eclipse.etrice.generator.cpp.gen.CppExtensions; +import org.eclipse.etrice.generator.cpp.gen.Initialization; +import org.eclipse.etrice.generator.cpp.gen.StateMachineGen; +import org.eclipse.etrice.generator.generic.GenericActorClassGenerator; +import org.eclipse.etrice.generator.generic.ProcedureHelpers; +import org.eclipse.etrice.generator.generic.RoomExtensions; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +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 + private JavaIoFileSystemAccess fileAccess; + + @Inject + private CppExtensions _cppExtensions; + + @Inject + private RoomExtensions _roomExtensions; + + @Inject + private Initialization _initialization; + + @Inject + private ProcedureHelpers _procedureHelpers; + + @Inject + private StateMachineGen _stateMachineGen; + + @Inject + private ILogger logger; + + public void doGenerate(final Root root) { + EList _xpActorClasses = root.getXpActorClasses(); + for (final ExpandedActorClass xpac : _xpActorClasses) { + { + ActorClass _actorClass = xpac.getActorClass(); + String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_actorClass); + ActorClass _actorClass_1 = xpac.getActorClass(); + String _path = this._roomExtensions.getPath(_actorClass_1); + String path = (_generationTargetPath + _path); + ActorClass _actorClass_2 = xpac.getActorClass(); + String _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(_actorClass_2); + String _plus = ("generating ActorClass header \'" + _cppHeaderFileName); + String _plus_1 = (_plus + "\' in \'"); + String _plus_2 = (_plus_1 + path); + String _plus_3 = (_plus_2 + "\'"); + this.logger.logInfo(_plus_3); + this.fileAccess.setOutputPath(path); + ActorClass _actorClass_3 = xpac.getActorClass(); + String _cppHeaderFileName_1 = this._cppExtensions.getCppHeaderFileName(_actorClass_3); + ActorClass _actorClass_4 = xpac.getActorClass(); + CharSequence _generateHeaderFile = this.generateHeaderFile(root, xpac, _actorClass_4); + this.fileAccess.generateFile(_cppHeaderFileName_1, _generateHeaderFile); + ActorClass _actorClass_5 = xpac.getActorClass(); + String _cppSourceFileName = this._cppExtensions.getCppSourceFileName(_actorClass_5); + String _plus_4 = ("generating ActorClass source \'" + _cppSourceFileName); + String _plus_5 = (_plus_4 + "\' in \'"); + String _plus_6 = (_plus_5 + path); + String _plus_7 = (_plus_6 + "\'"); + this.logger.logInfo(_plus_7); + this.fileAccess.setOutputPath(path); + ActorClass _actorClass_6 = xpac.getActorClass(); + String _cppSourceFileName_1 = this._cppExtensions.getCppSourceFileName(_actorClass_6); + ActorClass _actorClass_7 = xpac.getActorClass(); + CharSequence _generateSourceFile = this.generateSourceFile(root, xpac, _actorClass_7); + this.fileAccess.generateFile(_cppSourceFileName_1, _generateSourceFile); + } + } + } + + private CharSequence generateHeaderFile(final Root root, final ExpandedActorClass xpac, final ActorClass ac) { + CharSequence _xblockexpression = null; + { + EList _operations = ac.getOperations(); + final Function1 _function = new Function1() { + public Boolean apply(final StandardOperation op) { + boolean _isConstructor = RoomHelpers.isConstructor(op); + return Boolean.valueOf(_isConstructor); + } + }; + Iterable _filter = IterableExtensions.filter(_operations, _function); + final StandardOperation ctor = IterableExtensions.head(_filter); + EList _operations_1 = ac.getOperations(); + final Function1 _function_1 = new Function1() { + public Boolean apply(final StandardOperation op) { + boolean _isDestructor = op.isDestructor(); + return Boolean.valueOf(_isDestructor); + } + }; + Iterable _filter_1 = IterableExtensions.filter(_operations_1, _function_1); + final StandardOperation dtor = IterableExtensions.head(_filter_1); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("\t"); + _builder.append("/**"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* @author generated by eTrice"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* Header File of ActorClass "); + String _name = ac.getName(); + _builder.append(_name, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t "); + _builder.append("* "); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t"); + String _name_1 = ac.getName(); + CharSequence _generateIncludeGuardBegin = this._cppExtensions.generateIncludeGuardBegin(_name_1); + _builder.append(_generateIncludeGuardBegin, " "); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"platforms/generic/etDatatypes.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/IRTObject.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/PortBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/InterfaceItemBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/ActorClassBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/SubSystemClassBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/Address.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/IMessageReceiver.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/debugging/DebuggingService.h\""); + _builder.newLine(); + { + boolean _isUseEtUnit = GeneratorOptions.isUseEtUnit(); + if (_isUseEtUnit) { + _builder.append("\t"); + _builder.append("extern \"C\" {"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("\t"); + _builder.append("#include \"etUnit.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + } + } + _builder.append("\t"); + _builder.append("#include "); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include "); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + { + EList _referencedModels = root.getReferencedModels(ac); + for(final RoomModel model : _referencedModels) { + } + } + _builder.append("\t"); + _builder.newLine(); + { + EList _referencedProtocolClasses = root.getReferencedProtocolClasses(ac); + for(final ProtocolClass pc : _referencedProtocolClasses) { + _builder.append("\t"); + _builder.append("#include \""); + String _path = this._roomExtensions.getPath(pc); + _builder.append(_path, " "); + String _name_2 = pc.getName(); + _builder.append(_name_2, " "); + _builder.append(".h\""); + _builder.newLineIfNotEmpty(); + } + } + { + HashSet _referencedDataClasses = root.getReferencedDataClasses(ac); + for(final DataClass dc : _referencedDataClasses) { + _builder.append("\t"); + _builder.append("#include \""); + String _path_1 = this._roomExtensions.getPath(dc); + _builder.append(_path_1, " "); + String _name_3 = dc.getName(); + _builder.append(_name_3, " "); + _builder.append(".h\""); + _builder.newLineIfNotEmpty(); + } + } + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + CharSequence _userCode = this._procedureHelpers.userCode(ac, 1); + _builder.append(_userCode, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("class "); + String _name_4 = ac.getName(); + _builder.append(_name_4, " "); + _builder.append(" : public "); + { + ActorClass _base = ac.getBase(); + boolean _notEquals = (!Objects.equal(_base, null)); + if (_notEquals) { + ActorClass _base_1 = ac.getBase(); + String _name_5 = _base_1.getName(); + _builder.append(_name_5, " "); + } else { + _builder.append("etRuntime::ActorClassBase"); + } + } + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("protected:"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- ports"); + _builder.newLine(); + _builder.append("\t\t\t"); + List _endPorts = this._roomExtensions.getEndPorts(ac); + final Function1 _function_2 = new Function1() { + public CharSequence apply(final Port port) { + StringConcatenation _builder = new StringConcatenation(); + String _portClassName = ActorClassGen.this._roomExtensions.getPortClassName(port); + _builder.append(_portClassName, ""); + _builder.append(" "); + String _name = port.getName(); + _builder.append(_name, ""); + _builder.append(";"); + return _builder; + } + }; + List _map = ListExtensions.map(_endPorts, _function_2); + String _join = IterableExtensions.join(_map, "\n"); + _builder.append(_join, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- saps"); + _builder.newLine(); + _builder.append("\t\t\t"); + EList _strSAPs = ac.getStrSAPs(); + final Function1 _function_3 = new Function1() { + public CharSequence apply(final SAPRef sap) { + StringConcatenation _builder = new StringConcatenation(); + String _portClassName = ActorClassGen.this._roomExtensions.getPortClassName(sap); + _builder.append(_portClassName, ""); + _builder.append(" "); + String _name = sap.getName(); + _builder.append(_name, ""); + _builder.append(";"); + return _builder; + } + }; + List _map_1 = ListExtensions.map(_strSAPs, _function_3); + String _join_1 = IterableExtensions.join(_map_1, "\n"); + _builder.append(_join_1, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- services"); + _builder.newLine(); + _builder.append("\t\t\t"); + EList _serviceImplementations = ac.getServiceImplementations(); + final Function1 _function_4 = new Function1() { + public CharSequence apply(final ServiceImplementation svc) { + StringConcatenation _builder = new StringConcatenation(); + String _portClassName = ActorClassGen.this._roomExtensions.getPortClassName(svc); + _builder.append(_portClassName, ""); + _builder.append(" "); + SPPRef _spp = svc.getSpp(); + String _name = _spp.getName(); + _builder.append(_name, ""); + _builder.append(";"); + return _builder; + } + }; + List _map_2 = ListExtensions.map(_serviceImplementations, _function_4); + String _join_2 = IterableExtensions.join(_map_2, "\n"); + _builder.append(_join_2, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- interface item IDs"); + _builder.newLine(); + _builder.append("\t\t\t"); + String _genInterfaceItemConstants = this.genInterfaceItemConstants(xpac, ac); + _builder.append(_genInterfaceItemConstants, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t"); + _builder.newLine(); + _builder.append("\t\t\t"); + EList _attributes = ac.getAttributes(); + CharSequence _attributes_1 = this._procedureHelpers.attributes(_attributes); + _builder.append(_attributes_1, " "); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t\t\t"); + CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(ac); + _builder.append(_operationsImplementation, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("public:"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- construction"); + _builder.newLine(); + _builder.append("\t\t\t"); + String _name_6 = ac.getName(); + _builder.append(_name_6, " "); + _builder.append("(etRuntime::IRTObject* parent, std::string name, const std::vector >& port_addr, "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t "); + _builder.append("const std::vector >& peer_addr);"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("//--------------------- port getters"); + _builder.newLine(); + { + List _endPorts_1 = this._roomExtensions.getEndPorts(ac); + for(final Port ep : _endPorts_1) { + _builder.append("\t\t"); + String _portClassName = this._roomExtensions.getPortClassName(ep); + String _name_7 = ep.getName(); + String _name_8 = ac.getName(); + CharSequence _terImplementation = this._procedureHelpers.getterImplementation(_portClassName, _name_7, _name_8); + _builder.append(_terImplementation, " "); + _builder.newLineIfNotEmpty(); + } + } + { + EList _strSAPs_1 = ac.getStrSAPs(); + for(final SAPRef sap : _strSAPs_1) { + _builder.append("\t\t"); + String _portClassName_1 = this._roomExtensions.getPortClassName(sap); + String _name_9 = sap.getName(); + String _name_10 = ac.getName(); + CharSequence _terImplementation_1 = this._procedureHelpers.getterImplementation(_portClassName_1, _name_9, _name_10); + _builder.append(_terImplementation_1, " "); + _builder.newLineIfNotEmpty(); + } + } + { + EList _serviceImplementations_1 = ac.getServiceImplementations(); + for(final ServiceImplementation svc : _serviceImplementations_1) { + _builder.append("\t\t"); + String _portClassName_2 = this._roomExtensions.getPortClassName(svc); + SPPRef _spp = svc.getSpp(); + String _name_11 = _spp.getName(); + String _name_12 = ac.getName(); + CharSequence _terImplementation_2 = this._procedureHelpers.getterImplementation(_portClassName_2, _name_11, _name_12); + _builder.append(_terImplementation_2, " "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("//--------------------- lifecycle functions"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("virtual void init();"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("virtual void start();"); + _builder.newLine(); + { + boolean _overridesStop = this._roomExtensions.overridesStop(ac); + boolean _not = (!_overridesStop); + if (_not) { + _builder.append("\t\t"); + _builder.append("virtual void stop();"); + _builder.newLine(); + } + } + _builder.append("\t\t\t"); + _builder.append("virtual void destroy();\t\t\t"); + _builder.newLine(); + { + boolean _hasNonEmptyStateMachine = RoomHelpers.hasNonEmptyStateMachine(ac); + if (_hasNonEmptyStateMachine) { + _builder.append("\t\t"); + CharSequence _genStateMachineMethodDeclarations = this._stateMachineGen.genStateMachineMethodDeclarations(xpac); + _builder.append(_genStateMachineMethodDeclarations, " "); + _builder.newLineIfNotEmpty(); + } else { + boolean _hasStateMachine = xpac.hasStateMachine(); + boolean _not_1 = (!_hasStateMachine); + if (_not_1) { + _builder.append("\t\t"); + _builder.append("public: "); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("\t"); + _builder.append("//--------------------- no state machine"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("\t"); + _builder.append("virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("\t"); + _builder.append("virtual void executeInitTransition();"); + _builder.newLine(); + } + } + } + _builder.newLine(); + _builder.append("\t\t"); + CharSequence _userCode_1 = this._procedureHelpers.userCode(ac, 2); + _builder.append(_userCode_1, " "); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("};"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + String _name_13 = ac.getName(); + CharSequence _generateIncludeGuardEnd = this._cppExtensions.generateIncludeGuardEnd(_name_13); + _builder.append(_generateIncludeGuardEnd, " "); + _builder.newLineIfNotEmpty(); + _xblockexpression = (_builder); + } + return _xblockexpression; + } + + private CharSequence generateConstructorInitalizerList(final ActorClass ac) { + ArrayList _arrayList = new ArrayList(); + ArrayList initializerList = _arrayList; + ActorClass _base = ac.getBase(); + boolean _equals = Objects.equal(_base, null); + if (_equals) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0])"); + initializerList.add(_builder); + } else { + StringConcatenation _builder_1 = new StringConcatenation(); + ActorClass _base_1 = ac.getBase(); + String _name = _base_1.getName(); + _builder_1.append(_name, ""); + _builder_1.append("(*this, parent, name, port_addr, peer_addr)"); + initializerList.add(_builder_1); + } + List _endPorts = this._roomExtensions.getEndPorts(ac); + for (final Port ep : _endPorts) { + StringConcatenation _builder_2 = new StringConcatenation(); + String _name_1 = ep.getName(); + _builder_2.append(_name_1, ""); + _builder_2.append("(*this, this, \""); + String _name_2 = ep.getName(); + _builder_2.append(_name_2, ""); + _builder_2.append("\", IFITEM_"); + String _name_3 = ep.getName(); + _builder_2.append(_name_3, ""); + _builder_2.append(", "); + { + int _multiplicity = ep.getMultiplicity(); + boolean _equals_1 = (_multiplicity == 1); + if (_equals_1) { + _builder_2.append("0, "); + } + } + _builder_2.append("port_addr[IFITEM_"); + String _name_4 = ep.getName(); + _builder_2.append(_name_4, ""); + _builder_2.append("]"); + { + int _multiplicity_1 = ep.getMultiplicity(); + boolean _equals_2 = (_multiplicity_1 == 1); + if (_equals_2) { + _builder_2.append("[0]"); + } + } + _builder_2.append(", peer_addr[IFITEM_"); + String _name_5 = ep.getName(); + _builder_2.append(_name_5, ""); + _builder_2.append("]"); + { + int _multiplicity_2 = ep.getMultiplicity(); + boolean _equals_3 = (_multiplicity_2 == 1); + if (_equals_3) { + _builder_2.append("[0]"); + } + } + _builder_2.append(")"); + initializerList.add(_builder_2); + } + EList _strSAPs = ac.getStrSAPs(); + for (final SAPRef sap : _strSAPs) { + StringConcatenation _builder_3 = new StringConcatenation(); + String _name_6 = sap.getName(); + _builder_3.append(_name_6, ""); + _builder_3.append("(*this, this, \""); + String _name_7 = sap.getName(); + _builder_3.append(_name_7, ""); + _builder_3.append("\", IFITEM_"); + String _name_8 = sap.getName(); + _builder_3.append(_name_8, ""); + _builder_3.append(", 0, port_addr[IFITEM_"); + String _name_9 = sap.getName(); + _builder_3.append(_name_9, ""); + _builder_3.append("][0], peer_addr[IFITEM_"); + String _name_10 = sap.getName(); + _builder_3.append(_name_10, ""); + _builder_3.append("][0])"); + initializerList.add(_builder_3); + } + EList _serviceImplementations = ac.getServiceImplementations(); + for (final ServiceImplementation svc : _serviceImplementations) { + StringConcatenation _builder_4 = new StringConcatenation(); + SPPRef _spp = svc.getSpp(); + String _name_11 = _spp.getName(); + _builder_4.append(_name_11, ""); + _builder_4.append("(*this, this, \""); + SPPRef _spp_1 = svc.getSpp(); + String _name_12 = _spp_1.getName(); + _builder_4.append(_name_12, ""); + _builder_4.append("\", IFITEM_"); + SPPRef _spp_2 = svc.getSpp(); + String _name_13 = _spp_2.getName(); + _builder_4.append(_name_13, ""); + _builder_4.append(", port_addr[IFITEM_"); + SPPRef _spp_3 = svc.getSpp(); + String _name_14 = _spp_3.getName(); + _builder_4.append(_name_14, ""); + _builder_4.append("], peer_addr[IFITEM_"); + SPPRef _spp_4 = svc.getSpp(); + String _name_15 = _spp_4.getName(); + _builder_4.append(_name_15, ""); + _builder_4.append("])"); + initializerList.add(_builder_4); + } + EList _attributes = ac.getAttributes(); + for (final Attribute attrib : _attributes) { + CharSequence _attributeInitialization = this._initialization.attributeInitialization(attrib, false); + initializerList.add(_attributeInitialization); + } + StringConcatenation _builder_5 = new StringConcatenation(); + String _join = IterableExtensions.join(initializerList, ",\n"); + _builder_5.append(_join, ""); + _builder_5.newLineIfNotEmpty(); + return _builder_5; + } + + private CharSequence generateSourceFile(final Root root, final ExpandedActorClass xpac, final ActorClass ac) { + CharSequence _xblockexpression = null; + { + EList _operations = ac.getOperations(); + final Function1 _function = new Function1() { + public Boolean apply(final StandardOperation op) { + boolean _isConstructor = RoomHelpers.isConstructor(op); + return Boolean.valueOf(_isConstructor); + } + }; + Iterable _filter = IterableExtensions.filter(_operations, _function); + final StandardOperation ctor = IterableExtensions.head(_filter); + EList _operations_1 = ac.getOperations(); + final Function1 _function_1 = new Function1() { + public Boolean apply(final StandardOperation op) { + boolean _isDestructor = op.isDestructor(); + return Boolean.valueOf(_isDestructor); + } + }; + Iterable _filter_1 = IterableExtensions.filter(_operations_1, _function_1); + final StandardOperation dtor = IterableExtensions.head(_filter_1); + ActorClass _actorClass = xpac.getActorClass(); + ActorCommunicationType _commType = _actorClass.getCommType(); + final boolean async = Objects.equal(_commType, ActorCommunicationType.ASYNCHRONOUS); + 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 _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(ac); + _builder.append(_cppHeaderFileName, ""); + _builder.append("\""); + _builder.newLineIfNotEmpty(); + _builder.append("#include \"common/debugging/DebuggingService.h\""); + _builder.newLine(); + _builder.append("#include "); + _builder.newLine(); + _builder.newLine(); + _builder.append("using namespace etRuntime;"); + _builder.newLine(); + _builder.newLine(); + _builder.newLine(); + String _name_1 = ac.getName(); + _builder.append(_name_1, ""); + _builder.append("::"); + String _name_2 = ac.getName(); + _builder.append(_name_2, ""); + _builder.append("(etRuntime::IRTObject* parent, std::string name, const std::vector >& port_addr, "); + _builder.newLineIfNotEmpty(); + _builder.append(" \t\t\t\t\t\t \t\t\t\t\t\t\t\t\t\t\t "); + _builder.append("const std::vector >& peer_addr)"); + _builder.newLine(); + _builder.append(": "); + CharSequence _generateConstructorInitalizerList = this.generateConstructorInitalizerList(ac); + _builder.append(_generateConstructorInitalizerList, ""); + _builder.newLineIfNotEmpty(); + _builder.append("{"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("setClassName(\""); + String _name_3 = ac.getName(); + _builder.append(_name_3, " "); + _builder.append("\");"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + EList _attributes = ac.getAttributes(); + CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, false); + _builder.append(_attributeInitialization, " "); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + { + if (async) { + _builder.append("\t"); + _builder.append("getMsgsvc()->addAsyncActor(*this);"); + _builder.newLine(); + } + } + { + boolean _notEquals = (!Objects.equal(ctor, null)); + if (_notEquals) { + _builder.append("\t"); + _builder.append("// user defined constructor body"); + _builder.newLine(); + _builder.append("\t"); + AbstractGenerator _instance = AbstractGenerator.getInstance(); + DetailCode _detailCode = ctor.getDetailCode(); + String _translatedCode = _instance.getTranslatedCode(_detailCode); + _builder.append(_translatedCode, " "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + _builder.append("void "); + String _name_4 = ac.getName(); + _builder.append(_name_4, ""); + _builder.append("::init(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("initUser();"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("void "); + String _name_5 = ac.getName(); + _builder.append(_name_5, ""); + _builder.append("::start(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("startUser();"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + { + boolean _overridesStop = this._roomExtensions.overridesStop(ac); + boolean _not = (!_overridesStop); + if (_not) { + _builder.append("void "); + String _name_6 = ac.getName(); + _builder.append(_name_6, ""); + _builder.append("::stop(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("stopUser();"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + } + } + _builder.newLine(); + _builder.append("void "); + String _name_7 = ac.getName(); + _builder.append(_name_7, ""); + _builder.append("::destroy(){"); + _builder.newLineIfNotEmpty(); + { + boolean _notEquals_1 = (!Objects.equal(dtor, null)); + if (_notEquals_1) { + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("\t"); + _builder.append("// user defined destructor body"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("\t"); + AbstractGenerator _instance_1 = AbstractGenerator.getInstance(); + DetailCode _detailCode_1 = dtor.getDetailCode(); + String _translatedCode_1 = _instance_1.getTranslatedCode(_detailCode_1); + _builder.append(_translatedCode_1, " "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + { + boolean _hasNonEmptyStateMachine = RoomHelpers.hasNonEmptyStateMachine(ac); + if (_hasNonEmptyStateMachine) { + CharSequence _genStateMachine = this._stateMachineGen.genStateMachine(xpac, false); + _builder.append(_genStateMachine, ""); + _builder.newLineIfNotEmpty(); + } else { + boolean _hasStateMachine = xpac.hasStateMachine(); + boolean _not_1 = (!_hasStateMachine); + if (_not_1) { + _builder.append("//--------------------- no state machine"); + _builder.newLine(); + _builder.append("void "); + String _name_8 = ac.getName(); + _builder.append(_name_8, ""); + _builder.append("::receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data) {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("handleSystemEvent(ifitem, evt, data);"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + _builder.append("void "); + String _name_9 = ac.getName(); + _builder.append(_name_9, ""); + _builder.append("::executeInitTransition(){"); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + } + } + } + _xblockexpression = (_builder); + } + return _xblockexpression; + } +} diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java new file mode 100644 index 000000000..25db9c587 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java @@ -0,0 +1,558 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance; +import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase; +import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance; +import org.eclipse.etrice.core.room.ActorClass; +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.ExternalType; +import org.eclipse.etrice.core.room.InterfaceItem; +import org.eclipse.etrice.core.room.PortClass; +import org.eclipse.etrice.core.room.PrimitiveType; +import org.eclipse.etrice.core.room.RefableType; +import org.eclipse.etrice.core.room.util.RoomHelpers; +import org.eclipse.etrice.generator.base.IDataConfiguration; +import org.eclipse.etrice.generator.cpp.gen.CppExtensions; +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.Conversions; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.StringExtensions; + +@SuppressWarnings("all") +public class ConfigGenAddon { + @Inject + private CppExtensions stdExt; + + @Inject + private TypeHelpers typeHelpers; + + @Inject + private ProcedureHelpers helpers; + + @Inject + private IDataConfiguration dataConfigExt; + + @Inject + private RoomExtensions _roomExtensions; + + public CharSequence genActorInstanceConfig(final ActorInstance ai, final String aiVariableName) { + StringConcatenation _builder = new StringConcatenation(); + { + ActorClass _actorClass = ai.getActorClass(); + List _allAttributes = this._roomExtensions.getAllAttributes(_actorClass); + for(final Attribute a : _allAttributes) { + ArrayList _arrayList = new ArrayList(); + List _union = this._roomExtensions.union(_arrayList, a); + CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, aiVariableName, _union); + _builder.append(_applyInstanceConfig, ""); + _builder.newLineIfNotEmpty(); + } + } + { + EList _orderedIfItemInstances = ai.getOrderedIfItemInstances(); + for(final InterfaceItemInstance pi : _orderedIfItemInstances) { + InterfaceItem _interfaceItem = pi.getInterfaceItem(); + PortClass _portClass = RoomHelpers.getPortClass(_interfaceItem); + EList attribs = _portClass==null?(EList)null:_portClass.getAttributes(); + _builder.newLineIfNotEmpty(); + { + boolean _notEquals = (!Objects.equal(attribs, null)); + if (_notEquals) { + { + for(final Attribute a_1 : attribs) { + String _plus = (aiVariableName + "."); + String _name = pi.getName(); + CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null); + String _plus_1 = (_plus + _invokeGetter); + ArrayList _arrayList_1 = new ArrayList(); + List _union_1 = this._roomExtensions.union(_arrayList_1, a_1); + CharSequence _applyInstanceConfig_1 = this.applyInstanceConfig(pi, _plus_1, _union_1); + _builder.append(_applyInstanceConfig_1, ""); + _builder.newLineIfNotEmpty(); + } + } + } + } + } + } + return _builder; + } + + private CharSequence applyInstanceConfig(final InstanceBase instance, final String invokes, final List path) { + CharSequence _xblockexpression = null; + { + Attribute a = IterableExtensions.last(path); + RefableType _refType = a.getRefType(); + DataType aType = _refType.getType(); + CharSequence _xifexpression = null; + boolean _isPrimitive = this.typeHelpers.isPrimitive(aType); + if (_isPrimitive) { + CharSequence _xblockexpression_1 = null; + { + String value = this.typeHelpers.getAttrInstanceConfigValue(path, instance); + CharSequence _xifexpression_1 = null; + boolean _equals = Objects.equal(value, null); + if (_equals) { + StringConcatenation _builder = new StringConcatenation(); + _xifexpression_1 = _builder; + } else { + CharSequence _xifexpression_2 = null; + boolean _or = false; + int _size = a.getSize(); + boolean _equals_1 = (_size == 0); + if (_equals_1) { + _or = true; + } else { + boolean _isCharacterType = this.typeHelpers.isCharacterType(aType); + _or = (_equals_1 || _isCharacterType); + } + if (_or) { + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append(invokes, ""); + _builder_1.append("."); + String _name = a.getName(); + String _valueLiteral = this.stdExt.toValueLiteral(((PrimitiveType) aType), value); + CharSequence _invokeSetter = this.helpers.invokeSetter(_name, null, _valueLiteral); + _builder_1.append(_invokeSetter, ""); + _builder_1.append(";"); + _xifexpression_2 = _builder_1; + } else { + CharSequence _xifexpression_3 = null; + int _size_1 = a.getSize(); + String[] _split = value.split(","); + int _size_2 = ((List)Conversions.doWrapArray(_split)).size(); + boolean _equals_2 = (_size_1 == _size_2); + if (_equals_2) { + CharSequence _xblockexpression_2 = null; + { + StringConcatenation _builder_2 = new StringConcatenation(); + _builder_2.append("{ "); + { + String[] _split_1 = value.split(","); + boolean _hasElements = false; + for(final String s : _split_1) { + if (!_hasElements) { + _hasElements = true; + } else { + _builder_2.appendImmediate(", ", ""); + } + String _trim = s.trim(); + String _valueLiteral_1 = this.stdExt.toValueLiteral(((PrimitiveType) aType), _trim); + _builder_2.append(_valueLiteral_1, ""); + } + } + _builder_2.append(" }"); + CharSequence arrayExpr = _builder_2; + StringConcatenation _builder_3 = new StringConcatenation(); + _builder_3.append(invokes, ""); + _builder_3.append("."); + String _name_1 = a.getName(); + StringConcatenation _builder_4 = new StringConcatenation(); + _builder_4.append("new "); + String _typeName = this.typeHelpers.typeName(aType); + _builder_4.append(_typeName, ""); + _builder_4.append("[] "); + _builder_4.append(arrayExpr, ""); + String _string = _builder_4.toString(); + CharSequence _invokeSetter_1 = this.helpers.invokeSetter(_name_1, null, _string); + _builder_3.append(_invokeSetter_1, ""); + _builder_3.append(";"); + _xblockexpression_2 = (_builder_3); + } + _xifexpression_3 = _xblockexpression_2; + } else { + StringConcatenation _builder_2 = new StringConcatenation(); + _builder_2.append("{"); + _builder_2.newLine(); + _builder_2.append("\t"); + String _typeName = this.typeHelpers.typeName(aType); + _builder_2.append(_typeName, " "); + _builder_2.append("[] array = "); + _builder_2.append(invokes, " "); + _builder_2.append("."); + String _name_1 = a.getName(); + CharSequence _invokeGetter = this.helpers.invokeGetter(_name_1, null); + _builder_2.append(_invokeGetter, " "); + _builder_2.append(";"); + _builder_2.newLineIfNotEmpty(); + _builder_2.append("\t"); + _builder_2.append("for (int i=0;i<"); + int _size_3 = a.getSize(); + _builder_2.append(_size_3, " "); + _builder_2.append(";i++){"); + _builder_2.newLineIfNotEmpty(); + _builder_2.append("\t\t"); + _builder_2.append("array[i] = "); + String _valueLiteral_1 = this.stdExt.toValueLiteral(((PrimitiveType) aType), value); + _builder_2.append(_valueLiteral_1, " "); + _builder_2.append(";"); + _builder_2.newLineIfNotEmpty(); + _builder_2.append("}"); + _xifexpression_3 = _builder_2; + } + _xifexpression_2 = _xifexpression_3; + } + _xifexpression_1 = _xifexpression_2; + } + _xblockexpression_1 = (_xifexpression_1); + } + _xifexpression = _xblockexpression_1; + } else { + CharSequence _xifexpression_1 = null; + boolean _isDataClass = this.typeHelpers.isDataClass(aType); + if (_isDataClass) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _attributes = ((DataClass) aType).getAttributes(); + for(final Attribute e : _attributes) { + String _plus = (invokes + "."); + String _name = a.getName(); + CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null); + String _plus_1 = (_plus + _invokeGetter); + List _union = this._roomExtensions.union(path, e); + CharSequence _applyInstanceConfig = this.applyInstanceConfig(instance, _plus_1, _union); + _builder.append(_applyInstanceConfig, ""); + _builder.newLineIfNotEmpty(); + } + } + _xifexpression_1 = _builder; + } + _xifexpression = _xifexpression_1; + } + _xblockexpression = (_xifexpression); + } + return _xblockexpression; + } + + public CharSequence genDynConfigGetterSetter(final ActorClass ac) { + StringConcatenation _builder = new StringConcatenation(); + { + List _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac); + for(final Attribute a : _dynConfigReadAttributes) { + _builder.append("public "); + RefableType _refType = a.getRefType(); + DataType _type = _refType.getType(); + String _typeName = this.typeHelpers.typeName(_type); + _builder.append(_typeName, ""); + { + int _size = a.getSize(); + boolean _greaterThan = (_size > 0); + if (_greaterThan) { + _builder.append("[]"); + } + } + _builder.append(" get"); + String _name = a.getName(); + String _firstUpper = StringExtensions.toFirstUpper(_name); + _builder.append(_firstUpper, ""); + _builder.append("(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("if(lock_"); + String _name_1 = a.getName(); + _builder.append(_name_1, " "); + _builder.append(" == null)"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("return "); + String _name_2 = a.getName(); + _builder.append(_name_2, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("else"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("synchronized(lock_"); + String _name_3 = a.getName(); + _builder.append(_name_3, " "); + _builder.append("){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("return "); + String _name_4 = a.getName(); + _builder.append(_name_4, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("public void set"); + String _name_5 = a.getName(); + String _firstUpper_1 = StringExtensions.toFirstUpper(_name_5); + _builder.append(_firstUpper_1, ""); + _builder.append("("); + RefableType _refType_1 = a.getRefType(); + DataType _type_1 = _refType_1.getType(); + String _typeName_1 = this.typeHelpers.typeName(_type_1); + _builder.append(_typeName_1, ""); + { + int _size_1 = a.getSize(); + boolean _greaterThan_1 = (_size_1 > 0); + if (_greaterThan_1) { + _builder.append("[]"); + } + } + _builder.append(" "); + String _name_6 = a.getName(); + _builder.append(_name_6, ""); + _builder.append("){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("if(lock_"); + String _name_7 = a.getName(); + _builder.append(_name_7, " "); + _builder.append(" == null)"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("this."); + String _name_8 = a.getName(); + _builder.append(_name_8, " "); + _builder.append(" = "); + String _name_9 = a.getName(); + _builder.append(_name_9, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("else"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("synchronized(lock_"); + String _name_10 = a.getName(); + _builder.append(_name_10, " "); + _builder.append("){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t"); + _builder.append("this."); + String _name_11 = a.getName(); + _builder.append(_name_11, " "); + _builder.append(" = "); + String _name_12 = a.getName(); + _builder.append(_name_12, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("public DynConfigLock get"); + String _name_13 = a.getName(); + String _firstUpper_2 = StringExtensions.toFirstUpper(_name_13); + _builder.append(_firstUpper_2, ""); + _builder.append("Lock(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("return lock_"); + String _name_14 = a.getName(); + _builder.append(_name_14, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("}\t"); + _builder.newLine(); + } + } + { + List _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac); + for(final Attribute a_1 : _dynConfigWriteAttributes) { + _builder.append("public void setAndWrite"); + String _name_15 = a_1.getName(); + String _firstUpper_3 = StringExtensions.toFirstUpper(_name_15); + _builder.append(_firstUpper_3, ""); + _builder.append("("); + RefableType _refType_2 = a_1.getRefType(); + DataType _type_2 = _refType_2.getType(); + String _typeName_2 = this.typeHelpers.typeName(_type_2); + _builder.append(_typeName_2, ""); + { + int _size_2 = a_1.getSize(); + boolean _greaterThan_2 = (_size_2 > 0); + if (_greaterThan_2) { + _builder.append("[]"); + } + } + _builder.append(" "); + String _name_16 = a_1.getName(); + _builder.append(_name_16, ""); + _builder.append("){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("set"); + String _name_17 = a_1.getName(); + String _firstUpper_4 = StringExtensions.toFirstUpper(_name_17); + _builder.append(_firstUpper_4, " "); + _builder.append("("); + String _name_18 = a_1.getName(); + _builder.append(_name_18, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.append("variableService.write(this.getInstancePath()+\"/"); + String _name_19 = a_1.getName(); + _builder.append(_name_19, " "); + _builder.append("\", "); + String _name_20 = a_1.getName(); + _builder.append(_name_20, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + } + } + return _builder; + } + + public CharSequence genMinMaxConstants(final ActorClass ac) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _attributes = ac.getAttributes(); + for(final Attribute a : _attributes) { + String _name = a.getName(); + ArrayList _arrayList = new ArrayList(); + List _union = this._roomExtensions.union(_arrayList, a); + CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _name, _union); + _builder.append(_genMinMaxConstantsRec, ""); + _builder.newLineIfNotEmpty(); + } + } + CharSequence result = _builder; + int _length = result.length(); + boolean _notEquals = (_length != 0); + if (_notEquals) { + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("//--------------------- Attribute Specifications"); + String _plus = (result + _builder_1.toString()); + result = _plus; + } + return result; + } + + private CharSequence genMinMaxConstantsRec(final ActorClass ac, final String varNamePath, final List path) { + CharSequence _xblockexpression = null; + { + String temp = ((String) null); + CharSequence _xifexpression = null; + Attribute _last = IterableExtensions.last(path); + RefableType _refType = _last.getRefType(); + DataType _type = _refType.getType(); + boolean _isDataClass = this.typeHelpers.isDataClass(_type); + if (_isDataClass) { + StringConcatenation _builder = new StringConcatenation(); + { + Attribute _last_1 = IterableExtensions.last(path); + RefableType _refType_1 = _last_1.getRefType(); + DataType _type_1 = _refType_1.getType(); + List _allAttributes = this._roomExtensions.getAllAttributes(((DataClass) _type_1)); + for(final Attribute e : _allAttributes) { + String _plus = (varNamePath + "_"); + String _name = e.getName(); + String _plus_1 = (_plus + _name); + List _union = this._roomExtensions.union(path, e); + CharSequence _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _plus_1, _union); + _builder.append(_genMinMaxConstantsRec, ""); + _builder.newLineIfNotEmpty(); + } + } + _xifexpression = _builder; + } else { + CharSequence _xifexpression_1 = null; + Attribute _last_2 = IterableExtensions.last(path); + RefableType _refType_2 = _last_2.getRefType(); + DataType _type_2 = _refType_2.getType(); + if ((_type_2 instanceof ExternalType)) { + _xifexpression_1 = null; + } else { + CharSequence _xblockexpression_1 = null; + { + Attribute _last_3 = IterableExtensions.last(path); + RefableType _refType_3 = _last_3.getRefType(); + DataType _type_3 = _refType_3.getType(); + PrimitiveType aType = ((PrimitiveType) _type_3); + StringConcatenation _builder_1 = new StringConcatenation(); + { + String _attrClassConfigMinValue = this.dataConfigExt.getAttrClassConfigMinValue(ac, path); + String _temp = temp = _attrClassConfigMinValue; + boolean _notEquals = (!Objects.equal(_temp, null)); + if (_notEquals) { + _builder_1.append("public static "); + String _minMaxType = this.getMinMaxType(aType); + _builder_1.append(_minMaxType, ""); + _builder_1.append(" MIN_"); + _builder_1.append(varNamePath, ""); + _builder_1.append(" = "); + String _valueLiteral = this.stdExt.toValueLiteral(aType, temp); + _builder_1.append(_valueLiteral, ""); + _builder_1.append(";"); + _builder_1.newLineIfNotEmpty(); + } + } + { + String _attrClassConfigMaxValue = this.dataConfigExt.getAttrClassConfigMaxValue(ac, path); + String _temp_1 = temp = _attrClassConfigMaxValue; + boolean _notEquals_1 = (!Objects.equal(_temp_1, null)); + if (_notEquals_1) { + _builder_1.append("public static "); + String _minMaxType_1 = this.getMinMaxType(aType); + _builder_1.append(_minMaxType_1, ""); + _builder_1.append(" MAX_"); + _builder_1.append(varNamePath, ""); + _builder_1.append(" = "); + String _valueLiteral_1 = this.stdExt.toValueLiteral(aType, temp); + _builder_1.append(_valueLiteral_1, ""); + _builder_1.append(";"); + _builder_1.newLineIfNotEmpty(); + } + } + _xblockexpression_1 = (_builder_1); + } + _xifexpression_1 = _xblockexpression_1; + } + _xifexpression = _xifexpression_1; + } + _xblockexpression = (_xifexpression); + } + return _xblockexpression; + } + + private String getMinMaxType(final PrimitiveType type) { + String _switchResult = null; + String _typeName = this.typeHelpers.typeName(type); + final String _switchValue = _typeName; + boolean _matched = false; + if (!_matched) { + if (Objects.equal(_switchValue,"byte")) { + _matched=true; + _switchResult = "int"; + } + } + if (!_matched) { + if (Objects.equal(_switchValue,"short")) { + _matched=true; + _switchResult = "int"; + } + } + if (!_matched) { + if (Objects.equal(_switchValue,"float")) { + _matched=true; + _switchResult = "double"; + } + } + if (!_matched) { + String _typeName_1 = this.typeHelpers.typeName(type); + _switchResult = _typeName_1; + } + return _switchResult; + } +} diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/Initialization.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/Initialization.java new file mode 100644 index 000000000..25fb48169 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/Initialization.java @@ -0,0 +1,297 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import java.util.List; +import org.eclipse.etrice.core.room.Attribute; +import org.eclipse.etrice.core.room.ComplexType; +import org.eclipse.etrice.core.room.DataType; +import org.eclipse.etrice.core.room.RefableType; +import org.eclipse.etrice.generator.base.IDataConfiguration; +import org.eclipse.etrice.generator.generic.ILanguageExtension; +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.Conversions; +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 Initialization { + @Inject + private TypeHelpers _typeHelpers; + + @Inject + private RoomExtensions _roomExtensions; + + @Inject + private ILanguageExtension languageExt; + + @Inject + private IDataConfiguration dataConfigExt; + + @Inject + private ProcedureHelpers procedureHelpers; + + public CharSequence attributeInitialization(final List attribs, final boolean useClassDefaultsOnly) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("// initialize attributes"); + _builder.newLine(); + { + for(final Attribute a : attribs) { + RefableType _refType = a.getRefType(); + DataType aType = _refType.getType(); + _builder.newLineIfNotEmpty(); + String value = a.getDefaultValueLiteral(); + _builder.newLineIfNotEmpty(); + { + boolean _notEquals = (!Objects.equal(value, null)); + if (_notEquals) { + { + boolean _or = false; + int _size = a.getSize(); + boolean _equals = (_size == 0); + if (_equals) { + _or = true; + } else { + boolean _isCharacterType = this._typeHelpers.isCharacterType(aType); + _or = (_equals || _isCharacterType); + } + if (_or) { + } else { + boolean _startsWith = value.startsWith("{"); + if (_startsWith) { + String _name = a.getName(); + String _replace = value.replace("{", ""); + String _replace_1 = _replace.replace("}", ""); + String[] _split = _replace_1.split(","); + CharSequence _initializeArrayWithValues = this.initializeArrayWithValues(_name, _split); + _builder.append(_initializeArrayWithValues, ""); + _builder.newLineIfNotEmpty(); + } else { + _builder.append("for (int i=0;i<"); + int _size_1 = a.getSize(); + _builder.append(_size_1, ""); + _builder.append(";i++){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + String _name_1 = a.getName(); + _builder.append(_name_1, " "); + _builder.append("[i] = "); + _builder.append(value, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + } + } + } + } else { + boolean _or_1 = false; + boolean _or_2 = false; + if ((aType instanceof ComplexType)) { + _or_2 = true; + } else { + int _size_2 = a.getSize(); + boolean _greaterThan = (_size_2 > 1); + _or_2 = ((aType instanceof ComplexType) || _greaterThan); + } + if (_or_2) { + _or_1 = true; + } else { + boolean _not = (!useClassDefaultsOnly); + _or_1 = (_or_2 || _not); + } + if (_or_1) { + { + int _size_3 = a.getSize(); + boolean _equals_1 = (_size_3 == 0); + if (_equals_1) { + } else { + { + boolean _not_1 = (!useClassDefaultsOnly); + if (_not_1) { + _builder.append("for (int i=0;i<"); + int _size_4 = a.getSize(); + _builder.append(_size_4, ""); + _builder.append(";i++){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + String _name_2 = a.getName(); + _builder.append(_name_2, " "); + _builder.append("[i] = "); + { + RefableType _refType_1 = a.getRefType(); + boolean _isRef = _refType_1.isRef(); + if (_isRef) { + String _nullPointer = this.languageExt.nullPointer(); + _builder.append(_nullPointer, " "); + } else { + String _defaultValue = this.languageExt.defaultValue(aType); + _builder.append(_defaultValue, " "); + } + } + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + } + } + } + } + } + } + } + } + } + return _builder; + } + + public CharSequence initializeArrayWithValues(final String varName, final String[] values) { + StringConcatenation _builder = new StringConcatenation(); + final Function1 _function = new Function1() { + public String apply(final String v) { + String _plus = (varName + "["); + int _indexOf = ((List)Conversions.doWrapArray(values)).indexOf(v); + String _plus_1 = (_plus + Integer.valueOf(_indexOf)); + String _plus_2 = (_plus_1 + "] = "); + String _plus_3 = (_plus_2 + v); + String _plus_4 = (_plus_3 + ";"); + return _plus_4; + } + }; + List _map = ListExtensions.map(((List)Conversions.doWrapArray(values)), _function); + String _join = IterableExtensions.join(_map, "\r\n"); + _builder.append(_join, ""); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence attributeInitialization(final Attribute a, final boolean useClassDefaultsOnly) { + CharSequence _xblockexpression = null; + { + RefableType _refType = a.getRefType(); + DataType aType = _refType.getType(); + String value = a.getDefaultValueLiteral(); + CharSequence _xifexpression = null; + boolean _notEquals = (!Objects.equal(value, null)); + if (_notEquals) { + CharSequence _xifexpression_1 = null; + boolean _or = false; + int _size = a.getSize(); + boolean _equals = (_size == 0); + if (_equals) { + _or = true; + } else { + boolean _isCharacterType = this._typeHelpers.isCharacterType(aType); + _or = (_equals || _isCharacterType); + } + if (_or) { + CharSequence _xifexpression_2 = null; + RefableType _refType_1 = a.getRefType(); + boolean _isRef = _refType_1.isRef(); + if (_isRef) { + StringConcatenation _builder = new StringConcatenation(); + String _name = a.getName(); + _builder.append(_name, ""); + _builder.append("(new "); + String _name_1 = aType.getName(); + _builder.append(_name_1, ""); + _builder.append("("); + _builder.append(value, ""); + _builder.append("))"); + _xifexpression_2 = _builder; + } else { + StringConcatenation _builder_1 = new StringConcatenation(); + String _name_2 = a.getName(); + _builder_1.append(_name_2, ""); + _builder_1.append("("); + _builder_1.append(value, ""); + _builder_1.append(")"); + _xifexpression_2 = _builder_1; + } + _xifexpression_1 = _xifexpression_2; + } else { + CharSequence _xifexpression_3 = null; + boolean _startsWith = value.startsWith("{"); + if (_startsWith) { + StringConcatenation _builder_2 = new StringConcatenation(); + String _name_3 = a.getName(); + _builder_2.append(_name_3, ""); + _builder_2.append("()"); + _xifexpression_3 = _builder_2; + } else { + StringConcatenation _builder_3 = new StringConcatenation(); + String _name_4 = a.getName(); + _builder_3.append(_name_4, ""); + _builder_3.append("()"); + _xifexpression_3 = _builder_3; + } + _xifexpression_1 = _xifexpression_3; + } + _xifexpression = _xifexpression_1; + } else { + CharSequence _xifexpression_4 = null; + boolean _or_1 = false; + boolean _or_2 = false; + if ((aType instanceof ComplexType)) { + _or_2 = true; + } else { + int _size_1 = a.getSize(); + boolean _greaterThan = (_size_1 > 1); + _or_2 = ((aType instanceof ComplexType) || _greaterThan); + } + if (_or_2) { + _or_1 = true; + } else { + boolean _not = (!useClassDefaultsOnly); + _or_1 = (_or_2 || _not); + } + if (_or_1) { + CharSequence _xifexpression_5 = null; + int _size_2 = a.getSize(); + boolean _equals_1 = (_size_2 == 0); + if (_equals_1) { + CharSequence _xifexpression_6 = null; + RefableType _refType_2 = a.getRefType(); + boolean _isRef_1 = _refType_2.isRef(); + if (_isRef_1) { + StringConcatenation _builder_4 = new StringConcatenation(); + String _name_5 = a.getName(); + _builder_4.append(_name_5, ""); + _builder_4.append("("); + String _nullPointer = this.languageExt.nullPointer(); + _builder_4.append(_nullPointer, ""); + _builder_4.append(")"); + _xifexpression_6 = _builder_4; + } else { + StringConcatenation _builder_5 = new StringConcatenation(); + String _name_6 = a.getName(); + _builder_5.append(_name_6, ""); + _builder_5.append("("); + String _defaultValue = this.languageExt.defaultValue(aType); + _builder_5.append(_defaultValue, ""); + _builder_5.append(")"); + _xifexpression_6 = _builder_5; + } + _xifexpression_5 = _xifexpression_6; + } else { + StringConcatenation _builder_6 = new StringConcatenation(); + String _name_7 = a.getName(); + _builder_6.append(_name_7, ""); + _builder_6.append("()"); + _xifexpression_5 = _builder_6; + } + _xifexpression_4 = _xifexpression_5; + } + _xifexpression = _xifexpression_4; + } + _xblockexpression = (_xifexpression); + } + return _xblockexpression; + } +} diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java new file mode 100644 index 000000000..d0ea74df4 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java @@ -0,0 +1,143 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.emf.common.util.EList; +import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.room.InterfaceItem; +import org.eclipse.etrice.core.room.MessageFromIf; +import org.eclipse.etrice.core.room.State; +import org.eclipse.etrice.generator.cpp.gen.ProtocolClassGen; +import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator; +import org.eclipse.etrice.generator.generic.RoomExtensions; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.util.Pair; +import org.eclipse.xtext.util.Tuples; + +@Singleton +@SuppressWarnings("all") +public class StateMachineGen extends GenericStateMachineGenerator { + @Inject + private RoomExtensions _roomExtensions; + + @Inject + private ProtocolClassGen cppProtGen; + + public CharSequence genExtraDecl(final ExpandedActorClass xpac) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("protected:"); + _builder.newLine(); + _builder.append(" \t"); + _builder.append("static std::string s_stateStrings[];"); + _builder.newLine(); + _builder.newLine(); + _builder.append(" \t"); + _builder.append("int history[];"); + _builder.newLine(); + _builder.newLine(); + _builder.append("private:"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("void setState(int new_state);"); + _builder.newLine(); + return _builder; + } + + public CharSequence genExtra(final ExpandedActorClass xpac) { + CharSequence _xblockexpression = null; + { + final ActorClass ac = xpac.getActorClass(); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("std::string "); + String _name = ac.getName(); + _builder.append(_name, ""); + _builder.append("::s_stateStrings[] = {\"\",\"\","); + { + List _allBaseStatesLeavesLast = this._roomExtensions.getAllBaseStatesLeavesLast(ac); + boolean _hasElements = false; + for(final State state : _allBaseStatesLeavesLast) { + if (!_hasElements) { + _hasElements = true; + } else { + _builder.appendImmediate(",", ""); + } + _builder.append("\""); + String _statePathName = this._roomExtensions.getStatePathName(state); + _builder.append(_statePathName, ""); + _builder.append("\""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("};"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("void "); + String _name_1 = ac.getName(); + _builder.append(_name_1, ""); + _builder.append("::setState(int new_state) {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("if (s_stateStrings[new_state]!=\"Idle\") {"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("std::cout << getInstancePath() << \" -> \" << s_stateStrings[new_state] << std::endl;"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("m_state = new_state;"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _xblockexpression = (_builder); + } + return _xblockexpression; + } + + public String genTriggerConstants(final ExpandedActorClass xpac) { + EList _xifexpression = null; + boolean _usesInheritance = this.langExt.usesInheritance(); + if (_usesInheritance) { + EList _ownTriggers = xpac.getOwnTriggers(); + _xifexpression = _ownTriggers; + } else { + EList _triggers = xpac.getTriggers(); + _xifexpression = _triggers; + } + final EList triggers = _xifexpression; + ArrayList> _arrayList = new ArrayList>(); + final ArrayList> list = _arrayList; + Pair _pair = Tuples.pair("POLLING", "0"); + list.add(_pair); + for (final MessageFromIf mif : triggers) { + String _triggerCodeName = xpac.getTriggerCodeName(mif); + InterfaceItem _from = mif.getFrom(); + String _name = _from.getName(); + String _plus = ("IFITEM_" + _name); + String _plus_1 = (_plus + " + EVT_SHIFT*"); + String _messageID = this.cppProtGen.getMessageID(mif); + String _plus_2 = (_plus_1 + _messageID); + Pair _pair_1 = Tuples.pair(_triggerCodeName, _plus_2); + list.add(_pair_1); + } + return this.langExt.genEnumeration("triggers", list); + } + + public String constPointer(final String classname) { + String _plus = ("const " + classname); + return (_plus + "*"); + } + + public String boolType() { + return "bool"; + } +} diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.java new file mode 100644 index 000000000..368d980b1 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.java @@ -0,0 +1,930 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.genmodel.base.ILogger; +import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance; +import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance; +import org.eclipse.etrice.core.genmodel.etricegen.Root; +import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.room.LogicalThread; +import org.eclipse.etrice.core.room.RoomModel; +import org.eclipse.etrice.core.room.SubSystemClass; +import org.eclipse.etrice.generator.base.IDataConfiguration; +import org.eclipse.etrice.generator.base.Indexed; +import org.eclipse.etrice.generator.cpp.gen.ConfigGenAddon; +import org.eclipse.etrice.generator.cpp.gen.CppExtensions; +import org.eclipse.etrice.generator.generic.ProcedureHelpers; +import org.eclipse.etrice.generator.generic.RoomExtensions; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; + +@Singleton +@SuppressWarnings("all") +public class SubSystemClassGen { + @Inject + private JavaIoFileSystemAccess fileAccess; + + @Inject + private CppExtensions _cppExtensions; + + @Inject + private RoomExtensions _roomExtensions; + + @Inject + private ProcedureHelpers _procedureHelpers; + + @Inject + private IDataConfiguration dataConfigExt; + + @Inject + private ConfigGenAddon configGenAddon; + + @Inject + private ConfigGenAddon configAddon; + + @Inject + private ILogger logger; + + public void doGenerate(final Root root) { + EList _subSystemInstances = root.getSubSystemInstances(); + for (final SubSystemInstance ssi : _subSystemInstances) { + { + SubSystemClass _subSystemClass = ssi.getSubSystemClass(); + String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(_subSystemClass); + SubSystemClass _subSystemClass_1 = ssi.getSubSystemClass(); + String _path = this._roomExtensions.getPath(_subSystemClass_1); + String path = (_generationTargetPath + _path); + SubSystemClass _subSystemClass_2 = ssi.getSubSystemClass(); + String file = this._cppExtensions.getCppHeaderFileName(_subSystemClass_2); + String _plus = ("generating SubSystemClass declaration: \'" + file); + String _plus_1 = (_plus + "\' in \'"); + String _plus_2 = (_plus_1 + path); + String _plus_3 = (_plus_2 + "\'"); + this.logger.logInfo(_plus_3); + this.fileAccess.setOutputPath(path); + SubSystemClass _subSystemClass_3 = ssi.getSubSystemClass(); + CharSequence _generateHeaderFile = this.generateHeaderFile(root, ssi, _subSystemClass_3); + this.fileAccess.generateFile(file, _generateHeaderFile); + SubSystemClass _subSystemClass_4 = ssi.getSubSystemClass(); + String _cppSourceFileName = this._cppExtensions.getCppSourceFileName(_subSystemClass_4); + file = _cppSourceFileName; + String _plus_4 = ("generating SubSystemClass implementation: \'" + file); + String _plus_5 = (_plus_4 + "\' in \'"); + String _plus_6 = (_plus_5 + path); + String _plus_7 = (_plus_6 + "\'"); + this.logger.logInfo(_plus_7); + this.fileAccess.setOutputPath(path); + SubSystemClass _subSystemClass_5 = ssi.getSubSystemClass(); + CharSequence _generateSourceFile = this.generateSourceFile(root, ssi, _subSystemClass_5); + this.fileAccess.generateFile(file, _generateSourceFile); + } + } + } + + public CharSequence generateHeaderFile(final Root root, final SubSystemInstance comp, final SubSystemClass cc) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("/**"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* @author generated by eTrice"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* Header File of SubSystemClass "); + String _name = cc.getName(); + _builder.append(_name, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t "); + _builder.append("* "); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t"); + String _name_1 = cc.getName(); + CharSequence _generateIncludeGuardBegin = this._cppExtensions.generateIncludeGuardBegin(_name_1); + _builder.append(_generateIncludeGuardBegin, " "); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"platforms/generic/etDatatypes.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/IRTObject.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/PortBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/InterfaceItemBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/ActorClassBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/modelbase/SubSystemClassBase.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/Address.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/IMessageReceiver.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/debugging/DebuggingService.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include "); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include "); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + { + EList _referencedModels = root.getReferencedModels(cc); + for(final RoomModel model : _referencedModels) { + } + } + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + CharSequence _userCode = this._procedureHelpers.userCode(cc, 1); + _builder.append(_userCode, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("class "); + String _name_2 = cc.getName(); + _builder.append(_name_2, " "); + _builder.append(" : public etRuntime::SubSystemClassBase{"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t\t"); + CharSequence _userCode_1 = this._procedureHelpers.userCode(cc, 2); + _builder.append(_userCode_1, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("public:"); + _builder.newLine(); + _builder.append("\t\t\t"); + String _name_3 = cc.getName(); + _builder.append(_name_3, " "); + _builder.append("(IRTObject* parent, std::string name)"); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t"); + _builder.append(": etRuntime::SubSystemClassBase(parent, name)"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("{"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("virtual void instantiateMessageServices();"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("virtual void instantiateActors();"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("private:"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("std::vector m_msgServices;"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("};"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + String _name_4 = cc.getName(); + CharSequence _generateIncludeGuardEnd = this._cppExtensions.generateIncludeGuardEnd(_name_4); + _builder.append(_generateIncludeGuardEnd, " "); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence generateSourceFile(final Root root, final SubSystemInstance comp, final SubSystemClass cc) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("/**"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* @author generated by eTrice"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*"); + _builder.newLine(); + _builder.append("\t "); + _builder.append("* Source File of SubsystemClass "); + String _name = cc.getName(); + _builder.append(_name, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t "); + _builder.append("* "); + _builder.newLine(); + _builder.append("\t "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \""); + String _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(cc); + _builder.append(_cppHeaderFileName, " "); + _builder.append("\""); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("#include \"common/debugging/DebuggingService.h\""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("#include \"common/messaging/RTSystemServicesProtocol.h\""); + _builder.newLine(); + { + EList _allContainedInstances = comp.getAllContainedInstances(); + for(final ActorInstance ai : _allContainedInstances) { + _builder.append("\t"); + _builder.append("#include \""); + ActorClass _actorClass = ai.getActorClass(); + String _path = this._roomExtensions.getPath(_actorClass); + _builder.append(_path, " "); + ActorClass _actorClass_1 = ai.getActorClass(); + String _name_1 = _actorClass_1.getName(); + _builder.append(_name_1, " "); + _builder.append(".h\""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.append("#include "); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("using namespace etRuntime;"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("void "); + String _name_2 = cc.getName(); + _builder.append(_name_2, " "); + _builder.append("::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("void "); + String _name_3 = cc.getName(); + _builder.append(_name_3, " "); + _builder.append("::instantiateMessageServices(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("m_msgServices.push_back( new MessageService(this, Address(0, 0, 0),\"MessageService_Main\") );"); + _builder.newLine(); + { + EList _threads = cc.getThreads(); + for(final LogicalThread thread : _threads) { + _builder.append("\t\t"); + _builder.append("m_msgServices.push_back(new MessageService(this, Address(0, "); + EList _threads_1 = cc.getThreads(); + int _indexOf = _threads_1.indexOf(thread); + int _plus = (_indexOf + 1); + _builder.append(_plus, " "); + _builder.append(", 0),\"MessageService_"); + String _name_4 = thread.getName(); + _builder.append(_name_4, " "); + _builder.append("\", /* threadprio */ 0));"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t\t"); + _builder.append("for (std::vector::iterator it=m_msgServices.begin(); it != m_msgServices.end(); ++it) {"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("RTServices::getInstance().getMsgSvcCtrl().addMsgSvc( *(*it));"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("void "); + String _name_5 = cc.getName(); + _builder.append(_name_5, " "); + _builder.append("::instantiateActors(){"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("// all addresses"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// Addresses for the Subsystem Systemport"); + _builder.newLine(); + { + EList _allContainedInstances_1 = comp.getAllContainedInstances(); + int _maxObjId = comp.getMaxObjId(); + Iterable> _indexed = Indexed.indexed(_allContainedInstances_1, _maxObjId); + for(final Indexed ai_1 : _indexed) { + _builder.append("\t"); + _builder.append("Address addr_item_SystemPort_"); + EList _allContainedInstances_2 = comp.getAllContainedInstances(); + ActorInstance _value = ai_1.getValue(); + int _indexOf_1 = _allContainedInstances_2.indexOf(_value); + _builder.append(_indexOf_1, " "); + _builder.append("(0,0,"); + int _index1 = ai_1.getIndex1(); + _builder.append(_index1, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.newLine(); + { + EList _allContainedInstances_3 = comp.getAllContainedInstances(); + for(final ActorInstance ai_2 : _allContainedInstances_3) { + _builder.append("\t"); + _builder.append("// actor instance "); + String _path_1 = ai_2.getPath(); + _builder.append(_path_1, " "); + _builder.append(" itself => Systemport Address"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("// TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("Address addr_item_"); + String _path_2 = ai_2.getPath(); + String _pathName = this._roomExtensions.getPathName(_path_2); + _builder.append(_pathName, " "); + _builder.append("(0,"); + int _threadId = ai_2.getThreadId(); + _builder.append(_threadId, " "); + _builder.append(","); + int _objId = ai_2.getObjId(); + _builder.append(_objId, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("// interface items of "); + String _path_3 = ai_2.getPath(); + _builder.append(_path_3, " "); + _builder.newLineIfNotEmpty(); + { + EList _orderedIfItemInstances = ai_2.getOrderedIfItemInstances(); + for(final InterfaceItemInstance pi : _orderedIfItemInstances) { + { + boolean _isReplicated = pi.isReplicated(); + if (_isReplicated) { + { + EList _peers = pi.getPeers(); + for(final InterfaceItemInstance peer : _peers) { + _builder.append("\t"); + EList _peers_1 = pi.getPeers(); + int i = _peers_1.indexOf(peer); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("Address addr_item_"); + String _path_4 = pi.getPath(); + String _pathName_1 = this._roomExtensions.getPathName(_path_4); + _builder.append(_pathName_1, " "); + _builder.append("_"); + _builder.append(i, " "); + _builder.append("(0,"); + int _threadId_1 = pi.getThreadId(); + _builder.append(_threadId_1, " "); + _builder.append(","); + int _objId_1 = pi.getObjId(); + int _plus_1 = (_objId_1 + i); + _builder.append(_plus_1, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + } + } + } else { + _builder.append("\t"); + _builder.append("Address addr_item_"); + String _path_5 = pi.getPath(); + String _pathName_2 = this._roomExtensions.getPathName(_path_5); + _builder.append(_pathName_2, " "); + _builder.append("(0,"); + int _threadId_2 = ai_2.getThreadId(); + _builder.append(_threadId_2, " "); + _builder.append(","); + int _objId_2 = pi.getObjId(); + _builder.append(_objId_2, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + } + } + } + } + } + } + _builder.newLine(); + _builder.append("\t"); + _builder.append("// instantiate all actor instances"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("m_instances.reserve("); + EList _allContainedInstances_4 = comp.getAllContainedInstances(); + int _size = _allContainedInstances_4.size(); + _builder.append(_size, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + { + EList _allContainedInstances_5 = comp.getAllContainedInstances(); + for(final ActorInstance ai_3 : _allContainedInstances_5) { + _builder.append("\t"); + _builder.append("//----------------------------------------------------------------------------------------------"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// addresses for actor instance: "); + String _name_6 = ai_3.getName(); + _builder.append(_name_6, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("//----------------------------------------------------------------------------------------------"); + _builder.newLine(); + _builder.append("\t"); + CharSequence _generateOwnInterfaceItemAddresses = this.generateOwnInterfaceItemAddresses(ai_3); + _builder.append(_generateOwnInterfaceItemAddresses, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + CharSequence _generatePeerInterfaceItemAddresses = this.generatePeerInterfaceItemAddresses(ai_3, comp); + _builder.append(_generatePeerInterfaceItemAddresses, " "); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("m_instances["); + EList _allContainedInstances_6 = comp.getAllContainedInstances(); + int _indexOf_2 = _allContainedInstances_6.indexOf(ai_3); + _builder.append(_indexOf_2, " "); + _builder.append("] = new "); + ActorClass _actorClass_2 = ai_3.getActorClass(); + String _name_7 = _actorClass_2.getName(); + _builder.append(_name_7, " "); + _builder.append("("); + _builder.newLineIfNotEmpty(); + { + EObject _eContainer = ai_3.eContainer(); + if ((_eContainer instanceof SubSystemInstance)) { + _builder.append("\t"); + _builder.append("\t"); + _builder.append("this,"); + _builder.newLine(); + } else { + _builder.append("\t"); + _builder.append("\t"); + _builder.append("m_instances["); + EList _allContainedInstances_7 = comp.getAllContainedInstances(); + EObject _eContainer_1 = ai_3.eContainer(); + int _indexOf_3 = _allContainedInstances_7.indexOf(_eContainer_1); + _builder.append(_indexOf_3, " "); + _builder.append("],"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.append("\t"); + _builder.append("\""); + String _name_8 = ai_3.getName(); + _builder.append(_name_8, " "); + _builder.append("\","); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("\t"); + String _name_9 = ai_3.getName(); + _builder.append(_name_9, " "); + _builder.append("_ownInterfaceItemAddresses,"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("\t"); + String _name_10 = ai_3.getName(); + _builder.append(_name_10, " "); + _builder.append("_peerInterfaceItemAddresses"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("); "); + _builder.newLine(); + } + } + _builder.append("\t"); + _builder.newLine(); + _builder.newLine(); + _builder.append("// apply instance attribute configurations"); + _builder.newLine(); + { + EList _allContainedInstances_8 = comp.getAllContainedInstances(); + for(final ActorInstance ai_4 : _allContainedInstances_8) { + final CharSequence cfg = this.configGenAddon.genActorInstanceConfig(ai_4, "inst"); + _builder.newLineIfNotEmpty(); + { + int _length = cfg.length(); + boolean _greaterThan = (_length > 0); + if (_greaterThan) { + _builder.append("{"); + _builder.newLine(); + _builder.append("\t"); + ActorClass _actorClass_3 = ai_4.getActorClass(); + String _name_11 = _actorClass_3.getName(); + _builder.append(_name_11, " "); + _builder.append(" inst = ("); + ActorClass _actorClass_4 = ai_4.getActorClass(); + String _name_12 = _actorClass_4.getName(); + _builder.append(_name_12, " "); + _builder.append(") instances["); + EList _allContainedInstances_9 = comp.getAllContainedInstances(); + int _indexOf_4 = _allContainedInstances_9.indexOf(ai_4); + _builder.append(_indexOf_4, " "); + _builder.append("];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append(cfg, " "); + _builder.newLineIfNotEmpty(); + _builder.append("}"); + _builder.newLine(); + } + } + } + } + _builder.newLine(); + _builder.append("\t"); + _builder.append("//----------------------------------------------------------------------------------------------"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// addresses for the subsystem system port"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("//----------------------------------------------------------------------------------------------"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("std::vector
ownAddresses("); + EList _allContainedInstances_10 = comp.getAllContainedInstances(); + int _size_1 = _allContainedInstances_10.size(); + _builder.append(_size_1, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + { + EList _allContainedInstances_11 = comp.getAllContainedInstances(); + for(final ActorInstance ai_5 : _allContainedInstances_11) { + _builder.append("\t"); + _builder.append("ownAddresses["); + EList _allContainedInstances_12 = comp.getAllContainedInstances(); + int _indexOf_5 = _allContainedInstances_12.indexOf(ai_5); + _builder.append(_indexOf_5, " "); + _builder.append("] = addr_item_SystemPort_"); + EList _allContainedInstances_13 = comp.getAllContainedInstances(); + int _indexOf_6 = _allContainedInstances_13.indexOf(ai_5); + _builder.append(_indexOf_6, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.append("std::vector
peerAddresses("); + EList _allContainedInstances_14 = comp.getAllContainedInstances(); + int _size_2 = _allContainedInstances_14.size(); + _builder.append(_size_2, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + { + EList _allContainedInstances_15 = comp.getAllContainedInstances(); + for(final ActorInstance ai_6 : _allContainedInstances_15) { + _builder.append("\t"); + _builder.append("peerAddresses["); + EList _allContainedInstances_16 = comp.getAllContainedInstances(); + int _indexOf_7 = _allContainedInstances_16.indexOf(ai_6); + _builder.append(_indexOf_7, " "); + _builder.append("] = addr_item_"); + String _path_6 = ai_6.getPath(); + String _pathName_3 = this._roomExtensions.getPathName(_path_6); + _builder.append(_pathName_3, " "); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// create the subsystem system port\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("m_RTSystemPort = new RTSystemServicesProtocolConjPortRepl(*this, this, \"RTSystemPort\","); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("0, //local ID"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("ownAddresses,"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("peerAddresses);"); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + return _builder; + } + + public CharSequence generateOwnInterfaceItemAddresses(final ActorInstance ai) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("std::vector > "); + String _name = ai.getName(); + _builder.append(_name, ""); + _builder.append("_ownInterfaceItemAddresses;"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("std::vector
"); + String _name_1 = ai.getName(); + _builder.append(_name_1, ""); + _builder.append("_actorInstanceAddresses(1);"); + _builder.newLineIfNotEmpty(); + String _name_2 = ai.getName(); + _builder.append(_name_2, ""); + _builder.append("_actorInstanceAddresses[0] = addr_item_"); + String _path = ai.getPath(); + String _pathName = this._roomExtensions.getPathName(_path); + _builder.append(_pathName, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + String _name_3 = ai.getName(); + _builder.append(_name_3, ""); + _builder.append("_ownInterfaceItemAddresses.push_back("); + String _name_4 = ai.getName(); + _builder.append(_name_4, ""); + _builder.append("_actorInstanceAddresses);"); + _builder.newLineIfNotEmpty(); + { + EList _orderedIfItemInstances = ai.getOrderedIfItemInstances(); + for(final InterfaceItemInstance pi : _orderedIfItemInstances) { + { + boolean _isReplicated = pi.isReplicated(); + if (_isReplicated) { + { + EList _peers = pi.getPeers(); + boolean _isEmpty = _peers.isEmpty(); + if (_isEmpty) { + _builder.append("std::vector
"); + String _name_5 = ai.getName(); + _builder.append(_name_5, ""); + _builder.append("_"); + String _name_6 = pi.getName(); + _builder.append(_name_6, ""); + _builder.append("Addresses;"); + _builder.newLineIfNotEmpty(); + } else { + _builder.append("std::vector
"); + String _name_7 = ai.getName(); + _builder.append(_name_7, ""); + _builder.append("_"); + String _name_8 = pi.getName(); + _builder.append(_name_8, ""); + _builder.append("Addresses("); + EList _peers_1 = pi.getPeers(); + int _size = _peers_1.size(); + _builder.append(_size, ""); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + { + EList _peers_2 = pi.getPeers(); + for(final InterfaceItemInstance peer : _peers_2) { + String _name_9 = ai.getName(); + _builder.append(_name_9, ""); + _builder.append("_"); + String _name_10 = pi.getName(); + _builder.append(_name_10, ""); + _builder.append("Addresses["); + EList _peers_3 = pi.getPeers(); + int _indexOf = _peers_3.indexOf(peer); + _builder.append(_indexOf, ""); + _builder.append("] = addr_item_"); + String _path_1 = pi.getPath(); + String _pathName_1 = this._roomExtensions.getPathName(_path_1); + _builder.append(_pathName_1, ""); + _builder.append("_"); + EList _peers_4 = pi.getPeers(); + int _indexOf_1 = _peers_4.indexOf(peer); + _builder.append(_indexOf_1, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + } + } + } else { + _builder.append("std::vector
"); + String _name_11 = ai.getName(); + _builder.append(_name_11, ""); + _builder.append("_"); + String _name_12 = pi.getName(); + _builder.append(_name_12, ""); + _builder.append("Addresses(1);"); + _builder.newLineIfNotEmpty(); + String _name_13 = ai.getName(); + _builder.append(_name_13, ""); + _builder.append("_"); + String _name_14 = pi.getName(); + _builder.append(_name_14, ""); + _builder.append("Addresses[0] = addr_item_"); + String _path_2 = pi.getPath(); + String _pathName_2 = this._roomExtensions.getPathName(_path_2); + _builder.append(_pathName_2, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + String _name_15 = ai.getName(); + _builder.append(_name_15, ""); + _builder.append("_ownInterfaceItemAddresses.push_back("); + String _name_16 = ai.getName(); + _builder.append(_name_16, ""); + _builder.append("_"); + String _name_17 = pi.getName(); + _builder.append(_name_17, ""); + _builder.append("Addresses);"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + } + } + return _builder; + } + + public CharSequence generatePeerInterfaceItemAddresses(final ActorInstance ai, final SubSystemInstance comp) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("std::vector > "); + String _name = ai.getName(); + _builder.append(_name, ""); + _builder.append("_peerInterfaceItemAddresses;"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("std::vector
"); + String _name_1 = ai.getName(); + _builder.append(_name_1, ""); + _builder.append("_systemPortAddresses(1);"); + _builder.newLineIfNotEmpty(); + String _name_2 = ai.getName(); + _builder.append(_name_2, ""); + _builder.append("_systemPortAddresses[0] = addr_item_SystemPort_"); + EList _allContainedInstances = comp.getAllContainedInstances(); + int _indexOf = _allContainedInstances.indexOf(ai); + _builder.append(_indexOf, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + String _name_3 = ai.getName(); + _builder.append(_name_3, ""); + _builder.append("_peerInterfaceItemAddresses.push_back("); + String _name_4 = ai.getName(); + _builder.append(_name_4, ""); + _builder.append("_systemPortAddresses);"); + _builder.newLineIfNotEmpty(); + { + EList _orderedIfItemInstances = ai.getOrderedIfItemInstances(); + for(final InterfaceItemInstance pi : _orderedIfItemInstances) { + { + boolean _and = false; + boolean _isReplicated = pi.isReplicated(); + if (!_isReplicated) { + _and = false; + } else { + EList _peers = pi.getPeers(); + boolean _isEmpty = _peers.isEmpty(); + _and = (_isReplicated && _isEmpty); + } + if (_and) { + } else { + { + EList _peers_1 = pi.getPeers(); + boolean _isEmpty_1 = _peers_1.isEmpty(); + if (_isEmpty_1) { + _builder.append("std::vector
"); + String _name_5 = ai.getName(); + _builder.append(_name_5, ""); + _builder.append("_"); + String _name_6 = pi.getName(); + _builder.append(_name_6, ""); + _builder.append("PeerAddresses;"); + _builder.newLineIfNotEmpty(); + } else { + _builder.append("std::vector
"); + String _name_7 = ai.getName(); + _builder.append(_name_7, ""); + _builder.append("_"); + String _name_8 = pi.getName(); + _builder.append(_name_8, ""); + _builder.append("PeerAddresses("); + EList _peers_2 = pi.getPeers(); + int _size = _peers_2.size(); + _builder.append(_size, ""); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + { + EList _peers_3 = pi.getPeers(); + for(final InterfaceItemInstance pp : _peers_3) { + { + boolean _isReplicated_1 = pp.isReplicated(); + if (_isReplicated_1) { + String _name_9 = ai.getName(); + _builder.append(_name_9, ""); + _builder.append("_"); + String _name_10 = pi.getName(); + _builder.append(_name_10, ""); + _builder.append("PeerAddresses["); + EList _peers_4 = pi.getPeers(); + int _indexOf_1 = _peers_4.indexOf(pp); + _builder.append(_indexOf_1, ""); + _builder.append("] = addr_item_"); + String _path = pp.getPath(); + String _pathName = this._roomExtensions.getPathName(_path); + _builder.append(_pathName, ""); + _builder.append("_"); + EList _peers_5 = pp.getPeers(); + int _indexOf_2 = _peers_5.indexOf(pi); + _builder.append(_indexOf_2, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } else { + String _name_11 = ai.getName(); + _builder.append(_name_11, ""); + _builder.append("_"); + String _name_12 = pi.getName(); + _builder.append(_name_12, ""); + _builder.append("PeerAddresses["); + EList _peers_6 = pi.getPeers(); + int _indexOf_3 = _peers_6.indexOf(pp); + _builder.append(_indexOf_3, ""); + _builder.append("] = addr_item_"); + String _path_1 = pp.getPath(); + String _pathName_1 = this._roomExtensions.getPathName(_path_1); + _builder.append(_pathName_1, ""); + _builder.append(";"); + _builder.newLineIfNotEmpty(); + } + } + } + } + } + } + String _name_13 = ai.getName(); + _builder.append(_name_13, ""); + _builder.append("_peerInterfaceItemAddresses.push_back("); + String _name_14 = ai.getName(); + _builder.append(_name_14, ""); + _builder.append("_"); + String _name_15 = pi.getName(); + _builder.append(_name_15, ""); + _builder.append("PeerAddresses);"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder; + } +} diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.java new file mode 100644 index 000000000..b84ba20fd --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.java @@ -0,0 +1,263 @@ +package org.eclipse.etrice.generator.cpp.gen; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.eclipse.emf.common.util.EList; +import org.eclipse.etrice.core.genmodel.etricegen.Root; +import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance; +import org.eclipse.etrice.core.room.SubSystemClass; +import org.eclipse.etrice.generator.cpp.gen.CppExtensions; +import org.eclipse.etrice.generator.generic.RoomExtensions; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; + +@Singleton +@SuppressWarnings("all") +public class SubSystemRunnerGen { + @Inject + private JavaIoFileSystemAccess fileAccess; + + @Inject + private CppExtensions _cppExtensions; + + @Inject + private RoomExtensions roomExt; + + public void doGenerate(final Root root) { + EList _subSystemInstances = root.getSubSystemInstances(); + for (final SubSystemInstance sc : _subSystemInstances) { + { + SubSystemClass _subSystemClass = sc.getSubSystemClass(); + String _generationTargetPath = this.roomExt.getGenerationTargetPath(_subSystemClass); + SubSystemClass _subSystemClass_1 = sc.getSubSystemClass(); + String _path = this.roomExt.getPath(_subSystemClass_1); + String _plus = (_generationTargetPath + _path); + this.fileAccess.setOutputPath(_plus); + SubSystemClass _subSystemClass_2 = sc.getSubSystemClass(); + String _name = _subSystemClass_2.getName(); + String _plus_1 = (_name + "_Runner.h"); + SubSystemClass _subSystemClass_3 = sc.getSubSystemClass(); + CharSequence _generateHeaderFile = this.generateHeaderFile(root, sc, _subSystemClass_3); + this.fileAccess.generateFile(_plus_1, _generateHeaderFile); + SubSystemClass _subSystemClass_4 = sc.getSubSystemClass(); + String _generationTargetPath_1 = this.roomExt.getGenerationTargetPath(_subSystemClass_4); + SubSystemClass _subSystemClass_5 = sc.getSubSystemClass(); + String _path_1 = this.roomExt.getPath(_subSystemClass_5); + String _plus_2 = (_generationTargetPath_1 + _path_1); + this.fileAccess.setOutputPath(_plus_2); + SubSystemClass _subSystemClass_6 = sc.getSubSystemClass(); + String _name_1 = _subSystemClass_6.getName(); + String _plus_3 = (_name_1 + "_Runner.cpp"); + SubSystemClass _subSystemClass_7 = sc.getSubSystemClass(); + CharSequence _generateSourceFile = this.generateSourceFile(root, sc, _subSystemClass_7); + this.fileAccess.generateFile(_plus_3, _generateSourceFile); + } + } + } + + public CharSequence generateHeaderFile(final Root root, final SubSystemInstance ssc, final SubSystemClass cc) { + 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("* this class contains the main function running component "); + String _name = cc.getName(); + _builder.append(_name, " "); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("* it instantiates "); + String _name_1 = cc.getName(); + _builder.append(_name_1, " "); + _builder.append(" and starts and ends the lifecycle"); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + String _name_2 = cc.getName(); + String _plus = (_name_2 + "_Runner"); + CharSequence _generateIncludeGuardBegin = this._cppExtensions.generateIncludeGuardBegin(_plus); + _builder.append(_generateIncludeGuardBegin, ""); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("#include \"common/modelbase/SubSystemRunnerBase.h\""); + _builder.newLine(); + _builder.newLine(); + _builder.append("class "); + String _name_3 = cc.getName(); + String _plus_1 = (_name_3 + "Runner"); + _builder.append(_plus_1, ""); + _builder.append(" :public etRuntime::SubSystemRunnerBase {"); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("/**"); + _builder.newLine(); + _builder.append(" "); + _builder.append("* main function"); + _builder.newLine(); + _builder.append(" "); + _builder.append("* creates component and starts and stops the lifecycle"); + _builder.newLine(); + _builder.append(" "); + _builder.append("*/"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("public:"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("static void run(); "); + _builder.newLine(); + _builder.append("};"); + _builder.newLine(); + _builder.newLine(); + String _name_4 = cc.getName(); + String _plus_2 = (_name_4 + "_Runner"); + CharSequence _generateIncludeGuardEnd = this._cppExtensions.generateIncludeGuardEnd(_plus_2); + _builder.append(_generateIncludeGuardEnd, ""); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public CharSequence generateSourceFile(final Root root, final SubSystemInstance ssi, final SubSystemClass ssc) { + 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("* this class contains the main function running component "); + String _name = ssc.getName(); + _builder.append(_name, " "); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("* it instantiates "); + String _name_1 = ssc.getName(); + _builder.append(_name_1, " "); + _builder.append(" and starts and ends the lifecycle"); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + _builder.newLine(); + _builder.append("#include \""); + String _name_2 = ssc.getName(); + _builder.append(_name_2, ""); + _builder.append(".h\""); + _builder.newLineIfNotEmpty(); + _builder.append("#include \""); + String _name_3 = ssc.getName(); + _builder.append(_name_3, ""); + _builder.append("_Runner.h\""); + _builder.newLineIfNotEmpty(); + _builder.newLine(); + _builder.append("#include "); + _builder.newLine(); + _builder.newLine(); + _builder.newLine(); + _builder.append("/**"); + _builder.newLine(); + _builder.append(" "); + _builder.append("* main function"); + _builder.newLine(); + _builder.append(" "); + _builder.append("* creates component and starts and stops the lifecycle"); + _builder.newLine(); + _builder.append(" "); + _builder.append("*/"); + _builder.newLine(); + _builder.newLine(); + _builder.append("int main(void) {"); + _builder.newLine(); + _builder.append("\t"); + String _name_4 = ssc.getName(); + String _plus = (_name_4 + "Runner"); + _builder.append(_plus, " "); + _builder.append("::run();"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("return 0;"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("void "); + String _name_5 = ssc.getName(); + String _plus_1 = (_name_5 + "Runner"); + _builder.append(_plus_1, ""); + _builder.append("::run() {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + String _name_6 = ssc.getName(); + _builder.append(_name_6, " "); + _builder.append(" main_component(0, \""); + String _name_7 = ssc.getName(); + _builder.append(_name_7, " "); + _builder.append("\");"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("//etUserEntry(); /* platform specific */"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("std::cout << \"*** T H E B E G I N ***\" << std::endl;"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("main_component.init(); // lifecycle init"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("main_component.start(); // lifecycle start"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// application runs until quit "); + _builder.newLine(); + _builder.append("\t"); + _builder.append("waitForQuit(main_component);"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("// end the lifecycle"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("main_component.stop(); // lifecycle stop"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("main_component.destroy(); // lifecycle destroy"); + _builder.newLine(); + _builder.append("\t"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("std::cout << \"*** T H E E N D ***\" << std::endl;"); + _builder.newLine(); + _builder.newLine(); + _builder.append("\t"); + _builder.append("//etUserExit(); /* platform specific */"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + return _builder; + } +} diff --git a/plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.java b/plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.java new file mode 100644 index 000000000..ec54b2af0 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.doc/xtend-gen/org/eclipse/etrice/generator/doc/gen/InstanceDiagramGen.java @@ -0,0 +1,237 @@ +package org.eclipse.etrice.generator.doc.gen; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import java.io.File; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.etmap.util.ETMapUtil; +import org.eclipse.etrice.core.etphys.eTPhys.NodeRef; +import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread; +import org.eclipse.etrice.core.genmodel.base.ILogger; +import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance; +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.etricegen.SystemInstance; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.room.RoomModel; +import org.eclipse.etrice.core.room.SubSystemClass; +import org.eclipse.etrice.generator.base.IRoomGenerator; +import org.eclipse.etrice.generator.generic.RoomExtensions; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.xbase.lib.Exceptions; + +@Singleton +@SuppressWarnings("all") +public class InstanceDiagramGen implements IRoomGenerator { + @Inject + private JavaIoFileSystemAccess fileAccess; + + @Inject + private RoomExtensions roomExt; + + @Inject + private ILogger logger; + + public void doGenerate(final Root root) { + EList _models = root.getModels(); + for (final RoomModel model : _models) { + { + String _docGenerationTargetPath = this.roomExt.getDocGenerationTargetPath(model); + String path = (_docGenerationTargetPath + "/images"); + this.fileAccess.setOutputPath(path); + String batchFile = "dot2jpg.bat"; + EList _systemInstances = root.getSystemInstances(); + for (final SystemInstance sys : _systemInstances) { + { + String _name = sys.getName(); + String file = (_name + "_instanceTree.dot"); + String _plus = ("generating instance tree diagram: \'" + file); + String _plus_1 = (_plus + "\' in \'"); + String _plus_2 = (_plus_1 + path); + String _plus_3 = (_plus_2 + "\'"); + this.logger.logInfo(_plus_3); + CharSequence _generate = this.generate(root, sys); + this.fileAccess.generateFile(file, _generate); + } + } + CharSequence _generate2jpg = this.generate2jpg(root); + this.fileAccess.generateFile(batchFile, _generate2jpg); + this.runDot2Jpg(path, batchFile); + } + } + } + + public CharSequence generate2jpg(final Root root) { + StringConcatenation _builder = new StringConcatenation(); + { + EList _systemInstances = root.getSystemInstances(); + for(final SystemInstance sys : _systemInstances) { + _builder.append("dot -Tjpg -o "); + String _name = sys.getName(); + _builder.append(_name, ""); + _builder.append("_instanceTree.jpg "); + String _name_1 = sys.getName(); + _builder.append(_name_1, ""); + _builder.append("_instanceTree.dot"); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence generate(final Root root, final SystemInstance sys) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("digraph "); + String _name = sys.getName(); + _builder.append(_name, ""); + _builder.append(" {"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("rankdir=TD;"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("node [shape=box];"); + _builder.newLine(); + _builder.append("\t"); + String _path = sys.getPath(); + String _pathName = this.roomExt.getPathName(_path); + _builder.append(_pathName, " "); + _builder.append(" [label=\""); + String _name_1 = sys.getName(); + _builder.append(_name_1, " "); + _builder.append("\\n("); + String _name_2 = sys.getName(); + _builder.append(_name_2, " "); + _builder.append(")\" style=filled color=red];"); + _builder.newLineIfNotEmpty(); + { + EList _instances = sys.getInstances(); + for(final SubSystemInstance ssi : _instances) { + _builder.append("\t"); + String _path_1 = ssi.getPath(); + String _pathName_1 = this.roomExt.getPathName(_path_1); + _builder.append(_pathName_1, " "); + _builder.append(" [label=\""); + String _name_3 = ssi.getName(); + _builder.append(_name_3, " "); + _builder.append("\\n("); + SubSystemClass _subSystemClass = ssi.getSubSystemClass(); + String _name_4 = _subSystemClass.getName(); + _builder.append(_name_4, " "); + _builder.append(")\" style=filled color=yellow];"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + String _path_2 = sys.getPath(); + String _pathName_2 = this.roomExt.getPathName(_path_2); + _builder.append(_pathName_2, " "); + _builder.append(" -> "); + String _path_3 = ssi.getPath(); + String _pathName_3 = this.roomExt.getPathName(_path_3); + _builder.append(_pathName_3, " "); + _builder.append("; "); + _builder.newLineIfNotEmpty(); + { + EList _instances_1 = ssi.getInstances(); + for(final ActorInstance ai : _instances_1) { + _builder.append("\t"); + CharSequence _instance = this.instance(ai); + _builder.append(_instance, " "); + _builder.newLineIfNotEmpty(); + } + } + } + } + _builder.append("}"); + _builder.newLine(); + return _builder; + } + + public CharSequence instance(final ActorInstance ai) { + CharSequence _xblockexpression = null; + { + EObject _eContainer = ai.eContainer(); + final StructureInstance parent = ((StructureInstance) _eContainer); + final PhysicalThread pthread = ETMapUtil.getPhysicalThread(ai); + String _xifexpression = null; + boolean _equals = Objects.equal(pthread, null); + if (_equals) { + _xifexpression = "?"; + } else { + String _name = pthread.getName(); + _xifexpression = _name; + } + final String tname = _xifexpression; + final NodeRef node = ETMapUtil.getNodeRef(ai); + String _xifexpression_1 = null; + boolean _equals_1 = Objects.equal(node, null); + if (_equals_1) { + _xifexpression_1 = "?"; + } else { + String _name_1 = node.getName(); + _xifexpression_1 = _name_1; + } + final String nname = _xifexpression_1; + StringConcatenation _builder = new StringConcatenation(); + String _path = ai.getPath(); + String _pathName = this.roomExt.getPathName(_path); + _builder.append(_pathName, ""); + _builder.append(" [label=\""); + String _name_2 = ai.getName(); + _builder.append(_name_2, ""); + _builder.append("\\n("); + ActorClass _actorClass = ai.getActorClass(); + String _name_3 = _actorClass.getName(); + _builder.append(_name_3, ""); + _builder.append(")\\n@"); + _builder.append(nname, ""); + _builder.append(":"); + _builder.append(tname, ""); + _builder.append("\"];"); + _builder.newLineIfNotEmpty(); + String _path_1 = parent.getPath(); + String _pathName_1 = this.roomExt.getPathName(_path_1); + _builder.append(_pathName_1, ""); + _builder.append(" -> "); + String _path_2 = ai.getPath(); + String _pathName_2 = this.roomExt.getPathName(_path_2); + _builder.append(_pathName_2, ""); + _builder.append("; "); + _builder.newLineIfNotEmpty(); + { + EList _instances = ai.getInstances(); + for(final ActorInstance sub_ai : _instances) { + CharSequence _instance = this.instance(sub_ai); + _builder.append(_instance, ""); + _builder.newLineIfNotEmpty(); + } + } + _xblockexpression = (_builder); + } + return _xblockexpression; + } + + public void runDot2Jpg(final String path, final String bat) { + File _file = new File(path); + File wdir = _file; + try { + Runtime _runtime = Runtime.getRuntime(); + String _plus = ("cmd /C " + bat); + final Process p = _runtime.exec(_plus, null, wdir); + String _plus_1 = (bat + " finished with "); + int _waitFor = p.waitFor(); + String _plus_2 = (_plus_1 + Integer.valueOf(_waitFor)); + this.logger.logInfo(_plus_2); + } catch (final Throwable _t) { + if (_t instanceof Exception) { + final Exception e = (Exception)_t; + e.printStackTrace(); + } else { + throw Exceptions.sneakyThrow(_t); + } + } + } +} -- cgit v1.2.3