Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-09-20 16:17:17 +0000
committerHenrik Rentz-Reichert2012-09-20 16:17:17 +0000
commitc35b804780f182b40df5508dd904ad224cf8c1e1 (patch)
tree57c203a4038cd36995acdede4383c7fcaa734704 /plugins
parent91bd6ab8de4b1055d27cba242b47330634533c3b (diff)
downloadorg.eclipse.etrice-c35b804780f182b40df5508dd904ad224cf8c1e1.tar.gz
org.eclipse.etrice-c35b804780f182b40df5508dd904ad224cf8c1e1.tar.xz
org.eclipse.etrice-c35b804780f182b40df5508dd904ad224cf8c1e1.zip
[generator.c] basic initialization of attributes
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend6
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend43
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java47
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java124
4 files changed, 174 insertions, 46 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
index cd7c85c8c..5e3ab435e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/ActorClassGen.xtend
@@ -159,12 +159,6 @@ class ActorClassGen extends GenericActorClassGenerator {
«ENDFOR»
«ac.allAttributes.attributes»
-
- «FOR a:ac.allAttributes»
- «IF a.defaultValueLiteral!=null»
- «logger.logInfo(ac.name+" "+a.name+": Attribute initialization not supported in C")»
- «ENDIF»
- «ENDFOR»
«IF !xpac.stateMachine.empty»
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
index dd6acc8bc..1ebb6e129 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend
@@ -18,6 +18,7 @@ import java.util.ArrayList
import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.core.room.ProtocolClass
import org.eclipse.etrice.core.room.CommunicationType
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
@@ -34,6 +35,8 @@ import org.eclipse.etrice.core.room.ActorCommunicationType
import org.eclipse.etrice.generator.generic.TypeHelpers
import org.eclipse.etrice.generator.generic.ILanguageExtension
import static extension org.eclipse.etrice.generator.base.Indexed.*
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.generator.generic.ConfigExtension
@Singleton
class SubSystemClassGen {
@@ -43,6 +46,7 @@ class SubSystemClassGen {
@Inject extension RoomExtensions roomExt
@Inject extension ProcedureHelpers helpers
@Inject extension TypeHelpers
+ @Inject extension ConfigExtension
@Inject ILanguageExtension languageExt
@Inject ILogger logger
@@ -274,7 +278,7 @@ class SubSystemClassGen {
/* forward declaration of variable port structs */
«FOR ai: ssi.allContainedInstances»
«IF ai.orderedIfItemInstances.empty»
-/*nothing to do */
+ /*nothing to do */
«ELSE»
«FOR pi:ai.orderedIfItemInstances»
«IF pi.protocol.getPortClass(pi.conjugated)!=null»
@@ -338,6 +342,7 @@ class SubSystemClassGen {
var dataPorts = simplePorts.filter(p|p.protocol.commType==CommunicationType::DATA_DRIVEN)
var recvPorts = dataPorts.filter(p|p instanceof PortInstance && !(p as PortInstance).port.conjugated)
+ var sendPorts = dataPorts.filter(p|p instanceof PortInstance && (p as PortInstance).port.conjugated)
// compute replicated port offsets
var offsets = new HashMap<InterfaceItemInstance, Integer>()
@@ -375,7 +380,21 @@ class SubSystemClassGen {
«genRecvPortInitializer(root, ai, pi)»
«ENDFOR»
};
- static «ai.actorClass.name» «instName» = {&«instName»_const};
+ static «ai.actorClass.name» «instName» = {
+ &«instName»_const,
+
+ /* data send ports */
+ «FOR pi : sendPorts»
+ «pi.genSendPortInitializer»,
+ «ENDFOR»
+
+ /* attributes */
+ «FOR att : ai.actorClass.allAttributes»
+ «ai.genAttributeInitializer(att)»,
+ «ENDFOR»
+
+ /* state and history are initialized in init fuction */
+ };
«ENDIF»
'''}
@@ -390,6 +409,26 @@ class SubSystemClassGen {
+"} /* Port "+pi.name+" */"
}
+ def private genSendPortInitializer(InterfaceItemInstance pi) {
+ val pc = (pi as PortInstance).port.protocol as ProtocolClass
+
+ '''
+ {
+ «FOR m : pc.incomingMessages SEPARATOR ","»
+ «m.data.refType.type.defaultValue»
+ «ENDFOR»
+ }
+ '''
+ }
+
+ def private genAttributeInitializer(ActorInstance ai, Attribute att) {
+ val value = att.initValueLiteral
+ if (value==null)
+ att.refType.type.defaultValue
+ else
+ value.toString
+ }
+
def private getInterfaceItemInstanceData(InterfaceItemInstance pi){
if (pi.protocol.getPortClass(pi.conjugated)== null) return "0"
if (pi.protocol.getPortClass(pi.conjugated).attributes.empty){
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java
index c174aa5c4..110a5cc24 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/ActorClassGen.java
@@ -473,25 +473,6 @@ public class ActorClassGen extends GenericActorClassGenerator {
CharSequence _attributes = this._procedureHelpers.attributes(_allAttributes);
_builder.append(_attributes, " ");
_builder.newLineIfNotEmpty();
- _builder.newLine();
- {
- List<Attribute> _allAttributes_1 = this._roomExtensions.getAllAttributes(ac);
- for(final Attribute a : _allAttributes_1) {
- {
- String _defaultValueLiteral = a.getDefaultValueLiteral();
- boolean _notEquals_1 = (!Objects.equal(_defaultValueLiteral, null));
- if (_notEquals_1) {
- String _name_16 = ac.getName();
- String _plus = (_name_16 + " ");
- String _name_17 = a.getName();
- String _plus_1 = (_plus + _name_17);
- String _plus_2 = (_plus_1 + ": Attribute initialization not supported in C");
- this.logger.logInfo(_plus_2);
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
_builder.append("\t");
_builder.newLine();
{
@@ -512,17 +493,17 @@ public class ActorClassGen extends GenericActorClassGenerator {
_builder.newLine();
_builder.newLine();
_builder.append("void ");
- String _name_18 = ac.getName();
- _builder.append(_name_18, "");
+ String _name_16 = ac.getName();
+ _builder.append(_name_16, "");
_builder.append("_init(");
- String _name_19 = ac.getName();
- _builder.append(_name_19, "");
+ String _name_17 = ac.getName();
+ _builder.append(_name_17, "");
_builder.append("* self);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("void ");
- String _name_20 = ac.getName();
- _builder.append(_name_20, "");
+ String _name_18 = ac.getName();
+ _builder.append(_name_18, "");
_builder.append("_receiveMessage(void* self, void* ifitem, const etMessage* msg);");
_builder.newLineIfNotEmpty();
_builder.newLine();
@@ -535,19 +516,19 @@ public class ActorClassGen extends GenericActorClassGenerator {
}
if (_or) {
_builder.append("void ");
- String _name_21 = ac.getName();
- _builder.append(_name_21, "");
+ String _name_19 = ac.getName();
+ _builder.append(_name_19, "");
_builder.append("_execute(");
- String _name_22 = ac.getName();
- _builder.append(_name_22, "");
+ String _name_20 = ac.getName();
+ _builder.append(_name_20, "");
_builder.append("* self);");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
EList<StandardOperation> _operations = ac.getOperations();
- String _name_23 = ac.getName();
- CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(_operations, _name_23);
+ String _name_21 = ac.getName();
+ CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(_operations, _name_21);
_builder.append(_operationsDeclaration, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
@@ -555,8 +536,8 @@ public class ActorClassGen extends GenericActorClassGenerator {
_builder.append(_userCode_1, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
- String _name_24 = ac.getName();
- CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(_name_24);
+ String _name_22 = ac.getName();
+ CharSequence _generateIncludeGuardEnd = this._cExtensions.generateIncludeGuardEnd(_name_22);
_builder.append(_generateIncludeGuardEnd, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
index bb5b6d4af..0c5aea00b 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java
@@ -22,6 +22,7 @@ import org.eclipse.etrice.core.room.Attribute;
import org.eclipse.etrice.core.room.CommunicationType;
import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.GeneralProtocolClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.MessageHandler;
@@ -31,8 +32,10 @@ import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.generic.ConfigExtension;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
@@ -62,6 +65,9 @@ public class SubSystemClassGen {
private TypeHelpers _typeHelpers;
@Inject
+ private ConfigExtension _configExtension;
+
+ @Inject
private ILanguageExtension languageExt;
@Inject
@@ -982,6 +988,20 @@ public class SubSystemClassGen {
}
};
Iterable<InterfaceItemInstance> recvPorts = IterableExtensions.<InterfaceItemInstance>filter(dataPorts, _function_5);
+ final Function1<InterfaceItemInstance,Boolean> _function_6 = new Function1<InterfaceItemInstance,Boolean>() {
+ public Boolean apply(final InterfaceItemInstance p) {
+ boolean _and = false;
+ if (!(p instanceof PortInstance)) {
+ _and = false;
+ } else {
+ Port _port = ((PortInstance) p).getPort();
+ boolean _isConjugated = _port.isConjugated();
+ _and = ((p instanceof PortInstance) && _isConjugated);
+ }
+ return Boolean.valueOf(_and);
+ }
+ };
+ Iterable<InterfaceItemInstance> sendPorts = IterableExtensions.<InterfaceItemInstance>filter(dataPorts, _function_6);
HashMap<InterfaceItemInstance,Integer> _hashMap = new HashMap<InterfaceItemInstance,Integer>();
HashMap<InterfaceItemInstance,Integer> offsets = _hashMap;
int offset = 0;
@@ -1015,7 +1035,7 @@ public class SubSystemClassGen {
_builder.append("/* Replicated Sub Ports: {varData, msgService, peerAddress, localId, index} */");
_builder.newLine();
{
- final Function1<InterfaceItemInstance,Boolean> _function_6 = new Function1<InterfaceItemInstance,Boolean>() {
+ final Function1<InterfaceItemInstance,Boolean> _function_7 = new Function1<InterfaceItemInstance,Boolean>() {
public Boolean apply(final InterfaceItemInstance e) {
EList<InterfaceItemInstance> _peers = e.getPeers();
boolean _isEmpty = _peers.isEmpty();
@@ -1023,7 +1043,7 @@ public class SubSystemClassGen {
return Boolean.valueOf(_not);
}
};
- Iterable<InterfaceItemInstance> _filter_2 = IterableExtensions.<InterfaceItemInstance>filter(replPorts, _function_6);
+ Iterable<InterfaceItemInstance> _filter_2 = IterableExtensions.<InterfaceItemInstance>filter(replPorts, _function_7);
boolean _hasElements = false;
for(final InterfaceItemInstance pi : _filter_2) {
if (!_hasElements) {
@@ -1139,10 +1159,50 @@ public class SubSystemClassGen {
_builder.append(_name_1, "");
_builder.append(" ");
_builder.append(instName, "");
- _builder.append(" = {&");
- _builder.append(instName, "");
- _builder.append("_const};");
+ _builder.append(" = {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("&");
+ _builder.append(instName, " ");
+ _builder.append("_const,");
_builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* data send ports */");
+ _builder.newLine();
+ {
+ for(final InterfaceItemInstance pi_3 : sendPorts) {
+ _builder.append("\t");
+ CharSequence _genSendPortInitializer = this.genSendPortInitializer(pi_3);
+ _builder.append(_genSendPortInitializer, " ");
+ _builder.append(",");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* attributes */");
+ _builder.newLine();
+ {
+ ActorClass _actorClass_2 = ai.getActorClass();
+ List<Attribute> _allAttributes = this.roomExt.getAllAttributes(_actorClass_2);
+ for(final Attribute att : _allAttributes) {
+ _builder.append("\t");
+ String _genAttributeInitializer = this.genAttributeInitializer(ai, att);
+ _builder.append(_genAttributeInitializer, " ");
+ _builder.append(",");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/* state and history are initialized in init fuction */");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
}
}
_xblockexpression = (_builder);
@@ -1199,6 +1259,60 @@ public class SubSystemClassGen {
return _xblockexpression;
}
+ private CharSequence genSendPortInitializer(final InterfaceItemInstance pi) {
+ CharSequence _xblockexpression = null;
+ {
+ Port _port = ((PortInstance) pi).getPort();
+ GeneralProtocolClass _protocol = _port.getProtocol();
+ final ProtocolClass pc = ((ProtocolClass) _protocol);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ EList<Message> _incomingMessages = pc.getIncomingMessages();
+ boolean _hasElements = false;
+ for(final Message m : _incomingMessages) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
+ }
+ _builder.append("\t");
+ VarDecl _data = m.getData();
+ RefableType _refType = _data.getRefType();
+ DataType _type = _refType.getType();
+ String _defaultValue = this._typeHelpers.defaultValue(_type);
+ _builder.append(_defaultValue, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder);
+ }
+ return _xblockexpression;
+ }
+
+ private String genAttributeInitializer(final ActorInstance ai, final Attribute att) {
+ String _xblockexpression = null;
+ {
+ final String value = this._configExtension.getInitValueLiteral(att);
+ String _xifexpression = null;
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
+ RefableType _refType = att.getRefType();
+ DataType _type = _refType.getType();
+ String _defaultValue = this._typeHelpers.defaultValue(_type);
+ _xifexpression = _defaultValue;
+ } else {
+ String _string = value.toString();
+ _xifexpression = _string;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
private String getInterfaceItemInstanceData(final InterfaceItemInstance pi) {
ProtocolClass _protocol = pi.getProtocol();
boolean _isConjugated = this.roomExt.isConjugated(pi);

Back to the top