diff options
author | Philip Rauwolf <rauwolf@itestra.de> | 2013-02-19 15:16:21 +0100 |
---|---|---|
committer | Philip Rauwolf <rauwolf@itestra.de> | 2013-02-19 15:16:45 +0100 |
commit | 0e58661c9f80848bedf7f7156710a2e1fdbe1923 (patch) | |
tree | e5ffe76a20dbcc9a3dc5ecea77542e2e522a68a3 | |
parent | 5fbd42dc7e6eae42ac93af5dc7d1e129a5514dbe (diff) | |
download | genivi-common-api-runtime-0e58661c9f80848bedf7f7156710a2e1fdbe1923.tar.gz |
First working version for CommonAPI deployment
11 files changed, 307 insertions, 140 deletions
diff --git a/org.genivi.commonapi.core/.classpath b/org.genivi.commonapi.core/.classpath index c39b4cb..406ca4a 100644 --- a/org.genivi.commonapi.core/.classpath +++ b/org.genivi.commonapi.core/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="src-gen"/> <classpathentry kind="src" path="xtend-gen"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> diff --git a/org.genivi.commonapi.core/META-INF/MANIFEST.MF b/org.genivi.commonapi.core/META-INF/MANIFEST.MF index feb3072..4f80f52 100644 --- a/org.genivi.commonapi.core/META-INF/MANIFEST.MF +++ b/org.genivi.commonapi.core/META-INF/MANIFEST.MF @@ -14,4 +14,5 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="3.8.0", org.franca.deploymodel.dsl;bundle-version="0.8.0" Import-Package: javax.inject;version="1.0.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.genivi.commonapi.core.generator +Export-Package: org.genivi.commonapi.core.deployment, + org.genivi.commonapi.core.generator diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java new file mode 100644 index 0000000..cc68ee1 --- /dev/null +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/DeploymentInterfacePropertyAccessorWrapper.java @@ -0,0 +1,28 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +package org.genivi.commonapi.core.deployment; + +import org.franca.core.franca.FInterface; +import org.franca.deploymodel.core.FDeployedInterface; +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor; + +public class DeploymentInterfacePropertyAccessorWrapper extends DeploymentInterfacePropertyAccessor { + + boolean encapsulate; + + public DeploymentInterfacePropertyAccessorWrapper(FDeployedInterface target) { + super(target); + encapsulate = (target == null); + } + + public DeploymentInterfacePropertyAccessor.EnumBackingType getEnumBackingType(FInterface obj) { + if(encapsulate) { + return DeploymentInterfacePropertyAccessor.EnumBackingType.Int32; + } + return super.getEnumBackingType(obj); + } +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/deployment.fdepl b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/deployment.fdepl index 6332906..7167f2f 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/deployment.fdepl +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/deployment.fdepl @@ -1,6 +1,6 @@ -specification org.genivi.commonapi.dbus.deployment +specification org.genivi.commonapi.core.deployment.deployment { for interfaces { EnumBackingType: {UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64} (default: UInt32); diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend index b79032e..396f738 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceGenerator.xtend @@ -9,20 +9,21 @@ package org.genivi.commonapi.core.generator import javax.inject.Inject import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FInterface +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor class FInterfaceGenerator { @Inject private extension FTypeGenerator @Inject private extension FTypeCommonAreaGenerator @Inject private extension FrancaGeneratorExtensions - def generate(FInterface fInterface, IFileSystemAccess fileSystemAccess) { - fileSystemAccess.generateFile(fInterface.headerPath, fInterface.generateHeader) + def generate(FInterface fInterface, IFileSystemAccess fileSystemAccess, DeploymentInterfacePropertyAccessor deploymentAccessor) { + fileSystemAccess.generateFile(fInterface.headerPath, fInterface.generateHeader(deploymentAccessor)) if (fInterface.hasSourceFile) fileSystemAccess.generateFile(fInterface.sourcePath, fInterface.generateSource) } - def private generateHeader(FInterface fInterface) ''' + def private generateHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «generateCommonApiLicenseHeader» #ifndef «fInterface.defineName»_H_ #define «fInterface.defineName»_H_ @@ -39,7 +40,7 @@ class FInterfaceGenerator { static inline const char* getInterfaceId(); static inline CommonAPI::Version getInterfaceVersion(); - «fInterface.generateFTypeDeclarations» + «fInterface.generateFTypeDeclarations(deploymentAccessor)» }; const char* «fInterface.name»::getInterfaceId() { @@ -51,20 +52,20 @@ class FInterfaceGenerator { } «FOR type : fInterface.types» - «type.generateFTypeInlineImplementation(fInterface)» + «type.generateFTypeInlineImplementation(fInterface, deploymentAccessor)» «ENDFOR» «fInterface.model.generateNamespaceEndDeclaration» namespace CommonAPI { - «fInterface.generateTypeWriters» + «fInterface.generateTypeWriters(deploymentAccessor)» «fInterface.generateVariantComparators» } - - + + namespace std { - «fInterface.generateHashers» + «fInterface.generateHashers(deploymentAccessor)» } #endif // «fInterface.defineName»_H_ diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend index db9d293..c218864 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FInterfaceProxyGenerator.xtend @@ -15,17 +15,18 @@ import org.franca.core.franca.FInterface import org.franca.core.franca.FMethod import static com.google.common.base.Preconditions.* +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor class FInterfaceProxyGenerator { @Inject private extension FTypeGenerator @Inject private extension FrancaGeneratorExtensions - def generateProxy(FInterface fInterface, IFileSystemAccess fileSystemAccess) { - fileSystemAccess.generateFile(fInterface.proxyBaseHeaderPath, fInterface.generateProxyBaseHeader) + def generateProxy(FInterface fInterface, IFileSystemAccess fileSystemAccess, DeploymentInterfacePropertyAccessor deploymentAccessor) { + fileSystemAccess.generateFile(fInterface.proxyBaseHeaderPath, fInterface.generateProxyBaseHeader(deploymentAccessor)) fileSystemAccess.generateFile(fInterface.proxyHeaderPath, fInterface.generateProxyHeader) } - def private generateProxyBaseHeader(FInterface fInterface) ''' + def private generateProxyBaseHeader(FInterface fInterface, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «generateCommonApiLicenseHeader» #ifndef «fInterface.defineName»_PROXY_BASE_H_ #define «fInterface.defineName»_PROXY_BASE_H_ @@ -49,7 +50,7 @@ class FInterfaceProxyGenerator { class «fInterface.proxyBaseClassName»: virtual public CommonAPI::Proxy { public: «FOR method : fInterface.methods.filter[errors != null]» - «method.errors.generateDeclaration(method.errors.errorName)» + «method.errors.generateDeclaration(method.errors.errorName, deploymentAccessor)» «ENDFOR» «FOR attribute : fInterface.attributes» @@ -87,7 +88,7 @@ class FInterfaceProxyGenerator { }; «FOR method : fInterface.methods.filter[errors != null]» - «method.errors.generateInlineImplementation(method.errors.errorName, fInterface, fInterface.proxyBaseClassName)» + «method.errors.generateInlineImplementation(method.errors.errorName, fInterface, fInterface.proxyBaseClassName, deploymentAccessor)» «ENDFOR» «fInterface.model.generateNamespaceEndDeclaration» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend index 7e09879..741ac25 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCollectionGenerator.xtend @@ -9,21 +9,21 @@ package org.genivi.commonapi.core.generator import javax.inject.Inject import org.eclipse.xtext.generator.IFileSystemAccess import org.franca.core.franca.FTypeCollection - - +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor + class FTypeCollectionGenerator { @Inject private extension FTypeGenerator @Inject private extension FTypeCommonAreaGenerator @Inject private extension FrancaGeneratorExtensions - def generate(FTypeCollection fTypeCollection, IFileSystemAccess fileSystemAccess) { - fileSystemAccess.generateFile(fTypeCollection.headerPath, fTypeCollection.generateHeader) + def generate(FTypeCollection fTypeCollection, IFileSystemAccess fileSystemAccess, DeploymentInterfacePropertyAccessor deploymentAccessor) { + fileSystemAccess.generateFile(fTypeCollection.headerPath, fTypeCollection.generateHeader(deploymentAccessor)) if (fTypeCollection.hasSourceFile) fileSystemAccess.generateFile(fTypeCollection.sourcePath, fTypeCollection.generateSource) } - def private generateHeader(FTypeCollection fTypeCollection) ''' + def private generateHeader(FTypeCollection fTypeCollection, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «generateCommonApiLicenseHeader» #ifndef «fTypeCollection.defineName»_H_ #define «fTypeCollection.defineName»_H_ @@ -35,10 +35,10 @@ class FTypeCollectionGenerator { «fTypeCollection.model.generateNamespaceBeginDeclaration» namespace «fTypeCollection.name» { - «fTypeCollection.generateFTypeDeclarations» + «fTypeCollection.generateFTypeDeclarations(deploymentAccessor)» «FOR type : fTypeCollection.types» - «type.generateFTypeInlineImplementation(type)» + «type.generateFTypeInlineImplementation(type, deploymentAccessor)» «ENDFOR» @@ -58,14 +58,14 @@ class FTypeCollectionGenerator { namespace CommonAPI { - «fTypeCollection.generateTypeWriters» + «fTypeCollection.generateTypeWriters(deploymentAccessor)» «fTypeCollection.generateVariantComparators» } - - + + namespace std { - «fTypeCollection.generateHashers» + «fTypeCollection.generateHashers(deploymentAccessor)» } #endif // «fTypeCollection.defineName»_H_ diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend index d94a72c..3bfa1c5 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCommonAreaGenerator.xtend @@ -19,6 +19,8 @@ import org.franca.core.franca.FUnionType import java.util.LinkedList import java.util.ArrayList import org.franca.core.franca.FTypeRef +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor$EnumBackingType class FTypeCommonAreaGenerator { @Inject private extension FrancaGeneratorExtensions @@ -46,10 +48,10 @@ class FTypeCommonAreaGenerator { return fType as FUnionType } - def generateTypeWriters(FTypeCollection fTypes) ''' + def generateTypeWriters(FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «FOR type: fTypes.types» «IF type.isFEnumerationType» - «generateStreamImplementation(type.getFEnumerationType, type.name, fTypes, fTypes.name)» + «generateStreamImplementation(type.getFEnumerationType, type.name, fTypes, fTypes.name, deploymentAccessor)» «ENDIF» «ENDFOR» ''' @@ -68,47 +70,51 @@ class FTypeCommonAreaGenerator { parent.model.namespaceAsList.join("::") + "::" + fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName) } - def private generateStreamImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName) ''' + def private generateStreamImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' template<> struct BasicTypeWriter<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { inline static void writeType (CommonAPI::TypeOutputStream& typeStream) { - typeStream.write«fEnumerationType.generateTypeOutput»Type(); + typeStream.write«fEnumerationType.generateTypeOutput(deploymentAccessor)»Type(); } }; template<> struct InputStreamVectorHelper<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { static void beginReadVector(InputStream& inputStream, const std::vector<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»>& vectorValue) { - inputStream.beginRead«fEnumerationType.generateTypeOutput»Vector(); + inputStream.beginRead«fEnumerationType.generateTypeOutput(deploymentAccessor)»Vector(); } }; template <> struct OutputStreamVectorHelper<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»> { static void beginWriteVector(OutputStream& outputStream, const std::vector<«fEnumerationType.getWithNamespace(enumerationName, parent, parentName)»>& vectorValue) { - outputStream.beginWrite«fEnumerationType.generateTypeOutput»Vector(vectorValue.size()); + outputStream.beginWrite«fEnumerationType.generateTypeOutput(deploymentAccessor)»Vector(vectorValue.size()); } }; ''' - def private generateTypeOutput(FEnumerationType fEnumerationType) { - if (fEnumerationType.backingType.primitiveTypeName.equals("int8_t")) { - return "Int8Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("int16_t")) { - return "Int16Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("int32_t")) { - return "Int32Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("int64_t")) { - return "Int64Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("uint8_t")) { - return "UInt8Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("uint16_t")) { - return "UInt16Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("uint32_t")) { - return "UInt32Enum"; - } else if (fEnumerationType.backingType.primitiveTypeName.equals("uint64_t")) { - return "UInt64Enum"; - } + def private generateTypeOutput(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + if(fEnumerationType.containingInterface != null) { + switch(deploymentAccessor.getEnumBackingType(fEnumerationType.containingInterface)) { + case EnumBackingType::UInt8: + return "UInt8Enum" + case EnumBackingType::UInt16: + return "UInt16Enum" + case EnumBackingType::UInt32: + return "UInt32Enum" + case EnumBackingType::UInt64: + return "UInt64Enum" + case EnumBackingType::Int8: + return "Int8Enum" + case EnumBackingType::Int16: + return "Int16Enum" + case EnumBackingType::Int32: + return "Int32Enum" + case EnumBackingType::Int64: + return "Int64Enum" + } + } + return "Int32Enum" } def generateVariantComparators(FTypeCollection fTypes) ''' @@ -217,13 +223,13 @@ class FTypeCommonAreaGenerator { def getFQN(FType type, FTypeCollection fTypes) '''«fTypes.model.namespaceAsList.join("::")»::«type.getClassNamespaceWithName(type.name, fTypes, fTypes.name)»''' - def generateHashers(FTypeCollection fTypes) ''' + def generateHashers(FTypeCollection fTypes, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «FOR type: fTypes.types» «IF type.isFEnumerationType» template<> struct hash<«type.getFQN(fTypes)»> { inline size_t operator()(const «type.getFQN(fTypes)»& «type.name.toFirstLower») const { - return static_cast<«type.getFEnumerationType.backingType.primitiveTypeName»>(«type.name.toFirstLower»); + return static_cast<«type.getFEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(«type.name.toFirstLower»); } }; «ENDIF» diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend index f291c6f..41349fb 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeGenerator.xtend @@ -30,14 +30,15 @@ import java.util.HashSet import org.eclipse.emf.common.util.EList import static com.google.common.base.Preconditions.* +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor class FTypeGenerator { @Inject private extension FrancaGeneratorExtensions - def generateFTypeDeclarations(FTypeCollection fTypeCollection) ''' + def generateFTypeDeclarations(FTypeCollection fTypeCollection, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' «FOR type: fTypeCollection.types.sortTypes(fTypeCollection)» - «type.generateFTypeDeclaration» + «type.generateFTypeDeclaration(deploymentAccessor)» «ENDFOR» ''' @@ -136,19 +137,19 @@ class FTypeGenerator { } - def dispatch generateFTypeDeclaration(FTypeDef fTypeDef) ''' + def dispatch generateFTypeDeclaration(FTypeDef fTypeDef, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' typedef «fTypeDef.actualType.getNameReference(fTypeDef.eContainer)» «fTypeDef.name»; ''' - def dispatch generateFTypeDeclaration(FArrayType fArrayType) ''' + def dispatch generateFTypeDeclaration(FArrayType fArrayType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' typedef std::vector<«fArrayType.elementType.getNameReference(fArrayType.eContainer)»> «fArrayType.name»; ''' - def dispatch generateFTypeDeclaration(FMapType fMap) ''' + def dispatch generateFTypeDeclaration(FMapType fMap, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' typedef std::unordered_map<«fMap.generateKeyType»«fMap.generateValueType»> «fMap.name»; ''' - def dispatch generateFTypeDeclaration(FStructType fStructType) ''' + def dispatch generateFTypeDeclaration(FStructType fStructType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' struct «fStructType.name»: «fStructType.baseStructName» { «FOR element : fStructType.elements» «element.type.getNameReference(fStructType)» «element.name»; @@ -165,18 +166,18 @@ class FTypeGenerator { «fStructType.baseStructName»::writeToTypeOutputStream(typeOutputStream); «ENDIF» «FOR element : fStructType.elements» - «element.type.typeStreamSignature» + «element.type.typeStreamSignature(deploymentAccessor)» «ENDFOR» } }; ''' - def dispatch generateFTypeDeclaration(FEnumerationType fEnumerationType) { - fEnumerationType.generateDeclaration(fEnumerationType.name) + def dispatch generateFTypeDeclaration(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + generateDeclaration(fEnumerationType, fEnumerationType.name, deploymentAccessor) } - def generateDeclaration(FEnumerationType fEnumerationType, String name) ''' - enum class «name»: «fEnumerationType.backingType.primitiveTypeName» { + def generateDeclaration(FEnumerationType fEnumerationType, String name, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' + enum class «name»: «fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName» { «FOR parent : fEnumerationType.baseList SEPARATOR ',\n'» «FOR enumerator : parent.enumerators SEPARATOR ','» «enumerator.name» = «parent.getRelativeNameReference(fEnumerationType)»::«enumerator.name» @@ -192,7 +193,7 @@ class FTypeGenerator { struct «name»Comparator; ''' - def dispatch generateFTypeDeclaration(FUnionType fUnionType) ''' + def dispatch generateFTypeDeclaration(FUnionType fUnionType, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' typedef CommonAPI::Variant<«fUnionType.getElementNames»> «fUnionType.name»; ''' @@ -209,43 +210,44 @@ class FTypeGenerator { } - def dispatch generateFTypeInlineImplementation(FTypeDef fTypeDef, FModelElement parent) '''''' - def dispatch generateFTypeInlineImplementation(FArrayType fArrayType, FModelElement parent) '''''' - def dispatch generateFTypeInlineImplementation(FMapType fMap, FModelElement parent) '''''' + def dispatch generateFTypeInlineImplementation(FTypeDef fTypeDef, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeInlineImplementation(FArrayType fArrayType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeInlineImplementation(FMapType fMap, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' - def dispatch generateFTypeInlineImplementation(FStructType fStructType, FModelElement parent) ''' + def dispatch generateFTypeInlineImplementation(FStructType fStructType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' bool operator==(const «fStructType.getClassNamespace(parent)»& lhs, const «fStructType.getClassNamespace(parent)»& rhs); inline bool operator!=(const «fStructType.getClassNamespace(parent)»& lhs, const «fStructType.getClassNamespace(parent)»& rhs) { return !(lhs == rhs); } ''' - def dispatch generateFTypeInlineImplementation(FEnumerationType fEnumerationType, FModelElement parent) { - fEnumerationType.generateInlineImplementation(fEnumerationType.name, parent, parent.name) + def dispatch generateFTypeInlineImplementation(FEnumerationType fEnumerationType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) { + fEnumerationType.generateInlineImplementation(fEnumerationType.name, parent, parent.name, deploymentAccessor) } - def generateInlineImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName) ''' + def generateInlineImplementation(FEnumerationType fEnumerationType, String enumerationName, FModelElement parent, String parentName, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' inline CommonAPI::InputStream& operator>>(CommonAPI::InputStream& inputStream, «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& enumValue) { - return inputStream.readEnumValue<«fEnumerationType.backingType.primitiveTypeName»>(enumValue); + return inputStream.readEnumValue<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(enumValue); } inline CommonAPI::OutputStream& operator<<(CommonAPI::OutputStream& outputStream, const «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& enumValue) { - return outputStream.writeEnumValue(static_cast<«fEnumerationType.backingType.primitiveTypeName»>(enumValue)); + return outputStream.writeEnumValue(static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(enumValue)); } struct «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»Comparator { inline bool operator()(const «enumerationName»& lhs, const «enumerationName»& rhs) const { - return static_cast<«fEnumerationType.backingType.primitiveTypeName»>(lhs) < static_cast<«fEnumerationType.backingType.primitiveTypeName»>(rhs); + return static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(lhs) < static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(rhs); } }; «FOR base : fEnumerationType.baseList BEFORE "\n" SEPARATOR "\n"» - «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "==")» - «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "!=")» + «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "==", deploymentAccessor)» + «fEnumerationType.generateInlineOperatorWithName(enumerationName, base, parent, parentName, "!=", deploymentAccessor)» «ENDFOR» ''' - def dispatch generateFTypeInlineImplementation(FUnionType fUnionType, FModelElement parent) ''' ''' + def dispatch generateFTypeInlineImplementation(FUnionType fUnionType, FModelElement parent, DeploymentInterfacePropertyAccessor deploymentAccessor) '''''' + def dispatch generateFTypeImplementation(FTypeDef fTypeDef, FModelElement parent) '''''' def dispatch generateFTypeImplementation(FArrayType fArrayType, FModelElement parent) '''''' def dispatch generateFTypeImplementation(FMapType fMap, FModelElement parent) '''''' @@ -415,12 +417,12 @@ class FTypeGenerator { return elements } - def private generateInlineOperatorWithName(FEnumerationType fEnumerationType, String enumerationName, FEnumerationType base, FModelElement parent, String parentName, String operator) ''' + def private generateInlineOperatorWithName(FEnumerationType fEnumerationType, String enumerationName, FEnumerationType base, FModelElement parent, String parentName, String operator, DeploymentInterfacePropertyAccessor deploymentAccessor) ''' inline bool operator«operator»(const «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& lhs, const «base.getRelativeNameReference(fEnumerationType)»& rhs) { - return static_cast<«fEnumerationType.backingType.primitiveTypeName»>(lhs) «operator» static_cast<«fEnumerationType.backingType.primitiveTypeName»>(rhs); + return static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(lhs) «operator» static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(rhs); } inline bool operator«operator»(const «base.getRelativeNameReference(fEnumerationType)»& lhs, const «fEnumerationType.getClassNamespaceWithName(enumerationName, parent, parentName)»& rhs) { - return static_cast<«fEnumerationType.backingType.primitiveTypeName»>(lhs) «operator» static_cast<«fEnumerationType.backingType.primitiveTypeName»>(rhs); + return static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(lhs) «operator» static_cast<«fEnumerationType.getBackingType(deploymentAccessor).primitiveTypeName»>(rhs); } ''' @@ -458,4 +460,4 @@ class FTypeGenerator { } return null } -}
\ No newline at end of file +} diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend index b5a76f0..12dbe0a 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGenerator.xtend @@ -26,45 +26,139 @@ import org.franca.core.franca.FTypeCollection import org.franca.core.franca.FTypeDef import org.franca.core.franca.FTypeRef import org.franca.core.franca.FUnionType +import org.franca.deploymodel.dsl.FDeployPersistenceManager +import org.franca.deploymodel.core.FDModelExtender +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessorWrapper +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor import static com.google.common.base.Preconditions.* +import org.franca.deploymodel.core.FDeployedInterface class FrancaGenerator implements IGenerator { @Inject private extension FTypeCollectionGenerator @Inject private extension FInterfaceGenerator @Inject private extension FInterfaceProxyGenerator @Inject private extension FInterfaceStubGenerator + @Inject private extension FrancaGeneratorExtensions @Inject private FrancaPersistenceManager francaPersistenceManager + @Inject private FDeployPersistenceManager fDeployPersistenceManager + override doGenerate(Resource input, IFileSystemAccess fileSystemAccess) { - val isFrancaIDLResource = input.URI.fileExtension.equals(francaPersistenceManager.fileExtension) - checkArgument(isFrancaIDLResource, "Unknown input: " + input) + if(input.URI.fileExtension.equals(francaPersistenceManager.fileExtension)) { + doGenerateStandardFrancaComponents(input, fileSystemAccess) + } else if (input.URI.fileExtension.equals("fdepl" /* fDeployPersistenceManager.fileExtension */)) { + doGenerateDeployedFrancaComponents(input, fileSystemAccess) + } else { + checkArgument(false, "Unknown input: " + input) + } + + +// mainStubGenerator.generate(basicModel.interfaces, null, fileSystemAccess, outputLocation, skeletonFolderPath) +// automakeGenerator.generate(basicModel.interfaces, null, fileSystemAccess, outputLocation, skeletonFolderPath) +// initTypeGeneration +// for (fInterface: basicModel.interfaces) { +// generateInterface(fInterface, deploymentAccessor, fileSystemAccess) +// } +// finalizeTypeGeneration(fileSystemAccess, outputLocation) + } + + def private doGenerateStandardFrancaComponents(Resource input, IFileSystemAccess fileSystemAccess) { val fModel = francaPersistenceManager.loadModel(input.filePath) + + val deploymentAccessor = new DeploymentInterfacePropertyAccessorWrapper(null) as DeploymentInterfacePropertyAccessor + + val allReferencedFTypes = fModel.allReferencedFTypes + val allFTypeTypeCollections = allReferencedFTypes.filter[eContainer instanceof FTypeCollection].map[eContainer as FTypeCollection] val allFTypeFInterfaces = allReferencedFTypes.filter[eContainer instanceof FInterface].map[eContainer as FInterface] - - val generateTypeCollections = new HashSet<FTypeCollection> - generateTypeCollections.addAll(fModel.typeCollections) - allReferencedFTypes.filter[eContainer instanceof FTypeCollection].forEach[generateTypeCollections.add(eContainer as FTypeCollection)] - val generateInterfaces = fModel.allReferencedFInterfaces + val generateTypeCollections = fModel.typeCollections.toSet + generateTypeCollections.addAll(allFTypeTypeCollections) + + val generateInterfaces = fModel.allReferencedFInterfaces.toSet generateInterfaces.addAll(allFTypeFInterfaces) - val generateInterfaceProxies = fModel.interfaces - - val generateInterfaceStubs = fModel.interfaces - generateTypeCollections.forEach[generate(fileSystemAccess)] - generateInterfaces.forEach[generate(fileSystemAccess)] - generateInterfaceProxies.forEach[generateProxy(fileSystemAccess)] - generateInterfaceStubs.forEach[generateStub(fileSystemAccess)] - } + + generateTypeCollections.forEach[generate(it, fileSystemAccess, deploymentAccessor)] + generateInterfaces.forEach[ + generate(it, fileSystemAccess, deploymentAccessor) + ] + fModel.interfaces.forEach[ + it.generateProxy(fileSystemAccess, deploymentAccessor) + it.generateStub(fileSystemAccess) + ] + } + + + def private doGenerateDeployedFrancaComponents(Resource input, IFileSystemAccess access) { + var fDeployedModel = fDeployPersistenceManager.loadModel(input.filePathUrl); + val fModelExtender = new FDModelExtender(fDeployedModel); + + checkArgument(fModelExtender.getFDInterfaces().size > 0, "No Interfaces were deployed, nothing to generate.") + val fModel = fModelExtender.getFDInterfaces().get(0).target.model + + val allReferencedFTypes = fModel.allReferencedFTypes + val allFTypeTypeCollections = allReferencedFTypes.filter[eContainer instanceof FTypeCollection].map[eContainer as FTypeCollection] + val allFTypeFInterfaces = allReferencedFTypes.filter[eContainer instanceof FInterface].map[eContainer as FInterface] + + val generateTypeCollections = fModel.typeCollections.toSet + generateTypeCollections.addAll(allFTypeTypeCollections) + + val generateInterfaces = fModel.allReferencedFInterfaces.toSet + generateInterfaces.addAll(allFTypeFInterfaces) + + val deployedInterfaces = fModelExtender.getFDInterfaces() + val defaultDeploymentAccessor = new DeploymentInterfacePropertyAccessorWrapper(null) as DeploymentInterfacePropertyAccessor + + generateTypeCollections.forEach[generate(it, access, defaultDeploymentAccessor)] + + generateInterfaces.forEach[ + val currentInterface = it + var DeploymentInterfacePropertyAccessor deploymentAccessor + if(deployedInterfaces.exists[it.target == currentInterface]) { + deploymentAccessor = new DeploymentInterfacePropertyAccessor(new FDeployedInterface(deployedInterfaces.filter[it.target == currentInterface].last)) + } else { + deploymentAccessor = defaultDeploymentAccessor + } + generate(it, access, deploymentAccessor) + ] + + fModel.interfaces.forEach[ + val currentInterface = it + var DeploymentInterfacePropertyAccessor deploymentAccessor + if(deployedInterfaces.exists[it.target == currentInterface]) { + deploymentAccessor = new DeploymentInterfacePropertyAccessor(new FDeployedInterface(deployedInterfaces.filter[it.target == currentInterface].last)) + } else { + deploymentAccessor = defaultDeploymentAccessor + } + it.generateProxy(access, deploymentAccessor) + it.generateStub(access) + ] + + return; + } + + + + + + private var String filePrefix = "file://" + def private getFilePathUrl(Resource resource) { + val filePath = resource.filePath + return filePrefix + filePath + } + + + def private getFilePath(Resource resource) { - if (resource.URI.file) + if (resource.URI.file) { return resource.URI.toFileString + } val platformPath = new Path(resource.URI.toPlatformString(true)) val file = EcorePlugin::workspaceRoot.getFile(platformPath) diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend index 0bbef24..b8df488 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FrancaGeneratorExtensions.xtend @@ -8,11 +8,8 @@ package org.genivi.commonapi.core.generator import com.google.common.primitives.Ints import java.util.List -import org.eclipse.core.runtime.Path import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.plugin.EcorePlugin -import org.eclipse.emf.ecore.resource.Resource -import org.franca.core.franca.FBasicTypeId import org.franca.core.franca.FInterface import org.franca.core.franca.FMethod import org.franca.core.franca.FModel @@ -22,13 +19,18 @@ import org.franca.core.franca.FTypeRef import org.franca.core.franca.FAttribute import org.franca.core.franca.FBroadcast import org.franca.core.franca.FEnumerationType +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor +import org.genivi.commonapi.core.deployment.DeploymentInterfacePropertyAccessor$EnumBackingType import static com.google.common.base.Preconditions.* +import org.franca.core.franca.FBasicTypeId import org.franca.core.franca.FTypeDef import org.franca.core.franca.FArrayType import org.franca.core.franca.FMapType import org.franca.core.franca.FStructType import org.franca.core.franca.FUnionType +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.core.runtime.Path class FrancaGeneratorExtensions { def getFullyQualifiedName(FModelElement fModelElement) { @@ -46,6 +48,17 @@ class FrancaGeneratorExtensions { return (fModelElement.eContainer as FModel) return (fModelElement.eContainer as FModelElement).model } + + def FInterface getContainingInterface(FModelElement fModelElement) { + if (fModelElement.eContainer == null) { + return null + } + if (fModelElement.eContainer instanceof FInterface) { + return (fModelElement.eContainer as FInterface) + } + + return (fModelElement.eContainer as FModelElement).containingInterface + } def getDirectoryPath(FModel fModel) { fModel.name.replace('.', '/') @@ -352,8 +365,28 @@ class FrancaGeneratorExtensions { (fMethodErrors.eContainer as FMethod).name + 'Error' } - def getBackingType(FEnumerationType fEnumerationType) { - return FBasicTypeId::INT32 + def getBackingType(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + if(fEnumerationType.containingInterface != null) { + switch(deploymentAccessor.getEnumBackingType(fEnumerationType.containingInterface)) { + case EnumBackingType::UInt8: + return FBasicTypeId::UINT8 + case EnumBackingType::UInt16: + return FBasicTypeId::UINT16 + case EnumBackingType::UInt32: + return FBasicTypeId::UINT32 + case EnumBackingType::UInt64: + return FBasicTypeId::UINT64 + case EnumBackingType::Int8: + return FBasicTypeId::INT8 + case EnumBackingType::Int16: + return FBasicTypeId::INT16 + case EnumBackingType::Int32: + return FBasicTypeId::INT32 + case EnumBackingType::Int64: + return FBasicTypeId::INT64 + } + } + return FBasicTypeId::INT32 } def getPrimitiveTypeName(FBasicTypeId fBasicTypeId) { @@ -375,69 +408,69 @@ class FrancaGeneratorExtensions { } } - def String typeStreamSignature(FTypeRef fTypeRef) { + def String typeStreamSignature(FTypeRef fTypeRef, DeploymentInterfacePropertyAccessor deploymentAccessor) { if (fTypeRef.derived != null) - return fTypeRef.derived.typeStreamFTypeSignature - return fTypeRef.predefined.typeStreamSignature + return fTypeRef.derived.typeStreamFTypeSignature(deploymentAccessor) + return fTypeRef.predefined.basicTypeStreamSignature } - def private dispatch String typeStreamFTypeSignature(FTypeDef fTypeDef) { - return fTypeDef.actualType.typeStreamSignature + def private String getBasicTypeStreamSignature(FBasicTypeId fBasicTypeId) { + switch fBasicTypeId { + case FBasicTypeId::BOOLEAN: return "typeOutputStream.writeBoolType();" + case FBasicTypeId::INT8: return "typeOutputStream.writeInt8Type();" + case FBasicTypeId::UINT8: return "typeOutputStream.writeUInt8Type();" + case FBasicTypeId::INT16: return "typeOutputStream.writeInt16Type();" + case FBasicTypeId::UINT16: return "typeOutputStream.writeUInt16Type();" + case FBasicTypeId::INT32: return "typeOutputStream.writeInt32Type();" + case FBasicTypeId::UINT32: return "typeOutputStream.writeUInt32Type();" + case FBasicTypeId::INT64: return "typeOutputStream.writeInt64Type();" + case FBasicTypeId::UINT64: return "typeOutputStream.writeUInt64Type();" + case FBasicTypeId::FLOAT: return "typeOutputStream.writeFloatType();" + case FBasicTypeId::DOUBLE: return "typeOutputStream.writeDoubleType();" + case FBasicTypeId::STRING: return "typeOutputStream.writeStringType();" + case FBasicTypeId::BYTE_BUFFER: return "typeOutputStream.writeByteBufferType();" + } + } + + def private dispatch String typeStreamFTypeSignature(FTypeDef fTypeDef, DeploymentInterfacePropertyAccessor deploymentAccessor) { + return fTypeDef.actualType.typeStreamSignature(deploymentAccessor) } - def private dispatch String typeStreamFTypeSignature(FArrayType fArrayType) { + def private dispatch String typeStreamFTypeSignature(FArrayType fArrayType, DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteVectorType();\n' + - fArrayType.elementType.typeStreamSignature + '\n' + + fArrayType.elementType.typeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteVectorType();' } - def private dispatch String typeStreamFTypeSignature(FMapType fMap) { + def private dispatch String typeStreamFTypeSignature(FMapType fMap, DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.beginWriteMapType();\n' + - fMap.keyType.typeStreamSignature + '\n' + fMap.valueType.typeStreamSignature + '\n' + + fMap.keyType.typeStreamSignature(deploymentAccessor) + '\n' + fMap.valueType.typeStreamSignature(deploymentAccessor) + '\n' + 'typeOutputStream.endWriteMapType();' } - def private dispatch String typeStreamFTypeSignature(FStructType fStructType) { - return 'typeOutputStream.beginWriteStructType();\n' + - fStructType.elementsTypeStreamSignature + '\n' + - 'typeOutputStream.endWriteStructType();' + def private dispatch String typeStreamFTypeSignature(FStructType fStructType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + return 'typeOutputStream.beginWriteStructType();\n' + + fStructType.getElementsTypeStreamSignature(deploymentAccessor) + '\n' + + 'typeOutputStream.endWriteStructType();' } - def private dispatch String typeStreamFTypeSignature(FEnumerationType fEnumerationType) { - return fEnumerationType.backingType.typeStreamSignature + def private dispatch String typeStreamFTypeSignature(FEnumerationType fEnumerationType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + return fEnumerationType.getBackingType(deploymentAccessor).basicTypeStreamSignature } - def private dispatch String typeStreamFTypeSignature(FUnionType fUnionType) { + def private dispatch String typeStreamFTypeSignature(FUnionType fUnionType, DeploymentInterfacePropertyAccessor deploymentAccessor) { return 'typeOutputStream.writeVariantType();' } - def private String getElementsTypeStreamSignature(FStructType fStructType) { - var signature = fStructType.elements.map[type.typeStreamSignature].join + def private String getElementsTypeStreamSignature(FStructType fStructType, DeploymentInterfacePropertyAccessor deploymentAccessor) { + var signature = fStructType.elements.map[type.typeStreamSignature(deploymentAccessor)].join if (fStructType.base != null) - signature = fStructType.base.elementsTypeStreamSignature + signature + signature = fStructType.base.getElementsTypeStreamSignature(deploymentAccessor) + signature return signature } - def private String typeStreamSignature(FBasicTypeId fBasicTypeId) { - switch fBasicTypeId { - case FBasicTypeId::BOOLEAN: return "typeOutputStream.writeBoolType();" - case FBasicTypeId::INT8: return "typeOutputStream.writeInt8Type();" - case FBasicTypeId::UINT8: return "typeOutputStream.writeUInt8Type();" - case FBasicTypeId::INT16: return "typeOutputStream.writeInt16Type();" - case FBasicTypeId::UINT16: return "typeOutputStream.writeUInt16Type();" - case FBasicTypeId::INT32: return "typeOutputStream.writeInt32Type();" - case FBasicTypeId::UINT32: return "typeOutputStream.writeUInt32Type();" - case FBasicTypeId::INT64: return "typeOutputStream.writeInt64Type();" - case FBasicTypeId::UINT64: return "typeOutputStream.writeUInt64Type();" - case FBasicTypeId::FLOAT: return "typeOutputStream.writeFloatType();" - case FBasicTypeId::DOUBLE: return "typeOutputStream.writeDoubleType();" - case FBasicTypeId::STRING: return "typeOutputStream.writeStringType();" - case FBasicTypeId::BYTE_BUFFER: return "typeOutputStream.writeByteBufferType();" - } - } - def generateCppNamespace(FModel fModel) ''' «fModel.namespaceAsList.map[toString].join("::")»::''' |