77// ===----------------------------------------------------------------------===//
88
99#include " RedundantParenthesesCheck.h"
10+ #include " ../utils/Matchers.h"
11+ #include " ../utils/OptionsUtils.h"
1012#include " clang/AST/Expr.h"
1113#include " clang/ASTMatchers/ASTMatchFinder.h"
1214#include " clang/ASTMatchers/ASTMatchers.h"
@@ -32,15 +34,30 @@ AST_MATCHER(ParenExpr, isInMacro) {
3234
3335} // namespace
3436
37+ RedundantParenthesesCheck::RedundantParenthesesCheck (StringRef Name,
38+ ClangTidyContext *Context)
39+ : ClangTidyCheck(Name, Context),
40+ AllowedDecls (utils::options::parseStringList(
41+ Options.get(" AllowedDecls" , " std::max;std::min" ))) {}
42+
43+ void RedundantParenthesesCheck::storeOptions (
44+ ClangTidyOptions::OptionMap &Opts) {
45+ Options.store (Opts, " AllowedDecls" ,
46+ utils::options::serializeStringList (AllowedDecls));
47+ }
48+
3549void RedundantParenthesesCheck::registerMatchers (MatchFinder *Finder) {
3650 const auto ConstantExpr =
3751 expr (anyOf (integerLiteral (), floatLiteral (), characterLiteral (),
3852 cxxBoolLiteral (), stringLiteral (), cxxNullPtrLiteralExpr ()));
3953 Finder->addMatcher (
40- parenExpr (subExpr (anyOf (parenExpr (), ConstantExpr, declRefExpr ())),
41- unless (anyOf (isInMacro (),
42- // sizeof(...) is common used.
43- hasParent (unaryExprOrTypeTraitExpr ()))))
54+ parenExpr (
55+ subExpr (anyOf (parenExpr (), ConstantExpr,
56+ declRefExpr (to (namedDecl (unless (
57+ matchers::matchesAnyListedName (AllowedDecls))))))),
58+ unless (anyOf (isInMacro (),
59+ // sizeof(...) is common used.
60+ hasParent (unaryExprOrTypeTraitExpr ()))))
4461 .bind (" dup" ),
4562 this );
4663}
0 commit comments