diff options
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 460c94365..cace61b9c 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -244,7 +244,7 @@ static Node *findNodeForCursor(QDocDatabase* qdb, CXCursor cur) { case CXCursor_Constructor: case CXCursor_Destructor: case CXCursor_ConversionFunction: { - NodeList candidates; + NodeVector candidates; parent->findChildren(functionName(cur), candidates); if (candidates.isEmpty()) return nullptr; @@ -256,19 +256,19 @@ static Node *findNodeForCursor(QDocDatabase* qdb, CXCursor cur) { if (!candidate->isFunction(Node::CPP)) continue; auto fn = static_cast<FunctionNode*>(candidate); - const auto &funcParams = fn->parameters(); - const int actualArg = numArg - fn->isPrivateSignal(); - if (funcParams.count() != (actualArg + isVariadic)) + const Parameters ¶meters = fn->parameters(); + const int actualArg = numArg - parameters.isPrivateSignal(); + if (parameters.count() != actualArg + isVariadic) continue; if (fn->isConst() != bool(clang_CXXMethod_isConst(cur))) continue; - if (isVariadic && funcParams.last().dataType() != QLatin1String("...")) + if (isVariadic && parameters.last().type() != QLatin1String("...")) continue; bool different = false; for (int i = 0; i < actualArg; i++) { if (args.size() <= i) args.append(fromCXString(clang_getTypeSpelling(clang_getArgType(funcType, i)))); - QString t1 = funcParams.at(i).dataType(); + QString t1 = parameters.at(i).type(); QString t2 = args.at(i); auto p2 = parent; while (p2 && t1 != t2) { @@ -323,7 +323,7 @@ static Node *findFunctionNodeForCursor(QDocDatabase* qdb, CXCursor cur) { case CXCursor_Constructor: case CXCursor_Destructor: case CXCursor_ConversionFunction: { - NodeList candidates; + NodeVector candidates; parent->findChildren(functionName(cur), candidates); if (candidates.isEmpty()) return nullptr; @@ -335,18 +335,18 @@ static Node *findFunctionNodeForCursor(QDocDatabase* qdb, CXCursor cur) { if (!candidate->isFunction(Node::CPP)) continue; auto fn = static_cast<FunctionNode*>(candidate); - const auto &funcParams = fn->parameters(); - if (funcParams.count() != (numArg + isVariadic)) + const Parameters ¶meters = fn->parameters(); + if (parameters.count() != (numArg + isVariadic)) continue; if (fn->isConst() != bool(clang_CXXMethod_isConst(cur))) continue; - if (isVariadic && funcParams.last().dataType() != QLatin1String("...")) + if (isVariadic && parameters.last().type() != QLatin1String("...")) continue; bool different = false; for (int i = 0; i < numArg; i++) { if (args.size() <= i) args.append(fromCXString(clang_getTypeSpelling(clang_getArgType(funcType, i)))); - QString t1 = funcParams.at(i).dataType(); + QString t1 = parameters.at(i).type(); QString t2 = args.at(i); auto p2 = parent; while (p2 && t1 != t2) { @@ -691,15 +691,17 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l for (uint i = 0; i < numOverridden; ++i) { QString path = reconstructQualifiedPathForCursor(overridden[i]); if (!path.isEmpty()) { - fn->setReimplementedFrom(path); + fn->setOverride(true); + fn->setOverridesThis(path); break; } } clang_disposeOverriddenCursors(overridden); } auto numArg = clang_getNumArgTypes(funcType); - QVector<Parameter> pvect; - pvect.reserve(numArg); + Parameters ¶meters = fn->parameters(); + parameters.clear(); + parameters.reserve(numArg); for (int i = 0; i < numArg; ++i) { CXType argType = clang_getArgType(funcType, i); if (fn->isCtor()) { @@ -715,15 +717,16 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l else if (argType.kind == CXType_LValueReference) fn->setMetaness(FunctionNode::CAssign); } - pvect.append(Parameter(adjustTypeName(fromCXString(clang_getTypeSpelling(argType))))); + parameters.append(adjustTypeName(fromCXString(clang_getTypeSpelling(argType)))); } - if (pvect.size() > 0 && pvect.last().dataType().endsWith(QLatin1String("::QPrivateSignal"))) { - pvect.pop_back(); // remove the QPrivateSignal argument - fn->setPrivateSignal(); + if (parameters.count() > 0) { + if (parameters.last().type().endsWith(QLatin1String("::QPrivateSignal"))) { + parameters.pop_back(); // remove the QPrivateSignal argument + parameters.setPrivateSignal(); + } } if (clang_isFunctionTypeVariadic(funcType)) - pvect.append(Parameter(QStringLiteral("..."))); - fn->setParameters(pvect); + parameters.append(QStringLiteral("...")); readParameterNamesAndAttributes(fn, cursor); return CXChildVisit_Continue; } @@ -836,7 +839,7 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l void ClangVisitor::readParameterNamesAndAttributes(FunctionNode* fn, CXCursor cursor) { - auto pvect = fn->parameters(); + Parameters ¶meters = fn->parameters(); // Visit the parameters and attributes int i = 0; visitChildrenLambda(cursor, [&](CXCursor cur) { @@ -853,11 +856,11 @@ void ClangVisitor::readParameterNamesAndAttributes(FunctionNode* fn, CXCursor cu } else if (kind == CXCursor_CXXOverrideAttr) { fn->setOverride(true); } else if (kind == CXCursor_ParmDecl) { - if (i >= pvect.count()) + if (i >= parameters.count()) return CXChildVisit_Break; // Attributes comes before parameters so we can break. QString name = fromCXString(clang_getCursorSpelling(cur)); if (!name.isEmpty()) - pvect[i].setName(name); + parameters[i].setName(name); // Find the default value visitChildrenLambda(cur, [&](CXCursor cur) { if (clang_isExpression(clang_getCursorKind(cur))) { @@ -866,7 +869,7 @@ void ClangVisitor::readParameterNamesAndAttributes(FunctionNode* fn, CXCursor cu defaultValue = defaultValue.midRef(1).trimmed().toString(); if (defaultValue.isEmpty()) defaultValue = QStringLiteral("..."); - pvect[i].setDefaultValue(defaultValue); + parameters[i].setDefaultValue(defaultValue); return CXChildVisit_Break; } return CXChildVisit_Continue; @@ -875,7 +878,6 @@ void ClangVisitor::readParameterNamesAndAttributes(FunctionNode* fn, CXCursor cu } return CXChildVisit_Continue; }); - fn->setParameters(pvect); } void ClangVisitor::parseProperty(const QString& spelling, const Location& loc) @@ -1109,7 +1111,6 @@ static const char *defaultArgs_[] = { "-Wno-nullability-completeness", "-I" CLANG_RESOURCE_DIR }; -static QByteArray clangResourcePath = "-I"; /*! Load the default arguments and the defines into \a args. @@ -1154,7 +1155,6 @@ void ClangCodeParser::getMoreArgs() */ auto forest = qdb_->searchOrder(); - printParsingErrors_ = 0; QByteArray version = qdb_->version().toUtf8(); QString basicIncludeDir = QDir::cleanPath(QString(Config::installDir + "/../include")); moreArgs_ += "-I" + basicIncludeDir.toLatin1(); @@ -1326,6 +1326,11 @@ static float getUnpatchedVersion(QString t) */ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QString& filePath) { + /* + The set of open namespaces is cleared before parsing + each source file. The word "source" here means cpp file. + */ + qdb_->clearOpenNamespaces(); currentFile_ = filePath; flags_ = static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete | CXTranslationUnit_SkipFunctionBodies | CXTranslationUnit_KeepGoing); index_ = clang_createIndex(1, 0); @@ -1336,6 +1341,7 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin args_.push_back("-include-pch"); args_.push_back(pchName_.constData()); } + getMoreArgs(); for (const auto &p : qAsConst(moreArgs_)) args_.push_back(p.constData()); @@ -1356,7 +1362,7 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin CXToken *tokens; unsigned int numTokens = 0; - const QSet<QString>& metacommands = topicCommands() + otherMetaCommands(); + const QSet<QString> &commands = topicCommands() + metaCommands(); clang_tokenize(tu, clang_getCursorExtent(cur), &tokens, &numTokens); for (unsigned int i = 0; i < numTokens; ++i) { @@ -1371,7 +1377,7 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin Doc::trimCStyleComment(loc,comment); // Doc constructor parses the comment. - Doc doc(loc, end_loc, comment, metacommands, topicCommands()); + Doc doc(loc, end_loc, comment, commands, topicCommands()); if (hasTooManyTopics(doc)) continue; @@ -1416,7 +1422,7 @@ void ClangCodeParser::parseSourceFile(const Location& /*location*/, const QStrin } else { processTopicArgs(doc, topic, nodes, docs); } - processOtherMetaCommands(nodes, docs); + processMetaCommands(nodes, docs); } clang_disposeTokens(tu, tokens, numTokens); @@ -1459,9 +1465,9 @@ Node* ClangCodeParser::parseFnArg(const Location& location, const QString& fnArg QString params = rightParenSplit[0]; if (!params.isEmpty()) { QStringList commaSplit = params.split(','); - QVector<Parameter>& pvect = fn->parameters(); - if (pvect.size() == commaSplit.size()) { - for (int i = 0; i < pvect.size(); ++i) { + 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) { QString pName = blankSplit.last(); @@ -1470,8 +1476,8 @@ Node* ClangCodeParser::parseFnArg(const Location& location, const QString& fnArg j++; if (j > 0) pName = pName.mid(j); - if (!pName.isEmpty() && pName != pvect[i].name()) - pvect[i].setName(pName); + if (!pName.isEmpty() && pName != parameters[i].name()) + parameters[i].setName(pName); } } } @@ -1529,6 +1535,11 @@ Node* ClangCodeParser::parseFnArg(const Location& location, const QString& fnArg ClangVisitor visitor(qdb_, allHeaders_); bool ignoreSignature = false; visitor.visitFnArg(cur, &fnNode, ignoreSignature); + /* + If the visitor couldn't find a FunctionNode for the + signature, then print the clang diagnostics if there + were any. + */ if (fnNode == nullptr) { unsigned diagnosticCount = clang_getNumDiagnostics(tu); if (diagnosticCount > 0 && (!Generator::preparing() || Generator::singleExec())) { |