diff options
author | Martin Smith <martin.smith@qt.io> | 2018-02-12 12:11:25 +0100 |
---|---|---|
committer | Martin Smith <martin.smith@qt.io> | 2018-02-23 11:43:47 +0000 |
commit | 88472204d6ffd36eca05c88fb15233e9e8b94aa4 (patch) | |
tree | 35843663b0047bdf389e5bef37dbb99d4ccc18ba /src/qdoc/clangcodeparser.cpp | |
parent | c29a1b03fd0fe6cc3496a6a14c56f6ef3390b713 (diff) | |
download | qttools-88472204d6ffd36eca05c88fb15233e9e8b94aa4.tar.gz |
qdoc: Fix bugs in resolving inheritance and finding overridden functions
A class node must have pointers to the class nodes of its base classes, but these
pointers might not exist when qdoc creates the class node for the class. They might
not exist until all the index files and include files have been parsewd. qdoc was
trying to resolve the base classes too early. This update lets qdoc wait until it
is known that everything has been built before attempting to resolve inheritance.
This update also delays finding the pointer to the function node for the overridden
function for a function marked "override" until the pointer is needed. Instead of
storing the pointer to the node, the qualification path to the function is stored
as a string, and the string is used to look up the overridden function when it is
needed, which is only when the \reimp command is processed during output.
The function that resolves the pointer to the overridden function was moved to the
function node class, where it makes more sense. The way a few qdoc warnings are
reported was also changed.
Change-Id: Ia54642d11242386ae75139065f481e5d30f79fb5
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index d04a1b46c..61a5fd639 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -179,6 +179,40 @@ QString functionName(CXCursor cursor) } /*! + Reconstruct the qualified path name of a function that is + being overridden. + */ +static QString reconstructQualifiedPathForCursor(CXCursor cur) { + QString path; + auto kind = clang_getCursorKind(cur); + while (!clang_isInvalid(kind) && kind != CXCursor_TranslationUnit) { + switch (kind) { + case CXCursor_Namespace: + case CXCursor_StructDecl: + case CXCursor_ClassDecl: + case CXCursor_UnionDecl: + case CXCursor_ClassTemplate: + path.prepend("::"); + path.prepend(fromCXString(clang_getCursorSpelling(cur))); + break; + case CXCursor_FunctionDecl: + case CXCursor_FunctionTemplate: + case CXCursor_CXXMethod: + case CXCursor_Constructor: + case CXCursor_Destructor: + case CXCursor_ConversionFunction: + path = functionName(cur); + break; + default: + break; + } + cur = clang_getCursorSemanticParent(cur); + kind = clang_getCursorKind(cur); + } + return path; +} + +/*! Find the node from the QDocDatabase \a qdb that corrseponds to the declaration represented by the cursor \a cur, if it exists. */ @@ -361,7 +395,6 @@ public: isInteresting = allHeaders_.contains(fi.canonicalFilePath()); isInterestingCache_[file] = isInteresting; } - if (isInteresting) { return visitHeader(cur, loc); } @@ -655,9 +688,10 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l unsigned int numOverridden = 0; clang_getOverriddenCursors(cursor, &overridden, &numOverridden); for (uint i = 0; i < numOverridden; ++i) { - auto n = findNodeForCursor(qdb_, overridden[i]); - if (n && n->isFunction()) { - fn->setReimplementedFrom(static_cast<FunctionNode *>(n)); + QString path = reconstructQualifiedPathForCursor(overridden[i]); + if (!path.isEmpty()) { + fn->setReimplementedFrom(path); + break; } } clang_disposeOverriddenCursors(overridden); @@ -1218,7 +1252,6 @@ void ClangCodeParser::buildPCH() args_.pop_back(); // remove the "-xc++"; } } - qdb_->resolveInheritance(); } } |