summaryrefslogtreecommitdiffstats
path: root/generator/cppgenerator.cpp
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2010-12-16 15:58:23 -0300
committerRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2010-12-16 16:03:52 -0300
commit45d4e4b0eabc87cd50613a469ce400434b833d6d (patch)
tree6712d376d1209b58604d3e1c342db30b3afd9a05 /generator/cppgenerator.cpp
parent2d146fad966ae24940c65812cde4c28b645ecf6b (diff)
downloadshiboken-45d4e4b0eabc87cd50613a469ce400434b833d6d.tar.gz
shiboken-45d4e4b0eabc87cd50613a469ce400434b833d6d.tar.xz
shiboken-45d4e4b0eabc87cd50613a469ce400434b833d6d.zip
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.
Diffstat (limited to 'generator/cppgenerator.cpp')
-rw-r--r--generator/cppgenerator.cpp89
1 files changed, 68 insertions, 21 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 7664fb98..2b5a4584 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;
@@ -2960,16 +3009,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;
@@ -2982,6 +3041,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()));
@@ -2998,9 +3058,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";
@@ -3312,21 +3372,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.