diff options
author | Renato Araujo Oliveira Filho <renato.filho@openbossa.org> | 2010-12-16 15:58:23 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:12:49 -0300 |
commit | a3e731a9ea920ec6e1373e6ad6c74724ce36575f (patch) | |
tree | 5196ec5be2b1cc33d726d0528fa61cf89f60f837 | |
parent | 36c80e6daab7b8d69458c1a8154f4a17ee1ea303 (diff) |
Fix register type function to register the type with two names.
Fix signal register, to use arguments type name based on generated namespace.
Fix bug #498.
-rw-r--r-- | generator/cppgenerator.cpp | 89 | ||||
-rw-r--r-- | generator/cppgenerator.h | 4 |
2 files changed, 72 insertions, 21 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index a5b06457e..8158fe156 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -84,6 +84,14 @@ inline AbstractMetaType* getTypeWithoutContainer(AbstractMetaType* arg) return arg; } +static QString reduceTypeName(const AbstractMetaClass* metaClass) +{ + QString qualifiedCppName = metaClass->typeEntry()->qualifiedCppName(); + QString lookupName = metaClass->typeEntry()->lookupName(); + if (lookupName != qualifiedCppName) + return lookupName; + return QString(); +} CppGenerator::CppGenerator() : m_currentErrorCode(0) { @@ -123,6 +131,47 @@ QList<AbstractMetaFunctionList> CppGenerator::filterGroupedOperatorFunctions(con return results.values(); } +void CppGenerator::writeRegisterType(QTextStream& s, const AbstractMetaClass* metaClass) +{ + QString typeName = metaClass->qualifiedCppName(); + QString reducedName = reduceTypeName(metaClass); + + bool isObjectType = metaClass->typeEntry()->isObject(); + if (!isObjectType) { + s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<" << typeName << " >" << "(\"" << typeName << "\");\n"; + if (!reducedName.isEmpty()) + s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<" << typeName << " >" << "(\"" << reducedName << "\");\n"; + } + + s << INDENT << "Shiboken::TypeResolver::createObjectTypeResolver<" << typeName << " >" << "(\"" << typeName << "*\");\n"; + if (!reducedName.isEmpty()) + s << INDENT << "Shiboken::TypeResolver::createObjectTypeResolver<" << typeName << " >" << "(\"" << reducedName << "*\");\n"; + QString functionSufix = (isObjectType ? "Object" : "Value"); + s << INDENT << "Shiboken::TypeResolver::create" << functionSufix; + s << "TypeResolver<" << typeName << " >" << "(typeid(" << typeName << ").name());\n"; + if (shouldGenerateCppWrapper(metaClass)) { + s << INDENT << "Shiboken::TypeResolver::create" << functionSufix; + s << "TypeResolver<" << typeName << " >" << "(typeid(" << wrapperName(metaClass) << ").name());\n"; + } +} + +void CppGenerator::writeRegisterType(QTextStream& s, const AbstractMetaEnum* metaEnum) +{ + QString fullName; + QString shortName; + if (metaEnum->enclosingClass()) { + QString suffix = "::" + metaEnum->name(); + fullName = metaEnum->enclosingClass()->qualifiedCppName() + suffix; + shortName = reduceTypeName(metaEnum->enclosingClass()) + suffix; + } else { + fullName = metaEnum->name(); + } + s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<int>(\"" << fullName << "\");\n"; + if (!shortName.isEmpty()) + s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<int>(\"" << shortName << "\");\n"; + +} + void CppGenerator::writeToPythonFunction(QTextStream& s, const AbstractMetaClass* metaClass) { s << "static PyObject* " << cpythonBaseName(metaClass) << "_ToPythonFunc(PyObject* self)" << endl; @@ -2962,16 +3011,26 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu if (!cppEnum->isAnonymous()) { // TypeResolver stuff - s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<int>(\""; - if (cppEnum->enclosingClass()) - s << cppEnum->enclosingClass()->qualifiedCppName() << "::"; - s << cppEnum->name() << "\");\n"; + writeRegisterType(s, cppEnum); } s << INDENT << "// end of enum " << cppEnum->name() << endl << endl; } +static QString skipNamespace(const QString& typeName) +{ + QString namespaceName = typeName.split("::").first(); + if (namespaceName.isEmpty()) + return typeName; + + NamespaceTypeEntry* entry = TypeDatabase::instance()->findNamespaceType(namespaceName); + if (entry && !entry->generateCode()) + return QString(typeName).replace(namespaceName + "::", ""); + + return typeName; +} + void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaClass* metaClass) { QHash<QString, QStringList> signatures; @@ -2984,6 +3043,7 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC for (int i = 0; i < cppSignal->arguments().count(); ++i) { if (i > 0) signature += ", "; + AbstractMetaArgument *a = cppSignal->arguments().at(i); AbstractMetaType* type = a->type(); QString cppSignature = QMetaObject::normalizedType(qPrintable(type->cppSignature())); @@ -3000,9 +3060,9 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC knowTypes << originalSignature; s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<" << cppSignature << " >" - << "(\"" << originalSignature << "\"); // " << type->cppSignature() << "\n"; + << "(\"" << skipNamespace(originalSignature) << "\"); // " << type->cppSignature() << "\n"; } - signature += type->originalTypeDescription(); + signature += skipNamespace(type->originalTypeDescription()); } } else { signature = "void"; @@ -3310,21 +3370,8 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), CodeSnip::End, TypeSystem::TargetLangCode, 0, 0, metaClass); } - if (!metaClass->isNamespace()) { - bool isObjectType = metaClass->typeEntry()->isObject(); - QString typeName = metaClass->qualifiedCppName(); - if (!isObjectType) - s << INDENT << "Shiboken::TypeResolver::createValueTypeResolver<" << typeName << " >" << "(\"" << typeName << "\");\n"; - - s << INDENT << "Shiboken::TypeResolver::createObjectTypeResolver<" << typeName << " >" << "(\"" << typeName << "*\");\n"; - QString functionSufix = (isObjectType ? "Object" : "Value"); - s << INDENT << "Shiboken::TypeResolver::create" << functionSufix; - s << "TypeResolver<" << typeName << " >" << "(typeid(" << typeName << ").name());\n"; - if (shouldGenerateCppWrapper(metaClass)) { - s << INDENT << "Shiboken::TypeResolver::create" << functionSufix; - s << "TypeResolver<" << typeName << " >" << "(typeid(" << wrapperName(metaClass) << ").name());\n"; - } - } + if (!metaClass->isNamespace()) + writeRegisterType(s, metaClass); if (usePySideExtensions() && !metaClass->isNamespace()) { // Qt metatypes are registered only on their first use, so we do this now. diff --git a/generator/cppgenerator.h b/generator/cppgenerator.h index 6e064dd4f..f2bc30e05 100644 --- a/generator/cppgenerator.h +++ b/generator/cppgenerator.h @@ -192,10 +192,14 @@ private: void writeStdListWrapperMethods(QTextStream& s, const AbstractMetaClass* metaClass); QString writeReprFunction(QTextStream& s, const AbstractMetaClass* metaClass); + void writeRegisterType(QTextStream& s, const AbstractMetaClass* metaClass); + void writeRegisterType(QTextStream& s, const AbstractMetaEnum* metaEnum); + // Maps special function names to function parameters and return types // used by CPython API in the sequence protocol. QHash<QString, QPair<QString, QString> > m_sequenceProtocol; int m_currentErrorCode; + }; #endif // CPPGENERATOR_H |