[tidy] Move private ast matchers into anonymous namespaces to avoid ODR conflicts.

No functionality change intended.

llvm-svn: 325467
This commit is contained in:
Benjamin Kramer 2018-02-18 19:02:35 +00:00
parent adf6e88c74
commit f8c99297d3
14 changed files with 39 additions and 17 deletions

View File

@ -15,10 +15,12 @@ namespace clang {
namespace tidy { namespace tidy {
namespace boost { namespace boost {
namespace {
AST_MATCHER(Type, isStrictlyInteger) { AST_MATCHER(Type, isStrictlyInteger) {
return Node.isIntegerType() && !Node.isAnyCharacterType() && return Node.isIntegerType() && !Node.isAnyCharacterType() &&
!Node.isBooleanType(); !Node.isBooleanType();
} }
} // namespace
void UseToStringCheck::registerMatchers(MatchFinder *Finder) { void UseToStringCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus) if (!getLangOpts().CPlusPlus)

View File

@ -18,9 +18,11 @@ namespace clang {
namespace tidy { namespace tidy {
namespace bugprone { namespace bugprone {
namespace {
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) { AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
return Node.getValue().getZExtValue() > N; return Node.getValue().getZExtValue() > N;
} }
} // namespace
StringConstructorCheck::StringConstructorCheck(StringRef Name, StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context) ClangTidyContext *Context)

View File

@ -19,11 +19,13 @@ namespace clang {
namespace tidy { namespace tidy {
namespace bugprone { namespace bugprone {
namespace {
AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
AST_MATCHER(CXXMethodDecl, isOverloadedOperator) { AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
return Node.isOverloadedOperator(); return Node.isOverloadedOperator();
} }
} // namespace
/// Finds out if the given method overrides some method. /// Finds out if the given method overrides some method.
static bool isOverrideMethod(const CXXMethodDecl *MD) { static bool isOverrideMethod(const CXXMethodDecl *MD) {

View File

@ -17,9 +17,11 @@ namespace clang {
namespace tidy { namespace tidy {
namespace cppcoreguidelines { namespace cppcoreguidelines {
namespace {
AST_MATCHER(GotoStmt, isForwardJumping) { AST_MATCHER(GotoStmt, isForwardJumping) {
return Node.getLocStart() < Node.getLabel()->getLocStart(); return Node.getLocStart() < Node.getLabel()->getLocStart();
} }
} // namespace
void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) { void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus) if (!getLangOpts().CPlusPlus)

View File

@ -17,6 +17,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace cppcoreguidelines { namespace cppcoreguidelines {
namespace {
AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt, AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt,
ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) { ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()}) for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
@ -46,6 +47,7 @@ AST_MATCHER_P(Expr, hasParentIgnoringImpCasts,
return InnerMatcher.matches(*E, Finder, Builder); return InnerMatcher.matches(*E, Finder, Builder);
} }
} // namespace
void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) { void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus) if (!getLangOpts().CPlusPlus)

View File

@ -18,11 +18,13 @@ namespace clang {
namespace tidy { namespace tidy {
namespace fuchsia { namespace fuchsia {
namespace {
AST_MATCHER(CXXRecordDecl, hasBases) { AST_MATCHER(CXXRecordDecl, hasBases) {
if (Node.hasDefinition()) if (Node.hasDefinition())
return Node.getNumBases() > 0; return Node.getNumBases() > 0;
return false; return false;
} }
} // namespace
// Adds a node (by name) to the interface map, if it was not present in the map // Adds a node (by name) to the interface map, if it was not present in the map
// previously. // previously.

View File

@ -15,6 +15,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace fuchsia { namespace fuchsia {
namespace {
AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) { AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) { if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
if (CXXMethodNode->isCopyAssignmentOperator() || if (CXXMethodNode->isCopyAssignmentOperator() ||
@ -23,6 +24,7 @@ AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
} }
return Node.isOverloadedOperator(); return Node.isOverloadedOperator();
} }
} // namespace
void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) { void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"), Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),

View File

@ -15,6 +15,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace fuchsia { namespace fuchsia {
namespace {
AST_MATCHER(Expr, isConstantInitializer) { AST_MATCHER(Expr, isConstantInitializer) {
return Node.isConstantInitializer(Finder->getASTContext(), false); return Node.isConstantInitializer(Finder->getASTContext(), false);
} }
@ -22,6 +23,7 @@ AST_MATCHER(Expr, isConstantInitializer) {
AST_MATCHER(VarDecl, isGlobalStatic) { AST_MATCHER(VarDecl, isGlobalStatic) {
return Node.getStorageDuration() == SD_Static && !Node.isLocalVarDecl(); return Node.getStorageDuration() == SD_Static && !Node.isLocalVarDecl();
} }
} // namespace
void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) { void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) {
// Constructing global, non-trivial objects with static storage is // Constructing global, non-trivial objects with static storage is

View File

@ -15,18 +15,16 @@
using namespace clang::ast_matchers; using namespace clang::ast_matchers;
namespace clang { namespace clang {
namespace ast_matchers {
const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;
} // namespace ast_matchers
namespace tidy { namespace tidy {
namespace fuchsia { namespace fuchsia {
namespace {
const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;
AST_MATCHER(FunctionDecl, hasTrailingReturn) { AST_MATCHER(FunctionDecl, hasTrailingReturn) {
return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn(); return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn();
} }
} // namespace
void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) { void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {

View File

@ -17,6 +17,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace fuchsia { namespace fuchsia {
namespace {
AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) { AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
if (!Node.hasDefinition()) return false; if (!Node.hasDefinition()) return false;
if (!Node.getNumVBases()) return false; if (!Node.getNumVBases()) return false;
@ -24,6 +25,7 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
if (Base.isVirtual()) return true; if (Base.isVirtual()) return true;
return false; return false;
} }
} // namespace
void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) { void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) {
// Defining classes using direct virtual inheritance is disallowed. // Defining classes using direct virtual inheritance is disallowed.

View File

@ -13,18 +13,17 @@
using namespace clang::ast_matchers; using namespace clang::ast_matchers;
namespace clang {
namespace ast_matchers {
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
fileScopeAsmDecl;
}
}
namespace clang { namespace clang {
namespace tidy { namespace tidy {
namespace hicpp { namespace hicpp {
namespace {
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
FileScopeAsmDecl>
fileScopeAsmDecl;
} // namespace
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) { void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(asmStmt().bind("asm-stmt"), this); Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this); Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);

View File

@ -17,12 +17,14 @@ namespace clang {
namespace tidy { namespace tidy {
namespace misc { namespace misc {
namespace {
AST_MATCHER(StringLiteral, containsNul) { AST_MATCHER(StringLiteral, containsNul) {
for (size_t i = 0; i < Node.getLength(); ++i) for (size_t i = 0; i < Node.getLength(); ++i)
if (Node.getCodeUnit(i) == '\0') if (Node.getCodeUnit(i) == '\0')
return true; return true;
return false; return false;
} }
} // namespace
void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) { void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) {
// Match a string that contains embedded NUL character. Extra-checks are // Match a string that contains embedded NUL character. Extra-checks are

View File

@ -23,6 +23,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace modernize { namespace modernize {
namespace {
/// \brief Matches move-constructible classes. /// \brief Matches move-constructible classes.
/// ///
/// Given /// Given
@ -44,6 +45,7 @@ AST_MATCHER(CXXRecordDecl, isMoveConstructible) {
} }
return false; return false;
} }
} // namespace
static TypeMatcher constRefType() { static TypeMatcher constRefType() {
return lValueReferenceType(pointee(isConstQualified())); return lValueReferenceType(pointee(isConstQualified()));

View File

@ -21,6 +21,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace modernize { namespace modernize {
namespace {
static const char AutoPtrTokenId[] = "AutoPrTokenId"; static const char AutoPtrTokenId[] = "AutoPrTokenId";
static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId"; static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId";
@ -69,6 +70,8 @@ AST_MATCHER(Decl, isFromStdNamespace) {
return (Info && Info->isStr("std")); return (Info && Info->isStr("std"));
} }
} // namespace
ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name, ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
ClangTidyContext *Context) ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), : ClangTidyCheck(Name, Context),