[clang-tools-extra] c76edaa - [clang-tidy] Prune dead code. NFC.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 17 12:18:04 PDT 2020
Author: Benjamin Kramer
Date: 2020-06-17T21:16:59+02:00
New Revision: c76edaabddea8a9b077859fcfa4d1465b7ce6a46
URL: https://github.com/llvm/llvm-project/commit/c76edaabddea8a9b077859fcfa4d1465b7ce6a46
DIFF: https://github.com/llvm/llvm-project/commit/c76edaabddea8a9b077859fcfa4d1465b7ce6a46.diff
LOG: [clang-tidy] Prune dead code. NFC.
Added:
Modified:
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h
clang-tools-extra/clang-tidy/utils/FixItHintUtils.h
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
clang-tools-extra/clang-tidy/utils/IncludeSorter.h
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7c7de74a0c9e..6e7fcaa4345a 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<StringRef, IdentifierNamingCheck::CaseType>
{"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 53f9336b6fc7..c4bc1835057b 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<const DeclRefExpr *, 16>
-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<const DeclRefExpr *, 16> 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 11f25a4d2b83..abf3529cc0f6 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<const DeclRefExpr *, 16>
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<const DeclRefExpr *, 16>
-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 4fa5e0a8a4a2..2f5a74153f89 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 f7201a9fdcfe..df87dbe49cff 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
@@ -37,7 +37,7 @@ class IncludeInserterCallback : public PPCallbacks {
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<IncludeSorter>(
- &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 35cbb6ce8568..0d4b951beb1f 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.h
@@ -76,7 +76,6 @@ class IncludeInserter {
llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile;
llvm::DenseMap<FileID, std::set<std::string>> 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 a344fefdee11..6013412a4138 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<FixItHint> IncludeSorter::CreateIncludeInsertion(StringRef FileName,
IncludeStmt);
}
-std::vector<FixItHint> IncludeSorter::GetEdits() {
- if (SourceLocations.empty())
- return {};
-
- typedef std::map<int, std::pair<SourceRange, std::string>>
- 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<FixItHint> 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<std::pair<StringRef, IncludeSorter::IncludeStyle>>
IncludeSorter::getMapping() {
static constexpr std::pair<StringRef, IncludeSorter::IncludeStyle> Mapping[] =
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
index db8eadcc5615..7dab2cc536a4 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.h
@@ -38,22 +38,13 @@ class IncludeSorter {
/// ``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
diff erent blocks of includes are sorted separately
- /// within the same file).
- std::vector<FixItHint> 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<FixItHint> CreateIncludeInsertion(StringRef FileName, bool IsAngled);
@@ -62,7 +53,6 @@ class IncludeSorter {
typedef SmallVector<SourceRange, 1> 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 3301ba6343c7..03bece233240 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -195,10 +195,6 @@ class NameLookup {
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();
More information about the cfe-commits
mailing list