diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-03-19 17:24:00 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-04-19 12:51:14 +0000 |
commit | fb7386c18c15ca83aebe8f973c1b018d016baaa9 (patch) | |
tree | 91f0c2988af2e4133a2fdc702fccce69a623b9bf /sources/shiboken2/ApiExtractor/clangparser | |
parent | a89690409972501741c846ac8ad4a499f2982809 (diff) |
shiboken: Use enum values from Clang
Remove a lot of ugly value parsing code in favor of
clang_getEnumConstantDeclValue() and
clang_getEnumConstantDeclUnsignedValue() depending on the
type.
Introduce a class EnumValue containing a union of qint64 and quint64 values
to represent signed/unsigned values correctly and use that in the code model
and meta language classes.
Change-Id: If2efb7cfd560237907678b8f6fdfb0bc689c0c93
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/clangparser')
-rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index 0984246c8..b57ef2f43 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -124,6 +124,24 @@ static void setFileName(const CXCursor &cursor, _CodeModelItem *item) } } +static bool isSigned(CXTypeKind kind) +{ + switch (kind) { + case CXType_UChar: + case CXType_Char16: + case CXType_Char32: + case CXType_UShort: + case CXType_UInt: + case CXType_ULong: + case CXType_ULongLong: + case CXType_UInt128: + return false; + default: + break; + } + return true; +} + class BuilderPrivate { public: typedef QHash<CXCursor, ClassModelItem> CursorClassHash; @@ -687,6 +705,7 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) setFileName(cursor, d->m_currentEnum.data()); d->m_currentEnum->setScope(d->m_scope); d->m_currentEnum->setEnumKind(kind); + d->m_currentEnum->setSigned(isSigned(clang_getEnumDeclIntegerType(cursor).kind)); if (!qSharedPointerDynamicCast<_ClassModelItem>(d->m_scopeStack.back()).isNull()) d->m_currentEnum->setAccessPolicy(accessPolicy(clang_getCXXAccessSpecifier(cursor))); d->m_scopeStack.back()->addEnum(d->m_currentEnum); @@ -700,8 +719,14 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) appendDiagnostic(d); return Error; } + EnumValue enumValue; + if (d->m_currentEnum->isSigned()) + enumValue.setValue(clang_getEnumConstantDeclValue(cursor)); + else + enumValue.setUnsignedValue(clang_getEnumConstantDeclUnsignedValue(cursor)); EnumeratorModelItem enumConstant(new _EnumeratorModelItem(d->m_model, name)); - enumConstant->setValue(d->cursorValueExpression(this, cursor)); + enumConstant->setStringValue(d->cursorValueExpression(this, cursor)); + enumConstant->setValue(enumValue); d->m_currentEnum->addEnumerator(enumConstant); } break; |