Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-11-25 18:57:50 +0000
committerHenrik Rentz-Reichert2013-11-26 11:25:39 +0000
commit0b04558ad11532ae9ecdb6fabe5eb96551109aea (patch)
tree5fd146077f5981409ad8f4c0967ff7a88097d101
parent1c44891fc4dba4bf1b5cc85951f116b8908638fd (diff)
downloadorg.eclipse.etrice-0b04558ad11532ae9ecdb6fabe5eb96551109aea.tar.gz
org.eclipse.etrice-0b04558ad11532ae9ecdb6fabe5eb96551109aea.tar.xz
org.eclipse.etrice-0b04558ad11532ae9ecdb6fabe5eb96551109aea.zip
[generator.c] fix in attribute initialization
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/icons/EnumLiteral.gifbin0 -> 89 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/icons/EnumerationType.gifbin0 -> 132 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/labeling/RoomLabelProvider.java22
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend6
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend22
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java3
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java10
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java26
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend10
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java21
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/models/EnumTest.room6
12 files changed, 86 insertions, 42 deletions
diff --git a/plugins/org.eclipse.etrice.core.room.ui/icons/EnumLiteral.gif b/plugins/org.eclipse.etrice.core.room.ui/icons/EnumLiteral.gif
new file mode 100644
index 000000000..f1f8fe1f2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/icons/EnumLiteral.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.room.ui/icons/EnumerationType.gif b/plugins/org.eclipse.etrice.core.room.ui/icons/EnumerationType.gif
new file mode 100644
index 000000000..4997a2499
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/icons/EnumerationType.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/labeling/RoomLabelProvider.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/labeling/RoomLabelProvider.java
index 3935ff7ee..5487ad9f5 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/labeling/RoomLabelProvider.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/labeling/RoomLabelProvider.java
@@ -23,6 +23,8 @@ import org.eclipse.etrice.core.room.Attribute;
import org.eclipse.etrice.core.room.Binding;
import org.eclipse.etrice.core.room.CompoundProtocolClass;
import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.EnumLiteral;
+import org.eclipse.etrice.core.room.EnumerationType;
import org.eclipse.etrice.core.room.ExternalPort;
import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.Import;
@@ -210,6 +212,15 @@ public class RoomLabelProvider extends DefaultEObjectLabelProvider {
String image(AnnotationAttribute aa) {
return "Attribute.gif";
}
+
+ String image(EnumerationType et) {
+ return "EnumerationType.gif";
+ }
+
+ String image(EnumLiteral lit) {
+ return "EnumLiteral.gif";
+ }
+
// custom labels
StyledString text(Import im) {
@@ -352,6 +363,17 @@ public class RoomLabelProvider extends DefaultEObjectLabelProvider {
String text (LogicalThread lt ) {
return lt.getName();
}
+
+ StyledString text(EnumerationType et) {
+ StyledString txt = new StyledString("enum "+et.getName());
+ txt.setStyle(0, 4, getKeywordStyler());
+ return txt;
+ }
+
+ String text (EnumLiteral lit) {
+ return lit.getName()+" = "+lit.getLiteralValue();
+ }
+
private Styler getKeywordStyler() {
if (keywordStyler==null) {
FontDescriptor font = JFaceResources.getFontDescriptor(JFaceResources.TEXT_FONT);
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 56c83f7b8..48f6c45f7 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
@@ -217,7 +217,7 @@ class CExtensions implements ILanguageExtension {
var singleValues = value.replace('{', '').replace('}', '').trim.split(',')
'''{ «FOR v: singleValues SEPARATOR ', '»«convertStringEnumLiteral(type, v.trim)»«ENDFOR» }'''.toString
} else
- value
+ convertStringEnumLiteral(type, value)
}
def private convertStringEnumLiteral(EnumerationType type, String value){
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
index ffa4a3a85..a85e217b6 100644
--- 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
@@ -78,14 +78,14 @@ class Initialization {
PrimitiveType: {
var value = getPrimitiveValue(instance, path)
if(a.size > 0 && !aType.characterType && !value.trim.startsWith('{'))
- '''{ «FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR» }'''
+ '''{«FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR»}'''
else
value
}
EnumerationType: {
- var value = languageExt.getDefaultValue(aType)
+ var value = getPrimitiveValue(instance, path)
if (a.size > 0 && !value.trim.startsWith('{'))
- '''{ «FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR» }'''
+ '''{«FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR»}'''
else
value
}
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
index c142f9771..46a173e2f 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
@@ -482,21 +482,21 @@ class NodeGen {
«ENDFOR»
};
«ENDIF»
- static «ai.actorClass.name» «instName» = {
+ static «ai.actorClass.name» «instName» = {
«IF haveConstData»
&«instName»_const,
«ENDIF»
- /* data send ports */
- «FOR pi : sendPorts»
- «pi.genSendPortInitializer»,
- «ENDFOR»
-
- /* attributes */
- «attrInitGenAddon.generateAttributeInit(ai, ai.actorClass.allAttributes)»
-
- /* state and history are initialized in init fuction */
- };
+ /* data send ports */
+ «FOR pi : sendPorts»
+ «pi.genSendPortInitializer»,
+ «ENDFOR»
+
+ /* attributes */
+ «attrInitGenAddon.generateAttributeInit(ai, ai.actorClass.allAttributes)»
+
+ /* state and history are initialized in init function */
+ };
'''}
def private String genPortInitializer(Root root, ActorInstance ai, InterfaceItemInstance pi) {
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 fe3102884..2b1b7c3dc 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
@@ -453,7 +453,8 @@ public class CExtensions implements ILanguageExtension {
}
_xifexpression = _xblockexpression;
} else {
- _xifexpression = value;
+ String _convertStringEnumLiteral = this.convertStringEnumLiteral(type, value);
+ _xifexpression = _convertStringEnumLiteral;
}
return _xifexpression;
}
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
index 374c0a037..c88278af4 100644
--- 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
@@ -238,7 +238,7 @@ public class Initialization {
}
if (_and) {
StringConcatenation _builder = new StringConcatenation();
- _builder.append("{ ");
+ _builder.append("{");
{
int _size_1 = a.getSize();
IntegerRange _upTo = new IntegerRange(1, _size_1);
@@ -252,7 +252,7 @@ public class Initialization {
_builder.append(value, "");
}
}
- _builder.append(" }");
+ _builder.append("}");
_xifexpression_1 = _builder;
} else {
_xifexpression_1 = value;
@@ -268,7 +268,7 @@ public class Initialization {
_matched=true;
CharSequence _xblockexpression_1 = null;
{
- String value = this.languageExt.getDefaultValue(_enumerationType);
+ String value = this.getPrimitiveValue(instance, path);
CharSequence _xifexpression_1 = null;
boolean _and = false;
int _size = a.getSize();
@@ -283,7 +283,7 @@ public class Initialization {
}
if (_and) {
StringConcatenation _builder = new StringConcatenation();
- _builder.append("{ ");
+ _builder.append("{");
{
int _size_1 = a.getSize();
IntegerRange _upTo = new IntegerRange(1, _size_1);
@@ -297,7 +297,7 @@ public class Initialization {
_builder.append(value, "");
}
}
- _builder.append(" }");
+ _builder.append("}");
_xifexpression_1 = _builder;
} else {
_xifexpression_1 = value;
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
index 3757f2f97..944b77ed9 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
@@ -1530,13 +1530,12 @@ public class NodeGen {
_builder.newLine();
}
}
- _builder.append("\t");
_builder.append("static ");
ActorClass _actorClass_1 = ai.getActorClass();
String _name_1 = _actorClass_1.getName();
- _builder.append(_name_1, " ");
+ _builder.append(_name_1, "");
_builder.append(" ");
- _builder.append(instName, " ");
+ _builder.append(instName, "");
_builder.append(" = {");
_builder.newLineIfNotEmpty();
{
@@ -1550,35 +1549,34 @@ public class NodeGen {
_builder.newLine();
}
}
- _builder.append("\t\t");
+ _builder.append("\t");
_builder.append("/* data send ports */");
_builder.newLine();
{
for(final InterfaceItemInstance pi_6 : sendPorts) {
- _builder.append("\t\t");
+ _builder.append("\t");
CharSequence _genSendPortInitializer = this.genSendPortInitializer(pi_6);
- _builder.append(_genSendPortInitializer, " ");
+ _builder.append(_genSendPortInitializer, " ");
_builder.append(",");
_builder.newLineIfNotEmpty();
}
}
- _builder.append("\t\t");
+ _builder.append("\t");
_builder.newLine();
- _builder.append("\t\t");
+ _builder.append("\t");
_builder.append("/* attributes */");
_builder.newLine();
- _builder.append("\t\t");
+ _builder.append("\t");
ActorClass _actorClass_2 = ai.getActorClass();
List<Attribute> _allAttributes = RoomHelpers.getAllAttributes(_actorClass_2);
CharSequence _generateAttributeInit = this.attrInitGenAddon.generateAttributeInit(ai, _allAttributes);
- _builder.append(_generateAttributeInit, " ");
+ _builder.append(_generateAttributeInit, " ");
_builder.newLineIfNotEmpty();
- _builder.append("\t\t");
- _builder.newLine();
- _builder.append("\t\t");
- _builder.append("/* state and history are initialized in init fuction */");
+ _builder.append("\t");
_builder.newLine();
_builder.append("\t");
+ _builder.append("/* state and history are initialized in init function */");
+ _builder.newLine();
_builder.append("};");
_builder.newLine();
_xblockexpression = (_builder);
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 f76d372f9..c5d40e2ce 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
@@ -162,9 +162,15 @@ class JavaExtensions implements ILanguageExtension {
override toEnumLiteral(EnumerationType type, String value){
if(value.contains(',') || value.contains('{')) {
var singleValues = value.replace('{', '').replace('}', '').trim.split(',')
- '''{ «FOR v: singleValues SEPARATOR ', '»«v.trim»«ENDFOR» }'''.toString
+ '''{ «FOR v: singleValues SEPARATOR ', '»«convertStringEnumLiteral(type, v.trim)»«ENDFOR» }'''.toString
} else
- value
+ convertStringEnumLiteral(type, value)
+ }
+
+ def private convertStringEnumLiteral(EnumerationType type, String value){
+ for(EnumLiteral l : type.literals)
+ if(l.name.equals(value))
+ return type.getName()+"."+l.getName()
}
def private castValue(PrimitiveType type, String value){
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 a020d1f83..efbeda60b 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
@@ -371,7 +371,8 @@ public class JavaExtensions implements ILanguageExtension {
_builder.appendImmediate(", ", "");
}
String _trim_1 = v.trim();
- _builder.append(_trim_1, "");
+ String _convertStringEnumLiteral = this.convertStringEnumLiteral(type, _trim_1);
+ _builder.append(_convertStringEnumLiteral, "");
}
}
_builder.append(" }");
@@ -380,11 +381,27 @@ public class JavaExtensions implements ILanguageExtension {
}
_xifexpression = _xblockexpression;
} else {
- _xifexpression = value;
+ String _convertStringEnumLiteral = this.convertStringEnumLiteral(type, value);
+ _xifexpression = _convertStringEnumLiteral;
}
return _xifexpression;
}
+ private String convertStringEnumLiteral(final EnumerationType type, final String value) {
+ EList<EnumLiteral> _literals = type.getLiterals();
+ for (final EnumLiteral l : _literals) {
+ String _name = l.getName();
+ boolean _equals = _name.equals(value);
+ if (_equals) {
+ String _name_1 = type.getName();
+ String _plus = (_name_1 + ".");
+ String _name_2 = l.getName();
+ return (_plus + _name_2);
+ }
+ }
+ return null;
+ }
+
private String castValue(final PrimitiveType type, final String value) {
String _switchResult = null;
String _targetName = type.getTargetName();
diff --git a/tests/org.eclipse.etrice.generator.common.tests/models/EnumTest.room b/tests/org.eclipse.etrice.generator.common.tests/models/EnumTest.room
index 0021a6913..6453f1dba 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/models/EnumTest.room
+++ b/tests/org.eclipse.etrice.generator.common.tests/models/EnumTest.room
@@ -23,14 +23,14 @@ RoomModel EnumTest {
Attribute caseId: int32
Attribute first: FirstEnum
- Attribute second: SecondEnum = "SecondEnum.two"
+ Attribute second: SecondEnum = "two"
Attribute third: ThirdEnum
Attribute fourth: FourthEnum
Attribute fifth: FifthEnum
Attribute arrayFirst[1] : FirstEnum
- Attribute arrayFourth[65] : FourthEnum = "FourthEnum.sixtyfive"
- Attribute arrayFifth[2] : FifthEnum = "{ FifthEnum.f1, FifthEnum.f2}"
+ Attribute arrayFourth[65] : FourthEnum = "sixtyfive"
+ Attribute arrayFifth[2] : FifthEnum = "{f1, f2}"
}
Behavior {

Back to the top