summaryrefslogtreecommitdiff
path: root/src/qdoc/clangcodeparser.cpp
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@qt.io>2016-11-14 11:23:32 +0100
committerMartin Smith <martin.smith@qt.io>2017-08-10 07:33:19 +0000
commit55e84aa7d3fdcee269cee7adb4f253fda2293667 (patch)
treeef59ea70c0f0e3215be9a595817add6bd0b14dbd /src/qdoc/clangcodeparser.cpp
parent48063f1f1f016f940b240445e1144d05c2e8e92d (diff)
downloadqttools-55e84aa7d3fdcee269cee7adb4f253fda2293667.tar.gz
qdoc: Handle class decls outside the semantic parent
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ƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r--src/qdoc/clangcodeparser.cpp24
1 files changed, 22 insertions, 2 deletions
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<Aggregate*>(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)));