From 0a8e37cd60863773940d9d7f21403a841d744720 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Jul 2018 08:45:00 +0200 Subject: shiboken: Improve support for volatile Previously, the volatile keyword ended up as a part of the qualified type name while parsing in translateType(). Add the token to TypeParser and add it to AbstractMetaType. Task-number: PYSIDE-672 Change-Id: I553ea1b35e7e99ffde4442471b82e32be84731ba Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 2 ++ .../shiboken2/ApiExtractor/abstractmetalang.cpp | 6 ++++ sources/shiboken2/ApiExtractor/abstractmetalang.h | 6 +++- sources/shiboken2/ApiExtractor/typeparser.cpp | 36 +++++++++++++++++----- 4 files changed, 42 insertions(+), 8 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 1fa4bde9c..9ada2993a 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -2346,6 +2346,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo //newInfo.setArguments(typeInfo.arguments()); newInfo.setIndirectionsV(typeInfo.indirectionsV()); newInfo.setConstant(typeInfo.isConstant()); + newInfo.setVolatile(typeInfo.isVolatile()); newInfo.setFunctionPointer(typeInfo.isFunctionPointer()); newInfo.setQualifiedName(typeInfo.qualifiedName()); newInfo.setReferenceType(typeInfo.referenceType()); @@ -2460,6 +2461,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo metaType->setIndirectionsV(typeInfo.indirectionsV()); metaType->setReferenceType(typeInfo.referenceType()); metaType->setConstant(typeInfo.isConstant()); + metaType->setVolatile(typeInfo.isVolatile()); metaType->setOriginalTypeDescription(_typei.toString()); const auto &templateArguments = typeInfo.instantiations(); diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 489d2e4aa..634eae5a0 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -114,6 +114,7 @@ void AbstractMetaAttributes::assignMetaAttributes(const AbstractMetaAttributes & AbstractMetaType::AbstractMetaType() : m_constant(false), + m_volatile(false), m_cppInstantiation(true), m_reserved(0) { @@ -156,6 +157,7 @@ AbstractMetaType *AbstractMetaType::copy() const cpy->setTypeUsagePattern(typeUsagePattern()); cpy->setConstant(isConstant()); + cpy->setVolatile(isVolatile()); cpy->setReferenceType(referenceType()); cpy->setIndirectionsV(indirectionsV()); cpy->setInstantiations(instantiations()); @@ -302,6 +304,8 @@ QDebug operator<<(QDebug d, const AbstractMetaType *at) d << ", reftype=" << at->referenceType(); if (at->isConstant()) d << ", [const]"; + if (at->isVolatile()) + d << ", [volatile]"; if (at->isArray()) { d << ", array of \"" << at->arrayElementType()->cppSignature() << "\", arrayElementCount=" << at->arrayElementCount(); @@ -2237,6 +2241,8 @@ QString AbstractMetaType::formatSignature(bool minimal) const QString result; if (isConstant()) result += QLatin1String("const "); + if (isVolatile()) + result += QLatin1String("volatile "); if (isArray()) { // Build nested array dimensions a[2][3] in correct order result += m_arrayElementType->minimalSignature(); diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index e05079bdc..7b4ad2b21 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -437,6 +437,9 @@ public: m_constant = constant; } + bool isVolatile() const { return m_volatile; } + void setVolatile(bool v) { m_volatile = v; } + bool isConstRef() const; ReferenceType referenceType() const { return m_referenceType; } @@ -551,8 +554,9 @@ private: TypeUsagePattern m_pattern = InvalidPattern; uint m_constant : 1; + uint m_volatile : 1; uint m_cppInstantiation : 1; - uint m_reserved : 30; // unused + uint m_reserved : 29; // unused ReferenceType m_referenceType = NoReference; AbstractMetaTypeList m_children; diff --git a/sources/shiboken2/ApiExtractor/typeparser.cpp b/sources/shiboken2/ApiExtractor/typeparser.cpp index 11f04d079..0a60159ae 100644 --- a/sources/shiboken2/ApiExtractor/typeparser.cpp +++ b/sources/shiboken2/ApiExtractor/typeparser.cpp @@ -49,6 +49,7 @@ public: GreaterThanToken, ConstToken, + VolatileToken, Identifier, NoToken, InvalidToken @@ -137,13 +138,30 @@ Scanner::Token Scanner::nextToken(QString *errorMessage) } } - if (tok == Identifier && m_pos - m_tokenStart == 5) { - if (m_chars[m_tokenStart] == QLatin1Char('c') - && m_chars[m_tokenStart + 1] == QLatin1Char('o') - && m_chars[m_tokenStart + 2] == QLatin1Char('n') - && m_chars[m_tokenStart + 3] == QLatin1Char('s') - && m_chars[m_tokenStart + 4] == QLatin1Char('t')) - tok = ConstToken; + if (tok == Identifier) { + switch (m_pos - m_tokenStart) { + case 5: + if (m_chars[m_tokenStart] == QLatin1Char('c') + && m_chars[m_tokenStart + 1] == QLatin1Char('o') + && m_chars[m_tokenStart + 2] == QLatin1Char('n') + && m_chars[m_tokenStart + 3] == QLatin1Char('s') + && m_chars[m_tokenStart + 4] == QLatin1Char('t')) { + tok = ConstToken; + } + break; + case 8: + if (m_chars[m_tokenStart] == QLatin1Char('v') + && m_chars[m_tokenStart + 1] == QLatin1Char('o') + && m_chars[m_tokenStart + 2] == QLatin1Char('l') + && m_chars[m_tokenStart + 3] == QLatin1Char('a') + && m_chars[m_tokenStart + 4] == QLatin1Char('t') + && m_chars[m_tokenStart + 5] == QLatin1Char('i') + && m_chars[m_tokenStart + 6] == QLatin1Char('l') + && m_chars[m_tokenStart + 7] == QLatin1Char('e')) { + tok = VolatileToken; + } + break; + } } return tok; @@ -241,6 +259,10 @@ TypeInfo TypeParser::parse(const QString &str, QString *errorMessage) } break; + case Scanner::VolatileToken: + stack.top()->m_volatile = true; + break; + case Scanner::OpenParenToken: // function pointers not supported case Scanner::CloseParenToken: { const QString message = scanner.msgParseError(QStringLiteral("Function pointers are not supported")); -- cgit v1.2.3