diff options
author | Topi Reinio <topi.reinio@qt.io> | 2020-10-26 23:37:08 +0100 |
---|---|---|
committer | Topi Reinio <topi.reinio@qt.io> | 2020-10-27 13:10:48 +0100 |
commit | 58bca83555914cacf124acf0a687312bb547b85c (patch) | |
tree | 3794bf84eb754b11923052b1d7c217549b41e56b /src/qdoc/clangcodeparser.cpp | |
parent | 29c03c32804df3f9963774013998d969e6f4ae5b (diff) | |
download | qttools-58bca83555914cacf124acf0a687312bb547b85c.tar.gz |
qdoc: Fix handling of \fn signatures with unnamed parameters
A misplaced 'i++' caused an error where names of documented parameters
were shifted around if one or more of the parameters were unnamed.
Fixing the above uncovered issues with handling of \fn commands with
[tag] argument; improve and simplify related code.
Finally, avoid redundant space characters when generating signatures
with unnamed parameters or in 'All Members' page where parameter
names are omitted.
Fixes: QTBUG-87855
Change-Id: I526c89c10c66572b8c71106660f43346a4751e4e
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index bc894ccdf..b3df03cf6 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -880,8 +880,8 @@ void ClangVisitor::readParameterNamesAndAttributes(FunctionNode *fn, CXCursor cu } return CXChildVisit_Continue; }); - ++i; } + ++i; } return CXChildVisit_Continue; }); @@ -1602,9 +1602,9 @@ Node *ClangCodeParser::parseFnArg(const Location &location, const QString &fnArg not be found. Return 0 in that case. */ if (fnArg.startsWith('[')) { - int end = fnArg.indexOf(QChar(']', 0)); - if (end > 1) { - QString tag = fnArg.left(end + 1); + int tagEnd = fnArg.indexOf(QChar(']', 0)); + if (tagEnd > 1) { + QString tag = fnArg.left(++tagEnd); fnNode = qdb_->findFunctionNodeForTag(tag); if (!fnNode) { location.error( @@ -1613,11 +1613,12 @@ Node *ClangCodeParser::parseFnArg(const Location &location, const QString &fnArg } else { /* The function node was found. Use the formal - parameter names from the \FN command, because + parameter names from the \fn command, because they will be the names used in the documentation. */ + QString fnSignature = fnArg.mid(tagEnd); FunctionNode *fn = static_cast<FunctionNode *>(fnNode); - QStringList leftParenSplit = fnArg.split('('); + QStringList leftParenSplit = fnSignature.mid(fnSignature.indexOf(fn->name())).split('('); if (leftParenSplit.size() > 1) { QStringList rightParenSplit = leftParenSplit[1].split(')'); if (rightParenSplit.size() > 0) { @@ -1627,16 +1628,14 @@ Node *ClangCodeParser::parseFnArg(const Location &location, const QString &fnArg Parameters ¶meters = fn->parameters(); if (parameters.count() == commaSplit.size()) { for (int i = 0; i < parameters.count(); ++i) { - QStringList blankSplit = commaSplit[i].split(' '); - if (blankSplit.size() > 0) { + QStringList blankSplit = commaSplit[i].split(' ', Qt::SkipEmptyParts); + if (blankSplit.size() > 1) { QString pName = blankSplit.last(); - int j = 0; - while (j < pName.length() && !pName.at(j).isLetter()) - ++j; - if (j > 0) - pName = pName.mid(j); - if (!pName.isEmpty() && pName != parameters[i].name()) - parameters[i].setName(pName); + // Remove any non-letters from the start of parameter name + auto it = std::find_if(std::begin(pName), std::end(pName), + [](const QChar &c) { return c.isLetter(); }); + parameters[i].setName( + pName.remove(0, std::distance(std::begin(pName), it))); } } } |