diff options
author | Paul Wicking <paul.wicking@qt.io> | 2021-04-28 13:36:28 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2021-05-03 10:05:04 +0200 |
commit | 6f462ac37916d9fc3fae793e040690741845ef62 (patch) | |
tree | 66bc4b997e0b38cd3d2cd86e8787d54672ca38a6 /src/qdoc/clangcodeparser.cpp | |
parent | a1ed48d0d073a8bdd7b5e608982a5bbd9af47af8 (diff) | |
download | qttools-6f462ac37916d9fc3fae793e040690741845ef62.tar.gz |
QDoc: Code cleanup
* Use multiple arguments for QStrings instead of calling
.arg() multiple times.
* Define trivial constructor/destructor '= default' instead of adding
empty implementations.
* Remove unreachable code.
* Prefer ranged-based for loops.
* Initialize with auto from static_cast<>() and new.
* Simplify expressions.
* Prefer "QList::empty()" over "QList::size() > 0".
* Remove unused method.
* Return qsizetype instead of int to avoid narrowing conversion.
* Remove unused include.
* Remove unreachable return statement.
* Prefer raw string literals over escaped regexes.
* Initialize struct members.
* Make variables used as const refs const refs.
* Use std::move instead of passing const ref in ctor.
* Drop redundant 'virtual' from methods marked 'override'.
* Make local copies that arent ever modified const refs to avoid copying.
* Turn for-loop into std::any_of.
* Made single-argument constructor explicit.
* Don't shadow variable names from outer scope if not necessary.
* Remove const at top level that does not improve const correctness.
* Update copyright notice for affected classes.
Task-number: QTBUG-71176
Change-Id: Ia41e5b947b72f594b60d189b6b0ff68587c3afb9
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 75 |
1 files changed, 24 insertions, 51 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 866b8119d..16a632ec5 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the tools applications of the Qt Toolkit. @@ -37,10 +37,6 @@ ** ****************************************************************************/ -/* - clangcodeparser.cpp -*/ - #include "clangcodeparser.h" #include "access.h" @@ -461,7 +457,7 @@ private: */ struct SimpleLoc { - unsigned int line, column; + unsigned int line {}, column {}; friend bool operator<(const SimpleLoc &a, const SimpleLoc &b) { return a.line != b.line ? a.line < b.line : a.column < b.column; @@ -582,8 +578,8 @@ CXChildVisitResult ClangVisitor::visitFnSignature(CXCursor cursor, CXSourceLocat *fnNode = findNodeForCursor(qdb_, cursor); if (*fnNode) { if ((*fnNode)->isFunction(Node::CPP)) { - FunctionNode *fn = static_cast<FunctionNode *>(*fnNode); - readParameterNamesAndAttributes(fn, cursor); + auto *fn = static_cast<FunctionNode *>(*fnNode); + readParameterNamesAndAttributes(fn, cursor); } } else { // Possibly an implicitly generated special member QString name = functionName(cursor); @@ -622,14 +618,14 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l if (typeAlias.size() == 2) { typeAlias[0] = typeAlias[0].trimmed(); const QLatin1String usingString("using "); - int usingPos = typeAlias[0].indexOf(usingString); + qsizetype usingPos = typeAlias[0].indexOf(usingString); if (usingPos != -1) { if (kind == CXCursor_TypeAliasTemplateDecl) templateString = typeAlias[0].left(usingPos).trimmed(); typeAlias[0].remove(0, usingPos + usingString.size()); typeAlias[0] = typeAlias[0].split(QLatin1Char(' ')).first(); typeAlias[1] = typeAlias[1].trimmed(); - TypeAliasNode *ta = new TypeAliasNode(parent_, typeAlias[0], typeAlias[1]); + auto *ta = new TypeAliasNode(parent_, typeAlias[0], typeAlias[1]); ta->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); ta->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); ta->setTemplateDecl(templateString); @@ -668,7 +664,7 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l else if (actualKind == CXCursor_UnionDecl) type = Node::Union; - ClassNode *classe = new ClassNode(type, semanticParent, className); + auto *classe = new ClassNode(type, semanticParent, className); classe->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); classe->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); @@ -688,8 +684,8 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l auto classe = static_cast<ClassNode *>(parent_); if (baseNode == nullptr || !baseNode->isClassNode()) { QString bcName = reconstructQualifiedPathForCursor(baseCursor); - classe->addUnresolvedBaseClass( - access, bcName.split(QLatin1String("::"), Qt::SkipEmptyParts), bcName); + classe->addUnresolvedBaseClass(access, + bcName.split(QLatin1String("::"), Qt::SkipEmptyParts)); return CXChildVisit_Continue; } auto baseClasse = static_cast<ClassNode *>(baseNode); @@ -724,14 +720,14 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l if (ignoredSymbol(name)) return CXChildVisit_Continue; - FunctionNode *fn = new FunctionNode(parent_, name); + auto *fn = new FunctionNode(parent_, name); CXSourceRange range = clang_Cursor_getCommentRange(cursor); if (!clang_Range_isNull(range)) { QString comment = getSpelling(range); if (comment.startsWith("//!")) { - int tag = comment.indexOf(QChar('[')); + qsizetype tag = comment.indexOf(QChar('[')); if (tag > 0) { - int end = comment.indexOf(QChar(']'), tag); + qsizetype end = comment.indexOf(QChar(']'), tag); if (end > 0) fn->setTag(comment.mid(tag, 1 + end - tag)); } @@ -749,7 +745,7 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l } #endif case CXCursor_EnumDecl: { - EnumNode *en = static_cast<EnumNode *>(findNodeForCursor(qdb_, cursor)); + auto *en = static_cast<EnumNode *>(findNodeForCursor(qdb_, cursor)); if (en && en->items().count()) return CXChildVisit_Continue; // Was already parsed, probably in another TU QString enumTypeName = fromCXString(clang_getCursorSpelling(cursor)); @@ -810,7 +806,7 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l case CXCursor_TypedefDecl: { if (findNodeForCursor(qdb_, cursor)) // Was already parsed, probably in another TU return CXChildVisit_Continue; - TypedefNode *td = new TypedefNode(parent_, fromCXString(clang_getCursorSpelling(cursor))); + auto *td = new TypedefNode(parent_, fromCXString(clang_getCursorSpelling(cursor))); td->setAccess(fromCX_CXXAccessSpecifier(clang_getCXXAccessSpecifier(cursor))); td->setLocation(fromCXSourceLocation(clang_getCursorLocation(cursor))); // Search to see if this is a Q_DECLARE_FLAGS (if the type is QFlags<ENUM>) @@ -966,8 +962,8 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) && !spelling.startsWith(QLatin1String("Q_OVERRIDE"))) return false; - int lpIdx = spelling.indexOf(QChar('(')); - int rpIdx = spelling.lastIndexOf(QChar(')')); + qsizetype lpIdx = spelling.indexOf(QChar('(')); + qsizetype rpIdx = spelling.lastIndexOf(QChar(')')); if (lpIdx <= 0 || rpIdx <= lpIdx) return false; @@ -983,10 +979,10 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) parts.removeFirst(); // QTBUG-80027 type = parts.takeFirst(); - if (type == QLatin1String("const") && parts.size() > 0) + if (type == QLatin1String("const") && !parts.empty()) type += " " + parts.takeFirst(); - if (parts.size() > 0) + if (!parts.empty()) name = parts.takeFirst(); else return false; @@ -1006,8 +1002,6 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) // Keywords with no associated values if (key == "CONSTANT") { property->setConstant(); - } else if (key == "FINAL") { - property->setFinal(); } else if (key == "REQUIRED") { property->setRequired(); } @@ -1028,7 +1022,6 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) property->setDesignable(false); else { property->setDesignable(false); - property->setRuntimeDesFunc(value); } } else if (key == "BINDABLE") { property->setPropertyType(PropertyNode::Bindable); @@ -1036,14 +1029,6 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) qdb_->addPropertyFunction(property, value, PropertyNode::Resetter); } else if (key == "NOTIFY") { qdb_->addPropertyFunction(property, value, PropertyNode::Notifier); - } else if (key == "REVISION") { - int revision; - bool ok; - revision = value.toInt(&ok); - if (ok) - property->setRevision(revision); - else - loc.warning(QStringLiteral("Invalid revision number: %1").arg(value)); } else if (key == "SCRIPTABLE") { QString v = value.toLower(); if (v == "true") @@ -1052,7 +1037,6 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) property->setScriptable(false); else { property->setScriptable(false); - property->setRuntimeScrFunc(value); } } } @@ -1101,14 +1085,6 @@ Node *ClangVisitor::nodeForCommentAtLocation(CXSourceLocation loc, CXSourceLocat } /*! - The destructor is trivial. - */ -ClangCodeParser::~ClangCodeParser() -{ - // nothing. -} - -/*! Get the include paths from the qdoc configuration database \a config. Call the initializeParser() in the base class. Get the defines list from the qdocconf database. @@ -1290,9 +1266,7 @@ void ClangCodeParser::getMoreArgs() that list instead. */ qCWarning(lcQdoc) << "No include paths passed to qdoc; guessing reasonable include paths"; - auto forest = qdb_->searchOrder(); - QByteArray version = qdb_->version().toUtf8(); QString basicIncludeDir = QDir::cleanPath(QString(Config::installDir + "/../include")); m_moreArgs += "-I" + basicIncludeDir.toLatin1(); m_moreArgs += includePathsFromHeaders(m_allHeaders); @@ -1567,8 +1541,7 @@ void ClangCodeParser::parseSourceFile(const Location & /*location*/, const QStri "topic command (e.g., '\\%1', '\\%2') in the " "comment and no function definition following " "the comment.") - .arg(COMMAND_FN) - .arg(COMMAND_PAGE)); + .arg(COMMAND_FN, COMMAND_PAGE)); } } } else { @@ -1625,11 +1598,11 @@ Node *ClangCodeParser::parseFnArg(const Location &location, const QString &fnArg they will be the names used in the documentation. */ QString fnSignature = fnArg.mid(tagEnd); - FunctionNode *fn = static_cast<FunctionNode *>(fnNode); + auto *fn = static_cast<FunctionNode *>(fnNode); QStringList leftParenSplit = fnSignature.mid(fnSignature.indexOf(fn->name())).split('('); if (leftParenSplit.size() > 1) { QStringList rightParenSplit = leftParenSplit[1].split(')'); - if (rightParenSplit.size() > 0) { + if (!rightParenSplit.empty()) { QString params = rightParenSplit[0]; if (!params.isEmpty()) { QStringList commaSplit = params.split(','); @@ -1654,9 +1627,9 @@ Node *ClangCodeParser::parseFnArg(const Location &location, const QString &fnArg } return fnNode; } - CXTranslationUnit_Flags flags = static_cast<CXTranslationUnit_Flags>( - CXTranslationUnit_Incomplete | CXTranslationUnit_SkipFunctionBodies - | CXTranslationUnit_KeepGoing); + auto flags = static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete + | CXTranslationUnit_SkipFunctionBodies + | CXTranslationUnit_KeepGoing); CXIndex index = clang_createIndex(1, kClangDontDisplayDiagnostics); |