From f2443b02fce5dd4182e80ed0e5343586cbd72a31 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 4 Jul 2018 13:01:46 +0200 Subject: shiboken: Improve const handling - Use new enum in code. - Rewrite the Clang type parsing to make use of it. - Adapt some typesystem files. This enables the distinction between "int *" and "int *const" and fixes the signatures from "int const &" to the more common "const int&". Task-number: PYSIDE-672 Change-Id: Ic1bff0015188c32f53d0e6f347b1523254cb7e4f Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/parser/codemodel.cpp | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/parser/codemodel.cpp') diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp index 4ad86bd15..d3ada9235 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp @@ -198,13 +198,13 @@ TypeInfo TypeInfo::resolveType(CodeModelItem __item, TypeInfo const &__type, Cod QString TypeInfo::toString() const { QString tmp; - - tmp += m_qualifiedName.join(QLatin1String("::")); if (isConstant()) - tmp += QLatin1String(" const"); + tmp += QLatin1String("const "); if (isVolatile()) - tmp += QLatin1String(" volatile"); + tmp += QLatin1String("volatile "); + + tmp += m_qualifiedName.join(QLatin1String("::")); if (const int instantiationCount = m_instantiations.size()) { tmp += QLatin1Char('<'); @@ -276,7 +276,34 @@ bool TypeInfo::operator==(const TypeInfo &other) const QString TypeInfo::indirectionKeyword(Indirection i) { return i == Indirection::Pointer - ? QStringLiteral("*") : QStringLiteral("* const"); + ? QStringLiteral("*") : QStringLiteral("*const"); +} + +static inline QString constQualifier() { return QStringLiteral("const"); } +static inline QString volatileQualifier() { return QStringLiteral("volatile"); } + +bool TypeInfo::stripLeadingConst(QString *s) +{ + return stripLeadingQualifier(constQualifier(), s); +} + +bool TypeInfo::stripLeadingVolatile(QString *s) +{ + return stripLeadingQualifier(volatileQualifier(), s); +} + +bool TypeInfo::stripLeadingQualifier(const QString &qualifier, QString *s) +{ + // "const int x" + const int qualifierSize = qualifier.size(); + if (s->size() < qualifierSize + 1 || !s->startsWith(qualifier) + || !s->at(qualifierSize).isSpace()) { + return false; + } + s->remove(0, qualifierSize + 1); + while (!s->isEmpty() && s->at(0).isSpace()) + s->remove(0, 1); + return true; } #ifndef QT_NO_DEBUG_STREAM -- cgit v1.2.3