diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-06 12:51:24 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-06 16:12:35 +0200 |
commit | fd126b28e1d9b02ea16c813bc392461bdb05bd1d (patch) | |
tree | 63066d241027f67dcf58132dad4d70226af7a2a3 | |
parent | f7f12ba7f277d4c074382b5434123dc66b8791b8 (diff) |
shiboken: Fix generation of init functions and types for const-refs of smart pointers
Add a convenience to strip all qualifiers and use that.
This at least fixes the naming (for example, getInitFunctionName
returning "const_QSharedPointer_QSize___&"), the init function for the
type itself is missing, though.
Task-number: PYSIDE-1016
Change-Id: Id61b3c879199fc061e2846007951e3e9c82b85c4
Reviewed-by: Christian Tismer <tismer@stackless.com>
4 files changed, 19 insertions, 2 deletions
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp index eb0f44689..7bb7e0a83 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp @@ -353,6 +353,17 @@ bool TypeInfo::stripLeadingQualifier(const QString &qualifier, QString *s) return true; } +// Strip all const/volatile/*/& +void TypeInfo::stripQualifiers(QString *s) +{ + stripLeadingConst(s); + stripLeadingVolatile(s); + while (s->endsWith(QLatin1Char('&')) || s->endsWith(QLatin1Char('*')) + || s->endsWith(QLatin1Char(' '))) { + s->chop(1); + } +} + // Helper functionality to simplify a raw standard type as returned by // clang_getCanonicalType() for g++ standard containers from // "std::__cxx11::list<int, std::allocator<int> >" or diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h index 3bce5e216..6f3c17613 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.h +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h @@ -213,6 +213,7 @@ public: static bool stripLeadingConst(QString *s); static bool stripLeadingVolatile(QString *s); static bool stripLeadingQualifier(const QString &qualifier, QString *s); + static void stripQualifiers(QString *s); void simplifyStdType(); diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index 87758e533..fe03d3489 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -28,6 +28,7 @@ #include "generator.h" #include "abstractmetalang.h" +#include "parser/codemodel.h" #include "messages.h" #include "reporthandler.h" #include "fileout.h" @@ -911,6 +912,7 @@ QString getClassTargetFullName(const AbstractMetaType *metaType, bool includePac QString getFilteredCppSignatureString(QString signature) { + TypeInfo::stripQualifiers(&signature); // for const refs to smart pointers signature.replace(QLatin1String("::"), QLatin1String("_")); signature.replace(QLatin1Char('<'), QLatin1Char('_')); signature.replace(QLatin1Char('>'), QLatin1Char('_')); diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 8881d71f4..17ebbcde9 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -31,6 +31,7 @@ #include <typedatabase.h> #include <reporthandler.h> #include <fileout.h> +#include "parser/codemodel.h" #include <algorithm> @@ -592,8 +593,10 @@ void HeaderGenerator::writeSbkTypeFunction(QTextStream& s, const AbstractMetaCla void HeaderGenerator::writeSbkTypeFunction(QTextStream &s, const AbstractMetaType *metaType) { - s << "template<> inline PyTypeObject* SbkType< ::" << metaType->cppSignature() << " >() " - << "{ return reinterpret_cast<PyTypeObject*>(" << cpythonTypeNameExt(metaType) << "); }\n"; + QString signature = metaType->cppSignature(); + TypeInfo::stripQualifiers(&signature); // for const refs to smart pointers + s << "template<> inline PyTypeObject *SbkType< ::" << signature << " >() " + << "{ return reinterpret_cast<PyTypeObject *>(" << cpythonTypeNameExt(metaType) << "); }\n"; } void HeaderGenerator::writeInheritedOverloads(QTextStream& s) |