[clang-tools-extra] 4e3f4f0 - [ASTMatchers] StringRef'ify hasName
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 29 01:53:28 PST 2020
Author: Benjamin Kramer
Date: 2020-01-29T10:53:08+01:00
New Revision: 4e3f4f03f3e4dccfac6212a66d54d584fea328a2
URL: https://github.com/llvm/llvm-project/commit/4e3f4f03f3e4dccfac6212a66d54d584fea328a2
DIFF: https://github.com/llvm/llvm-project/commit/4e3f4f03f3e4dccfac6212a66d54d584fea328a2.diff
LOG: [ASTMatchers] StringRef'ify hasName
This was just inconvenient, and we make a copy anyways.
Added:
Modified:
clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/DeclPrinterTest.cpp
clang/unittests/AST/NamedDeclPrinterTest.cpp
clang/unittests/AST/StmtPrinterTest.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
clang/unittests/StaticAnalyzer/Reusables.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index f3bcc2a220fb..4bcb46b39032 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -36,8 +36,7 @@ using llvm::SmallSetVector;
static const RecordDecl *findDefinition(StringRef RecordName,
ASTContext &Context) {
auto Results =
- match(recordDecl(hasName(std::string(RecordName)), isDefinition())
- .bind("recordDecl"),
+ match(recordDecl(hasName(RecordName), isDefinition()).bind("recordDecl"),
Context);
if (Results.empty()) {
llvm::errs() << "Definition of " << RecordName << " not found\n";
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
index d4db02174f50..3466cdbbdcff 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
@@ -91,8 +91,7 @@ rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
DurationScale Scale, const Expr &Node) {
llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
if (const auto *MaybeCallArg = selectFirst<const Expr>(
- "e", match(callExpr(callee(functionDecl(
- hasName(std::string(InverseFunction)))),
+ "e", match(callExpr(callee(functionDecl(hasName(InverseFunction))),
hasArgument(0, expr().bind("e"))),
Node, *Result.Context))) {
return tooling::fixit::getText(*MaybeCallArg, *Result.Context).str();
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
index 78ef1cca36e9..a3866651dced 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -108,11 +108,11 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
// a 'Duration'. If we know the result is a 'Duration', we can then infer
// that the second operand must be a 'Time'.
auto CallMatcher =
- callExpr(callee(functionDecl(
- hasName(std::string(getDurationFactoryForScale(*Scale))))),
- hasArgument(0, binaryOperator(hasOperatorName("-"),
- hasLHS(TimeInverseMatcher))
- .bind("binop")))
+ callExpr(
+ callee(functionDecl(hasName(getDurationFactoryForScale(*Scale)))),
+ hasArgument(0, binaryOperator(hasOperatorName("-"),
+ hasLHS(TimeInverseMatcher))
+ .bind("binop")))
.bind("outer_call");
Finder->addMatcher(CallMatcher, this);
@@ -160,8 +160,8 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
// latter case (addressed first), we also need to worry about parenthesis.
const auto *MaybeCallArg = selectFirst<const CallExpr>(
"arg", match(expr(hasAncestor(
- callExpr(callee(functionDecl(hasName(std::string(
- getDurationFactoryForScale(*Scale))))))
+ callExpr(callee(functionDecl(hasName(
+ getDurationFactoryForScale(*Scale)))))
.bind("arg"))),
*BinOp, *Result.Context));
if (MaybeCallArg && MaybeCallArg->getArg(0)->IgnoreImpCasts() == BinOp &&
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index 2db2300693a0..27307c000f78 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -242,10 +242,10 @@ static bool
derivedTypeHasReplacementMethod(const MatchFinder::MatchResult &Result,
llvm::StringRef ReplacementMethod) {
const auto *Class = Result.Nodes.getNodeAs<CXXRecordDecl>("class");
- return !match(cxxRecordDecl(unless(isExpansionInFileMatching(
- "gtest/gtest(-typed-test)?\\.h$")),
- hasMethod(cxxMethodDecl(
- hasName(std::string(ReplacementMethod))))),
+ return !match(cxxRecordDecl(
+ unless(isExpansionInFileMatching(
+ "gtest/gtest(-typed-test)?\\.h$")),
+ hasMethod(cxxMethodDecl(hasName(ReplacementMethod)))),
*Class, *Result.Context)
.empty();
}
diff --git a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
index 934bee29cb26..e852532af418 100644
--- a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp
@@ -58,7 +58,7 @@ Optional<FixItHint> UsingInserter::createUsingDeclaration(
return None;
}
// Find conflicting declarations and references.
- auto ConflictingDecl = namedDecl(hasName(std::string(UnqualifiedName)));
+ auto ConflictingDecl = namedDecl(hasName(UnqualifiedName));
bool HasConflictingDeclaration =
!match(findAll(ConflictingDecl), *Function, Context).empty();
bool HasConflictingDeclRef =
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2e932dbf3daa..ac6ce076d60d 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2663,8 +2663,9 @@ inline internal::Matcher<Stmt> sizeOfExpr(
/// \code
/// namespace a { namespace b { class X; } }
/// \endcode
-inline internal::Matcher<NamedDecl> hasName(const std::string &Name) {
- return internal::Matcher<NamedDecl>(new internal::HasNameMatcher({Name}));
+inline internal::Matcher<NamedDecl> hasName(StringRef Name) {
+ return internal::Matcher<NamedDecl>(
+ new internal::HasNameMatcher({std::string(Name)}));
}
/// Matches NamedDecl nodes that have any of the specified names.
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 8c3dc6caba56..3e8f804374f4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -115,8 +115,8 @@ class TestImportBase : public CompilerOptionSpecificTest,
const BindableMatcher<NodeType> &VerificationMatcher) {
return testImport(
FromCode, FromArgs, ToCode, ToArgs, Verifier,
- translationUnitDecl(has(namedDecl(hasName(std::string(DeclToImportID)))
- .bind(DeclToImportID))),
+ translationUnitDecl(
+ has(namedDecl(hasName(DeclToImportID)).bind(DeclToImportID))),
VerificationMatcher);
}
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index 3bb17aba96c2..f85358b8f6c8 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -108,9 +108,8 @@ PrintedDeclCXX98Matches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted,
PrintingPolicyModifier PolicyModifier = nullptr) {
std::vector<std::string> Args(1, "-std=c++98");
- return PrintedDeclMatches(
- Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"),
- ExpectedPrinted, "input.cc", PolicyModifier);
+ return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.cc", PolicyModifier);
}
::testing::AssertionResult
@@ -130,9 +129,8 @@ ::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args(1, "-std=c++11");
- return PrintedDeclMatches(
- Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"),
- ExpectedPrinted, "input.cc");
+ return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.cc");
}
::testing::AssertionResult PrintedDeclCXX11Matches(
diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp
index d5077b8da868..a38b28bddaf4 100644
--- a/clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -112,45 +112,41 @@ ::testing::AssertionResult
PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args(1, "-std=c++98");
- return PrintedNamedDeclMatches(
- Code, Args,
- /*SuppressUnwrittenScope*/ false,
- namedDecl(hasName(std::string(DeclName))).bind("id"), ExpectedPrinted,
- "input.cc");
+ return PrintedNamedDeclMatches(Code, Args,
+ /*SuppressUnwrittenScope*/ false,
+ namedDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.cc");
}
::testing::AssertionResult
PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args(1, "-std=c++11");
- return PrintedNamedDeclMatches(
- Code, Args,
- /*SuppressUnwrittenScope*/ true,
- namedDecl(hasName(std::string(DeclName))).bind("id"), ExpectedPrinted,
- "input.cc");
+ return PrintedNamedDeclMatches(Code, Args,
+ /*SuppressUnwrittenScope*/ true,
+ namedDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.cc");
}
::testing::AssertionResult
PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args{"-std=c++11", "-xobjective-c++"};
- return PrintedNamedDeclMatches(
- Code, Args,
- /*SuppressUnwrittenScope*/ true,
- objcPropertyDecl(hasName(std::string(DeclName))).bind("id"),
- ExpectedPrinted, "input.m");
+ return PrintedNamedDeclMatches(Code, Args,
+ /*SuppressUnwrittenScope*/ true,
+ objcPropertyDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.m");
}
::testing::AssertionResult
PrintedNestedNameSpecifierMatches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args{"-std=c++11"};
- return PrintedDeclMatches(
- Code, Args, namedDecl(hasName(std::string(DeclName))).bind("id"),
- ExpectedPrinted, "input.cc",
- [](llvm::raw_ostream &Out, const NamedDecl *D) {
- D->printNestedNameSpecifier(Out);
- });
+ return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"),
+ ExpectedPrinted, "input.cc",
+ [](llvm::raw_ostream &Out, const NamedDecl *D) {
+ D->printNestedNameSpecifier(Out);
+ });
}
} // unnamed namespace
diff --git a/clang/unittests/AST/StmtPrinterTest.cpp b/clang/unittests/AST/StmtPrinterTest.cpp
index 76195af6636a..080c18b0737b 100644
--- a/clang/unittests/AST/StmtPrinterTest.cpp
+++ b/clang/unittests/AST/StmtPrinterTest.cpp
@@ -34,7 +34,7 @@ namespace {
enum class StdVer { CXX98, CXX11, CXX14, CXX17, CXX2a };
DeclarationMatcher FunctionBodyMatcher(StringRef ContainingFunction) {
- return functionDecl(hasName(std::string(ContainingFunction)),
+ return functionDecl(hasName(ContainingFunction),
has(compoundStmt(has(stmt().bind("id")))));
}
diff --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index b24ec07f399b..1c3e00ca4ae8 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -44,7 +44,7 @@ std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code) {
}
ExprMatcher declRefTo(StringRef Name) {
- return declRefExpr(to(namedDecl(hasName(std::string(Name)))));
+ return declRefExpr(to(namedDecl(hasName(Name))));
}
StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {
diff --git a/clang/unittests/StaticAnalyzer/Reusables.h b/clang/unittests/StaticAnalyzer/Reusables.h
index db9c085272db..bac2808369c2 100644
--- a/clang/unittests/StaticAnalyzer/Reusables.h
+++ b/clang/unittests/StaticAnalyzer/Reusables.h
@@ -34,7 +34,7 @@ const T *findNode(const Decl *Where, MatcherT What) {
template <typename T>
const T *findDeclByName(const Decl *Where, StringRef Name) {
using namespace ast_matchers;
- return findNode<T>(Where, namedDecl(hasName(std::string(Name))));
+ return findNode<T>(Where, namedDecl(hasName(Name)));
}
// A re-usable consumer that constructs ExprEngine out of CompilerInvocation.
More information about the cfe-commits
mailing list