Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2012-11-23 12:13:03 +0000
committerJuergen Haug2012-11-23 12:13:03 +0000
commit50fcc9f9b85408eb13037b6cfad0af69d756f495 (patch)
tree2579e609252fdc58f0c75d3eae76b409a30d4651 /plugins/org.eclipse.etrice.generator.c
parentcee5a6f76524b0a1412f48ff759c95da41d06c62 (diff)
downloadorg.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.tar.gz
org.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.tar.xz
org.eclipse.etrice-50fcc9f9b85408eb13037b6cfad0af69d756f495.zip
[CQ][generator] first config c generator
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c')
-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
8 files changed, 600 insertions, 263 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 e9a528d86..412e494ab 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 cb217c6d5..2b33adacc 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 000000000..b7dcf1411
--- /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 bc73031ec..cd495f1f4 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 ef3849a1b..5700b78b7 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 a25ace5e9..6cd31c449 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 000000000..9af39c776
--- /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 8da690926..fbfe286aa 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);

Back to the top