summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2012-11-23 07:13:03 (EST)
committerJuergen Haug2012-11-23 07:13:03 (EST)
commit50fcc9f9b85408eb13037b6cfad0af69d756f495 (patch)
tree2579e609252fdc58f0c75d3eae76b409a30d4651
parentcee5a6f76524b0a1412f48ff759c95da41d06c62 (diff)
downloadorg.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.zip
org.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.tar.gz
org.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.tar.bz2
[CQ][generator] first config c generatorrefs/changes/32/8832/1
-rw-r--r--plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend34
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend92
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend71
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java4
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java131
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java317
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java211
-rw-r--r--plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend22
-rw-r--r--plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/.DataConfiguration.java._tracebin45396 -> 43716 bytes
-rw-r--r--plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java24
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend41
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend141
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend3
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java150
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java549
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java4
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java4
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend32
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend15
20 files changed, 1025 insertions, 823 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
index e9a528d..412e494 100644
--- a/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.c/META-INF/MANIFEST.MF
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.2.0",
org.eclipse.ui.ide;bundle-version="3.7.0",
org.eclipse.xtend.lib;bundle-version="2.3.0",
org.eclipse.xtext.generator;bundle-version="2.1.1",
- org.eclipse.xtext.util;bundle-version="2.1.1"
+ org.eclipse.xtext.util;bundle-version="2.1.1",
+ org.eclipse.etrice.generator.config;bundle-version="0.2.0"
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.etrice.generator.c
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
index cb217c6..2b33ada 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend
@@ -156,26 +156,32 @@ class CExtensions implements ILanguageExtension {
""
}
override String toValueLiteral(PrimitiveType type, String value){
- throw new UnsupportedOperationException("TODO Config for C");
+ switch(type.targetName){
+ case "char":
+ "'"+value+"'"
+ case "charPtr":
+ "\""+value+"\""
+ case "stringPtr":
+ "\""+value+"\""
+ default:
+ value
+ }
}
override String defaultValue(DataType dt) {
- if (dt instanceof PrimitiveType) {
- return (dt as PrimitiveType).getDefaultValueLiteral
- }
- else if (dt instanceof ExternalType) {
- if ((dt as ExternalType).defaultValueLiteral != null ){
- return (dt as ExternalType).getDefaultValueLiteral
+ switch dt{
+ PrimitiveType:
+ toValueLiteral(dt, dt.defaultValueLiteral)
+ ExternalType:{
+ if (dt.defaultValueLiteral != null )
+ return dt.getDefaultValueLiteral
+ diagnostician.error("cannot initialize external type "+dt.name, dt.eContainer, dt.eContainingFeature)
+ "cannot instantiate external data type "+dt.name
}
- diagnostician.error("cannot initialize external type "+dt.name, dt.eContainer, dt.eContainingFeature)
- return "cannot instantiate external data type "+dt.name
- }
- else {
- val dc = dt as DataClass
-
+ DataClass:
'''
{
- «FOR att : dc.allAttributes SEPARATOR ","»
+ «FOR att : dt.allAttributes SEPARATOR ","»
«att.initializationWithDefaultValues»
«ENDFOR»
}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend
new file mode 100644
index 0000000..b7dcf14
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend
@@ -0,0 +1,92 @@
+package org.eclipse.etrice.generator.c.gen
+
+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.genmodel.etricegen.InterfaceItemInstance
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.ExternalType
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.generator.base.IDataConfiguration
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+class Initialization {
+
+ @Inject CExtensions languageExt
+ @Inject extension RoomExtensions
+ @Inject extension TypeHelpers
+ @Inject IDataConfiguration dataExt
+
+ def generateAttributeInit(InstanceBase instance, List<Attribute> attributes){'''
+ «FOR a : attributes SEPARATOR ','»
+ «initAttributeArray(instance, new ArrayList<Attribute>.union(a))»
+ «ENDFOR»
+ '''
+ }
+
+ def private initAttributeArray(InstanceBase instance, List<Attribute> path){
+ var a = path.last
+ var COMMENT = ''' /* «a.name»«IF a.size>1»[«a.size»]«ENDIF» */'''.toString
+ if(a.size == 0 || a.refType.type.primitive)
+ initAttribute(instance, path)+COMMENT
+ else
+ '''
+ { «FOR Integer i:1..a.size SEPARATOR ', '»«initAttribute(instance, path)»«ENDFOR» } «COMMENT»
+ '''
+ }
+
+ def private initAttribute(InstanceBase instance, List<Attribute> path) {
+ var a = path.last
+ var aType = a.refType.type
+ if(a.refType.ref){
+ return if(a.defaultValueLiteral != null)
+ a.defaultValueLiteral
+ else
+ languageExt.nullPointer
+ }
+ switch aType{
+ DataClass:
+ '''
+ {
+ «FOR subA : (aType as DataClass).allAttributes SEPARATOR ','»
+ «initAttributeArray(instance, path.union(subA))»
+ «ENDFOR»
+ }'''
+ ExternalType:
+ if(a.defaultValueLiteral != null)
+ a.defaultValueLiteral
+ else
+ languageExt.defaultValue(aType)
+ PrimitiveType: {
+ var value = getPrimitiveValue(instance, path)
+ if(a.size > 0 && aType.characterType && !value.trim.startsWith('{'))
+ '''{ «FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR» }'''
+ else
+ value
+ }
+ }
+ }
+
+ def private getPrimitiveValue(InstanceBase instance, List<Attribute> path){
+ var value = switch instance {
+ ActorInstance: dataExt.getAttrInstanceConfigValue(instance, path)
+ InterfaceItemInstance: dataExt.getAttrInstanceConfigValue(instance, path)
+ }
+ if(value == null)
+ value = switch instance {
+ ActorInstance: dataExt.getAttrClassConfigValue(instance.actorClass, path)
+ InterfaceItemInstance: dataExt.getAttrClassConfigValue(instance.protocol, !instance.conjugated, path)
+ }
+ if(value == null)
+ value = path.last.defaultValueLiteral
+ return if(value != null) languageExt.toValueLiteral(path.last.refType.type as PrimitiveType, value)
+ else languageExt.defaultValue(path.last.refType.type)
+ }
+
+
+
+} \ No newline at end of file
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 bc73031..cd495f1 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
@@ -13,28 +13,26 @@
package org.eclipse.etrice.generator.c.gen
-import java.util.HashMap
-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.*
-
+import java.util.ArrayList
+import java.util.HashMap
import org.eclipse.etrice.core.genmodel.base.ILogger
-import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
-import org.eclipse.etrice.core.genmodel.etricegen.PortInstance
import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance
+import org.eclipse.etrice.core.genmodel.etricegen.PortInstance
+import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.core.room.ActorCommunicationType
+import org.eclipse.etrice.core.room.CommunicationType
+import org.eclipse.etrice.core.room.ProtocolClass
+import org.eclipse.etrice.core.room.SubSystemClass
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.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
@Singleton
class SubSystemClassGen {
@@ -43,6 +41,7 @@ class SubSystemClassGen {
@Inject extension CExtensions stdExt
@Inject extension RoomExtensions roomExt
@Inject extension ProcedureHelpers helpers
+ @Inject Initialization attrInitGenAddon
@Inject ILanguageExtension languageExt
@Inject ILogger logger
@@ -277,14 +276,11 @@ class SubSystemClassGen {
/*nothing to do */
«ELSE»
«FOR pi:ai.orderedIfItemInstances»
- «IF pi.protocol.getPortClass(pi.conjugated)!=null»
- «IF !pi.protocol.getPortClass(pi.conjugated).attributes.empty»
- «IF pi.replicated»
- static «pi.protocol.getPortClassName(pi.conjugated)»_var «pi.path.pathName»_var[«pi.peers.size»]={«genReplPortAttributeInitializer(pi)»};
- «ELSE»
- static «pi.protocol.getPortClassName(pi.conjugated)»_var «pi.path.pathName»_var={«genPortAttributeInitializer(pi)»};
- «ENDIF»
- «ENDIF»
+ «IF !pi.protocol.getPortClass(pi.conjugated)?.attributes?.empty»
+ static «pi.protocol.getPortClassName(pi.conjugated)»_var «pi.path.pathName»_var«IF pi.replicated»[«pi.peers.size»]«ENDIF»={
+ «FOR Integer i:1..pi.peers.size SEPARATOR ', '»
+ «attrInitGenAddon.generateAttributeInit(pi, pi.interfaceItem.portClass.attributes)»
+ «ENDFOR»};
«ENDIF»
«ENDFOR»
«ENDIF»
@@ -302,25 +298,6 @@ class SubSystemClassGen {
'''
}
-
- def private genReplPortAttributeInitializer(InterfaceItemInstance pi){
- var int i
- var retval=""
- i=pi.peers.size
-
- while (i>0){
- retval=retval+"
- {"+genPortAttributeInitializer(pi)+"}"
- i=i-1
- if (i>0){retval=retval+","}
- }
- return retval
- }
-
- def private genPortAttributeInitializer(InterfaceItemInstance pi){
- '''
- «FOR attr:pi.protocol.getPortClass(pi.conjugated).attributes SEPARATOR ","»«IF attr.defaultValueLiteral != null»«attr.defaultValueLiteral»«ELSE»«attr.refType.type.defaultValue»«ENDIF»«ENDFOR»'''
- }
def private genActorInstanceInitializer(Root root, ActorInstance ai) {
var instName = ai.path.pathName
@@ -385,9 +362,7 @@ class SubSystemClassGen {
«ENDFOR»
/* attributes */
- «FOR att : ai.actorClass.allAttributes»
- «ai.genAttributeInitializer(att)», /* «att.name»«IF att.size>1»[«att.size»]«ENDIF» */
- «ENDFOR»
+ «attrInitGenAddon.generateAttributeInit(ai, ai.actorClass.allAttributes)»
/* state and history are initialized in init fuction */
};
@@ -417,14 +392,6 @@ class SubSystemClassGen {
'''
}
- def private genAttributeInitializer(ActorInstance ai, Attribute att) {
- val value = null as String // att.initValueLiteral
- if (value==null)
- att.initializationWithDefaultValues
- 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/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
index ef3849a..5700b78 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java
@@ -14,6 +14,7 @@ package org.eclipse.etrice.generator.c.setup;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.GeneratorBaseModule;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.c.Main;
import org.eclipse.etrice.generator.c.gen.CTranslationProvider;
@@ -21,6 +22,7 @@ import org.eclipse.etrice.generator.c.gen.MainGen;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.etrice.generator.c.gen.CExtensions;
+import org.eclipse.etrice.generator.config.DataConfiguration;
import com.google.inject.Binder;
@@ -37,6 +39,8 @@ public class GeneratorModule extends GeneratorBaseModule {
binder.bind(ILanguageExtension.class).to(CExtensions.class);
binder.bind(ITranslationProvider.class).to(CTranslationProvider.class);
+
+ binder.bind(IDataConfiguration.class).to(DataConfiguration.class);
}
}
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
index a25ace5..6cd31c4 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java
@@ -250,60 +250,103 @@ public class CExtensions implements ILanguageExtension {
}
public String toValueLiteral(final PrimitiveType type, final String value) {
- UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("TODO Config for C");
- throw _unsupportedOperationException;
+ String _switchResult = null;
+ String _targetName = type.getTargetName();
+ final String _switchValue = _targetName;
+ boolean _matched = false;
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"char")) {
+ _matched=true;
+ String _plus = ("\'" + value);
+ String _plus_1 = (_plus + "\'");
+ _switchResult = _plus_1;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"charPtr")) {
+ _matched=true;
+ String _plus_2 = ("\"" + value);
+ String _plus_3 = (_plus_2 + "\"");
+ _switchResult = _plus_3;
+ }
+ }
+ if (!_matched) {
+ if (Objects.equal(_switchValue,"stringPtr")) {
+ _matched=true;
+ String _plus_4 = ("\"" + value);
+ String _plus_5 = (_plus_4 + "\"");
+ _switchResult = _plus_5;
+ }
+ }
+ if (!_matched) {
+ _switchResult = value;
+ }
+ return _switchResult;
}
public String defaultValue(final DataType dt) {
- String _xifexpression = null;
- if ((dt instanceof PrimitiveType)) {
- return ((PrimitiveType) dt).getDefaultValueLiteral();
- } else {
- String _xifexpression_1 = null;
- if ((dt instanceof ExternalType)) {
- String _defaultValueLiteral = ((ExternalType) dt).getDefaultValueLiteral();
- boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
- if (_notEquals) {
- return ((ExternalType) dt).getDefaultValueLiteral();
- }
- String _name = dt.getName();
- String _plus = ("cannot initialize external type " + _name);
- EObject _eContainer = dt.eContainer();
- EStructuralFeature _eContainingFeature = dt.eContainingFeature();
- this.diagnostician.error(_plus, _eContainer, _eContainingFeature);
- String _name_1 = dt.getName();
- return ("cannot instantiate external data type " + _name_1);
- } else {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (dt instanceof PrimitiveType) {
+ final PrimitiveType _primitiveType = (PrimitiveType)dt;
+ _matched=true;
+ String _defaultValueLiteral = _primitiveType.getDefaultValueLiteral();
+ String _valueLiteral = this.toValueLiteral(_primitiveType, _defaultValueLiteral);
+ _switchResult = _valueLiteral;
+ }
+ }
+ if (!_matched) {
+ if (dt instanceof ExternalType) {
+ final ExternalType _externalType = (ExternalType)dt;
+ _matched=true;
String _xblockexpression = null;
{
- final DataClass dc = ((DataClass) dt);
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("{");
- _builder.newLine();
- {
- List<Attribute> _allAttributes = this._roomExtensions.getAllAttributes(dc);
- boolean _hasElements = false;
- for(final Attribute att : _allAttributes) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(",", " ");
- }
- _builder.append("\t");
- String _initializationWithDefaultValues = this.initializationWithDefaultValues(att);
- _builder.append(_initializationWithDefaultValues, " ");
- _builder.newLineIfNotEmpty();
+ String _defaultValueLiteral = _externalType.getDefaultValueLiteral();
+ boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
+ if (_notEquals) {
+ return _externalType.getDefaultValueLiteral();
+ }
+ String _name = _externalType.getName();
+ String _plus = ("cannot initialize external type " + _name);
+ EObject _eContainer = _externalType.eContainer();
+ EStructuralFeature _eContainingFeature = _externalType.eContainingFeature();
+ this.diagnostician.error(_plus, _eContainer, _eContainingFeature);
+ String _name_1 = _externalType.getName();
+ String _plus_1 = ("cannot instantiate external data type " + _name_1);
+ _xblockexpression = (_plus_1);
+ }
+ _switchResult = _xblockexpression;
+ }
+ }
+ if (!_matched) {
+ if (dt instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)dt;
+ _matched=true;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ List<Attribute> _allAttributes = this._roomExtensions.getAllAttributes(_dataClass);
+ boolean _hasElements = false;
+ for(final Attribute att : _allAttributes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
}
+ _builder.append("\t");
+ String _initializationWithDefaultValues = this.initializationWithDefaultValues(att);
+ _builder.append(_initializationWithDefaultValues, " ");
+ _builder.newLineIfNotEmpty();
}
- _builder.append("}");
- _builder.newLine();
- _xblockexpression = (_builder.toString());
}
- _xifexpression_1 = _xblockexpression;
+ _builder.append("}");
+ _builder.newLine();
+ _switchResult = _builder.toString();
}
- _xifexpression = _xifexpression_1;
}
- return _xifexpression;
+ return _switchResult;
}
public String initializationWithDefaultValues(final DataType dt, final int size) {
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java
new file mode 100644
index 0000000..9af39c7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java
@@ -0,0 +1,317 @@
+package org.eclipse.etrice.generator.c.gen;
+
+import com.google.common.base.Objects;
+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.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.PrimitiveType;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.c.gen.CExtensions;
+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.IntegerRange;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@SuppressWarnings("all")
+public class Initialization {
+ @Inject
+ private CExtensions languageExt;
+
+ @Inject
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ private TypeHelpers _typeHelpers;
+
+ @Inject
+ private IDataConfiguration dataExt;
+
+ public CharSequence generateAttributeInit(final InstanceBase instance, final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ boolean _hasElements = false;
+ for(final Attribute a : attributes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", "");
+ }
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _initAttributeArray = this.initAttributeArray(instance, _union);
+ _builder.append(_initAttributeArray, "");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ return _builder;
+ }
+
+ private CharSequence initAttributeArray(final InstanceBase instance, final List<Attribute> path) {
+ CharSequence _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("\t\t");
+ _builder.append("/* ");
+ String _name = a.getName();
+ _builder.append(_name, " ");
+ {
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 1);
+ if (_greaterThan) {
+ _builder.append("[");
+ int _size_1 = a.getSize();
+ _builder.append(_size_1, " ");
+ _builder.append("]");
+ }
+ }
+ _builder.append(" */");
+ String COMMENT = _builder.toString();
+ CharSequence _xifexpression = null;
+ boolean _or = false;
+ int _size_2 = a.getSize();
+ boolean _equals = (_size_2 == 0);
+ if (_equals) {
+ _or = true;
+ } else {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
+ _or = (_equals || _isPrimitive);
+ }
+ if (_or) {
+ String _initAttribute = this.initAttribute(instance, path);
+ String _plus = (_initAttribute + COMMENT);
+ _xifexpression = _plus;
+ } else {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("{ ");
+ {
+ int _size_3 = a.getSize();
+ IntegerRange _upTo = new IntegerRange(1, _size_3);
+ boolean _hasElements = false;
+ for(final Integer i : _upTo) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder_1.appendImmediate(", ", "");
+ }
+ String _initAttribute_1 = this.initAttribute(instance, path);
+ _builder_1.append(_initAttribute_1, "");
+ }
+ }
+ _builder_1.append(" } ");
+ _builder_1.append(COMMENT, "");
+ _builder_1.newLineIfNotEmpty();
+ _xifexpression = _builder_1;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
+
+ private String initAttribute(final InstanceBase instance, final List<Attribute> path) {
+ String _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ RefableType _refType_1 = a.getRefType();
+ boolean _isRef = _refType_1.isRef();
+ if (_isRef) {
+ String _xifexpression = null;
+ String _defaultValueLiteral = a.getDefaultValueLiteral();
+ boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
+ if (_notEquals) {
+ String _defaultValueLiteral_1 = a.getDefaultValueLiteral();
+ _xifexpression = _defaultValueLiteral_1;
+ } else {
+ String _nullPointer = this.languageExt.nullPointer();
+ _xifexpression = _nullPointer;
+ }
+ return _xifexpression;
+ }
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (aType instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)aType;
+ _matched=true;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ List<Attribute> _allAttributes = this._roomExtensions.getAllAttributes(((DataClass) _dataClass));
+ boolean _hasElements = false;
+ for(final Attribute subA : _allAttributes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
+ }
+ _builder.append("\t");
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(path, subA);
+ CharSequence _initAttributeArray = this.initAttributeArray(instance, _union);
+ _builder.append(_initAttributeArray, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _switchResult = _builder.toString();
+ }
+ }
+ if (!_matched) {
+ if (aType instanceof ExternalType) {
+ final ExternalType _externalType = (ExternalType)aType;
+ _matched=true;
+ String _xifexpression_1 = null;
+ String _defaultValueLiteral_2 = a.getDefaultValueLiteral();
+ boolean _notEquals_1 = (!Objects.equal(_defaultValueLiteral_2, null));
+ if (_notEquals_1) {
+ String _defaultValueLiteral_3 = a.getDefaultValueLiteral();
+ _xifexpression_1 = _defaultValueLiteral_3;
+ } else {
+ String _defaultValue = this.languageExt.defaultValue(_externalType);
+ _xifexpression_1 = _defaultValue;
+ }
+ _switchResult = _xifexpression_1;
+ }
+ }
+ if (!_matched) {
+ if (aType instanceof PrimitiveType) {
+ final PrimitiveType _primitiveType = (PrimitiveType)aType;
+ _matched=true;
+ String _xblockexpression_1 = null;
+ {
+ String value = this.getPrimitiveValue(instance, path);
+ String _xifexpression_1 = null;
+ boolean _and = false;
+ boolean _and_1 = false;
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (!_greaterThan) {
+ _and_1 = false;
+ } else {
+ boolean _isCharacterType = this._typeHelpers.isCharacterType(_primitiveType);
+ _and_1 = (_greaterThan && _isCharacterType);
+ }
+ if (!_and_1) {
+ _and = false;
+ } else {
+ String _trim = value.trim();
+ boolean _startsWith = _trim.startsWith("{");
+ boolean _not = (!_startsWith);
+ _and = (_and_1 && _not);
+ }
+ if (_and) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{ ");
+ {
+ int _size_1 = a.getSize();
+ IntegerRange _upTo = new IntegerRange(1, _size_1);
+ boolean _hasElements = false;
+ for(final Integer i : _upTo) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(", ", "");
+ }
+ _builder.append(value, "");
+ }
+ }
+ _builder.append(" }");
+ _xifexpression_1 = _builder.toString();
+ } else {
+ _xifexpression_1 = value;
+ }
+ _xblockexpression_1 = (_xifexpression_1);
+ }
+ _switchResult = _xblockexpression_1;
+ }
+ }
+ _xblockexpression = (_switchResult);
+ }
+ return _xblockexpression;
+ }
+
+ private String getPrimitiveValue(final InstanceBase instance, final List<Attribute> path) {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (instance instanceof ActorInstance) {
+ final ActorInstance _actorInstance = (ActorInstance)instance;
+ _matched=true;
+ String _attrInstanceConfigValue = this.dataExt.getAttrInstanceConfigValue(_actorInstance, path);
+ _switchResult = _attrInstanceConfigValue;
+ }
+ }
+ if (!_matched) {
+ if (instance instanceof InterfaceItemInstance) {
+ final InterfaceItemInstance _interfaceItemInstance = (InterfaceItemInstance)instance;
+ _matched=true;
+ String _attrInstanceConfigValue = this.dataExt.getAttrInstanceConfigValue(_interfaceItemInstance, path);
+ _switchResult = _attrInstanceConfigValue;
+ }
+ }
+ String value = _switchResult;
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
+ String _switchResult_1 = null;
+ boolean _matched_1 = false;
+ if (!_matched_1) {
+ if (instance instanceof ActorInstance) {
+ final ActorInstance _actorInstance = (ActorInstance)instance;
+ _matched_1=true;
+ ActorClass _actorClass = _actorInstance.getActorClass();
+ String _attrClassConfigValue = this.dataExt.getAttrClassConfigValue(_actorClass, path);
+ _switchResult_1 = _attrClassConfigValue;
+ }
+ }
+ if (!_matched_1) {
+ if (instance instanceof InterfaceItemInstance) {
+ final InterfaceItemInstance _interfaceItemInstance = (InterfaceItemInstance)instance;
+ _matched_1=true;
+ ProtocolClass _protocol = _interfaceItemInstance.getProtocol();
+ boolean _isConjugated = this._roomExtensions.isConjugated(_interfaceItemInstance);
+ boolean _not = (!_isConjugated);
+ String _attrClassConfigValue = this.dataExt.getAttrClassConfigValue(_protocol, _not, path);
+ _switchResult_1 = _attrClassConfigValue;
+ }
+ }
+ value = _switchResult_1;
+ }
+ boolean _equals_1 = Objects.equal(value, null);
+ if (_equals_1) {
+ Attribute _last = IterableExtensions.<Attribute>last(path);
+ String _defaultValueLiteral = _last.getDefaultValueLiteral();
+ value = _defaultValueLiteral;
+ }
+ String _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(value, null));
+ if (_notEquals) {
+ Attribute _last_1 = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = _last_1.getRefType();
+ DataType _type = _refType.getType();
+ String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) _type), value);
+ _xifexpression = _valueLiteral;
+ } else {
+ Attribute _last_2 = IterableExtensions.<Attribute>last(path);
+ RefableType _refType_1 = _last_2.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _defaultValue = this.languageExt.defaultValue(_type_1);
+ _xifexpression = _defaultValue;
+ }
+ return _xifexpression;
+ }
+}
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 8da6909..fbfe286 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
@@ -35,12 +35,14 @@ 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.c.gen.Initialization;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@@ -60,6 +62,9 @@ public class SubSystemClassGen {
private ProcedureHelpers helpers;
@Inject
+ private Initialization attrInitGenAddon;
+
+ @Inject
private ILanguageExtension languageExt;
@Inject
@@ -761,56 +766,55 @@ public class SubSystemClassGen {
ProtocolClass _protocol = pi.getProtocol();
boolean _isConjugated = this.roomExt.isConjugated(pi);
PortClass _portClass = this.roomExt.getPortClass(_protocol, _isConjugated);
- boolean _notEquals = (!Objects.equal(_portClass, null));
- if (_notEquals) {
+ EList<Attribute> _attributes = _portClass==null?(EList<Attribute>)null:_portClass.getAttributes();
+ boolean _isEmpty_1 = _attributes==null?false:_attributes.isEmpty();
+ boolean _not = (!_isEmpty_1);
+ if (_not) {
+ _builder.append("static ");
+ ProtocolClass _protocol_1 = pi.getProtocol();
+ boolean _isConjugated_1 = this.roomExt.isConjugated(pi);
+ String _portClassName = this.roomExt.getPortClassName(_protocol_1, _isConjugated_1);
+ _builder.append(_portClassName, "");
+ _builder.append("_var ");
+ String _path_1 = pi.getPath();
+ String _pathName_1 = this.roomExt.getPathName(_path_1);
+ _builder.append(_pathName_1, "");
+ _builder.append("_var");
{
- ProtocolClass _protocol_1 = pi.getProtocol();
- boolean _isConjugated_1 = this.roomExt.isConjugated(pi);
- PortClass _portClass_1 = this.roomExt.getPortClass(_protocol_1, _isConjugated_1);
- EList<Attribute> _attributes = _portClass_1.getAttributes();
- boolean _isEmpty_1 = _attributes.isEmpty();
- boolean _not = (!_isEmpty_1);
- if (_not) {
- {
- boolean _isReplicated = pi.isReplicated();
- if (_isReplicated) {
- _builder.append("static ");
- ProtocolClass _protocol_2 = pi.getProtocol();
- boolean _isConjugated_2 = this.roomExt.isConjugated(pi);
- String _portClassName = this.roomExt.getPortClassName(_protocol_2, _isConjugated_2);
- _builder.append(_portClassName, "");
- _builder.append("_var ");
- String _path_1 = pi.getPath();
- String _pathName_1 = this.roomExt.getPathName(_path_1);
- _builder.append(_pathName_1, "");
- _builder.append("_var[");
- EList<InterfaceItemInstance> _peers = pi.getPeers();
- int _size = _peers.size();
- _builder.append(_size, "");
- _builder.append("]={");
- String _genReplPortAttributeInitializer = this.genReplPortAttributeInitializer(pi);
- _builder.append(_genReplPortAttributeInitializer, "");
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- } else {
- _builder.append("static ");
- ProtocolClass _protocol_3 = pi.getProtocol();
- boolean _isConjugated_3 = this.roomExt.isConjugated(pi);
- String _portClassName_1 = this.roomExt.getPortClassName(_protocol_3, _isConjugated_3);
- _builder.append(_portClassName_1, "");
- _builder.append("_var ");
- String _path_2 = pi.getPath();
- String _pathName_2 = this.roomExt.getPathName(_path_2);
- _builder.append(_pathName_2, "");
- _builder.append("_var={");
- CharSequence _genPortAttributeInitializer = this.genPortAttributeInitializer(pi);
- _builder.append(_genPortAttributeInitializer, "");
- _builder.append("};");
- _builder.newLineIfNotEmpty();
- }
+ boolean _isReplicated = pi.isReplicated();
+ if (_isReplicated) {
+ _builder.append("[");
+ EList<InterfaceItemInstance> _peers = pi.getPeers();
+ int _size = _peers.size();
+ _builder.append(_size, "");
+ _builder.append("]");
+ }
+ }
+ _builder.append("={");
+ _builder.newLineIfNotEmpty();
+ {
+ EList<InterfaceItemInstance> _peers_1 = pi.getPeers();
+ int _size_1 = _peers_1.size();
+ IntegerRange _upTo = new IntegerRange(1, _size_1);
+ boolean _hasElements = false;
+ for(final Integer i : _upTo) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(", ", " ");
}
+ _builder.append("\t");
+ InterfaceItem _interfaceItem = pi.getInterfaceItem();
+ PortClass _portClass_1 = RoomHelpers.getPortClass(_interfaceItem);
+ EList<Attribute> _attributes_1 = _portClass_1.getAttributes();
+ CharSequence _generateAttributeInit = this.attrInitGenAddon.generateAttributeInit(pi, _attributes_1);
+ _builder.append(_generateAttributeInit, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t\t\t\t\t");
}
}
+ _builder.append("};");
+ _builder.newLineIfNotEmpty();
}
}
}
@@ -825,9 +829,9 @@ public class SubSystemClassGen {
for(final ActorInstance ai_2 : _allContainedInstances_2) {
_builder.newLine();
_builder.append("/* instance ");
- String _path_3 = ai_2.getPath();
- String _pathName_3 = this.roomExt.getPathName(_path_3);
- _builder.append(_pathName_3, "");
+ String _path_2 = ai_2.getPath();
+ String _pathName_2 = this.roomExt.getPathName(_path_2);
+ _builder.append(_pathName_2, "");
_builder.append(" */");
_builder.newLineIfNotEmpty();
{
@@ -848,67 +852,6 @@ public class SubSystemClassGen {
return _builder;
}
- private String genReplPortAttributeInitializer(final InterfaceItemInstance pi) {
- int i = 0;
- String retval = "";
- EList<InterfaceItemInstance> _peers = pi.getPeers();
- int _size = _peers.size();
- i = _size;
- boolean _greaterThan = (i > 0);
- boolean _while = _greaterThan;
- while (_while) {
- {
- String _plus = (retval + "\r\n\t\t\t{");
- CharSequence _genPortAttributeInitializer = this.genPortAttributeInitializer(pi);
- String _plus_1 = (_plus + _genPortAttributeInitializer);
- String _plus_2 = (_plus_1 + "}");
- retval = _plus_2;
- int _minus = (i - 1);
- i = _minus;
- boolean _greaterThan_1 = (i > 0);
- if (_greaterThan_1) {
- String _plus_3 = (retval + ",");
- retval = _plus_3;
- }
- }
- boolean _greaterThan_1 = (i > 0);
- _while = _greaterThan_1;
- }
- return retval;
- }
-
- private CharSequence genPortAttributeInitializer(final InterfaceItemInstance pi) {
- StringConcatenation _builder = new StringConcatenation();
- {
- ProtocolClass _protocol = pi.getProtocol();
- boolean _isConjugated = this.roomExt.isConjugated(pi);
- PortClass _portClass = this.roomExt.getPortClass(_protocol, _isConjugated);
- EList<Attribute> _attributes = _portClass.getAttributes();
- boolean _hasElements = false;
- for(final Attribute attr : _attributes) {
- if (!_hasElements) {
- _hasElements = true;
- } else {
- _builder.appendImmediate(",", "");
- }
- {
- String _defaultValueLiteral = attr.getDefaultValueLiteral();
- boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
- if (_notEquals) {
- String _defaultValueLiteral_1 = attr.getDefaultValueLiteral();
- _builder.append(_defaultValueLiteral_1, "");
- } else {
- RefableType _refType = attr.getRefType();
- DataType _type = _refType.getType();
- String _defaultValue = this.stdExt.defaultValue(_type);
- _builder.append(_defaultValue, "");
- }
- }
- }
- }
- return _builder;
- }
-
private CharSequence genActorInstanceInitializer(final Root root, final ActorInstance ai) {
CharSequence _xblockexpression = null;
{
@@ -1177,30 +1120,12 @@ public class SubSystemClassGen {
_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(",\t/* ");
- String _name_2 = att.getName();
- _builder.append(_name_2, " ");
- {
- int _size_1 = att.getSize();
- boolean _greaterThan = (_size_1 > 1);
- if (_greaterThan) {
- _builder.append("[");
- int _size_2 = att.getSize();
- _builder.append(_size_2, " ");
- _builder.append("]");
- }
- }
- _builder.append(" */");
- _builder.newLineIfNotEmpty();
- }
- }
+ _builder.append("\t");
+ ActorClass _actorClass_2 = ai.getActorClass();
+ List<Attribute> _allAttributes = this.roomExt.getAllAttributes(_actorClass_2);
+ CharSequence _generateAttributeInit = this.attrInitGenAddon.generateAttributeInit(ai, _allAttributes);
+ _builder.append(_generateAttributeInit, " ");
+ _builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
@@ -1298,24 +1223,6 @@ public class SubSystemClassGen {
return _xblockexpression;
}
- private String genAttributeInitializer(final ActorInstance ai, final Attribute att) {
- String _xblockexpression = null;
- {
- final String value = ((String) null);
- String _xifexpression = null;
- boolean _equals = Objects.equal(value, null);
- if (_equals) {
- String _initializationWithDefaultValues = this.stdExt.initializationWithDefaultValues(att);
- _xifexpression = _initializationWithDefaultValues;
- } 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);
diff --git a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
index df5949b..4cf04e7 100644
--- a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
+++ b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
@@ -16,21 +16,21 @@ import java.util.ArrayList
import java.util.List
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.etrice.core.ConfigStandaloneSetup
+import org.eclipse.etrice.core.config.BooleanLiteral
+import org.eclipse.etrice.core.config.IntLiteral
+import org.eclipse.etrice.core.config.Literal
+import org.eclipse.etrice.core.config.LiteralArray
+import org.eclipse.etrice.core.config.RealLiteral
+import org.eclipse.etrice.core.config.StringLiteral
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.room.ActorClass
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.ProtocolClass
import org.eclipse.etrice.core.room.SubSystemClass
import org.eclipse.etrice.generator.base.IDataConfiguration
import org.eclipse.etrice.generator.config.util.DataConfigurationHelper
-import org.eclipse.etrice.core.config.BooleanLiteral
-import org.eclipse.etrice.core.config.IntLiteral
-import org.eclipse.etrice.core.config.RealLiteral
-import org.eclipse.etrice.core.config.StringLiteral
-import org.eclipse.etrice.core.config.LiteralArray
-import org.eclipse.etrice.core.config.Literal
-import org.eclipse.etrice.core.room.InterfaceItem
class DataConfiguration implements IDataConfiguration {
@@ -76,11 +76,9 @@ class DataConfiguration implements IDataConfiguration {
DataConfigurationHelper::actorInstanceAttrMap.get(id)?.value?.toStringExpr
}
- override getAttrInstanceConfigValue(ActorInstance ai, InterfaceItem port, List<Attribute> path) {
- var id = ai.path+"/"+port.name+"/"+path.toStringPath
- DataConfigurationHelper::actorInstanceAttrMap.get(id)?.value?.toStringExpr
+ override getAttrInstanceConfigValue(InterfaceItemInstance item, List<Attribute> path) {
+ DataConfigurationHelper::actorInstanceAttrMap.get(item.path)?.value?.toStringExpr
}
-
// dynamic
override getPollingTimerUser(SubSystemClass subsystem) {
@@ -157,4 +155,6 @@ class DataConfiguration implements IDataConfiguration {
return result
}
+
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/.DataConfiguration.java._trace b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/.DataConfiguration.java._trace
index 2a02988..81c6451 100644
--- a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/.DataConfiguration.java._trace
+++ b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/.DataConfiguration.java._trace
Binary files differ
diff --git a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
index 3109e59..a9a36f5 100644
--- a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
+++ b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
@@ -19,9 +19,9 @@ import org.eclipse.etrice.core.config.StringLiteral;
import org.eclipse.etrice.core.config.SubSystemConfig;
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.room.ActorClass;
import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.generator.base.IDataConfiguration;
@@ -139,22 +139,12 @@ public class DataConfiguration implements IDataConfiguration {
return _xblockexpression;
}
- public String getAttrInstanceConfigValue(final ActorInstance ai, final InterfaceItem port, final List<Attribute> path) {
- String _xblockexpression = null;
- {
- String _path = ai.getPath();
- String _plus = (_path + "/");
- String _name = port.getName();
- String _plus_1 = (_plus + _name);
- String _plus_2 = (_plus_1 + "/");
- String _stringPath = this.toStringPath(path);
- String id = (_plus_2 + _stringPath);
- AttrInstanceConfig _get = DataConfigurationHelper.actorInstanceAttrMap.get(id);
- LiteralArray _value = _get==null?(LiteralArray)null:_get.getValue();
- String _stringExpr = _value==null?(String)null:this.toStringExpr(_value);
- _xblockexpression = (_stringExpr);
- }
- return _xblockexpression;
+ public String getAttrInstanceConfigValue(final InterfaceItemInstance item, final List<Attribute> path) {
+ String _path = item.getPath();
+ AttrInstanceConfig _get = DataConfigurationHelper.actorInstanceAttrMap.get(_path);
+ LiteralArray _value = _get==null?(LiteralArray)null:_get.getValue();
+ String _stringExpr = _value==null?(String)null:this.toStringExpr(_value);
+ return _stringExpr;
}
public int getPollingTimerUser(final SubSystemClass subsystem) {
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend
index bb4c4e3..347862c 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend
@@ -16,17 +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.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.GeneralProtocolClass
-import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.PrimitiveType
-import org.eclipse.etrice.core.room.ProtocolClass
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.util.RoomHelpers
class ConfigGenAddon {
@@ -40,39 +40,24 @@ class ConfigGenAddon {
def public genActorInstanceConfig(ActorInstance ai, String aiVariableName){'''
«FOR a : ai.actorClass.attributes»
- «applyInstanceConfig(ai, null, aiVariableName, new ArrayList<Attribute>().union(a))»
+ «applyInstanceConfig(ai, aiVariableName, new ArrayList<Attribute>().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<Attribute>().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<Attribute>().union(a))»
+ «FOR pi : ai.orderedIfItemInstances»
+ «FOR a : RoomHelpers::getPortClass(pi.interfaceItem).attributes»
+ «applyInstanceConfig(pi, aiVariableName+"."+invokeGetter(pi.name, null), new ArrayList<Attribute>().union(a))»
«ENDFOR»
«ENDFOR»
'''
}
- def private List<Attribute> getAttributes(GeneralProtocolClass gpc, boolean regular){
- var result = new ArrayList<Attribute>
- 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<Attribute> path){
+ def private applyInstanceConfig(InstanceBase instance, String invokes, List<Attribute> 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 = switch instance {
+ ActorInstance: dataConfigExt.getAttrInstanceConfigValue(instance, path)
+ InterfaceItemInstance: dataConfigExt.getAttrInstanceConfigValue(instance, path)
+ }
if(value == null)
''''''
else if(a.size == 0 || aType.characterType)
@@ -89,7 +74,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.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
index f3484e9..a8a587e 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
@@ -17,116 +17,107 @@ import com.google.inject.Singleton
import java.util.ArrayList
import java.util.List
import org.eclipse.emf.ecore.EObject
-import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.Attribute
-import org.eclipse.etrice.core.room.ComplexType
import org.eclipse.etrice.core.room.DataClass
-import org.eclipse.etrice.core.room.PortClass
import org.eclipse.etrice.core.room.PrimitiveType
-import org.eclipse.etrice.core.room.ProtocolClass
import org.eclipse.etrice.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.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.PortClass
+import org.eclipse.etrice.core.room.ProtocolClass
@Singleton
class Initialization {
- @Inject extension TypeHelpers
+ @Inject extension TypeHelpers typeHelpers
@Inject extension RoomExtensions
- @Inject ILanguageExtension languageExt
+ @Inject extension ILanguageExtension languageExt
+ @Inject extension ProcedureHelpers procedureHelpers
@Inject IDataConfiguration dataConfigExt
- @Inject ProcedureHelpers procedureHelpers
def attributeInitialization(List<Attribute> attribs, EObject roomClass, boolean useClassDefaultsOnly) {
- var tmp = ''''''
'''
// initialize attributes
«FOR a : attribs»
- «tmp = dataConfigurationInit(roomClass, new ArrayList<Attribute>.union(a))»
- «IF tmp.length==0»«(tmp = valueInit(new ArrayList<Attribute>.union(a), getRoomDefaulValue(a)))»«ENDIF»
- «IF tmp.length==0»«defaultInit(a, useClassDefaultsOnly)»«ENDIF»
+ «attributeClassInit(a, roomClass, useClassDefaultsOnly)»
+ «IF a.refType.type.dataClass»«attributeInitPrimitiveRec(new ArrayList<Attribute>.union(a), roomClass)»«ENDIF»
«ENDFOR»
'''
- }
- def private dataConfigurationInit(EObject roomClass, List<Attribute> path){
+ }
+
+ def private attributeClassInit(Attribute a, EObject roomClass, boolean useClassDefaultsOnly){
+ var aType = a.refType.type
+ if(a.refType.ref){
+ if(a.defaultValueLiteral != null)
+ attributeInit(a, a.defaultValueLiteral)
+ else if(!useClassDefaultsOnly)
+ attributeInit(a, languageExt.nullPointer)
+ }
+ else{
+ if(aType.primitive){
+ var value = getDataConfigValueLiteral(new ArrayList<Attribute>.union(a), roomClass)
+ if(value == null) value = a.defaultValueLiteral
+ if(value != null) attributeInit(a, languageExt.toValueLiteral(aType as PrimitiveType, value))
+ else if(!useClassDefaultsOnly) attributeInit(a, languageExt.defaultValue(aType))
+ } else
+ attributeInit(a, languageExt.defaultValue(aType))
+ }
+ }
+
+ def private attributeInitPrimitiveRec(List<Attribute> path, EObject roomClass){
var a = path.last
var aType = a.refType.type
if(aType.dataClass){
return '''
- «FOR e : (aType as DataClass).attributes»
- «dataConfigurationInit(roomClass, path.union(e))»
+ «FOR e : (aType as DataClass).allAttributes»
+ «attributeInitPrimitiveRec(path.union(e), roomClass)»
«ENDFOR»
'''
}
- else if(aType.primitive)
- return valueInit(path, getDataConfigValue(roomClass, path))
- ''''''
+ else if(aType.primitive){
+ var value = getDataConfigValueLiteral(path, roomClass)
+ return if(value != null) attributeInit(path, value)
+ }
+ }
+
+ def private attributeInit(Attribute a, String value){
+ attributeInit(new ArrayList<Attribute>.union(a), value)
}
- def private valueInit(List<Attribute> path, String literalValue){
- if(literalValue == null) return ''''''
+ def private attributeInit(List<Attribute> path, String value){
var a = path.last
var aType = a.refType.type
var getter = if(path.size > 1)procedureHelpers.invokeGetters(path.take(path.size-1), null)+"." else ""
- '''
- «IF a.size == 0 || aType.characterType»
- «getter»«procedureHelpers.invokeSetter(a.name,null,literalValue)»;
- «ELSEIF literalValue.startsWith("{")»
- «getter»«procedureHelpers.invokeSetter(a.name,null, '''new «aType.typeName»[] «literalValue»''')»;
- «ELSE»
- {
- «aType.typeName»[] _«a.name» = new «aType.typeName»[«a.size»];
- for (int i=0;i<«a.size»;i++){
- _«a.name»[i] = «literalValue»;
- }
- «getter»«procedureHelpers.invokeSetter(a.name,null,"_"+a.name)»;
- }
- «ENDIF»
- '''
- }
-
- def private defaultInit(Attribute a, boolean useClassDefaultsOnly){
- '''
- «IF a.refType.type instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
- «IF a.size==0»
- «IF a.refType.isRef»
- «a.name» = «languageExt.nullPointer()»;
- «ELSE»
- «a.name» = «languageExt.defaultValue(a.refType.type)»;
- «ENDIF»
- «ELSE»
- «a.name» = new «a.refType.type.typeName»[«a.size»];
- «IF !useClassDefaultsOnly»
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«languageExt.defaultValue(a.refType.type)»«ENDIF»;
- }
- «ENDIF»
- «ENDIF»
- «ENDIF»
- '''
+ return '''
+ «IF a.size == 0 || aType.characterType»
+ «getter»«procedureHelpers.invokeSetter(a.name, null, value)»;
+ «ELSEIF !value.trim.startsWith('{')»
+ {
+ «aType.typeName»[] «a.name» = new «aType.typeName»[«a.size»];
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «value»;
+ }
+ «getter»«procedureHelpers.invokeSetter(a.name, null, a.name)»;
+ }
+ «ELSE»
+ «getter»«procedureHelpers.invokeSetter(a.name,null, '''new «aType.typeName»[] «value»''')»;
+ «ENDIF»
+ '''
}
- def String getRoomDefaulValue(Attribute a){
- if(a.refType.type.primitive && a.defaultValueLiteral != null)
- languageExt.toValueLiteral(a.refType.type as PrimitiveType, a.defaultValueLiteral)
- }
-
- def private String getDataConfigValue(EObject roomClass, List<Attribute> path){
- var a = path.last
- if(a.refType.type.primitive){
- var aType = a.refType.type as PrimitiveType
- var result = switch roomClass {
- ActorClass: dataConfigExt.getAttrClassConfigValue(roomClass, path)
- PortClass:
- if(roomClass.eContainer instanceof ProtocolClass){
- var pc = roomClass.eContainer as ProtocolClass
- dataConfigExt.getAttrClassConfigValue(pc, pc.regular.equals(roomClass), path)
- }
- }
- if(result != null)
- return languageExt.toValueLiteral(aType, result)
+ def private getDataConfigValueLiteral(List<Attribute> path, EObject roomClass){
+ return switch roomClass{
+ ActorClass:
+ dataConfigExt.getAttrClassConfigValue(roomClass, path)
+ PortClass:
+ if(roomClass.eContainer instanceof ProtocolClass){
+ var pc = roomClass.eContainer as ProtocolClass
+ dataConfigExt.getAttrClassConfigValue(pc, pc.regular.equals(roomClass), path)
+ }
+ DataClass: null
}
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
index d76f23f..11a3f9f 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
@@ -151,7 +151,8 @@ class JavaExtensions implements ILanguageExtension {
override defaultValue(DataType dt) {
if (dt instanceof PrimitiveType) {
- return (dt as PrimitiveType).getDefaultValueLiteral
+ var pType = dt as PrimitiveType
+ return toValueLiteral(pType, pType.defaultValueLiteral)
}
else if (dt instanceof ExternalType)
return "new "+(dt as ExternalType).targetName+"()"
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
index 2ff8234..5296320 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.java
@@ -6,18 +6,17 @@ 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.GeneralProtocolClass;
import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.PortClass;
import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RefableType;
-import org.eclipse.etrice.core.room.SAPRef;
+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;
@@ -53,98 +52,36 @@ public class ConfigGenAddon {
for(final Attribute a : _attributes) {
ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, null, aiVariableName, _union);
+ CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, aiVariableName, _union);
_builder.append(_applyInstanceConfig, "");
_builder.newLineIfNotEmpty();
}
}
{
- ActorClass _actorClass_1 = ai.getActorClass();
- List<Port> _allEndPorts = this._roomExtensions.getAllEndPorts(_actorClass_1);
- for(final Port p : _allEndPorts) {
+ EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
+ for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
{
- GeneralProtocolClass _protocol = p.getProtocol();
- boolean _isConjugated = p.isConjugated();
- boolean _not = (!_isConjugated);
- List<Attribute> _attributes_1 = this.getAttributes(_protocol, _not);
+ InterfaceItem _interfaceItem = pi.getInterfaceItem();
+ PortClass _portClass = RoomHelpers.getPortClass(_interfaceItem);
+ EList<Attribute> _attributes_1 = _portClass.getAttributes();
for(final Attribute a_1 : _attributes_1) {
String _plus = (aiVariableName + ".");
- String _name = p.getName();
+ String _name = pi.getName();
CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
String _plus_1 = (_plus + _invokeGetter);
ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
List<Attribute> _union_1 = this._roomExtensions.<Attribute>union(_arrayList_1, a_1);
- CharSequence _applyInstanceConfig_1 = this.applyInstanceConfig(ai, p, _plus_1, _union_1);
+ CharSequence _applyInstanceConfig_1 = this.applyInstanceConfig(pi, _plus_1, _union_1);
_builder.append(_applyInstanceConfig_1, "");
_builder.newLineIfNotEmpty();
}
}
}
}
- {
- ActorClass _actorClass_2 = ai.getActorClass();
- List<SAPRef> _allSAPs = this._roomExtensions.getAllSAPs(_actorClass_2);
- for(final SAPRef sap : _allSAPs) {
- {
- ProtocolClass _protocol_1 = sap.getProtocol();
- List<Attribute> _attributes_2 = this.getAttributes(_protocol_1, true);
- for(final Attribute a_2 : _attributes_2) {
- String _plus_2 = (aiVariableName + ".");
- String _name_1 = sap.getName();
- CharSequence _invokeGetter_1 = this.helpers.invokeGetter(_name_1, null);
- String _plus_3 = (_plus_2 + _invokeGetter_1);
- ArrayList<Attribute> _arrayList_2 = new ArrayList<Attribute>();
- List<Attribute> _union_2 = this._roomExtensions.<Attribute>union(_arrayList_2, a_2);
- CharSequence _applyInstanceConfig_2 = this.applyInstanceConfig(ai, sap, _plus_3, _union_2);
- _builder.append(_applyInstanceConfig_2, "");
- _builder.newLineIfNotEmpty();
- }
- }
- }
- }
return _builder;
}
- private List<Attribute> getAttributes(final GeneralProtocolClass gpc, final boolean regular) {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- ArrayList<Attribute> result = _arrayList;
- if ((gpc instanceof ProtocolClass)) {
- ProtocolClass protocol = ((ProtocolClass) gpc);
- boolean _and = false;
- if (!regular) {
- _and = false;
- } else {
- PortClass _regular = protocol.getRegular();
- EList<Attribute> _attributes = _regular==null?(EList<Attribute>)null:_regular.getAttributes();
- boolean _notEquals = (!Objects.equal(_attributes, null));
- _and = (regular && _notEquals);
- }
- if (_and) {
- PortClass _regular_1 = protocol.getRegular();
- EList<Attribute> _attributes_1 = _regular_1.getAttributes();
- result.addAll(_attributes_1);
- } else {
- boolean _and_1 = false;
- boolean _not = (!regular);
- if (!_not) {
- _and_1 = false;
- } else {
- PortClass _conjugate = protocol.getConjugate();
- EList<Attribute> _attributes_2 = _conjugate==null?(EList<Attribute>)null:_conjugate.getAttributes();
- boolean _notEquals_1 = (!Objects.equal(_attributes_2, null));
- _and_1 = (_not && _notEquals_1);
- }
- if (_and_1) {
- PortClass _conjugate_1 = protocol.getConjugate();
- EList<Attribute> _attributes_3 = _conjugate_1.getAttributes();
- result.addAll(_attributes_3);
- }
- }
- }
- return result;
- }
-
- private CharSequence applyInstanceConfig(final ActorInstance ai, final InterfaceItem port, final String invokes, final List<Attribute> path) {
+ private CharSequence applyInstanceConfig(final InstanceBase instance, final String invokes, final List<Attribute> path) {
CharSequence _xblockexpression = null;
{
Attribute a = IterableExtensions.<Attribute>last(path);
@@ -155,31 +92,40 @@ public class ConfigGenAddon {
if (_isPrimitive) {
CharSequence _xblockexpression_1 = null;
{
- String _xifexpression_1 = null;
- boolean _equals = Objects.equal(port, null);
- if (_equals) {
- String _attrInstanceConfigValue = this.dataConfigExt.getAttrInstanceConfigValue(ai, path);
- _xifexpression_1 = _attrInstanceConfigValue;
- } else {
- String _attrInstanceConfigValue_1 = this.dataConfigExt.getAttrInstanceConfigValue(ai, port, path);
- _xifexpression_1 = _attrInstanceConfigValue_1;
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (instance instanceof ActorInstance) {
+ final ActorInstance _actorInstance = (ActorInstance)instance;
+ _matched=true;
+ String _attrInstanceConfigValue = this.dataConfigExt.getAttrInstanceConfigValue(_actorInstance, path);
+ _switchResult = _attrInstanceConfigValue;
+ }
}
- String value = _xifexpression_1;
- CharSequence _xifexpression_2 = null;
- boolean _equals_1 = Objects.equal(value, null);
- if (_equals_1) {
+ if (!_matched) {
+ if (instance instanceof InterfaceItemInstance) {
+ final InterfaceItemInstance _interfaceItemInstance = (InterfaceItemInstance)instance;
+ _matched=true;
+ String _attrInstanceConfigValue = this.dataConfigExt.getAttrInstanceConfigValue(_interfaceItemInstance, path);
+ _switchResult = _attrInstanceConfigValue;
+ }
+ }
+ String value = _switchResult;
+ CharSequence _xifexpression_1 = null;
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
StringConcatenation _builder = new StringConcatenation();
- _xifexpression_2 = _builder;
+ _xifexpression_1 = _builder;
} else {
- CharSequence _xifexpression_3 = null;
+ CharSequence _xifexpression_2 = null;
boolean _or = false;
int _size = a.getSize();
- boolean _equals_2 = (_size == 0);
- if (_equals_2) {
+ boolean _equals_1 = (_size == 0);
+ if (_equals_1) {
_or = true;
} else {
boolean _isCharacterType = this.typeHelpers.isCharacterType(aType);
- _or = (_equals_2 || _isCharacterType);
+ _or = (_equals_1 || _isCharacterType);
}
if (_or) {
StringConcatenation _builder_1 = new StringConcatenation();
@@ -190,14 +136,14 @@ public class ConfigGenAddon {
CharSequence _invokeSetter = this.helpers.invokeSetter(_name, null, _valueLiteral);
_builder_1.append(_invokeSetter, "");
_builder_1.append(";");
- _xifexpression_3 = _builder_1;
+ _xifexpression_2 = _builder_1;
} else {
- CharSequence _xifexpression_4 = null;
+ CharSequence _xifexpression_3 = null;
int _size_1 = a.getSize();
String[] _split = value.split(",");
int _size_2 = ((List<String>)Conversions.doWrapArray(_split)).size();
- boolean _equals_3 = (_size_1 == _size_2);
- if (_equals_3) {
+ boolean _equals_2 = (_size_1 == _size_2);
+ if (_equals_2) {
CharSequence _xblockexpression_2 = null;
{
StringConcatenation _builder_2 = new StringConcatenation();
@@ -234,7 +180,7 @@ public class ConfigGenAddon {
_builder_3.append(";");
_xblockexpression_2 = (_builder_3);
}
- _xifexpression_4 = _xblockexpression_2;
+ _xifexpression_3 = _xblockexpression_2;
} else {
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("{");
@@ -263,13 +209,13 @@ public class ConfigGenAddon {
_builder_2.append(";");
_builder_2.newLineIfNotEmpty();
_builder_2.append("}");
- _xifexpression_4 = _builder_2;
+ _xifexpression_3 = _builder_2;
}
- _xifexpression_3 = _xifexpression_4;
+ _xifexpression_2 = _xifexpression_3;
}
- _xifexpression_2 = _xifexpression_3;
+ _xifexpression_1 = _xifexpression_2;
}
- _xblockexpression_1 = (_xifexpression_2);
+ _xblockexpression_1 = (_xifexpression_1);
}
_xifexpression = _xblockexpression_1;
} else {
@@ -285,7 +231,7 @@ public class ConfigGenAddon {
CharSequence _invokeGetter = this.helpers.invokeGetter(_name, null);
String _plus_1 = (_plus + _invokeGetter);
List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
- CharSequence _applyInstanceConfig = this.applyInstanceConfig(ai, port, _plus_1, _union);
+ CharSequence _applyInstanceConfig = this.applyInstanceConfig(instance, _plus_1, _union);
_builder.append(_applyInstanceConfig, "");
_builder.newLineIfNotEmpty();
}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
index e3ff634..af337b3 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
@@ -5,11 +5,9 @@ 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.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.ComplexType;
import org.eclipse.etrice.core.room.DataClass;
import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.PortClass;
@@ -28,7 +26,7 @@ import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class Initialization {
@Inject
- private TypeHelpers _typeHelpers;
+ private TypeHelpers typeHelpers;
@Inject
private RoomExtensions _roomExtensions;
@@ -37,367 +35,290 @@ public class Initialization {
private ILanguageExtension languageExt;
@Inject
- private IDataConfiguration dataConfigExt;
+ private ProcedureHelpers procedureHelpers;
@Inject
- private ProcedureHelpers procedureHelpers;
+ private IDataConfiguration dataConfigExt;
public CharSequence attributeInitialization(final List<Attribute> attribs, final EObject roomClass, final boolean useClassDefaultsOnly) {
- CharSequence _xblockexpression = null;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("// initialize attributes");
+ _builder.newLine();
{
- StringConcatenation _builder = new StringConcatenation();
- CharSequence tmp = _builder;
- StringConcatenation _builder_1 = new StringConcatenation();
- _builder_1.append("// initialize attributes");
- _builder_1.newLine();
- {
- for(final Attribute a : attribs) {
- ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
- List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
- CharSequence _dataConfigurationInit = this.dataConfigurationInit(roomClass, _union);
- CharSequence _tmp = tmp = _dataConfigurationInit;
- _builder_1.append(_tmp, "");
- _builder_1.newLineIfNotEmpty();
- {
- int _length = tmp.length();
- boolean _equals = (_length == 0);
- if (_equals) {
- ArrayList<Attribute> _arrayList_1 = new ArrayList<Attribute>();
- List<Attribute> _union_1 = this._roomExtensions.<Attribute>union(_arrayList_1, a);
- String _roomDefaulValue = this.getRoomDefaulValue(a);
- CharSequence _valueInit = this.valueInit(_union_1, _roomDefaulValue);
- CharSequence _tmp_1 = tmp = _valueInit;
- _builder_1.append(_tmp_1, "");
- }
- }
- _builder_1.newLineIfNotEmpty();
- {
- int _length_1 = tmp.length();
- boolean _equals_1 = (_length_1 == 0);
- if (_equals_1) {
- CharSequence _defaultInit = this.defaultInit(a, useClassDefaultsOnly);
- _builder_1.append(_defaultInit, "");
- }
+ for(final Attribute a : attribs) {
+ CharSequence _attributeClassInit = this.attributeClassInit(a, roomClass, useClassDefaultsOnly);
+ _builder.append(_attributeClassInit, "");
+ _builder.newLineIfNotEmpty();
+ {
+ RefableType _refType = a.getRefType();
+ DataType _type = _refType.getType();
+ boolean _isDataClass = this.typeHelpers.isDataClass(_type);
+ if (_isDataClass) {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
+ _builder.append(_attributeInitPrimitiveRec, "");
}
- _builder_1.newLineIfNotEmpty();
}
+ _builder.newLineIfNotEmpty();
}
- _xblockexpression = (_builder_1);
}
- return _xblockexpression;
+ return _builder;
}
- private CharSequence dataConfigurationInit(final EObject roomClass, final List<Attribute> path) {
+ private CharSequence attributeClassInit(final Attribute a, final EObject roomClass, final boolean useClassDefaultsOnly) {
CharSequence _xblockexpression = null;
{
- Attribute a = IterableExtensions.<Attribute>last(path);
RefableType _refType = a.getRefType();
DataType aType = _refType.getType();
- boolean _isDataClass = this._typeHelpers.isDataClass(aType);
- if (_isDataClass) {
- StringConcatenation _builder = new StringConcatenation();
- {
- EList<Attribute> _attributes = ((DataClass) aType).getAttributes();
- for(final Attribute e : _attributes) {
- List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
- CharSequence _dataConfigurationInit = this.dataConfigurationInit(roomClass, _union);
- _builder.append(_dataConfigurationInit, "");
- _builder.newLineIfNotEmpty();
+ CharSequence _xifexpression = null;
+ RefableType _refType_1 = a.getRefType();
+ boolean _isRef = _refType_1.isRef();
+ if (_isRef) {
+ CharSequence _xifexpression_1 = null;
+ String _defaultValueLiteral = a.getDefaultValueLiteral();
+ boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
+ if (_notEquals) {
+ String _defaultValueLiteral_1 = a.getDefaultValueLiteral();
+ CharSequence _attributeInit = this.attributeInit(a, _defaultValueLiteral_1);
+ _xifexpression_1 = _attributeInit;
+ } else {
+ CharSequence _xifexpression_2 = null;
+ boolean _not = (!useClassDefaultsOnly);
+ if (_not) {
+ String _nullPointer = this.languageExt.nullPointer();
+ CharSequence _attributeInit_1 = this.attributeInit(a, _nullPointer);
+ _xifexpression_2 = _attributeInit_1;
}
+ _xifexpression_1 = _xifexpression_2;
}
- return _builder;
+ _xifexpression = _xifexpression_1;
} else {
- boolean _isPrimitive = this._typeHelpers.isPrimitive(aType);
+ CharSequence _xifexpression_3 = null;
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
if (_isPrimitive) {
- String _dataConfigValue = this.getDataConfigValue(roomClass, path);
- return this.valueInit(path, _dataConfigValue);
+ CharSequence _xblockexpression_1 = null;
+ {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ String value = this.getDataConfigValueLiteral(_union, roomClass);
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
+ String _defaultValueLiteral_2 = a.getDefaultValueLiteral();
+ value = _defaultValueLiteral_2;
+ }
+ CharSequence _xifexpression_4 = null;
+ boolean _notEquals_1 = (!Objects.equal(value, null));
+ if (_notEquals_1) {
+ String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) aType), value);
+ CharSequence _attributeInit_2 = this.attributeInit(a, _valueLiteral);
+ _xifexpression_4 = _attributeInit_2;
+ } else {
+ CharSequence _xifexpression_5 = null;
+ boolean _not_1 = (!useClassDefaultsOnly);
+ if (_not_1) {
+ String _defaultValue = this.languageExt.defaultValue(aType);
+ CharSequence _attributeInit_3 = this.attributeInit(a, _defaultValue);
+ _xifexpression_5 = _attributeInit_3;
+ }
+ _xifexpression_4 = _xifexpression_5;
+ }
+ _xblockexpression_1 = (_xifexpression_4);
+ }
+ _xifexpression_3 = _xblockexpression_1;
+ } else {
+ String _defaultValue = this.languageExt.defaultValue(aType);
+ CharSequence _attributeInit_2 = this.attributeInit(a, _defaultValue);
+ _xifexpression_3 = _attributeInit_2;
}
+ _xifexpression = _xifexpression_3;
}
- StringConcatenation _builder_1 = new StringConcatenation();
- _xblockexpression = (_builder_1);
+ _xblockexpression = (_xifexpression);
}
return _xblockexpression;
}
- private CharSequence valueInit(final List<Attribute> path, final String literalValue) {
- CharSequence _xblockexpression = null;
- {
- boolean _equals = Objects.equal(literalValue, null);
- if (_equals) {
- StringConcatenation _builder = new StringConcatenation();
- return _builder;
- }
- Attribute a = IterableExtensions.<Attribute>last(path);
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- String _xifexpression = null;
- int _size = path.size();
- boolean _greaterThan = (_size > 1);
- if (_greaterThan) {
- int _size_1 = path.size();
- int _minus = (_size_1 - 1);
- Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
- CharSequence _invokeGetters = this.procedureHelpers.invokeGetters(_take, null);
- String _plus = (_invokeGetters + ".");
- _xifexpression = _plus;
- } else {
- _xifexpression = "";
- }
- String getter = _xifexpression;
- StringConcatenation _builder_1 = new StringConcatenation();
+ private CharSequence attributeInitPrimitiveRec(final List<Attribute> path, final EObject roomClass) {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ boolean _isDataClass = this.typeHelpers.isDataClass(aType);
+ if (_isDataClass) {
+ StringConcatenation _builder = new StringConcatenation();
{
- boolean _or = false;
- int _size_2 = a.getSize();
- boolean _equals_1 = (_size_2 == 0);
- if (_equals_1) {
- _or = true;
- } else {
- boolean _isCharacterType = this._typeHelpers.isCharacterType(aType);
- _or = (_equals_1 || _isCharacterType);
+ List<Attribute> _allAttributes = this._roomExtensions.getAllAttributes(((DataClass) aType));
+ for(final Attribute e : _allAttributes) {
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(path, e);
+ CharSequence _attributeInitPrimitiveRec = this.attributeInitPrimitiveRec(_union, roomClass);
+ _builder.append(_attributeInitPrimitiveRec, "");
+ _builder.newLineIfNotEmpty();
}
- if (_or) {
- _builder_1.append(getter, "");
- String _name = a.getName();
- CharSequence _invokeSetter = this.procedureHelpers.invokeSetter(_name, null, literalValue);
- _builder_1.append(_invokeSetter, "");
- _builder_1.append(";");
- _builder_1.newLineIfNotEmpty();
- } else {
- boolean _startsWith = literalValue.startsWith("{");
- if (_startsWith) {
- _builder_1.append(getter, "");
- String _name_1 = a.getName();
- StringConcatenation _builder_2 = new StringConcatenation();
- _builder_2.append("new ");
- String _typeName = this._typeHelpers.typeName(aType);
- _builder_2.append(_typeName, "");
- _builder_2.append("[] ");
- _builder_2.append(literalValue, "");
- CharSequence _invokeSetter_1 = this.procedureHelpers.invokeSetter(_name_1, null, _builder_2.toString());
- _builder_1.append(_invokeSetter_1, "");
- _builder_1.append(";");
- _builder_1.newLineIfNotEmpty();
- } else {
- _builder_1.append("{");
- _builder_1.newLine();
- _builder_1.append("\t");
- String _typeName_1 = this._typeHelpers.typeName(aType);
- _builder_1.append(_typeName_1, " ");
- _builder_1.append("[] _");
- String _name_2 = a.getName();
- _builder_1.append(_name_2, " ");
- _builder_1.append(" = new ");
- String _typeName_2 = this._typeHelpers.typeName(aType);
- _builder_1.append(_typeName_2, " ");
- _builder_1.append("[");
- int _size_3 = a.getSize();
- _builder_1.append(_size_3, " ");
- _builder_1.append("];");
- _builder_1.newLineIfNotEmpty();
- _builder_1.append("\t");
- _builder_1.append("for (int i=0;i<");
- int _size_4 = a.getSize();
- _builder_1.append(_size_4, " ");
- _builder_1.append(";i++){");
- _builder_1.newLineIfNotEmpty();
- _builder_1.append("\t\t");
- _builder_1.append("_");
- String _name_3 = a.getName();
- _builder_1.append(_name_3, " ");
- _builder_1.append("[i] = ");
- _builder_1.append(literalValue, " ");
- _builder_1.append(";");
- _builder_1.newLineIfNotEmpty();
- _builder_1.append("\t");
- _builder_1.append("}");
- _builder_1.newLine();
- _builder_1.append("\t");
- _builder_1.append(getter, " ");
- String _name_4 = a.getName();
- String _name_5 = a.getName();
- String _plus_1 = ("_" + _name_5);
- CharSequence _invokeSetter_2 = this.procedureHelpers.invokeSetter(_name_4, null, _plus_1);
- _builder_1.append(_invokeSetter_2, " ");
- _builder_1.append(";");
- _builder_1.newLineIfNotEmpty();
- _builder_1.append("}");
- _builder_1.newLine();
- }
+ }
+ return _builder;
+ } else {
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
+ if (_isPrimitive) {
+ String value = this.getDataConfigValueLiteral(path, roomClass);
+ CharSequence _xifexpression = null;
+ boolean _notEquals = (!Objects.equal(value, null));
+ if (_notEquals) {
+ CharSequence _attributeInit = this.attributeInit(path, value);
+ _xifexpression = _attributeInit;
}
+ return _xifexpression;
}
- _xblockexpression = (_builder_1);
}
- return _xblockexpression;
+ return null;
+ }
+
+ private CharSequence attributeInit(final Attribute a, final String value) {
+ ArrayList<Attribute> _arrayList = new ArrayList<Attribute>();
+ List<Attribute> _union = this._roomExtensions.<Attribute>union(_arrayList, a);
+ CharSequence _attributeInit = this.attributeInit(_union, value);
+ return _attributeInit;
}
- private CharSequence defaultInit(final Attribute a, final boolean useClassDefaultsOnly) {
+ private CharSequence attributeInit(final List<Attribute> path, final String value) {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ String _xifexpression = null;
+ int _size = path.size();
+ boolean _greaterThan = (_size > 1);
+ if (_greaterThan) {
+ int _size_1 = path.size();
+ int _minus = (_size_1 - 1);
+ Iterable<Attribute> _take = IterableExtensions.<Attribute>take(path, _minus);
+ CharSequence _invokeGetters = this.procedureHelpers.invokeGetters(_take, null);
+ String _plus = (_invokeGetters + ".");
+ _xifexpression = _plus;
+ } else {
+ _xifexpression = "";
+ }
+ String getter = _xifexpression;
StringConcatenation _builder = new StringConcatenation();
{
boolean _or = false;
- boolean _or_1 = false;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- if ((_type instanceof ComplexType)) {
- _or_1 = true;
- } else {
- int _size = a.getSize();
- boolean _greaterThan = (_size > 1);
- _or_1 = ((_type instanceof ComplexType) || _greaterThan);
- }
- if (_or_1) {
+ int _size_2 = a.getSize();
+ boolean _equals = (_size_2 == 0);
+ if (_equals) {
_or = true;
} else {
- boolean _not = (!useClassDefaultsOnly);
- _or = (_or_1 || _not);
+ boolean _isCharacterType = this.typeHelpers.isCharacterType(aType);
+ _or = (_equals || _isCharacterType);
}
if (_or) {
- {
- int _size_1 = a.getSize();
- boolean _equals = (_size_1 == 0);
- if (_equals) {
- {
- RefableType _refType_1 = a.getRefType();
- boolean _isRef = _refType_1.isRef();
- if (_isRef) {
- String _name = a.getName();
- _builder.append(_name, "");
- _builder.append(" = ");
- String _nullPointer = this.languageExt.nullPointer();
- _builder.append(_nullPointer, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- String _name_1 = a.getName();
- _builder.append(_name_1, "");
- _builder.append(" = ");
- RefableType _refType_2 = a.getRefType();
- DataType _type_1 = _refType_2.getType();
- String _defaultValue = this.languageExt.defaultValue(_type_1);
- _builder.append(_defaultValue, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- } else {
- String _name_2 = a.getName();
- _builder.append(_name_2, "");
- _builder.append(" = new ");
- RefableType _refType_3 = a.getRefType();
- DataType _type_2 = _refType_3.getType();
- String _typeName = this._typeHelpers.typeName(_type_2);
- _builder.append(_typeName, "");
- _builder.append("[");
- int _size_2 = a.getSize();
- _builder.append(_size_2, "");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- {
- boolean _not_1 = (!useClassDefaultsOnly);
- if (_not_1) {
- _builder.append("for (int i=0;i<");
- int _size_3 = a.getSize();
- _builder.append(_size_3, "");
- _builder.append(";i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_3 = a.getName();
- _builder.append(_name_3, " ");
- _builder.append("[i] = ");
- {
- RefableType _refType_4 = a.getRefType();
- boolean _isRef_1 = _refType_4.isRef();
- if (_isRef_1) {
- String _nullPointer_1 = this.languageExt.nullPointer();
- _builder.append(_nullPointer_1, " ");
- } else {
- RefableType _refType_5 = a.getRefType();
- DataType _type_3 = _refType_5.getType();
- String _defaultValue_1 = this.languageExt.defaultValue(_type_3);
- _builder.append(_defaultValue_1, " ");
- }
- }
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
+ _builder.append(getter, "");
+ String _name = a.getName();
+ CharSequence _invokeSetter = this.procedureHelpers.invokeSetter(_name, null, value);
+ _builder.append(_invokeSetter, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ String _trim = value.trim();
+ boolean _startsWith = _trim.startsWith("{");
+ boolean _not = (!_startsWith);
+ if (_not) {
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ String _typeName = this.typeHelpers.typeName(aType);
+ _builder.append(_typeName, " ");
+ _builder.append("[] ");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, " ");
+ _builder.append(" = new ");
+ String _typeName_1 = this.typeHelpers.typeName(aType);
+ _builder.append(_typeName_1, " ");
+ _builder.append("[");
+ int _size_3 = a.getSize();
+ _builder.append(_size_3, " ");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("for (int i=0;i<");
+ int _size_4 = a.getSize();
+ _builder.append(_size_4, " ");
+ _builder.append(";i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, " ");
+ _builder.append("[i] = ");
+ _builder.append(value, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append(getter, " ");
+ String _name_3 = a.getName();
+ String _name_4 = a.getName();
+ CharSequence _invokeSetter_1 = this.procedureHelpers.invokeSetter(_name_3, null, _name_4);
+ _builder.append(_invokeSetter_1, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ _builder.append(getter, "");
+ String _name_5 = a.getName();
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("new ");
+ String _typeName_2 = this.typeHelpers.typeName(aType);
+ _builder_1.append(_typeName_2, "");
+ _builder_1.append("[] ");
+ _builder_1.append(value, "");
+ CharSequence _invokeSetter_2 = this.procedureHelpers.invokeSetter(_name_5, null, _builder_1.toString());
+ _builder.append(_invokeSetter_2, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
}
}
}
return _builder;
}
- public String getRoomDefaulValue(final Attribute a) {
- String _xifexpression = null;
- boolean _and = false;
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (!_isPrimitive) {
- _and = false;
- } else {
- String _defaultValueLiteral = a.getDefaultValueLiteral();
- boolean _notEquals = (!Objects.equal(_defaultValueLiteral, null));
- _and = (_isPrimitive && _notEquals);
- }
- if (_and) {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- String _defaultValueLiteral_1 = a.getDefaultValueLiteral();
- String _valueLiteral = this.languageExt.toValueLiteral(((PrimitiveType) _type_1), _defaultValueLiteral_1);
- _xifexpression = _valueLiteral;
- }
- return _xifexpression;
- }
-
- private String getDataConfigValue(final EObject roomClass, final List<Attribute> path) {
- Attribute a = IterableExtensions.<Attribute>last(path);
- RefableType _refType = a.getRefType();
- DataType _type = _refType.getType();
- boolean _isPrimitive = this._typeHelpers.isPrimitive(_type);
- if (_isPrimitive) {
- RefableType _refType_1 = a.getRefType();
- DataType _type_1 = _refType_1.getType();
- PrimitiveType aType = ((PrimitiveType) _type_1);
- String _switchResult = null;
- boolean _matched = false;
- if (!_matched) {
- if (roomClass instanceof ActorClass) {
- final ActorClass _actorClass = (ActorClass)roomClass;
- _matched=true;
- String _attrClassConfigValue = this.dataConfigExt.getAttrClassConfigValue(_actorClass, path);
- _switchResult = _attrClassConfigValue;
- }
+ private String getDataConfigValueLiteral(final List<Attribute> path, final EObject roomClass) {
+ String _switchResult = null;
+ boolean _matched = false;
+ if (!_matched) {
+ if (roomClass instanceof ActorClass) {
+ final ActorClass _actorClass = (ActorClass)roomClass;
+ _matched=true;
+ String _attrClassConfigValue = this.dataConfigExt.getAttrClassConfigValue(_actorClass, path);
+ _switchResult = _attrClassConfigValue;
}
- if (!_matched) {
- if (roomClass instanceof PortClass) {
- final PortClass _portClass = (PortClass)roomClass;
- _matched=true;
- String _xifexpression = null;
- EObject _eContainer = _portClass.eContainer();
- if ((_eContainer instanceof ProtocolClass)) {
- String _xblockexpression = null;
- {
- EObject _eContainer_1 = _portClass.eContainer();
- ProtocolClass pc = ((ProtocolClass) _eContainer_1);
- PortClass _regular = pc.getRegular();
- boolean _equals = _regular.equals(_portClass);
- String _attrClassConfigValue = this.dataConfigExt.getAttrClassConfigValue(pc, _equals, path);
- _xblockexpression = (_attrClassConfigValue);
- }
- _xifexpression = _xblockexpression;
+ }
+ if (!_matched) {
+ if (roomClass instanceof PortClass) {
+ final PortClass _portClass = (PortClass)roomClass;
+ _matched=true;
+ String _xifexpression = null;
+ EObject _eContainer = _portClass.eContainer();
+ if ((_eContainer instanceof ProtocolClass)) {
+ String _xblockexpression = null;
+ {
+ EObject _eContainer_1 = _portClass.eContainer();
+ ProtocolClass pc = ((ProtocolClass) _eContainer_1);
+ PortClass _regular = pc.getRegular();
+ boolean _equals = _regular.equals(_portClass);
+ String _attrClassConfigValue = this.dataConfigExt.getAttrClassConfigValue(pc, _equals, path);
+ _xblockexpression = (_attrClassConfigValue);
}
- _switchResult = _xifexpression;
+ _xifexpression = _xblockexpression;
}
+ _switchResult = _xifexpression;
}
- String result = _switchResult;
- boolean _notEquals = (!Objects.equal(result, null));
- if (_notEquals) {
- return this.languageExt.toValueLiteral(aType, result);
+ }
+ if (!_matched) {
+ if (roomClass instanceof DataClass) {
+ final DataClass _dataClass = (DataClass)roomClass;
+ _matched=true;
+ _switchResult = null;
}
}
- return null;
+ return _switchResult;
}
}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
index 782b272..1064c96 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java
@@ -299,7 +299,9 @@ public class JavaExtensions implements ILanguageExtension {
public String defaultValue(final DataType dt) {
if ((dt instanceof PrimitiveType)) {
- return ((PrimitiveType) dt).getDefaultValueLiteral();
+ PrimitiveType pType = ((PrimitiveType) dt);
+ String _defaultValueLiteral = pType.getDefaultValueLiteral();
+ return this.toValueLiteral(pType, _defaultValueLiteral);
} else {
if ((dt instanceof ExternalType)) {
String _targetName = ((ExternalType) dt).getTargetName();
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
index bfcef55..bd07b96 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
@@ -16,9 +16,9 @@ import java.util.List;
import org.eclipse.emf.ecore.resource.ResourceSet;
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.room.ActorClass;
import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.SubSystemClass;
@@ -35,7 +35,7 @@ public interface IDataConfiguration {
public String getAttrClassConfigMaxValue(ActorClass actor, List<Attribute> path);
public String getAttrInstanceConfigValue(ActorInstance ai, List<Attribute> path);
- public String getAttrInstanceConfigValue(ActorInstance ai, InterfaceItem port, List<Attribute> path);
+ public String getAttrInstanceConfigValue(InterfaceItemInstance item, List<Attribute> path);
// dynamic configuration
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend
index b4f4ae0..6c10506 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend
@@ -30,7 +30,7 @@ import org.eclipse.etrice.core.room.VarDecl
import org.eclipse.etrice.generator.base.AbstractGenerator
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
-
+import org.eclipse.etrice.core.room.PrimitiveType
@Singleton
class ProcedureHelpers {
@@ -234,4 +234,34 @@ class ProcedureHelpers {
'''«languageExt.accessLevelPublic()»«returnType» «languageExt.memberInDeclaration(classname, operationname)»(«languageExt.selfPointer(classname, !argumentList.empty)»«argumentList»)'''
}
+// def attributeInitializer(Attribute a, String valueFromModel){
+// if(a.refType.type.primitive){
+// var aType = a.refType.type as PrimitiveType
+// var value = languageExt.toValueLiteral(aType, valueFromModel)
+// return switch null {
+// case a.size == 0 || aType.characterType:
+// value
+// case value.startsWith("{")
+// }
+// '''
+// «IF a.size == 0 || aType.characterType»
+// «getter»«procedureHelpers.invokeSetter(a.name,null,literalValue)»;
+// «ELSEIF literalValue.startsWith("{")»
+// «getter»«procedureHelpers.invokeSetter(a.name,null, '''new «aType.typeName»[] «literalValue»''')»;
+// «ELSE»
+// {
+// «aType.typeName»[] _«a.name» = new «aType.typeName»[«a.size»];
+// for (int i=0;i<«a.size»;i++){
+// _«a.name»[i] = «literalValue»;
+// }
+// «getter»«procedureHelpers.invokeSetter(a.name,null,"_"+a.name)»;
+// }
+// «ENDIF»
+// '''
+// }
+// }
+//
+// def attributeDefaultInitialzier(Attribute a){
+//
+// }
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend
index 50cf307..18b646f 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend
@@ -15,18 +15,17 @@
*/
-package org.eclipse.etrice.generator.generic
-
-import com.google.inject.Inject
+package org.eclipse.etrice.generator.generic
+
+import com.google.inject.Inject
import com.google.inject.Singleton
+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.LiteralType
-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.PrimitiveType
+import org.eclipse.etrice.core.room.PrimitiveType
import org.eclipse.etrice.core.room.VarDecl
-
@Singleton
class TypeHelpers {