// Match static functions/variable definitions which are defined in named
// namespaces.
- Optional<ast_matchers::internal::Matcher<NamedDecl>> HasAnySymbolNames;
+ SmallVector<std::string, 4> QualNames;
+ QualNames.reserve(Context->Spec.Names.size());
for (StringRef SymbolName : Context->Spec.Names) {
- llvm::StringRef GlobalSymbolName = SymbolName.trim().ltrim(':');
- const auto HasName = hasName(("::" + GlobalSymbolName).str());
- HasAnySymbolNames =
- HasAnySymbolNames ? anyOf(*HasAnySymbolNames, HasName) : HasName;
+ QualNames.push_back(("::" + SymbolName.trim().ltrim(':')).str());
}
- if (!HasAnySymbolNames) {
+ if (QualNames.empty()) {
llvm::errs() << "No symbols being moved.\n";
return;
}
+
+ ast_matchers::internal::Matcher<NamedDecl> HasAnySymbolNames =
+ hasAnyName(SmallVector<StringRef, 4>(QualNames.begin(), QualNames.end()));
+
auto InMovedClass =
- hasOutermostEnclosingClass(cxxRecordDecl(*HasAnySymbolNames));
+ hasOutermostEnclosingClass(cxxRecordDecl(HasAnySymbolNames));
// Matchers for helper declarations in old.cc.
auto InAnonymousNS = hasParent(namespaceDecl(isAnonymous()));
// Create a MatchCallback for class declarations.
MatchCallbacks.push_back(std::make_unique<ClassDeclarationMatch>(this));
// Match moved class declarations.
- auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
- isDefinition(), TopLevelDecl)
- .bind("moved_class");
+ auto MovedClass =
+ cxxRecordDecl(InOldFiles, HasAnySymbolNames, isDefinition(), TopLevelDecl)
+ .bind("moved_class");
Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
// Match moved class methods (static methods included) which are defined
// outside moved class declaration.
- Finder->addMatcher(
- cxxMethodDecl(InOldFiles, ofOutermostEnclosingClass(*HasAnySymbolNames),
- isDefinition())
- .bind("class_method"),
- MatchCallbacks.back().get());
+ Finder->addMatcher(cxxMethodDecl(InOldFiles,
+ ofOutermostEnclosingClass(HasAnySymbolNames),
+ isDefinition())
+ .bind("class_method"),
+ MatchCallbacks.back().get());
// Match static member variable definition of the moved class.
Finder->addMatcher(
varDecl(InMovedClass, InOldFiles, isDefinition(), isStaticDataMember())
MatchCallbacks.back().get());
MatchCallbacks.push_back(std::make_unique<FunctionDeclarationMatch>(this));
- Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
+ Finder->addMatcher(functionDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl)
.bind("function"),
MatchCallbacks.back().get());
MatchCallbacks.push_back(std::make_unique<VarDeclarationMatch>(this));
Finder->addMatcher(
- varDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl).bind("var"),
+ varDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl).bind("var"),
MatchCallbacks.back().get());
// Match enum definition in old.h. Enum helpers (which are defined in old.cc)
// will not be moved for now no matter whether they are used or not.
MatchCallbacks.push_back(std::make_unique<EnumDeclarationMatch>(this));
Finder->addMatcher(
- enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
+ enumDecl(InOldHeader, HasAnySymbolNames, isDefinition(), TopLevelDecl)
.bind("enum"),
MatchCallbacks.back().get());
MatchCallbacks.push_back(std::make_unique<TypeAliasMatch>(this));
Finder->addMatcher(namedDecl(anyOf(typedefDecl().bind("typedef"),
typeAliasDecl().bind("type_alias")),
- InOldHeader, *HasAnySymbolNames, TopLevelDecl),
+ InOldHeader, HasAnySymbolNames, TopLevelDecl),
MatchCallbacks.back().get());
}
void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
MatchFinder *Finder) {
- const auto StrLenFunc = functionDecl(anyOf(
- hasName("::strlen"), hasName("::std::strlen"), hasName("::strnlen"),
- hasName("::std::strnlen"), hasName("::strnlen_s"),
- hasName("::std::strnlen_s"), hasName("::wcslen"),
- hasName("::std::wcslen"), hasName("::wcsnlen"), hasName("::std::wcsnlen"),
- hasName("::wcsnlen_s"), hasName("std::wcsnlen_s")));
+ const auto StrLenFunc = functionDecl(hasAnyName(
+ "::strlen", "::std::strlen", "::strnlen", "::std::strnlen", "::strnlen_s",
+ "::std::strnlen_s", "::wcslen", "::std::wcslen", "::wcsnlen",
+ "::std::wcsnlen", "::wcsnlen_s", "std::wcsnlen_s"));
const auto BadUse =
callExpr(callee(StrLenFunc),
hasDescendant(BadUse)),
BadUse);
- const auto Alloc0Func =
- functionDecl(anyOf(hasName("::malloc"), hasName("std::malloc"),
- hasName("::alloca"), hasName("std::alloca")));
- const auto Alloc1Func =
- functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
- hasName("::realloc"), hasName("std::realloc")));
+ const auto Alloc0Func = functionDecl(
+ hasAnyName("::malloc", "std::malloc", "::alloca", "std::alloca"));
+ const auto Alloc1Func = functionDecl(
+ hasAnyName("::calloc", "std::calloc", "::realloc", "std::realloc"));
const auto Alloc0FuncPtr =
varDecl(hasType(isConstQualified()),
void MisplacedPointerArithmeticInAllocCheck::registerMatchers(
MatchFinder *Finder) {
- const auto AllocFunc = functionDecl(
- anyOf(hasName("::malloc"), hasName("std::malloc"), hasName("::alloca"),
- hasName("::calloc"), hasName("std::calloc"), hasName("::realloc"),
- hasName("std::realloc")));
+ const auto AllocFunc =
+ functionDecl(hasAnyName("::malloc", "std::malloc", "::alloca", "::calloc",
+ "std::calloc", "::realloc", "std::realloc"));
const auto AllocFuncPtr =
varDecl(hasType(isConstQualified()),
.bind("wait"));
auto hasWaitDescendantC = hasDescendant(
- callExpr(callee(functionDecl(
- anyOf(hasName("cnd_wait"), hasName("cnd_timedwait")))))
+ callExpr(callee(functionDecl(hasAnyName("cnd_wait", "cnd_timedwait"))))
.bind("wait"));
if (getLangOpts().CPlusPlus) {
// Check for `CON54-CPP`
void CommandProcessorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(
- callee(functionDecl(anyOf(hasName("::system"), hasName("::popen"),
- hasName("::_popen")))
+ callee(functionDecl(hasAnyName("::system", "::popen", "::_popen"))
.bind("func")),
// Do not diagnose when the call expression passes a null pointer
// constant to system(); that only checks for the presence of a
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
namespaceDecl(unless(isExpansionInSystemHeader()),
- anyOf(hasName("std"), hasName("posix")),
+ hasAnyName("std", "posix"),
has(decl(unless(anyOf(
functionDecl(isExplicitTemplateSpecialization()),
cxxRecordDecl(isExplicitTemplateSpecialization()))))))
auto CallExpression =
callExpr(
- allOf(unless(isMacroID()), unless(cxxMemberCallExpr()),
- allOf(callee(namedDecl(anyOf(hasName("isa"), hasName("cast"),
- hasName("cast_or_null"),
- hasName("dyn_cast"),
- hasName("dyn_cast_or_null")))
- .bind("func")),
- hasArgument(0, anyOf(declRefExpr().bind("arg"),
- cxxMemberCallExpr().bind("arg"))))))
+ allOf(
+ unless(isMacroID()), unless(cxxMemberCallExpr()),
+ allOf(callee(namedDecl(hasAnyName("isa", "cast", "cast_or_null",
+ "dyn_cast", "dyn_cast_or_null"))
+ .bind("func")),
+ hasArgument(0, anyOf(declRefExpr().bind("arg"),
+ cxxMemberCallExpr().bind("arg"))))))
.bind("rhs");
Finder->addMatcher(
void AvoidBindCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(
- callee(namedDecl(
- anyOf(hasName("::boost::bind"), hasName("::std::bind")))),
+ callee(namedDecl(hasAnyName("::boost::bind", "::std::bind"))),
hasArgument(
0, anyOf(expr(hasType(memberPointerType())).bind("ref"),
expr(hasParent(materializeTemporaryExpr().bind("ref"))),
/// - If the end iterator variable 'g' is defined, it is the same as 'f'.
StatementMatcher makeIteratorLoopMatcher() {
StatementMatcher BeginCallMatcher =
- cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("begin"), hasName("cbegin")))))
+ cxxMemberCallExpr(argumentCountIs(0),
+ callee(cxxMethodDecl(hasAnyName("begin", "cbegin"))))
.bind(BeginCallName);
DeclarationMatcher InitDeclMatcher =
varDecl(hasInitializer(anything())).bind(EndVarName);
StatementMatcher EndCallMatcher = cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("end"), hasName("cend")))));
+ argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "cend"))));
StatementMatcher IteratorBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
));
StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))),
+ argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("size", "length"))),
on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
hasType(RecordWithBeginEnd))));
auto FieldAccessM = memberExpr(hasDeclaration(equalsNode(FD))).bind("access");
auto AssertLikeM = callExpr(callee(functionDecl(
- anyOf(hasName("exit"), hasName("panic"), hasName("error"),
- hasName("Assert"), hasName("assert"), hasName("ziperr"),
- hasName("assfail"), hasName("db_error"), hasName("__assert"),
- hasName("__assert2"), hasName("_wassert"), hasName("__assert_rtn"),
- hasName("__assert_fail"), hasName("dtrace_assfail"),
- hasName("yy_fatal_error"), hasName("_XCAssertionFailureHandler"),
- hasName("_DTAssertionFailureHandler"),
- hasName("_TSAssertionFailureHandler")))));
+ hasAnyName("exit", "panic", "error", "Assert", "assert", "ziperr",
+ "assfail", "db_error", "__assert", "__assert2", "_wassert",
+ "__assert_rtn", "__assert_fail", "dtrace_assfail",
+ "yy_fatal_error", "_XCAssertionFailureHandler",
+ "_DTAssertionFailureHandler", "_TSAssertionFailureHandler"))));
auto NoReturnFuncM = callExpr(callee(functionDecl(isNoReturn())));