From c76edaabddea8a9b077859fcfa4d1465b7ce6a46 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 17 Jun 2020 21:16:59 +0200 Subject: [PATCH] [clang-tidy] Prune dead code. NFC. --- .../readability/IdentifierNamingCheck.cpp | 27 ----- .../clang-tidy/utils/DeclRefExprUtils.cpp | 34 ------- .../clang-tidy/utils/DeclRefExprUtils.h | 6 -- .../clang-tidy/utils/FixItHintUtils.h | 3 - .../clang-tidy/utils/IncludeInserter.cpp | 4 +- .../clang-tidy/utils/IncludeInserter.h | 1 - .../clang-tidy/utils/IncludeSorter.cpp | 109 +-------------------- clang-tools-extra/clang-tidy/utils/IncludeSorter.h | 14 +-- .../clang-tidy/utils/RenamerClangTidyCheck.cpp | 4 - 9 files changed, 8 insertions(+), 194 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index 7c7de74..6e7fcaa 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -109,33 +109,6 @@ static constexpr std::pair {"Camel_Snake_Case", IdentifierNamingCheck::CT_CamelSnakeCase}, {"camel_Snake_Back", IdentifierNamingCheck::CT_CamelSnakeBack}}; -namespace { -/// Callback supplies macros to IdentifierNamingCheck::checkMacro -class IdentifierNamingCheckPPCallbacks : public PPCallbacks { -public: - IdentifierNamingCheckPPCallbacks(Preprocessor *PP, - IdentifierNamingCheck *Check) - : PP(PP), Check(Check) {} - - /// MacroDefined calls checkMacro for macros in the main file - void MacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) override { - Check->checkMacro(PP->getSourceManager(), MacroNameTok, MD->getMacroInfo()); - } - - /// MacroExpands calls expandMacro for macros in the main file - void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, - SourceRange /*Range*/, - const MacroArgs * /*Args*/) override { - Check->expandMacro(MacroNameTok, MD.getMacroInfo()); - } - -private: - Preprocessor *PP; - IdentifierNamingCheck *Check; -}; -} // namespace - IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context) : RenamerClangTidyCheck(Name, Context), diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp index 53f9336..c4bc183 100644 --- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp @@ -70,40 +70,6 @@ constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, return DeclRefs; } -// Finds all DeclRefExprs where a const method is called on VarDecl or VarDecl -// is the a const reference or value argument to a CallExpr or CXXConstructExpr. -SmallPtrSet -constReferenceDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, - ASTContext &Context) { - auto DeclRefToVar = - declRefExpr(to(varDecl(equalsNode(&VarDecl)))).bind("declRef"); - auto ConstMethodCallee = callee(cxxMethodDecl(isConst())); - // Match method call expressions where the variable is referenced as the this - // implicit object argument and opertor call expression for member operators - // where the variable is the 0-th argument. - auto Matches = - match(decl(forEachDescendant(expr( - anyOf(cxxMemberCallExpr(ConstMethodCallee, on(DeclRefToVar)), - cxxOperatorCallExpr(ConstMethodCallee, - hasArgument(0, DeclRefToVar)))))), - Decl, Context); - SmallPtrSet DeclRefs; - extractNodesByIdTo(Matches, "declRef", DeclRefs); - auto ConstReferenceOrValue = - qualType(anyOf(referenceType(pointee(qualType(isConstQualified()))), - unless(anyOf(referenceType(), pointerType())))); - auto UsedAsConstRefOrValueArg = forEachArgumentWithParam( - DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValue))); - Matches = match(decl(forEachDescendant(callExpr(UsedAsConstRefOrValueArg))), - Decl, Context); - extractNodesByIdTo(Matches, "declRef", DeclRefs); - Matches = - match(decl(forEachDescendant(cxxConstructExpr(UsedAsConstRefOrValueArg))), - Decl, Context); - extractNodesByIdTo(Matches, "declRef", DeclRefs); - return DeclRefs; -} - bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt, ASTContext &Context) { // Collect all DeclRefExprs to the loop variable and all CallExprs and diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h index 11f25a4..abf3529 100644 --- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h +++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h @@ -41,12 +41,6 @@ llvm::SmallPtrSet constReferenceDeclRefExprs(const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context); -/// Returns set of all ``DeclRefExprs`` to ``VarDecl`` within ``Decl`` where -/// ``VarDecl`` is guaranteed to be accessed in a const fashion. -llvm::SmallPtrSet -constReferenceDeclRefExprs(const VarDecl &VarDecl, const Decl &Decl, - ASTContext &Context); - /// Returns ``true`` if ``DeclRefExpr`` is the argument of a copy-constructor /// call expression within ``Decl``. bool isCopyConstructorArgument(const DeclRefExpr &DeclRef, const Decl &Decl, diff --git a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.h b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.h index 4fa5e0a..2f5a741 100644 --- a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.h +++ b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.h @@ -21,9 +21,6 @@ namespace fixit { /// Creates fix to make ``VarDecl`` a reference by adding ``&``. FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context); -/// Creates fix to make ``VarDecl`` const qualified. -FixItHint changeVarDeclToConst(const VarDecl &Var); - /// This enum defines where the qualifier shall be preferably added. enum class QualifierPolicy { Left, // Add the qualifier always to the left side, if that is possible. diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index f7201a9..df87dbe 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -37,7 +37,7 @@ private: IncludeInserter::IncludeInserter(const SourceManager &SourceMgr, const LangOptions &LangOpts, IncludeSorter::IncludeStyle Style) - : SourceMgr(SourceMgr), LangOpts(LangOpts), Style(Style) {} + : SourceMgr(SourceMgr), Style(Style) {} IncludeInserter::~IncludeInserter() {} @@ -52,7 +52,7 @@ IncludeSorter &IncludeInserter::getOrCreate(FileID FileID) { if (!Entry) { // If it wasn't found, Entry will be default constructed to nullptr. Entry = std::make_unique( - &SourceMgr, &LangOpts, FileID, + &SourceMgr, FileID, SourceMgr.getFilename(SourceMgr.getLocForStartOfFile(FileID)), Style); } return *Entry; diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h index 35cbb6c..0d4b951 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h @@ -76,7 +76,6 @@ private: llvm::DenseMap> IncludeSorterByFile; llvm::DenseMap> InsertedHeaders; const SourceManager &SourceMgr; - const LangOptions &LangOpts; const IncludeSorter::IncludeStyle Style; friend class IncludeInserterCallback; }; diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp index a344fef..6013412 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp @@ -83,11 +83,10 @@ DetermineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile, } // namespace IncludeSorter::IncludeSorter(const SourceManager *SourceMgr, - const LangOptions *LangOpts, const FileID FileID, - StringRef FileName, IncludeStyle Style) - : SourceMgr(SourceMgr), LangOpts(LangOpts), Style(Style), - CurrentFileID(FileID), CanonicalFile(MakeCanonicalName(FileName, Style)) { -} + const FileID FileID, StringRef FileName, + IncludeStyle Style) + : SourceMgr(SourceMgr), Style(Style), CurrentFileID(FileID), + CanonicalFile(MakeCanonicalName(FileName, Style)) {} void IncludeSorter::AddInclude(StringRef FileName, bool IsAngled, SourceLocation HashLocation, @@ -175,106 +174,6 @@ Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName, IncludeStmt); } -std::vector IncludeSorter::GetEdits() { - if (SourceLocations.empty()) - return {}; - - typedef std::map> - FileLineToSourceEditMap; - FileLineToSourceEditMap Edits; - auto SourceLocationIterator = SourceLocations.begin(); - auto SourceLocationIteratorEnd = SourceLocations.end(); - - // Compute the Edits that need to be done to each line to add, replace, or - // delete inclusions. - for (int IncludeKind = 0; IncludeKind < IK_InvalidInclude; ++IncludeKind) { - std::sort(IncludeBucket[IncludeKind].begin(), - IncludeBucket[IncludeKind].end()); - for (const auto &IncludeEntry : IncludeBucket[IncludeKind]) { - auto &Location = IncludeLocations[IncludeEntry]; - SourceRangeVector::iterator LocationIterator = Location.begin(); - SourceRangeVector::iterator LocationIteratorEnd = Location.end(); - SourceRange FirstLocation = *LocationIterator; - - // If the first occurrence of a particular include is on the current - // source line we are examining, leave it alone. - if (FirstLocation == *SourceLocationIterator) - ++LocationIterator; - - // Add the deletion Edits for any (remaining) instances of this inclusion, - // and remove their Locations from the source Locations to be processed. - for (; LocationIterator != LocationIteratorEnd; ++LocationIterator) { - int LineNumber = - SourceMgr->getSpellingLineNumber(LocationIterator->getBegin()); - Edits[LineNumber] = std::make_pair(*LocationIterator, ""); - SourceLocationIteratorEnd = - std::remove(SourceLocationIterator, SourceLocationIteratorEnd, - *LocationIterator); - } - - if (FirstLocation == *SourceLocationIterator) { - // Do nothing except move to the next source Location (Location of an - // inclusion in the original, unchanged source file). - ++SourceLocationIterator; - continue; - } - - // Add (or append to) the replacement text for this line in source file. - int LineNumber = - SourceMgr->getSpellingLineNumber(SourceLocationIterator->getBegin()); - if (Edits.find(LineNumber) == Edits.end()) { - Edits[LineNumber].first = - SourceRange(SourceLocationIterator->getBegin()); - } - StringRef SourceText = Lexer::getSourceText( - CharSourceRange::getCharRange(FirstLocation), *SourceMgr, *LangOpts); - Edits[LineNumber].second.append(SourceText.data(), SourceText.size()); - } - - // Clear the bucket. - IncludeBucket[IncludeKind].clear(); - } - - // Go through the single-line Edits and combine them into blocks of Edits. - int CurrentEndLine = 0; - SourceRange CurrentRange; - std::string CurrentText; - std::vector Fixes; - for (const auto &LineEdit : Edits) { - // If the current edit is on the next line after the previous edit, add it - // to the current block edit. - if (LineEdit.first == CurrentEndLine + 1 && - CurrentRange.getBegin() != CurrentRange.getEnd()) { - SourceRange EditRange = LineEdit.second.first; - if (EditRange.getBegin() != EditRange.getEnd()) { - ++CurrentEndLine; - CurrentRange.setEnd(EditRange.getEnd()); - } - CurrentText += LineEdit.second.second; - // Otherwise report the current block edit and start a new block. - } else { - if (CurrentEndLine) { - Fixes.push_back(FixItHint::CreateReplacement( - CharSourceRange::getCharRange(CurrentRange), CurrentText)); - } - - CurrentEndLine = LineEdit.first; - CurrentRange = LineEdit.second.first; - CurrentText = LineEdit.second.second; - } - } - // Finally, report the current block edit if there is one. - if (CurrentEndLine) { - Fixes.push_back(FixItHint::CreateReplacement( - CharSourceRange::getCharRange(CurrentRange), CurrentText)); - } - - // Reset the remaining internal state. - SourceLocations.clear(); - IncludeLocations.clear(); - return Fixes; -} - llvm::ArrayRef> IncludeSorter::getMapping() { static constexpr std::pair Mapping[] = diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h index db8eadc..7dab2cc 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h +++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h @@ -38,22 +38,13 @@ public: /// ``IncludeSorter`` constructor; takes the FileID and name of the file to be /// processed by the sorter. - IncludeSorter(const SourceManager *SourceMgr, const LangOptions *LangOpts, - const FileID FileID, StringRef FileName, IncludeStyle Style); - - /// Returns the ``SourceManager``-specific file ID for the file being handled - /// by the sorter. - const FileID current_FileID() const { return CurrentFileID; } + IncludeSorter(const SourceManager *SourceMgr, const FileID FileID, + StringRef FileName, IncludeStyle Style); /// Adds the given include directive to the sorter. void AddInclude(StringRef FileName, bool IsAngled, SourceLocation HashLocation, SourceLocation EndLocation); - /// Returns the edits needed to sort the current set of includes and reset the - /// internal state (so that different blocks of includes are sorted separately - /// within the same file). - std::vector GetEdits(); - /// Creates a quoted inclusion directive in the right sort order. Returns None /// on error or if header inclusion directive for header already exists. Optional CreateIncludeInsertion(StringRef FileName, bool IsAngled); @@ -62,7 +53,6 @@ private: typedef SmallVector SourceRangeVector; const SourceManager *SourceMgr; - const LangOptions *LangOpts; const IncludeStyle Style; FileID CurrentFileID; /// The file name stripped of common suffixes. diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 3301ba6..03bece2 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -195,10 +195,6 @@ public: NameLookup() : NameLookup(nullptr) {} bool hasMultipleResolutions() const { return Data.getInt(); } - bool hasDecl() const { - assert(!hasMultipleResolutions() && "Found multiple decls"); - return Data.getPointer() != nullptr; - } const NamedDecl *getDecl() const { assert(!hasMultipleResolutions() && "Found multiple decls"); return Data.getPointer(); -- 2.7.4