Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-09-24 08:37:46 +0000
committerHenrik Rentz-Reichert2012-09-24 08:43:46 +0000
commit9daf836415f2203319f6683cd6a5c33ca8f05889 (patch)
tree27a0ec587ddae22b6f081e9ec38060a6424c977b /plugins
parentfb7825cab56407379667ac58499e24ad9d936f5b (diff)
downloadorg.eclipse.etrice-9daf836415f2203319f6683cd6a5c33ca8f05889.tar.gz
org.eclipse.etrice-9daf836415f2203319f6683cd6a5c33ca8f05889.tar.xz
org.eclipse.etrice-9daf836415f2203319f6683cd6a5c33ca8f05889.zip
[generator, generatr.c, generator.java] fixes in C initialization
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend47
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java102
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/SubSystemClassGen.java13
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend55
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend31
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java6
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java6
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java190
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java58
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java6
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ConfigExtension.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend3
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java16
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ITypedDataProvider.java2
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ProcedureHelpers.xtend41
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend13
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ConfigExtension.java8
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java4
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java170
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java22
24 files changed, 529 insertions, 273 deletions
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 9ab45875c..4f52a60ed 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
@@ -27,14 +27,16 @@ import org.eclipse.etrice.generator.generic.ILanguageExtension
import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
import java.util.List
import org.eclipse.xtext.util.Pair
-
-
+import org.eclipse.etrice.core.room.DataType
+import org.eclipse.etrice.core.room.ExternalType
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician
+import org.eclipse.etrice.core.room.DataClass
@Singleton
class CExtensions implements ILanguageExtension {
@Inject AbstractTransitionChainGenerator chainGenerator
-
+ @Inject IDiagnostician diagnostician
override String getTypedDataDefinition(Message m) {
return chainGenerator.generateTypedData(m.data)
@@ -157,4 +159,43 @@ class CExtensions implements ILanguageExtension {
override String toValueLiteral(PrimitiveType type, String value){
throw new UnsupportedOperationException("TODO Config for C");
}
+
+ override String defaultValue(DataType dt) {
+ if (dt instanceof PrimitiveType) {
+ return (dt as PrimitiveType).getDefaultValueLiteral
+ }
+ else if (dt instanceof ExternalType) {
+ 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
+
+ '''
+ {
+ «FOR att : dc.attributes SEPARATOR ","»
+ «att.refType.type.initializationWithDefaultValues(att.size)»
+ «ENDFOR»
+ }
+ '''
+ }
+ }
+
+ override initializationWithDefaultValues(DataType dt, int size) {
+ val dv = dt.defaultValue
+ if (size>1) {
+ var res = "{"
+ var i = 0
+ while (i<size) {
+ res = res + dv
+ i = i+1
+ if (i<size)
+ res = res + ","
+ }
+ res+"}"
+ }
+ else
+ dv
+ }
+
} \ 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 1ebb6e129..8062f370f 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
@@ -32,7 +32,6 @@ 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.generator.generic.TypeHelpers
import org.eclipse.etrice.generator.generic.ILanguageExtension
import static extension org.eclipse.etrice.generator.base.Indexed.*
import org.eclipse.etrice.core.room.Attribute
@@ -45,7 +44,6 @@ class SubSystemClassGen {
@Inject extension CExtensions stdExt
@Inject extension RoomExtensions roomExt
@Inject extension ProcedureHelpers helpers
- @Inject extension TypeHelpers
@Inject extension ConfigExtension
@Inject ILanguageExtension languageExt
@Inject ILogger logger
@@ -424,7 +422,7 @@ class SubSystemClassGen {
def private genAttributeInitializer(ActorInstance ai, Attribute att) {
val value = att.initValueLiteral
if (value==null)
- att.refType.type.defaultValue
+ att.refType.type.initializationWithDefaultValues(att.size)
else
value.toString
}
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 628d1c15f..3dc649011 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
@@ -3,8 +3,17 @@ package org.eclipse.etrice.generator.c.gen;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.RoomClass;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
@@ -18,6 +27,9 @@ public class CExtensions implements ILanguageExtension {
@Inject
private AbstractTransitionChainGenerator chainGenerator;
+ @Inject
+ private IDiagnostician diagnostician;
+
public String getTypedDataDefinition(final Message m) {
VarDecl _data = m.getData();
return this.chainGenerator.generateTypedData(_data);
@@ -243,4 +255,94 @@ public class CExtensions implements ILanguageExtension {
UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("TODO Config for C");
throw _unsupportedOperationException;
}
+
+ 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 _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 _xblockexpression = null;
+ {
+ final DataClass dc = ((DataClass) dt);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ boolean _hasElements = false;
+ for(final Attribute att : _attributes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", " ");
+ }
+ _builder.append("\t");
+ RefableType _refType = att.getRefType();
+ DataType _type = _refType.getType();
+ int _size = att.getSize();
+ String _initializationWithDefaultValues = this.initializationWithDefaultValues(_type, _size);
+ _builder.append(_initializationWithDefaultValues, " ");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _xblockexpression = (_builder.toString());
+ }
+ _xifexpression_1 = _xblockexpression;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ return _xifexpression;
+ }
+
+ public String initializationWithDefaultValues(final DataType dt, final int size) {
+ String _xblockexpression = null;
+ {
+ final String dv = this.defaultValue(dt);
+ String _xifexpression = null;
+ boolean _greaterThan = (size > 1);
+ if (_greaterThan) {
+ String _xblockexpression_1 = null;
+ {
+ String res = "{";
+ int i = 0;
+ boolean _lessThan = (i < size);
+ boolean _while = _lessThan;
+ while (_while) {
+ {
+ String _plus = (res + dv);
+ res = _plus;
+ int _plus_1 = (i + 1);
+ i = _plus_1;
+ boolean _lessThan_1 = (i < size);
+ if (_lessThan_1) {
+ String _plus_2 = (res + ",");
+ res = _plus_2;
+ }
+ }
+ boolean _lessThan_1 = (i < size);
+ _while = _lessThan_1;
+ }
+ String _plus = (res + "}");
+ _xblockexpression_1 = (_plus);
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ _xifexpression = dv;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
}
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 0c5aea00b..178ae7487 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
@@ -39,7 +39,6 @@ import org.eclipse.etrice.generator.generic.ConfigExtension;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
@@ -62,9 +61,6 @@ public class SubSystemClassGen {
private ProcedureHelpers helpers;
@Inject
- private TypeHelpers _typeHelpers;
-
- @Inject
private ConfigExtension _configExtension;
@Inject
@@ -908,7 +904,7 @@ public class SubSystemClassGen {
} else {
RefableType _refType = attr.getRefType();
DataType _type = _refType.getType();
- String _defaultValue = this._typeHelpers.defaultValue(_type);
+ String _defaultValue = this.stdExt.defaultValue(_type);
_builder.append(_defaultValue, "");
}
}
@@ -1281,7 +1277,7 @@ public class SubSystemClassGen {
VarDecl _data = m.getData();
RefableType _refType = _data.getRefType();
DataType _type = _refType.getType();
- String _defaultValue = this._typeHelpers.defaultValue(_type);
+ String _defaultValue = this.stdExt.defaultValue(_type);
_builder.append(_defaultValue, " ");
_builder.newLineIfNotEmpty();
}
@@ -1302,8 +1298,9 @@ public class SubSystemClassGen {
if (_equals) {
RefableType _refType = att.getRefType();
DataType _type = _refType.getType();
- String _defaultValue = this._typeHelpers.defaultValue(_type);
- _xifexpression = _defaultValue;
+ int _size = att.getSize();
+ String _initializationWithDefaultValues = this.stdExt.initializationWithDefaultValues(_type, _size);
+ _xifexpression = _initializationWithDefaultValues;
} else {
String _string = value.toString();
_xifexpression = _string;
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend
index 83762b97b..0dbba91ba 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend
@@ -36,6 +36,7 @@ class ActorClassGen extends GenericActorClassGenerator {
@Inject ConfigGenAddon configAddon
@Inject extension ProcedureHelpers
+ @Inject extension Initialization
@Inject extension StateMachineGen
@Inject ILogger logger
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend
index 416c0c988..6c8c44c6d 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend
@@ -34,6 +34,7 @@ class DataClassGen {
@Inject extension JavaExtensions
@Inject extension RoomExtensions
@Inject extension ProcedureHelpers
+ @Inject extension Initialization
@Inject ILogger logger
def doGenerate(Root root) {
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
new file mode 100644
index 000000000..2d0ca0e0f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
@@ -0,0 +1,55 @@
+package org.eclipse.etrice.generator.java.gen
+
+import org.eclipse.etrice.core.room.Attribute
+import java.util.List
+import com.google.inject.Inject
+import org.eclipse.etrice.generator.generic.ConfigExtension
+import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.core.room.ComplexType
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import com.google.inject.Singleton
+
+@Singleton
+class Initialization {
+
+ @Inject extension ConfigExtension
+ @Inject extension TypeHelpers
+ @Inject ILanguageExtension languageExt
+
+ def attributeInitialization(List<Attribute> attribs, boolean useClassDefaultsOnly) {
+ '''
+ // initialize attributes
+ «FOR a : attribs»
+ «var aType = a.refType.type»
+ «var value = a.initValueLiteral»
+ «IF value!=null»
+ «IF a.size == 0 || aType.characterType»
+ «a.name» = «value»;
+ «ELSEIF value.startsWith("{")»
+ «a.name» = new «aType.typeName»[] «value»;
+ «ELSE»
+ «a.name» = new «aType.typeName»[«a.size»];
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «value»;
+ }
+ «ENDIF»
+ «ELSEIF aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
+ «IF a.size==0»
+ «IF a.refType.isRef»
+ «a.name» = «languageExt.nullPointer()»;
+ «ELSE»
+ «a.name» = «languageExt.defaultValue(aType)»;
+ «ENDIF»
+ «ELSE»
+ «a.name» = new «aType.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(aType)»«ENDIF»;
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+} \ No newline at end of file
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 9832ea0e1..4a1d3550f 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
@@ -26,7 +26,8 @@ import org.eclipse.etrice.generator.generic.ILanguageExtension
import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
import java.util.List
import org.eclipse.xtext.util.Pair
-
+import org.eclipse.etrice.core.room.DataType
+import org.eclipse.etrice.core.room.ExternalType
@Singleton
class JavaExtensions implements ILanguageExtension {
@@ -138,5 +139,33 @@ class JavaExtensions implements ILanguageExtension {
throw new UnsupportedOperationException(type.targetName)
}
+
+ override defaultValue(DataType dt) {
+ if (dt instanceof PrimitiveType) {
+ return (dt as PrimitiveType).getDefaultValueLiteral
+ }
+ else if (dt instanceof ExternalType)
+ return "new "+(dt as ExternalType).targetName+"()"
+ else
+ return "new "+dt.name+"()"
+ }
+
+
+ override initializationWithDefaultValues(DataType dt, int size) {
+ val dv = dt.defaultValue
+ if (size>1) {
+ var res = "{"
+ var i = 0
+ while (i<size) {
+ res = res + dv
+ i = i+1
+ if (i<size)
+ res = res + ","
+ }
+ res+"}"
+ }
+ else
+ dv
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
index c2ac4c9f2..036d195e6 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend
@@ -35,6 +35,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
@Inject extension JavaExtensions
@Inject extension RoomExtensions
@Inject extension ProcedureHelpers
+ @Inject extension Initialization
@Inject extension TypeHelpers
@Inject extension DataClassGen
@Inject ILogger logger
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
index a26f52a48..83cf12c9f 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ActorClassGen.java
@@ -26,6 +26,7 @@ import org.eclipse.etrice.generator.generic.GenericActorClassGenerator;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
import org.eclipse.etrice.generator.java.gen.ConfigGenAddon;
+import org.eclipse.etrice.generator.java.gen.Initialization;
import org.eclipse.etrice.generator.java.gen.JavaExtensions;
import org.eclipse.etrice.generator.java.gen.StateMachineGen;
import org.eclipse.xtend2.lib.StringConcatenation;
@@ -55,6 +56,9 @@ public class ActorClassGen extends GenericActorClassGenerator {
private ProcedureHelpers _procedureHelpers;
@Inject
+ private Initialization _initialization;
+
+ @Inject
private StateMachineGen _stateMachineGen;
@Inject
@@ -348,7 +352,7 @@ public class ActorClassGen extends GenericActorClassGenerator {
_builder.newLine();
_builder.append("\t\t");
EList<Attribute> _attributes_2 = ac.getAttributes();
- CharSequence _attributeInitialization = this._procedureHelpers.attributeInitialization(_attributes_2, false);
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_2, false);
_builder.append(_attributeInitialization, " ");
_builder.newLineIfNotEmpty();
_builder.newLine();
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
index a187baa53..c694b0817 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/DataClassGen.java
@@ -18,6 +18,7 @@ import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.generator.generic.ProcedureHelpers;
import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.java.gen.Initialization;
import org.eclipse.etrice.generator.java.gen.JavaExtensions;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
@@ -40,6 +41,9 @@ public class DataClassGen {
private ProcedureHelpers _procedureHelpers;
@Inject
+ private Initialization _initialization;
+
+ @Inject
private ILogger logger;
public void doGenerate(final Root root) {
@@ -160,7 +164,7 @@ public class DataClassGen {
_builder.newLine();
_builder.append("\t\t");
EList<Attribute> _attributes_3 = dc.getAttributes();
- CharSequence _attributeInitialization = this._procedureHelpers.attributeInitialization(_attributes_3, true);
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes_3, true);
_builder.append(_attributeInitialization, " ");
_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
new file mode 100644
index 000000000..41fdc15f4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/Initialization.java
@@ -0,0 +1,190 @@
+package org.eclipse.etrice.generator.java.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.ComplexType;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.generator.generic.ConfigExtension;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtend2.lib.StringConcatenation;
+
+@Singleton
+@SuppressWarnings("all")
+public class Initialization {
+ @Inject
+ private ConfigExtension _configExtension;
+
+ @Inject
+ private TypeHelpers _typeHelpers;
+
+ @Inject
+ private ILanguageExtension languageExt;
+
+ public CharSequence attributeInitialization(final List<Attribute> attribs, final boolean useClassDefaultsOnly) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("// initialize attributes");
+ _builder.newLine();
+ {
+ for(final Attribute a : attribs) {
+ RefableType _refType = a.getRefType();
+ DataType aType = _refType.getType();
+ _builder.newLineIfNotEmpty();
+ String value = this._configExtension.getInitValueLiteral(a);
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(value, null));
+ if (_notEquals) {
+ {
+ boolean _or = false;
+ int _size = a.getSize();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ _or = true;
+ } else {
+ boolean _isCharacterType = this._typeHelpers.isCharacterType(aType);
+ _or = (_equals || _isCharacterType);
+ }
+ if (_or) {
+ String _name = a.getName();
+ _builder.append(_name, "");
+ _builder.append(" = ");
+ _builder.append(value, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ boolean _startsWith = value.startsWith("{");
+ if (_startsWith) {
+ String _name_1 = a.getName();
+ _builder.append(_name_1, "");
+ _builder.append(" = new ");
+ String _typeName = this._typeHelpers.typeName(aType);
+ _builder.append(_typeName, "");
+ _builder.append("[] ");
+ _builder.append(value, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ String _name_2 = a.getName();
+ _builder.append(_name_2, "");
+ _builder.append(" = new ");
+ String _typeName_1 = this._typeHelpers.typeName(aType);
+ _builder.append(_typeName_1, "");
+ _builder.append("[");
+ int _size_1 = a.getSize();
+ _builder.append(_size_1, "");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("for (int i=0;i<");
+ int _size_2 = a.getSize();
+ _builder.append(_size_2, "");
+ _builder.append(";i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, " ");
+ _builder.append("[i] = ");
+ _builder.append(value, " ");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ } else {
+ boolean _or_1 = false;
+ boolean _or_2 = false;
+ if ((aType instanceof ComplexType)) {
+ _or_2 = true;
+ } else {
+ int _size_3 = a.getSize();
+ boolean _greaterThan = (_size_3 > 1);
+ _or_2 = ((aType instanceof ComplexType) || _greaterThan);
+ }
+ if (_or_2) {
+ _or_1 = true;
+ } else {
+ boolean _not = (!useClassDefaultsOnly);
+ _or_1 = (_or_2 || _not);
+ }
+ if (_or_1) {
+ {
+ int _size_4 = a.getSize();
+ boolean _equals_1 = (_size_4 == 0);
+ if (_equals_1) {
+ {
+ RefableType _refType_1 = a.getRefType();
+ boolean _isRef = _refType_1.isRef();
+ if (_isRef) {
+ String _name_4 = a.getName();
+ _builder.append(_name_4, "");
+ _builder.append(" = ");
+ String _nullPointer = this.languageExt.nullPointer();
+ _builder.append(_nullPointer, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ String _name_5 = a.getName();
+ _builder.append(_name_5, "");
+ _builder.append(" = ");
+ String _defaultValue = this.languageExt.defaultValue(aType);
+ _builder.append(_defaultValue, "");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ } else {
+ String _name_6 = a.getName();
+ _builder.append(_name_6, "");
+ _builder.append(" = new ");
+ String _typeName_2 = this._typeHelpers.typeName(aType);
+ _builder.append(_typeName_2, "");
+ _builder.append("[");
+ int _size_5 = a.getSize();
+ _builder.append(_size_5, "");
+ _builder.append("];");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _not_1 = (!useClassDefaultsOnly);
+ if (_not_1) {
+ _builder.append("for (int i=0;i<");
+ int _size_6 = a.getSize();
+ _builder.append(_size_6, "");
+ _builder.append(";i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, " ");
+ _builder.append("[i] = ");
+ {
+ RefableType _refType_2 = a.getRefType();
+ boolean _isRef_1 = _refType_2.isRef();
+ if (_isRef_1) {
+ String _nullPointer_1 = this.languageExt.nullPointer();
+ _builder.append(_nullPointer_1, " ");
+ } else {
+ String _defaultValue_1 = this.languageExt.defaultValue(aType);
+ _builder.append(_defaultValue_1, " ");
+ }
+ }
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+}
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 395be27a5..e3c821388 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
@@ -4,6 +4,8 @@ import com.google.common.base.Objects;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.RoomClass;
@@ -237,4 +239,60 @@ public class JavaExtensions implements ILanguageExtension {
UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(_targetName_1);
throw _unsupportedOperationException;
}
+
+ public String defaultValue(final DataType dt) {
+ if ((dt instanceof PrimitiveType)) {
+ return ((PrimitiveType) dt).getDefaultValueLiteral();
+ } else {
+ if ((dt instanceof ExternalType)) {
+ String _targetName = ((ExternalType) dt).getTargetName();
+ String _plus = ("new " + _targetName);
+ return (_plus + "()");
+ } else {
+ String _name = dt.getName();
+ String _plus_1 = ("new " + _name);
+ return (_plus_1 + "()");
+ }
+ }
+ }
+
+ public String initializationWithDefaultValues(final DataType dt, final int size) {
+ String _xblockexpression = null;
+ {
+ final String dv = this.defaultValue(dt);
+ String _xifexpression = null;
+ boolean _greaterThan = (size > 1);
+ if (_greaterThan) {
+ String _xblockexpression_1 = null;
+ {
+ String res = "{";
+ int i = 0;
+ boolean _lessThan = (i < size);
+ boolean _while = _lessThan;
+ while (_while) {
+ {
+ String _plus = (res + dv);
+ res = _plus;
+ int _plus_1 = (i + 1);
+ i = _plus_1;
+ boolean _lessThan_1 = (i < size);
+ if (_lessThan_1) {
+ String _plus_2 = (res + ",");
+ res = _plus_2;
+ }
+ }
+ boolean _lessThan_1 = (i < size);
+ _while = _lessThan_1;
+ }
+ String _plus = (res + "}");
+ _xblockexpression_1 = (_plus);
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ _xifexpression = dv;
+ }
+ _xblockexpression = (_xifexpression);
+ }
+ return _xblockexpression;
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
index 7b2090992..a5a0e83d0 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.java
@@ -25,6 +25,7 @@ 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.generator.java.gen.DataClassGen;
+import org.eclipse.etrice.generator.java.gen.Initialization;
import org.eclipse.etrice.generator.java.gen.JavaExtensions;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
@@ -45,6 +46,9 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator {
private ProcedureHelpers _procedureHelpers;
@Inject
+ private Initialization _initialization;
+
+ @Inject
private TypeHelpers _typeHelpers;
@Inject
@@ -246,7 +250,7 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator {
if (_notEquals_1) {
_builder.append("\t\t");
EList<Attribute> _attributes = pclass.getAttributes();
- CharSequence _attributeInitialization = this._procedureHelpers.attributeInitialization(_attributes, true);
+ CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, true);
_builder.append(_attributeInitialization, " ");
_builder.newLineIfNotEmpty();
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ConfigExtension.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ConfigExtension.xtend
index 1a794cb6b..af1502dda 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ConfigExtension.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ConfigExtension.xtend
@@ -45,8 +45,6 @@ import org.eclipse.etrice.generator.base.ConfigHelper
@Singleton
class ConfigExtension {
@Inject ILanguageExtension languageExt
- @Inject TypeHelpers typeHelpers
- @Inject RoomExtensions roomExt
// language operations
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
index 921999223..247add64a 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend
@@ -61,7 +61,6 @@ class GenericStateMachineGenerator {
}
def private genTransitionChainConstants(ExpandedActorClass xpac) {
- val ac = xpac.actorClass
var chains = if (langExt.usesInheritance)
xpac.getOwnTransitionChains() else xpac.transitionChains
var offset = if (langExt.usesInheritance)
@@ -77,7 +76,6 @@ class GenericStateMachineGenerator {
}
def private genTriggerConstants(ExpandedActorClass xpac) {
- val ac = xpac.actorClass
val triggers = if (langExt.usesInheritance)
xpac.getOwnTriggers() else xpac.triggers
@@ -94,7 +92,6 @@ class GenericStateMachineGenerator {
val ac = xpac.actorClass
val async = ac.commType==ActorCommunicationType::ASYNCHRONOUS
val eventDriven = ac.commType==ActorCommunicationType::EVENT_DRIVEN
- val dataDriven = ac.commType==ActorCommunicationType::DATA_DRIVEN
val handleEvents = async || eventDriven
'''
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java
index 2aab1647f..ebd45b117 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java
@@ -1,6 +1,7 @@
package org.eclipse.etrice.generator.generic;
+import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.PrimitiveType;
import java.util.List;
@@ -189,4 +190,19 @@ public interface ILanguageExtension {
* toPrimitve("PrimitiveType int8: ptInteger -> byte (Byte)", Byte value = 12) -> (byte)12
*/
String toValueLiteral(PrimitiveType type, String value);
+
+ /**
+ * returns a default value for a type
+ * @param dt the data type
+ * @return the default value string
+ */
+ String defaultValue(DataType dt);
+
+ /**
+ * returns an initializer for an array with default values
+ * @param dt the data type
+ * @param size
+ * @return the array initializer
+ */
+ String initializationWithDefaultValues(DataType dt, int size);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ITypedDataProvider.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ITypedDataProvider.java
index 2d485bd0a..4a908e331 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ITypedDataProvider.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ITypedDataProvider.java
@@ -26,7 +26,7 @@ public interface ITypedDataProvider {
* @param data the variable declaration
* @return an array of three strings
* <ol>
- * <li>the string that performs the cast from generic_data to the correct type and assigns it to a new variabley</li>
+ * <li>the string that performs the cast from generic_data to the correct type and assigns it to a new variable</li>
* <li>the data as it appears in a method call</li>
* <li>the data as it is used in the method declaration</li>
* </ol>
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 979e5efe9..bff6fcdf6 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
@@ -21,7 +21,6 @@ import org.eclipse.etrice.core.genmodel.base.ILogger
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.ActorContainerClass
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.DetailCode
import org.eclipse.etrice.core.room.Operation
@@ -37,7 +36,6 @@ import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
class ProcedureHelpers {
@Inject ILanguageExtension languageExt
- @Inject extension ConfigExtension
@Inject extension TypeHelpers
@Inject ILogger logger
@@ -100,7 +98,7 @@ class ProcedureHelpers {
}
def arrayInitializer(Attribute att) {
- var dflt = if (att.defaultValueLiteral!=null) att.defaultValueLiteral else att.refType.type.defaultValue
+ var dflt = if (att.defaultValueLiteral!=null) att.defaultValueLiteral else languageExt.defaultValue(att.refType.type)
if (dflt.startsWith("{")) {
if (dflt.split(",").size!=att.size)
@@ -120,43 +118,6 @@ class ProcedureHelpers {
return result+"}"
}
- def attributeInitialization(List<Attribute> attribs, boolean useClassDefaultsOnly) {
- '''
- // initialize attributes
- «FOR a : attribs»
- «var aType = a.refType.type»
- «var value = a.initValueLiteral»
- «IF value!=null»
- «IF a.size == 0 || aType.characterType»
- «a.name» = «value»;
- «ELSEIF value.startsWith("{")»
- «a.name» = new «aType.typeName»[] «value»;
- «ELSE»
- «a.name» = new «aType.typeName»[«a.size»];
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «value»;
- }
- «ENDIF»
- «ELSEIF aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
- «IF a.size==0»
- «IF a.refType.isRef»
- «a.name» = «languageExt.nullPointer()»;
- «ELSE»
- «a.name» = «aType.defaultValue»;
- «ENDIF»
- «ELSE»
- «a.name» = new «aType.typeName»[«a.size»];
- «IF !useClassDefaultsOnly»
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«aType.defaultValue»«ENDIF»;
- }
- «ENDIF»
- «ENDIF»
- «ENDIF»
- «ENDFOR»
- '''
- }
-
// Attribute setters & getters
def attributeSettersGettersDeclaration(List<Attribute> attribs, String classname) {'''
//--------------------- attribute setters and getters
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 278bad335..e5a9e3251 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
@@ -33,6 +33,7 @@ import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
class TypeHelpers {
@Inject AbstractTransitionChainGenerator chainGenerator
+ @Inject ILanguageExtension languageExt
def String typeName(DataType type) {
if (type instanceof PrimitiveType)
@@ -42,19 +43,9 @@ class TypeHelpers {
else
return type.name
}
-
- def String defaultValue(DataType dt) {
- if (dt instanceof PrimitiveType) {
- return (dt as PrimitiveType).getDefaultValueLiteral
- }
- else if (dt instanceof ExternalType)
- return "new "+(dt as ExternalType).targetName+"()"
- else
- return "new "+dt.name+"()"
- }
def String defaultValue(VarDecl a) {
- return defaultValue(a.refType.type)
+ return languageExt.defaultValue(a.refType.type)
}
def String getTypedDataDefinition(Message m) {
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ConfigExtension.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ConfigExtension.java
index 5af9d7c8f..aac2378b6 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ConfigExtension.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ConfigExtension.java
@@ -38,8 +38,6 @@ import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.generator.base.ConfigHelper;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.etrice.generator.generic.RoomExtensions;
-import org.eclipse.etrice.generator.generic.TypeHelpers;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
@@ -52,12 +50,6 @@ public class ConfigExtension {
@Inject
private ILanguageExtension languageExt;
- @Inject
- private TypeHelpers typeHelpers;
-
- @Inject
- private RoomExtensions roomExt;
-
public String toArrayValueLiteral(final PrimitiveType type, final String[] values) {
StringConcatenation _builder = new StringConcatenation();
{
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
index 37a70ec95..d055668ac 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java
@@ -100,7 +100,6 @@ public class GenericStateMachineGenerator {
}
private String genTransitionChainConstants(final ExpandedActorClass xpac) {
- final ActorClass ac = xpac.getActorClass();
EList<TransitionChain> _xifexpression = null;
boolean _usesInheritance = this.langExt.usesInheritance();
if (_usesInheritance) {
@@ -139,7 +138,6 @@ public class GenericStateMachineGenerator {
}
private String genTriggerConstants(final ExpandedActorClass xpac) {
- final ActorClass ac = xpac.getActorClass();
EList<MessageFromIf> _xifexpression = null;
boolean _usesInheritance = this.langExt.usesInheritance();
if (_usesInheritance) {
@@ -176,8 +174,6 @@ public class GenericStateMachineGenerator {
final boolean async = Objects.equal(_commType, ActorCommunicationType.ASYNCHRONOUS);
ActorCommunicationType _commType_1 = ac.getCommType();
final boolean eventDriven = Objects.equal(_commType_1, ActorCommunicationType.EVENT_DRIVEN);
- ActorCommunicationType _commType_2 = ac.getCommType();
- final boolean dataDriven = Objects.equal(_commType_2, ActorCommunicationType.DATA_DRIVEN);
boolean _or = false;
if (async) {
_or = true;
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java
index e8021c119..c543098c3 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java
@@ -9,7 +9,6 @@ import org.eclipse.etrice.core.genmodel.base.ILogger;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
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.DetailCode;
@@ -20,7 +19,6 @@ import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.generator.base.AbstractGenerator;
-import org.eclipse.etrice.generator.generic.ConfigExtension;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.TypeHelpers;
import org.eclipse.xtend2.lib.StringConcatenation;
@@ -34,9 +32,6 @@ public class ProcedureHelpers {
private ILanguageExtension languageExt;
@Inject
- private ConfigExtension _configExtension;
-
- @Inject
private TypeHelpers _typeHelpers;
@Inject
@@ -229,7 +224,7 @@ public class ProcedureHelpers {
} else {
RefableType _refType = att.getRefType();
DataType _type = _refType.getType();
- String _defaultValue = this._typeHelpers.defaultValue(_type);
+ String _defaultValue = this.languageExt.defaultValue(_type);
_xifexpression = _defaultValue;
}
String dflt = _xifexpression;
@@ -277,169 +272,6 @@ public class ProcedureHelpers {
return (result + "}");
}
- public CharSequence attributeInitialization(final List<Attribute> attribs, final boolean useClassDefaultsOnly) {
- StringConcatenation _builder = new StringConcatenation();
- _builder.append("// initialize attributes");
- _builder.newLine();
- {
- for(final Attribute a : attribs) {
- RefableType _refType = a.getRefType();
- DataType aType = _refType.getType();
- _builder.newLineIfNotEmpty();
- String value = this._configExtension.getInitValueLiteral(a);
- _builder.newLineIfNotEmpty();
- {
- boolean _notEquals = (!Objects.equal(value, null));
- if (_notEquals) {
- {
- boolean _or = false;
- int _size = a.getSize();
- boolean _equals = (_size == 0);
- if (_equals) {
- _or = true;
- } else {
- boolean _isCharacterType = this._typeHelpers.isCharacterType(aType);
- _or = (_equals || _isCharacterType);
- }
- if (_or) {
- String _name = a.getName();
- _builder.append(_name, "");
- _builder.append(" = ");
- _builder.append(value, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- boolean _startsWith = value.startsWith("{");
- if (_startsWith) {
- String _name_1 = a.getName();
- _builder.append(_name_1, "");
- _builder.append(" = new ");
- String _typeName = this._typeHelpers.typeName(aType);
- _builder.append(_typeName, "");
- _builder.append("[] ");
- _builder.append(value, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- String _name_2 = a.getName();
- _builder.append(_name_2, "");
- _builder.append(" = new ");
- String _typeName_1 = this._typeHelpers.typeName(aType);
- _builder.append(_typeName_1, "");
- _builder.append("[");
- int _size_1 = a.getSize();
- _builder.append(_size_1, "");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- _builder.append("for (int i=0;i<");
- int _size_2 = a.getSize();
- _builder.append(_size_2, "");
- _builder.append(";i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_3 = a.getName();
- _builder.append(_name_3, " ");
- _builder.append("[i] = ");
- _builder.append(value, " ");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- } else {
- boolean _or_1 = false;
- boolean _or_2 = false;
- if ((aType instanceof ComplexType)) {
- _or_2 = true;
- } else {
- int _size_3 = a.getSize();
- boolean _greaterThan = (_size_3 > 1);
- _or_2 = ((aType instanceof ComplexType) || _greaterThan);
- }
- if (_or_2) {
- _or_1 = true;
- } else {
- boolean _not = (!useClassDefaultsOnly);
- _or_1 = (_or_2 || _not);
- }
- if (_or_1) {
- {
- int _size_4 = a.getSize();
- boolean _equals_1 = (_size_4 == 0);
- if (_equals_1) {
- {
- RefableType _refType_1 = a.getRefType();
- boolean _isRef = _refType_1.isRef();
- if (_isRef) {
- String _name_4 = a.getName();
- _builder.append(_name_4, "");
- _builder.append(" = ");
- String _nullPointer = this.languageExt.nullPointer();
- _builder.append(_nullPointer, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- } else {
- String _name_5 = a.getName();
- _builder.append(_name_5, "");
- _builder.append(" = ");
- String _defaultValue = this._typeHelpers.defaultValue(aType);
- _builder.append(_defaultValue, "");
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- }
- }
- } else {
- String _name_6 = a.getName();
- _builder.append(_name_6, "");
- _builder.append(" = new ");
- String _typeName_2 = this._typeHelpers.typeName(aType);
- _builder.append(_typeName_2, "");
- _builder.append("[");
- int _size_5 = a.getSize();
- _builder.append(_size_5, "");
- _builder.append("];");
- _builder.newLineIfNotEmpty();
- {
- boolean _not_1 = (!useClassDefaultsOnly);
- if (_not_1) {
- _builder.append("for (int i=0;i<");
- int _size_6 = a.getSize();
- _builder.append(_size_6, "");
- _builder.append(";i++){");
- _builder.newLineIfNotEmpty();
- _builder.append("\t");
- String _name_7 = a.getName();
- _builder.append(_name_7, " ");
- _builder.append("[i] = ");
- {
- RefableType _refType_2 = a.getRefType();
- boolean _isRef_1 = _refType_2.isRef();
- if (_isRef_1) {
- String _nullPointer_1 = this.languageExt.nullPointer();
- _builder.append(_nullPointer_1, " ");
- } else {
- String _defaultValue_1 = this._typeHelpers.defaultValue(aType);
- _builder.append(_defaultValue_1, " ");
- }
- }
- _builder.append(";");
- _builder.newLineIfNotEmpty();
- _builder.append("}");
- _builder.newLine();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return _builder;
- }
-
public CharSequence attributeSettersGettersDeclaration(final List<Attribute> attribs, final String classname) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("//--------------------- attribute setters and getters");
diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java
index 80078c381..29fea1c0b 100644
--- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java
+++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java
@@ -12,6 +12,7 @@ import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.RefableType;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
@Singleton
@SuppressWarnings("all")
@@ -19,6 +20,9 @@ public class TypeHelpers {
@Inject
private AbstractTransitionChainGenerator chainGenerator;
+ @Inject
+ private ILanguageExtension languageExt;
+
public String typeName(final DataType type) {
if ((type instanceof PrimitiveType)) {
return ((PrimitiveType) type).getTargetName();
@@ -31,26 +35,10 @@ public class TypeHelpers {
}
}
- public String defaultValue(final DataType dt) {
- if ((dt instanceof PrimitiveType)) {
- return ((PrimitiveType) dt).getDefaultValueLiteral();
- } else {
- if ((dt instanceof ExternalType)) {
- String _targetName = ((ExternalType) dt).getTargetName();
- String _plus = ("new " + _targetName);
- return (_plus + "()");
- } else {
- String _name = dt.getName();
- String _plus_1 = ("new " + _name);
- return (_plus_1 + "()");
- }
- }
- }
-
public String defaultValue(final VarDecl a) {
RefableType _refType = a.getRefType();
DataType _type = _refType.getType();
- return this.defaultValue(_type);
+ return this.languageExt.defaultValue(_type);
}
public String getTypedDataDefinition(final Message m) {

Back to the top