From 612bfd01e1e7698cb3a06d619cc7d7c7acd3d273 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Jul 2018 12:54:25 +0200 Subject: shiboken: Move detection of template arguments to ClangBuilder Obtain the template arguments from Clang and fall back to parsing the type name where this is not possible (which may be the case inside a template declaration). The string-based formatting and re-parsing of the type in AbstractMetaBuilder::translateType() can then be removed, opening the way to passing up more complex types from Clang into the MetaBuilder. Task-number: PYSIDE-672 Change-Id: I43ff285c5f3720319bf40c65b1c27302ef1b934e Reviewed-by: Qt CI Bot Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/parser/codemodel.cpp | 49 ++++++++++++++++++++++ sources/shiboken2/ApiExtractor/parser/codemodel.h | 5 +++ 2 files changed, 54 insertions(+) (limited to 'sources/shiboken2/ApiExtractor/parser') diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp index d3ada9235..a560c0faf 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp @@ -29,11 +29,15 @@ #include "codemodel.h" + +#include + #include #include #include #include #include +#include // Predicate to find an item by name in a list of QSharedPointer template class ModelItemNamePredicate : public std::unary_function > @@ -195,6 +199,51 @@ TypeInfo TypeInfo::resolveType(CodeModelItem __item, TypeInfo const &__type, Cod return otherType; } +// Handler for clang::parseTemplateArgumentList() that populates +// TypeInfo::m_instantiations +class TypeInfoTemplateArgumentHandler : + public std::binary_function +{ +public: + explicit TypeInfoTemplateArgumentHandler(TypeInfo *t) + { + m_parseStack.append(t); + } + + void operator()(int level, const QStringRef &name) + { + if (level > m_parseStack.size()) { + Q_ASSERT(!top()->m_instantiations.isEmpty()); + m_parseStack.push(&top()->m_instantiations.back()); + } + while (level < m_parseStack.size()) + m_parseStack.pop(); + TypeInfo instantiation; + instantiation.setQualifiedName(qualifiedName(name)); + top()->addInstantiation(instantiation); + } + +private: + TypeInfo *top() const { return m_parseStack.back(); } + + static QStringList qualifiedName(const QStringRef &name) + { + QStringList result; + const QVector nameParts = name.split(QLatin1String("::")); + result.reserve(nameParts.size()); + for (const QStringRef &p : nameParts) + result.append(p.toString()); + return result; + } + + QStack m_parseStack; +}; + +QPair TypeInfo::parseTemplateArgumentList(const QString &l, int from) +{ + return clang::parseTemplateArgumentList(l, clang::TemplateArgumentHandler(TypeInfoTemplateArgumentHandler(this)), from); +} + QString TypeInfo::toString() const { QString tmp; diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h index d0381c4e3..c61f640e1 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.h +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h @@ -36,6 +36,7 @@ #include "enumvalue.h" #include +#include #include #include #include @@ -185,6 +186,8 @@ public: void addInstantiation(const TypeInfo &i) { m_instantiations.append(i); } void clearInstantiations() { m_instantiations.clear(); } + QPair parseTemplateArgumentList(const QString &l, int from = 0); + bool operator==(const TypeInfo &other) const; bool operator!=(const TypeInfo &other) const @@ -210,6 +213,8 @@ public: static bool stripLeadingQualifier(const QString &qualifier, QString *s); private: + friend class TypeInfoTemplateArgumentHandler; + static TypeInfo resolveType(CodeModelItem item, TypeInfo const &__type, CodeModelItem __scope); QStringList m_qualifiedName; -- cgit v1.2.3