aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-07-23 15:53:03 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-07-26 08:24:29 +0000
commit831b22fcd6eb9b45c9e7834799a91698ec00a6a4 (patch)
tree536212de56d2aec949f504b275dcb77ff2d76540 /sources/shiboken2/ApiExtractor
parentf645e5c8fe02bc6eb177061cfec4fa5bddab05d3 (diff)
shiboken: Add support for type aliases (using)
QAbstractRayCaster is the first class in Qt to use type aliases: using Hits = QVector<QRayCasterHit>; Treat them as typedefs if a canonical type can be obtained for them. This requires adding some simplification of the canonical types obtained for standard containers. Task-number: PYSIDE-751 Change-Id: I521a8b02d3c8cb89e4f72a817fbacc5955041570 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp30
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp32
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.h4
3 files changed, 56 insertions, 10 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index e3d7d0273..e3e52cdd3 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -190,6 +190,8 @@ public:
TypeInfo *t) const;
bool addTemplateInstantiationsRecursion(const CXType &type, TypeInfo *t) const;
+ void addTypeDef(const CXCursor &cursor, const TypeInfo &ti);
+
TemplateParameterModelItem createTemplateParameter(const CXCursor &cursor) const;
TemplateParameterModelItem createNonTypeTemplateParameter(const CXCursor &cursor) const;
void addField(const CXCursor &cursor);
@@ -511,6 +513,7 @@ TypeInfo BuilderPrivate::createTypeInfoHelper(const CXType &type) const
typeInfo.setQualifiedName(qualifiedName(typeName));
// 3320:CINDEX_LINKAGE int clang_getNumArgTypes(CXType T); function ptr types?
+ typeInfo.simplifyStdType();
return typeInfo;
}
@@ -522,6 +525,16 @@ TypeInfo BuilderPrivate::createTypeInfo(const CXType &type) const
return it.value();
}
+void BuilderPrivate::addTypeDef(const CXCursor &cursor, const TypeInfo &ti)
+{
+ TypeDefModelItem item(new _TypeDefModelItem(m_model, getCursorSpelling(cursor)));
+ setFileName(cursor, item.data());
+ item->setType(ti);
+ item->setScope(m_scope);
+ m_scopeStack.back()->addTypeDef(item);
+ m_cursorTypedefHash.insert(cursor, item);
+}
+
// extract an expression from the cursor via source
// CXCursor_EnumConstantDecl, ParmDecl (a = Flag1 | Flag2)
QString BuilderPrivate::cursorValueExpression(BaseVisitor *bv, const CXCursor &cursor) const
@@ -912,17 +925,14 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
}
break;
case CXCursor_TypeAliasDecl:
- case CXCursor_TypeAliasTemplateDecl: // May contain nested CXCursor_TemplateTypeParameter
- return Skip;
- case CXCursor_TypedefDecl: {
- const QString name = getCursorSpelling(cursor);
- TypeDefModelItem item(new _TypeDefModelItem(d->m_model, name));
- setFileName(cursor, item.data());
- item->setType(d->createTypeInfo(clang_getTypedefDeclUnderlyingType(cursor)));
- item->setScope(d->m_scope);
- d->m_scopeStack.back()->addTypeDef(item);
- d->m_cursorTypedefHash.insert(cursor, item);
+ case CXCursor_TypeAliasTemplateDecl: { // May contain nested CXCursor_TemplateTypeParameter
+ const CXType type = clang_getCanonicalType(clang_getCursorType(cursor));
+ if (type.kind > CXType_Unexposed)
+ d->addTypeDef(cursor, d->createTypeInfo(type));
}
+ return Skip;
+ case CXCursor_TypedefDecl:
+ d->addTypeDef(cursor, d->createTypeInfo(clang_getTypedefDeclUnderlyingType(cursor)));
break;
case CXCursor_TypeRef:
if (!d->m_currentFunction.isNull()) {
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
index 485222bb0..c9861b510 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
@@ -355,6 +355,38 @@ bool TypeInfo::stripLeadingQualifier(const QString &qualifier, QString *s)
return true;
}
+// 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
+// "std::__1::list<int, std::allocator<int> >" -> "std::list<int>".
+
+bool TypeInfo::isStdType() const
+{
+ return m_qualifiedName.size() > 1
+ && m_qualifiedName.constFirst() == QLatin1String("std");
+}
+
+static inline bool discardStdType(const QString &name)
+{
+ return name == QLatin1String("allocator") || name == QLatin1String("less");
+}
+
+void TypeInfo::simplifyStdType()
+{
+ if (isStdType()) {
+ if (m_qualifiedName.at(1).startsWith(QLatin1String("__")))
+ m_qualifiedName.removeAt(1);
+ for (int t = m_instantiations.size() - 1; t >= 0; --t) {
+ if (m_instantiations.at(t).isStdType()) {
+ if (discardStdType(m_instantiations.at(t).m_qualifiedName.constLast()))
+ m_instantiations.removeAt(t);
+ else
+ m_instantiations[t].simplifyStdType();
+ }
+ }
+ }
+}
+
#ifndef QT_NO_DEBUG_STREAM
template <class It>
void formatSequence(QDebug &d, It i1, It i2, const char *separator=", ")
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
index eef2bf281..aad1a8eaa 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
@@ -186,6 +186,8 @@ public:
void addInstantiation(const TypeInfo &i) { m_instantiations.append(i); }
void clearInstantiations() { m_instantiations.clear(); }
+ bool isStdType() const;
+
QPair<int, int> parseTemplateArgumentList(const QString &l, int from = 0);
bool operator==(const TypeInfo &other) const;
@@ -212,6 +214,8 @@ public:
static bool stripLeadingVolatile(QString *s);
static bool stripLeadingQualifier(const QString &qualifier, QString *s);
+ void simplifyStdType();
+
private:
friend class TypeInfoTemplateArgumentHandler;