Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-11-25 15:26:10 +0000
committerHenrik Rentz-Reichert2013-11-25 15:26:10 +0000
commit3641f9620fd07822e07c05676c0f9e1e375a8b07 (patch)
treee0c3c4396eb5bd197887243ad5a639718875653f /plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c
parent53c33e15786cb41839455689d0086d7320099b5b (diff)
parentd9871bb6cfbd3b146f6c0da07136192291bedd24 (diff)
downloadorg.eclipse.etrice-3641f9620fd07822e07c05676c0f9e1e375a8b07.tar.gz
org.eclipse.etrice-3641f9620fd07822e07c05676c0f9e1e375a8b07.tar.xz
org.eclipse.etrice-3641f9620fd07822e07c05676c0f9e1e375a8b07.zip
Merge branch 'change/18572/5'
Conflicts: plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/Initialization.java plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend16
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/Initialization.xtend10
2 files changed, 20 insertions, 6 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 b03cefe5a..56c83f7b8 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
@@ -201,7 +201,7 @@ class CExtensions implements ILanguageExtension {
"'"+value+"'"
case type.type == LiteralType::CHAR:
"\""+value+"\""
- case value.contains(','): {
+ case value.contains(',') || value.contains('{'): {
var singleValues = value.replace('{', '').replace('}', '').trim.split(',')
'''{ «FOR v: singleValues SEPARATOR ', '»«toValueLiteral(type, v.trim)»«ENDFOR» }'''.toString
}
@@ -211,6 +211,20 @@ class CExtensions implements ILanguageExtension {
value
}
}
+
+ override toEnumLiteral(EnumerationType type, String value) {
+ if(value.contains(',') || value.contains('{')){
+ var singleValues = value.replace('{', '').replace('}', '').trim.split(',')
+ '''{ «FOR v: singleValues SEPARATOR ', '»«convertStringEnumLiteral(type, v.trim)»«ENDFOR» }'''.toString
+ } else
+ value
+ }
+
+ def private convertStringEnumLiteral(EnumerationType type, String value){
+ for(EnumLiteral l : type.literals)
+ if(l.name.equals(value))
+ return type.getName()+"_"+l.getName()
+ }
override String defaultValue(DataType dt) {
switch dt{
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 fa98da120..7424035e2 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
@@ -75,7 +75,7 @@ class Initialization {
a.defaultValueLiteral
else
languageExt.defaultValue(aType)
- PrimitiveType: {
+ case aType.enumerationOrPrimitive: {
var value = getPrimitiveValue(instance, path)
if(a.size > 0 && !aType.characterType && !value.trim.startsWith('{'))
'''{ «FOR Integer i:1..a.size SEPARATOR ', '»«value»«ENDFOR» }'''
@@ -102,9 +102,9 @@ class Initialization {
if(value == null)
value = path.last.defaultValueLiteral
- // TODO-Enum: was it guaranteed that path.last.type.type is a PrimitiveType?
- // now: treat EnumerationType separately
- return if(value != null) languageExt.toValueLiteral(path.last.type.type as PrimitiveType, value)
- else languageExt.defaultValue(path.last.type.type)
+ var type = path.last.type.type
+ return if(value != null && type.primitive) languageExt.toValueLiteral(type as PrimitiveType, value)
+ else if(value != null && type.enumeration) languageExt.toEnumLiteral(type as EnumerationType, value)
+ else languageExt.defaultValue(type)
}
}

Back to the top