From 55e84aa7d3fdcee269cee7adb4f253fda2293667 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Mon, 14 Nov 2016 11:23:32 +0100 Subject: qdoc: Handle class decls outside the semantic parent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have the class declaration for QMetaObject::Connection in qobjectdefs.h, which is outside the declaration for QMetaObject. clangqdoc wasn't handling this correctly. It created the class node for Connection with the wrong parent. This update ensures that the class node for Connection is given the class node of QMetaObject as its parent. If the semantic and lexical parent cursors of the current cursor are not the same, find the Aggregate node for the semantic parent cursor and use that node as the parent when the new class node is created. Change-Id: I40f73dad9879e39452f83bb7c0f514a7ef319208 Reviewed-by: Topi Reiniƶ --- src/qdoc/clangcodeparser.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/qdoc/clangcodeparser.cpp') diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 25d268c0e..0f75724be 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -333,6 +333,7 @@ private: CXChildVisitResult visitHeader(CXCursor cursor, CXSourceLocation loc); void parseProperty(const QString &spelling, const Location &loc); void readParameterNamesAndAttributes(FunctionNode* fn, CXCursor cursor); + Aggregate *getSemanticParent(CXCursor cursor); }; /*! @@ -351,6 +352,24 @@ CXChildVisitResult ClangVisitor::visitSource(CXCursor cursor, CXSourceLocation l return CXChildVisit_Continue; } +/*! + If the semantic and lexical parent cursors of \a cursor are + not the same, find the Aggregate node for the semantic parent + cursor and return it. Otherwise return the current parent. + */ +Aggregate *ClangVisitor::getSemanticParent(CXCursor cursor) +{ + CXCursor sp = clang_getCursorSemanticParent(cursor); + CXCursor lp = clang_getCursorLexicalParent(cursor); + if (!clang_equalCursors(sp, lp) && clang_isDeclaration(clang_getCursorKind(sp))) { + Node* spn = findNodeForCursor(qdb_, sp); + if (spn && spn->isAggregate()) { + return static_cast(spn); + } + } + return parent_; +} + CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation loc) { auto kind = clang_getCursorKind(cursor); @@ -368,11 +387,12 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l QString className = fromCXString(clang_getCursorSpelling(cursor)); - if (parent_ && parent_->findChildNode(className, Node::Class)) { + Aggregate* semanticParent = getSemanticParent(cursor); + if (semanticParent && semanticParent->findChildNode(className, Node::Class)) { return CXChildVisit_Continue; } - ClassNode *classe = new ClassNode(parent_, className); + ClassNode *classe = new ClassNode(semanticParent, className); classe->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); classe->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); -- cgit v1.2.1