
io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions Maven / Gradle / Ivy
package io.joynr.generator.cpp.util;
import com.google.common.base.Objects;
import com.google.common.collect.UnmodifiableIterator;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.joynr.generator.cpp.util.CommonApiJoynrGeneratorExtensions;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FBasicTypeId;
import org.franca.core.franca.FCompoundType;
import org.franca.core.franca.FField;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FModelElement;
import org.franca.core.franca.FType;
import org.franca.core.franca.FTypeRef;
import org.franca.core.franca.FTypedElement;
@SuppressWarnings("all")
public class JoynrCppGeneratorExtensions extends CommonApiJoynrGeneratorExtensions {
@Inject
@Named("generationId")
private String dllExportName;
private Map primitiveDataTypeDefaultMap;
public String getPrimitiveTypeName(final FBasicTypeId basicType) {
String _xblockexpression = null;
{
boolean _equals = Objects.equal(basicType, FBasicTypeId.BYTE_BUFFER);
if (_equals) {
return "QByteArray";
}
String _primitiveTypeName = super.getPrimitiveTypeName(basicType);
_xblockexpression = (_primitiveTypeName);
}
return _xblockexpression;
}
public String getNamespaceStarter(final FInterface interfaceType) {
UnmodifiableIterator _packageNames = this.getPackageNames(interfaceType);
String _namespaceStarter = this.getNamespaceStarter(_packageNames);
return _namespaceStarter;
}
public String getNamespaceStarter(final FType datatype) {
UnmodifiableIterator _packageNames = this.getPackageNames(datatype);
String _namespaceStarter = this.getNamespaceStarter(_packageNames);
return _namespaceStarter;
}
public String getNamespaceEnder(final FInterface interfaceType) {
UnmodifiableIterator _packageNames = this.getPackageNames(interfaceType);
String _namespaceEnder = this.getNamespaceEnder(_packageNames);
return _namespaceEnder;
}
public String getNamespaceEnder(final FType datatype) {
UnmodifiableIterator _packageNames = this.getPackageNames(datatype);
String _namespaceEnder = this.getNamespaceEnder(_packageNames);
return _namespaceEnder;
}
private String getNamespaceStarter(final Iterator packageList) {
return this.getNamespaceStarterFromPackageList(packageList);
}
public String getNamespaceStarterFromPackageList(final Iterator packageList) {
StringBuilder _stringBuilder = new StringBuilder();
StringBuilder sb = _stringBuilder;
String _joynrGenerationPrefix = this.getJoynrGenerationPrefix();
String _plus = ("namespace " + _joynrGenerationPrefix);
String _plus_1 = (_plus + " { ");
sb.append(_plus_1);
boolean _hasNext = packageList.hasNext();
boolean _while = _hasNext;
while (_while) {
String _next = packageList.next();
String _plus_2 = ("namespace " + _next);
String _plus_3 = (_plus_2 + " { ");
sb.append(_plus_3);
boolean _hasNext_1 = packageList.hasNext();
_while = _hasNext_1;
}
return sb.toString();
}
private String getNamespaceEnder(final Iterator packageList) {
return this.getNameSpaceEnderFromPackageList(packageList);
}
public String getNameSpaceEnderFromPackageList(final Iterator packageList) {
StringBuilder _stringBuilder = new StringBuilder();
StringBuilder sb = _stringBuilder;
String _joynrGenerationPrefix = this.getJoynrGenerationPrefix();
String _plus = ("} /* namespace " + _joynrGenerationPrefix);
String _plus_1 = (_plus + " */ ");
sb.append(_plus_1);
boolean _hasNext = packageList.hasNext();
boolean _while = _hasNext;
while (_while) {
String _next = packageList.next();
String _plus_2 = ("} /* namespace " + _next);
String _plus_3 = (_plus_2 + " */ ");
sb.insert(0, _plus_3);
boolean _hasNext_1 = packageList.hasNext();
_while = _hasNext_1;
}
return sb.toString();
}
public JoynrCppGeneratorExtensions() {
HashMap _hashMap = new HashMap();
final Map bMap = _hashMap;
bMap.put(FBasicTypeId.BOOLEAN, "false");
bMap.put(FBasicTypeId.INT8, "-1");
bMap.put(FBasicTypeId.UINT8, "-1");
bMap.put(FBasicTypeId.INT16, "-1");
bMap.put(FBasicTypeId.UINT16, "-1");
bMap.put(FBasicTypeId.INT32, "-1");
bMap.put(FBasicTypeId.UINT32, "-1");
bMap.put(FBasicTypeId.INT64, "-1");
bMap.put(FBasicTypeId.UINT64, "-1");
bMap.put(FBasicTypeId.FLOAT, "-1");
bMap.put(FBasicTypeId.DOUBLE, "-1");
bMap.put(FBasicTypeId.STRING, "\"\"");
bMap.put(FBasicTypeId.BYTE_BUFFER, "\"\"");
bMap.put(FBasicTypeId.UNDEFINED, "");
Map _unmodifiableMap = Collections.unmodifiableMap(bMap);
this.primitiveDataTypeDefaultMap = _unmodifiableMap;
}
public String getCommaSeperatedTypedOutputParameterList(final FMethod method) {
StringBuilder _stringBuilder = new StringBuilder();
final StringBuilder returnStringBuilder = _stringBuilder;
Iterable _outputParameters = this.getOutputParameters(method);
for (final FArgument argument : _outputParameters) {
{
String _mappedDatatypeOrList = this.getMappedDatatypeOrList(argument);
returnStringBuilder.append(_mappedDatatypeOrList);
returnStringBuilder.append("& ");
String _joynrName = this.joynrName(argument);
returnStringBuilder.append(_joynrName);
returnStringBuilder.append(", ");
}
}
final String returnString = returnStringBuilder.toString();
int _length = returnString.length();
boolean _equals = (_length == 0);
if (_equals) {
return "";
} else {
int _length_1 = returnString.length();
int _minus = (_length_1 - 2);
return returnString.substring(0, _minus);
}
}
public String getCommaSeperatedUntypedOutputParameterList(final FMethod method) {
StringBuilder _stringBuilder = new StringBuilder();
final StringBuilder returnStringBuilder = _stringBuilder;
Iterable _outputParameters = this.getOutputParameters(method);
for (final FArgument argument : _outputParameters) {
{
String _joynrName = this.joynrName(argument);
returnStringBuilder.append(_joynrName);
returnStringBuilder.append(", ");
}
}
final String returnString = returnStringBuilder.toString();
int _length = returnString.length();
boolean _equals = (_length == 0);
if (_equals) {
return "";
} else {
int _length_1 = returnString.length();
int _minus = (_length_1 - 2);
return returnString.substring(0, _minus);
}
}
public String getCommaSeperatedTypedParameterList(final FMethod method) {
StringBuilder _stringBuilder = new StringBuilder();
final StringBuilder returnStringBuilder = _stringBuilder;
Iterable _inputParameters = this.getInputParameters(method);
for (final FArgument param : _inputParameters) {
{
String _mappedDatatypeOrList = this.getMappedDatatypeOrList(param);
returnStringBuilder.append(_mappedDatatypeOrList);
returnStringBuilder.append(" ");
String _joynrName = this.joynrName(param);
returnStringBuilder.append(_joynrName);
returnStringBuilder.append(", ");
}
}
final String returnString = returnStringBuilder.toString();
int _length = returnString.length();
boolean _equals = (_length == 0);
if (_equals) {
return "";
} else {
int _length_1 = returnString.length();
int _minus = (_length_1 - 2);
return returnString.substring(0, _minus);
}
}
public String buildPackagePath(final FType datatype, final String separator) {
boolean _equals = Objects.equal(datatype, null);
if (_equals) {
return "";
}
String packagepath = "";
try {
String _packagePathWithJoynrPrefix = this.getPackagePathWithJoynrPrefix(datatype, separator);
packagepath = _packagePathWithJoynrPrefix;
} catch (final Throwable _t) {
if (_t instanceof IllegalStateException) {
final IllegalStateException e = (IllegalStateException)_t;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
boolean _notEquals = (!Objects.equal(packagepath, ""));
if (_notEquals) {
String _plus = (packagepath + separator);
packagepath = _plus;
}
return packagepath;
}
public String getMappedDatatype(final FType datatype) {
final String packagepath = this.buildPackagePath(datatype, "::");
boolean _isEnum = this.isEnum(datatype);
if (_isEnum) {
String _joynrName = this.joynrName(datatype);
String _plus = (packagepath + _joynrName);
String _plus_1 = (_plus + "::");
String _nestedEnumName = this.getNestedEnumName();
return (_plus_1 + _nestedEnumName);
} else {
String _joynrName_1 = this.joynrName(datatype);
return (packagepath + _joynrName_1);
}
}
public String getMappedDatatypeOrList(final FType datatype, final boolean array) {
final String mappedDatatype = this.getMappedDatatype(datatype);
if (array) {
String _plus = ("QList<" + mappedDatatype);
return (_plus + "> ");
} else {
return mappedDatatype;
}
}
public String getMappedDatatypeOrList(final FBasicTypeId datatype, final boolean array) {
final String mappedDatatype = this.getPrimitiveTypeName(datatype);
if (array) {
String _plus = ("QList<" + mappedDatatype);
return (_plus + "> ");
} else {
return mappedDatatype;
}
}
public String getDefaultValue(final FTypedElement element) {
String _xifexpression = null;
boolean _equals = (1 == 0);
if (_equals) {
_xifexpression = null;
} else {
FTypeRef _type = element.getType();
boolean _isComplex = this.isComplex(_type);
if (_isComplex) {
return "";
} else {
boolean _isArray = this.isArray(element);
if (_isArray) {
return "";
} else {
FTypeRef _type_1 = element.getType();
boolean _isEnum = this.isEnum(_type_1);
if (_isEnum) {
return " /* should have enum default value here */";
} else {
FTypeRef _type_2 = element.getType();
FBasicTypeId _predefined = _type_2.getPredefined();
boolean _containsKey = this.primitiveDataTypeDefaultMap.containsKey(_predefined);
boolean _not = (!_containsKey);
if (_not) {
return "NaN";
} else {
FTypeRef _type_3 = element.getType();
FBasicTypeId _predefined_1 = _type_3.getPredefined();
return this.primitiveDataTypeDefaultMap.get(_predefined_1);
}
}
}
}
}
return _xifexpression;
}
public Iterable getRequiredIncludesFor(final FCompoundType datatype) {
final Iterable members = this.getComplexAndEnumMembers(datatype);
TreeSet _treeSet = new TreeSet();
final TreeSet typeList = _treeSet;
boolean _hasExtendsDeclaration = this.hasExtendsDeclaration(datatype);
if (_hasExtendsDeclaration) {
FCompoundType _extendedType = this.getExtendedType(datatype);
String _includeOf = this.getIncludeOf(_extendedType);
typeList.add(_includeOf);
}
for (final FField member : members) {
{
FTypeRef _type = member.getType();
final Object type = this.getDatatype(_type);
if ((type instanceof FType)) {
String _includeOf_1 = this.getIncludeOf(((FType) type));
typeList.add(_includeOf_1);
}
}
}
return typeList;
}
public Iterable getRequiredIncludesFor(final FInterface serviceInterface) {
TreeSet _treeSet = new TreeSet();
final TreeSet includeSet = _treeSet;
HashSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy