Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-09-25 10:22:42 +0000
committerHenrik Rentz-Reichert2012-09-25 10:22:42 +0000
commita2af6f1d2a437fc44a0ff0f51322c52229eb29f4 (patch)
treeccd8d51cbc7f68caecfc721ea5be35c2ae83b0c6 /plugins
parent5e0fff52e9cc1423e4c668c938e9107f2ef405b7 (diff)
downloadorg.eclipse.etrice-a2af6f1d2a437fc44a0ff0f51322c52229eb29f4.tar.gz
org.eclipse.etrice-a2af6f1d2a437fc44a0ff0f51322c52229eb29f4.tar.xz
org.eclipse.etrice-a2af6f1d2a437fc44a0ff0f51322c52229eb29f4.zip
[generator, generator.c, generator.java] refactoring and unifications
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend46
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CLanguageGenerator.java50
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/setup/GeneratorModule.java3
-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.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend43
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java30
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java3
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java59
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend11
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java15
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainGenerator.java (renamed from plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/AbstractTransitionChainGenerator.java)18
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java8
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TypeHelpers.xtend15
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java8
-rw-r--r--plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/TypeHelpers.java26
15 files changed, 286 insertions, 151 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 4f52a60ed..4fc54b1f4 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
@@ -24,22 +24,21 @@ import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.core.room.PrimitiveType
import org.eclipse.etrice.core.room.RoomClass
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
+import org.eclipse.etrice.core.room.VarDecl
@Singleton
class CExtensions implements ILanguageExtension {
- @Inject AbstractTransitionChainGenerator chainGenerator
@Inject IDiagnostician diagnostician
override String getTypedDataDefinition(Message m) {
- return chainGenerator.generateTypedData(m.data)
+ generateArglistAndTypedData(m.data).get(1)
}
// in C no access levels can be defined
@@ -198,4 +197,45 @@ class CExtensions implements ILanguageExtension {
dv
}
+ override generateArglistAndTypedData(VarDecl data) {
+ if (data==null)
+ return newArrayList("", "", "")
+
+ var typeName = data.getRefType().getType().getName()
+ var castTypeName = typeName+"*"
+ var typedData = ""
+ var ref = ""
+ if (data.getRefType().getType() instanceof PrimitiveType) {
+ typeName = (data.getRefType().getType() as PrimitiveType).getTargetName()
+ castTypeName = typeName+"*"
+ var ct = (data.getRefType().getType() as PrimitiveType).getCastName()
+ if (ct!=null && !ct.isEmpty()){
+ castTypeName = ct
+ }
+ if (data.getRefType().isRef()) {
+ ref = "*"
+ typedData = typeName+" "+data.getName() + " = **(("+castTypeName+"*) generic_data);\n"
+ }
+ else {
+ typedData = typeName+" "+data.getName() + " = *(("+castTypeName+") generic_data);\n"
+ }
+ }
+ else {
+ if (data.getRefType().isRef()) {
+ ref = "*"
+ typeName = typeName+"*"
+ typedData = typeName+" "+data.getName() + " = *(("+castTypeName+"*) generic_data);\n"
+ }
+ else{
+ typeName = typeName+"*"
+ typedData = typeName+" "+data.getName() + " = (("+castTypeName+") generic_data);\n"
+ }
+ }
+
+ val dataArg = ", "+data.getName()
+ val typedArgList = ", "+typeName+" "+ref+data.getName()
+
+ return newArrayList(dataArg, typedData, typedArgList);
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CLanguageGenerator.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CLanguageGenerator.java
deleted file mode 100644
index 207913a16..000000000
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CLanguageGenerator.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.eclipse.etrice.generator.c.gen;
-
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
-
-public class CLanguageGenerator extends AbstractTransitionChainGenerator {
-
- public String[] generateArglistAndTypedData(VarDecl data) {
- if (data==null)
- return new String[] {"", "", ""};
-
- String typeName = data.getRefType().getType().getName();
- String castTypeName = typeName+"*";
- String typedData;
- String ref = "";
- if (data.getRefType().getType() instanceof PrimitiveType) {
- typeName = ((PrimitiveType)data.getRefType().getType()).getTargetName();
- castTypeName = typeName+"*";
- String ct = ((PrimitiveType)data.getRefType().getType()).getCastName();
- if (ct!=null && !ct.isEmpty()){
- castTypeName = ct;
- }
- if (data.getRefType().isRef()) {
- ref = "*";
- typedData = typeName+" "+data.getName() + " = **(("+castTypeName+"*) generic_data);\n";
- }
- else {
- typedData = typeName+" "+data.getName() + " = *(("+castTypeName+") generic_data);\n";
- }
- }
- else {
- if (data.getRefType().isRef()) {
- ref = "*";
- typeName = typeName+"*";
- typedData = typeName+" "+data.getName() + " = *(("+castTypeName+"*) generic_data);\n";
- }
- else{
- typeName = typeName+"*";
- typedData = typeName+" "+data.getName() + " = (("+castTypeName+") generic_data);\n";
- }
- }
-
- String dataArg = ", "+data.getName();
- String typedArgList = ", "+typeName+" "+ref+data.getName();
-
- return new String[]{dataArg, typedData, typedArgList};
- }
-
-}
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 f02d109ef..ef3849a1b 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
@@ -16,11 +16,9 @@ import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.GeneratorBaseModule;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.c.Main;
-import org.eclipse.etrice.generator.c.gen.CLanguageGenerator;
import org.eclipse.etrice.generator.c.gen.CTranslationProvider;
import org.eclipse.etrice.generator.c.gen.MainGen;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.etrice.generator.c.gen.CExtensions;
@@ -37,7 +35,6 @@ public class GeneratorModule extends GeneratorBaseModule {
// bind language specific code to generic Interfaces
binder.bind(ILanguageExtension.class).to(CExtensions.class);
- binder.bind(AbstractTransitionChainGenerator.class).to(CLanguageGenerator.class);
binder.bind(ITranslationProvider.class).to(CTranslationProvider.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 3dc649011..3a284606b 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
@@ -1,5 +1,6 @@
package org.eclipse.etrice.generator.c.gen;
+import com.google.common.base.Objects;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
@@ -16,23 +17,23 @@ 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;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
@Singleton
@SuppressWarnings("all")
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);
+ String[] _generateArglistAndTypedData = this.generateArglistAndTypedData(_data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(1);
+ return _get;
}
public String accessLevelPrivate() {
@@ -345,4 +346,95 @@ public class CExtensions implements ILanguageExtension {
}
return _xblockexpression;
}
+
+ public String[] generateArglistAndTypedData(final VarDecl data) {
+ boolean _equals = Objects.equal(data, null);
+ if (_equals) {
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
+ }
+ RefableType _refType = data.getRefType();
+ DataType _type = _refType.getType();
+ String typeName = _type.getName();
+ String castTypeName = (typeName + "*");
+ String typedData = "";
+ String ref = "";
+ RefableType _refType_1 = data.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ if ((_type_1 instanceof PrimitiveType)) {
+ RefableType _refType_2 = data.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _targetName = ((PrimitiveType) _type_2).getTargetName();
+ typeName = _targetName;
+ String _plus = (typeName + "*");
+ castTypeName = _plus;
+ RefableType _refType_3 = data.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ String ct = ((PrimitiveType) _type_3).getCastName();
+ boolean _and = false;
+ boolean _notEquals = (!Objects.equal(ct, null));
+ if (!_notEquals) {
+ _and = false;
+ } else {
+ boolean _isEmpty = ct.isEmpty();
+ boolean _not = (!_isEmpty);
+ _and = (_notEquals && _not);
+ }
+ if (_and) {
+ castTypeName = ct;
+ }
+ RefableType _refType_4 = data.getRefType();
+ boolean _isRef = _refType_4.isRef();
+ if (_isRef) {
+ ref = "*";
+ String _plus_1 = (typeName + " ");
+ String _name = data.getName();
+ String _plus_2 = (_plus_1 + _name);
+ String _plus_3 = (_plus_2 + " = **((");
+ String _plus_4 = (_plus_3 + castTypeName);
+ String _plus_5 = (_plus_4 + "*) generic_data);\n");
+ typedData = _plus_5;
+ } else {
+ String _plus_6 = (typeName + " ");
+ String _name_1 = data.getName();
+ String _plus_7 = (_plus_6 + _name_1);
+ String _plus_8 = (_plus_7 + " = *((");
+ String _plus_9 = (_plus_8 + castTypeName);
+ String _plus_10 = (_plus_9 + ") generic_data);\n");
+ typedData = _plus_10;
+ }
+ } else {
+ RefableType _refType_5 = data.getRefType();
+ boolean _isRef_1 = _refType_5.isRef();
+ if (_isRef_1) {
+ ref = "*";
+ String _plus_11 = (typeName + "*");
+ typeName = _plus_11;
+ String _plus_12 = (typeName + " ");
+ String _name_2 = data.getName();
+ String _plus_13 = (_plus_12 + _name_2);
+ String _plus_14 = (_plus_13 + " = *((");
+ String _plus_15 = (_plus_14 + castTypeName);
+ String _plus_16 = (_plus_15 + "*) generic_data);\n");
+ typedData = _plus_16;
+ } else {
+ String _plus_17 = (typeName + "*");
+ typeName = _plus_17;
+ String _plus_18 = (typeName + " ");
+ String _name_3 = data.getName();
+ String _plus_19 = (_plus_18 + _name_3);
+ String _plus_20 = (_plus_19 + " = ((");
+ String _plus_21 = (_plus_20 + castTypeName);
+ String _plus_22 = (_plus_21 + ") generic_data);\n");
+ typedData = _plus_22;
+ }
+ }
+ String _name_4 = data.getName();
+ final String dataArg = (", " + _name_4);
+ String _plus_23 = (", " + typeName);
+ String _plus_24 = (_plus_23 + " ");
+ String _plus_25 = (_plus_24 + ref);
+ String _name_5 = data.getName();
+ final String typedArgList = (_plus_25 + _name_5);
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class));
+ }
}
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 4a1d3550f..e461a45fd 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
@@ -15,31 +15,26 @@
*/
-package org.eclipse.etrice.generator.java.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.RoomClass
+package org.eclipse.etrice.generator.java.gen
+
+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
+import org.eclipse.etrice.core.room.VarDecl
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 {
- @Inject AbstractTransitionChainGenerator chainGenerator
-
-
override String getTypedDataDefinition(Message m) {
- return chainGenerator.generateTypedData(m.data)
+ generateArglistAndTypedData(m.data).get(1)
}
-
def String getJavaFileName(RoomClass rc) {rc.name+".java"}
def String toWrapper(String type){
@@ -167,5 +162,25 @@ class JavaExtensions implements ILanguageExtension {
else
dv
}
+
+ override generateArglistAndTypedData(VarDecl data) {
+ if (data==null)
+ return newArrayList("", "", "")
+
+ var typeName = data.getRefType().getType().getName();
+ var castTypeName = typeName;
+ if (data.getRefType().getType() instanceof PrimitiveType) {
+ typeName = (data.getRefType().getType() as PrimitiveType).getTargetName();
+ val ct = (data.getRefType().getType() as PrimitiveType).getCastName();
+ if (ct!=null && !ct.isEmpty())
+ castTypeName = ct;
+ }
+
+ val typedData = typeName+" "+data.getName() + " = ("+castTypeName+") generic_data;\n";
+ val dataArg = ", "+data.getName();
+ val typedArgList = ", "+typeName+" "+data.getName();
+
+ return newArrayList(dataArg, typedData, typedArgList);
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java
deleted file mode 100644
index 670788c6e..000000000
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaLanguageGenerator.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.eclipse.etrice.generator.java.gen;
-
-import org.eclipse.etrice.core.room.PrimitiveType;
-import org.eclipse.etrice.core.room.VarDecl;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
-
-public class JavaLanguageGenerator extends AbstractTransitionChainGenerator {
-
- @Override
- public String[] generateArglistAndTypedData(VarDecl data) {
- if (data==null)
- return new String[] {"", "", ""};
-
- String typeName = data.getRefType().getType().getName();
- String castTypeName = typeName;
- if (data.getRefType().getType() instanceof PrimitiveType) {
- typeName = ((PrimitiveType)data.getRefType().getType()).getTargetName();
- String ct = ((PrimitiveType)data.getRefType().getType()).getCastName();
- if (ct!=null && !ct.isEmpty())
- castTypeName = ct;
- }
-
- String typedData = typeName+" "+data.getName() + " = ("+castTypeName+") generic_data;\n";
- String dataArg = ", "+data.getName();
- String typedArgList = ", "+typeName+" "+data.getName();
-
- return new String[]{dataArg, typedData, typedArgList};
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
index 4242475ba..e1e35d80c 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/setup/GeneratorModule.java
@@ -17,11 +17,9 @@ import org.eclipse.etrice.generator.base.GeneratorBaseModule;
import org.eclipse.etrice.generator.base.ITranslationProvider;
import org.eclipse.etrice.generator.java.Main;
import org.eclipse.etrice.generator.java.gen.MainGen;
-import org.eclipse.etrice.generator.java.gen.JavaLanguageGenerator;
import org.eclipse.etrice.generator.java.gen.JavaTranslationProvider;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
import org.eclipse.etrice.generator.java.gen.JavaExtensions;
@@ -39,7 +37,6 @@ public class GeneratorModule extends GeneratorBaseModule {
// bind language specific code to generic Interfaces
binder.bind(ILanguageExtension.class).to(JavaExtensions.class);
- binder.bind(AbstractTransitionChainGenerator.class).to(JavaLanguageGenerator.class);
binder.bind(ITranslationProvider.class).to(JavaTranslationProvider.class);
}
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 e3c821388..5ee96b333 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
@@ -1,30 +1,30 @@
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.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;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
@Singleton
@SuppressWarnings("all")
public class JavaExtensions implements ILanguageExtension {
- @Inject
- private AbstractTransitionChainGenerator chainGenerator;
-
public String getTypedDataDefinition(final Message m) {
VarDecl _data = m.getData();
- return this.chainGenerator.generateTypedData(_data);
+ String[] _generateArglistAndTypedData = this.generateArglistAndTypedData(_data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(1);
+ return _get;
}
public String getJavaFileName(final RoomClass rc) {
@@ -295,4 +295,51 @@ public class JavaExtensions implements ILanguageExtension {
}
return _xblockexpression;
}
+
+ public String[] generateArglistAndTypedData(final VarDecl data) {
+ boolean _equals = Objects.equal(data, null);
+ if (_equals) {
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
+ }
+ RefableType _refType = data.getRefType();
+ DataType _type = _refType.getType();
+ String typeName = _type.getName();
+ String castTypeName = typeName;
+ RefableType _refType_1 = data.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ if ((_type_1 instanceof PrimitiveType)) {
+ RefableType _refType_2 = data.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ String _targetName = ((PrimitiveType) _type_2).getTargetName();
+ typeName = _targetName;
+ RefableType _refType_3 = data.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ final String ct = ((PrimitiveType) _type_3).getCastName();
+ boolean _and = false;
+ boolean _notEquals = (!Objects.equal(ct, null));
+ if (!_notEquals) {
+ _and = false;
+ } else {
+ boolean _isEmpty = ct.isEmpty();
+ boolean _not = (!_isEmpty);
+ _and = (_notEquals && _not);
+ }
+ if (_and) {
+ castTypeName = ct;
+ }
+ }
+ String _plus = (typeName + " ");
+ String _name = data.getName();
+ String _plus_1 = (_plus + _name);
+ String _plus_2 = (_plus_1 + " = (");
+ String _plus_3 = (_plus_2 + castTypeName);
+ final String typedData = (_plus_3 + ") generic_data;\n");
+ String _name_1 = data.getName();
+ final String dataArg = (", " + _name_1);
+ String _plus_4 = (", " + typeName);
+ String _plus_5 = (_plus_4 + " ");
+ String _name_2 = data.getName();
+ final String typedArgList = (_plus_5 + _name_2);
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(dataArg, typedData, typedArgList), String.class));
+ }
}
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 247add64a..3a69c5856 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
@@ -25,17 +25,20 @@ import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedRefinedState
import org.eclipse.etrice.core.genmodel.etricegen.ActiveTrigger
import org.eclipse.etrice.generator.generic.RoomExtensions
-import static extension org.eclipse.etrice.generator.base.CodegenHelpers.*
import org.eclipse.etrice.generator.base.AbstractGenerator
import org.eclipse.xtext.util.Pair
+import org.eclipse.etrice.generator.generic.TransitionChainGenerator
+
import static org.eclipse.xtext.util.Tuples.*
+import static extension org.eclipse.etrice.generator.base.CodegenHelpers.*
+
class GenericStateMachineGenerator {
@Inject protected ILanguageExtension langExt
@Inject protected extension RoomExtensions
@Inject protected GenericProtocolClassGenerator pcGen
- @Inject protected org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator languageGen
+ @Inject protected TransitionChainGenerator transitionChainGenerator
def private genStateIdConstants(ExpandedActorClass xpac) {
val ac = xpac.actorClass
@@ -119,7 +122,7 @@ class GenericStateMachineGenerator {
«IF (!langExt.usesInheritance || xpac.isOwnObject(tr)) && tr.hasActionCode()»
«var start = xpac.getChain(tr).transition»
«var hasArgs = start instanceof NonInitialTransition && !(start instanceof GuardedTransition)»
- «langExt.accessLevelProtected»void «tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, hasArgs)»«IF hasArgs»InterfaceItemBase ifitem«languageGen.generateArgumentList(xpac, tr)»«ENDIF») {
+ «langExt.accessLevelProtected»void «tr.getActionCodeOperationName()»(«langExt.selfPointer(ac.name, hasArgs)»«IF hasArgs»InterfaceItemBase ifitem«transitionChainGenerator.generateArgumentList(xpac, tr)»«ENDIF») {
«AbstractGenerator::getInstance().getTranslatedCode(tr.action)»
}
«ENDIF»
@@ -159,7 +162,7 @@ class GenericStateMachineGenerator {
«FOR tc : allchains»
case «tc.getChainId()»:
{
- «languageGen.generateExecuteChain(xpac, tc)»
+ «transitionChainGenerator.generateExecuteChain(xpac, tc)»
}
«ENDFOR»
}
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 ebd45b117..8ed211edc 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
@@ -4,6 +4,8 @@ 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 org.eclipse.etrice.core.room.VarDecl;
+
import java.util.List;
import org.eclipse.xtext.util.Pair;
@@ -192,6 +194,19 @@ public interface ILanguageExtension {
String toValueLiteral(PrimitiveType type, String value);
/**
+ * return three strings used by the generator
+ *
+ * @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 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>
+ */
+ String[] generateArglistAndTypedData(VarDecl data);
+
+ /**
* returns a default value for a type
* @param dt the data type
* @return the default value string
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/AbstractTransitionChainGenerator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainGenerator.java
index 293b2a711..5439ebe48 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/AbstractTransitionChainGenerator.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainGenerator.java
@@ -20,15 +20,19 @@ import org.eclipse.etrice.core.room.TriggeredTransition;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.base.AbstractGenerator;
+import com.google.inject.Inject;
+
/**
* base class for
* @author Henrik Rentz-Reichert
*
*/
-public abstract class AbstractTransitionChainGenerator implements ITypedDataProvider {
+public class TransitionChainGenerator {
+
+ @Inject ILanguageExtension languageExt;
public String generateExecuteChain(ExpandedActorClass ac, TransitionChain tc) {
- TransitionChainVisitor tcv = new TransitionChainVisitor(ac, this);
+ TransitionChainVisitor tcv = new TransitionChainVisitor(ac);
AbstractGenerator.getInjector().injectMembers(tcv);
tcv.init(tc);
@@ -47,15 +51,7 @@ public abstract class AbstractTransitionChainGenerator implements ITypedDataProv
return generateTypedArgumentList(xpac.getData(t));
}
- public String generateArgumentList(VarDecl data) {
- return generateArglistAndTypedData(data)[0];
- }
-
- public String generateTypedData(VarDecl data) {
- return generateArglistAndTypedData(data)[1];
- }
-
public String generateTypedArgumentList(VarDecl data) {
- return generateArglistAndTypedData(data)[2];
+ return languageExt.generateArglistAndTypedData(data)[2];
}
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
index c090e2952..43c9f81fe 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/TransitionChainVisitor.java
@@ -37,12 +37,10 @@ public class TransitionChainVisitor implements ITransitionChainVisitor {
@Inject private ILanguageExtension langExt;
private ExpandedActorClass xpac;
- private ITypedDataProvider dataProvider;
private boolean dataDriven;
- protected TransitionChainVisitor(ExpandedActorClass xpac, ITypedDataProvider dataProvider) {
+ protected TransitionChainVisitor(ExpandedActorClass xpac) {
this.xpac = xpac;
- this.dataProvider = dataProvider;
}
protected void init(TransitionChain tc) {
@@ -66,7 +64,7 @@ public class TransitionChainVisitor implements ITransitionChainVisitor {
else if (dataDriven)
return CodegenHelpers.getActionCodeOperationName(tr)+"("+langExt.selfPointer(false)+");\n";
else {
- String[] result = dataProvider.generateArglistAndTypedData(xpac.getData(tr));
+ String[] result = langExt.generateArglistAndTypedData(xpac.getData(tr));
String dataArg = result[0];
return CodegenHelpers.getActionCodeOperationName(tr)+"("+langExt.selfPointer(true)+"ifitem"+dataArg+");\n";
@@ -108,7 +106,7 @@ public class TransitionChainVisitor implements ITransitionChainVisitor {
}
public String genTypedData(TransitionChain tc) {
- String[] result = dataProvider.generateArglistAndTypedData(tc.getData());
+ String[] result = langExt.generateArglistAndTypedData(tc.getData());
return result[1];
}
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 e5a9e3251..50cf3071f 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
@@ -25,14 +25,11 @@ 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.VarDecl
-import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator
@Singleton
class TypeHelpers {
- @Inject AbstractTransitionChainGenerator chainGenerator
@Inject ILanguageExtension languageExt
def String typeName(DataType type) {
@@ -48,8 +45,16 @@ class TypeHelpers {
return languageExt.defaultValue(a.refType.type)
}
- def String getTypedDataDefinition(Message m) {
- return chainGenerator.generateTypedData(m.data)
+ def String getArgumentList(VarDecl data) {
+ languageExt.generateArglistAndTypedData(data).get(0)
+ }
+
+ def String getTypedDataDefinition(VarDecl data) {
+ languageExt.generateArglistAndTypedData(data).get(1);
+ }
+
+ def String generateTypedArgumentList(VarDecl data) {
+ languageExt.generateArglistAndTypedData(data).get(2);
}
def isPrimitive(DataType type){
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 d055668ac..cdef50228 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
@@ -27,10 +27,10 @@ import org.eclipse.etrice.core.room.Trigger;
import org.eclipse.etrice.core.room.TriggeredTransition;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.CodegenHelpers;
-import org.eclipse.etrice.generator.generic.AbstractTransitionChainGenerator;
import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator;
import org.eclipse.etrice.generator.generic.ILanguageExtension;
import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TransitionChainGenerator;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
@@ -49,7 +49,7 @@ public class GenericStateMachineGenerator {
protected GenericProtocolClassGenerator pcGen;
@Inject
- protected AbstractTransitionChainGenerator languageGen;
+ protected TransitionChainGenerator transitionChainGenerator;
private String genStateIdConstants(final ExpandedActorClass xpac) {
final ActorClass ac = xpac.getActorClass();
@@ -278,7 +278,7 @@ public class GenericStateMachineGenerator {
{
if (hasArgs) {
_builder.append("InterfaceItemBase ifitem");
- String _generateArgumentList = this.languageGen.generateArgumentList(xpac, tr);
+ String _generateArgumentList = this.transitionChainGenerator.generateArgumentList(xpac, tr);
_builder.append(_generateArgumentList, "");
}
}
@@ -446,7 +446,7 @@ public class GenericStateMachineGenerator {
_builder.newLine();
_builder.append("\t\t");
_builder.append("\t");
- String _generateExecuteChain = this.languageGen.generateExecuteChain(xpac, tc);
+ String _generateExecuteChain = this.transitionChainGenerator.generateExecuteChain(xpac, tc);
_builder.append(_generateExecuteChain, " ");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
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 29fea1c0b..419fc7e48 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
@@ -3,24 +3,21 @@ package org.eclipse.etrice.generator.generic;
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.DataClass;
import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.ExternalType;
import org.eclipse.etrice.core.room.LiteralType;
-import org.eclipse.etrice.core.room.Message;
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;
+import org.eclipse.xtext.xbase.lib.Conversions;
@Singleton
@SuppressWarnings("all")
public class TypeHelpers {
@Inject
- private AbstractTransitionChainGenerator chainGenerator;
-
- @Inject
private ILanguageExtension languageExt;
public String typeName(final DataType type) {
@@ -41,9 +38,22 @@ public class TypeHelpers {
return this.languageExt.defaultValue(_type);
}
- public String getTypedDataDefinition(final Message m) {
- VarDecl _data = m.getData();
- return this.chainGenerator.generateTypedData(_data);
+ public String getArgumentList(final VarDecl data) {
+ String[] _generateArglistAndTypedData = this.languageExt.generateArglistAndTypedData(data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(0);
+ return _get;
+ }
+
+ public String getTypedDataDefinition(final VarDecl data) {
+ String[] _generateArglistAndTypedData = this.languageExt.generateArglistAndTypedData(data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(1);
+ return _get;
+ }
+
+ public String generateTypedArgumentList(final VarDecl data) {
+ String[] _generateArglistAndTypedData = this.languageExt.generateArglistAndTypedData(data);
+ String _get = ((List<String>)Conversions.doWrapArray(_generateArglistAndTypedData)).get(2);
+ return _get;
}
public boolean isPrimitive(final DataType type) {

Back to the top