https://github.com/Gitspike updated https://github.com/llvm/llvm-project/pull/102152
>From 869b955eb55bc53e445a8809b56c702d7c312b46 Mon Sep 17 00:00:00 2001 From: hehouhua <hehou...@feysh.com> Date: Wed, 7 Aug 2024 11:55:30 +0800 Subject: [PATCH 1/4] [clang][ASTMatcher] Add matches for StringLiteral which matches literals on given RegExp Add Matcher matchesString. --- clang/docs/LibASTMatchersReference.html | 14 +++++++++++ clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/ASTMatchers/ASTMatchers.h | 24 +++++++++++++++++++ clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 + .../ASTMatchers/ASTMatchersNarrowingTest.cpp | 22 +++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index a16b9c44ef0eab..77b789b1ec4b94 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -5582,6 +5582,20 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2> </pre></td></tr> +<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>></td><td class="name" onclick="toggle('matchesString0')"><a name="matchesString0A">matchesString</a></td><td>StringRef RegExp, Regex::RegexFlags Flags = NoFlags</td></tr> +<tr><td colspan="4" class="doc" id="matchesString0"><pre>Matches string literals that contain a substring matched by the given RegExp + +Example matches "foo" and "foobar" but not "bar" + (matcher = stringLiteral(matchesString("foo.*"))) + const char* a = "foo"; + const char* b = "foobar"; + const char* c = "bar"; + +Usable as: Matcher<StringLiteral> +</pre></td></tr> + + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1StringLiteral.html">StringLiteral</a>></td><td class="name" onclick="toggle('hasSize1')"><a name="hasSize1Anchor">hasSize</a></td><td>unsigned N</td></tr> <tr><td colspan="4" class="doc" id="hasSize1"><pre>Matches nodes that have the specified size. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7beef7be0e6a53..760d566eabe9e3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -307,6 +307,8 @@ AST Matchers - Fixed an issue with the `hasName` and `hasAnyName` matcher when matching inline namespaces with an enclosing namespace of the same name. +Add `matchesString` for `StringLiteral` which matches literals on given `RegExp`. + clang-format ------------ diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index ca44c3ee085654..bff415294c4561 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -3116,6 +3116,30 @@ AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) { return RegExp->match(FullNameString); } +/// Matches string literals that contain a substring matched by the given RegExp. +/// +/// Example matches "foo" and "foobar" but not "bar" +/// (matcher = stringLiteral(matchesString("foo.*"))) +/// \code +/// const char* a = "foo"; +/// const char* b = "foobar"; +/// const char* c = "bar"; +/// \endcode +/// +/// Usable as: Matcher<StringLiteral> +AST_MATCHER_REGEX(StringLiteral, matchesString, RegExp) { + constexpr unsigned StringLength = 64; + SmallString<StringLength> Str; + llvm::raw_svector_ostream OS(Str); + Node.outputString(OS); + StringRef OSRef = OS.str(); + if (OSRef.size() < 2U) { + return false; + } + OSRef = OSRef.substr(1, OSRef.size() - 2); + return RegExp->match(OSRef); +} + /// Matches overloaded operator names. /// /// Matches overloaded operator names specified in strings without the diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 2c75e6beb74301..a3a2515d86be70 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -125,6 +125,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER_OVERLOAD(equals); REGISTER_REGEX_MATCHER(isExpansionInFileMatching); + REGISTER_REGEX_MATCHER(matchesString); REGISTER_REGEX_MATCHER(matchesName); REGISTER_REGEX_MATCHER(matchesSelector); diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 611e1f9ba5327c..2d2b71c5393c58 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2503,6 +2503,28 @@ TEST_P(ASTMatchersTest, IsDelegatingConstructor) { cxxConstructorDecl(isDelegatingConstructor(), parameterCountIs(1)))); } +TEST_P(ASTMatchersTest, MatchesString) { + StatementMatcher Literal = stringLiteral(matchesString("foo.*")); + EXPECT_TRUE(matches("const char* a = \"foo\";", Literal)); + EXPECT_TRUE(matches("const char* b = \"foobar\";", Literal)); + EXPECT_TRUE(matches("const char* b = \"fo\"\"obar\";", Literal)); + EXPECT_TRUE(notMatches("const char* c = \"bar\";", Literal)); + // test embedded nulls + StatementMatcher Literal2 = stringLiteral(matchesString("bar")); + EXPECT_TRUE(matches("const char* b = \"foo\\0bar\";", Literal2)); + EXPECT_TRUE(notMatches("const char* b = \"foo\\0b\\0ar\";", Literal2)); +} + +TEST(MatchesString, MatchesStringPrefixed) { + StatementMatcher Literal = stringLiteral(matchesString("foo.*")); + EXPECT_TRUE(matchesConditionally("const char16_t* a = u\"foo\";", Literal, + true, {"-std=c++11"})); + EXPECT_TRUE(matchesConditionally("const char32_t* a = U\"foo\";", Literal, + true, {"-std=c++11"})); + EXPECT_TRUE(matchesConditionally("const wchar_t* a = L\"foo\";", Literal, + true, {"-std=c++11"})); +} + TEST_P(ASTMatchersTest, HasSize) { StatementMatcher Literal = stringLiteral(hasSize(4)); EXPECT_TRUE(matches("const char *s = \"abcd\";", Literal)); >From df10be46105dfa73278c7a3bd78a02ce21a93f97 Mon Sep 17 00:00:00 2001 From: hehouhua <hehou...@feysh.com> Date: Wed, 14 Aug 2024 15:46:17 +0800 Subject: [PATCH 2/4] sort in alphabetical order --- clang/lib/ASTMatchers/Dynamic/Registry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index a3a2515d86be70..0576cb3a413301 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -125,9 +125,9 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER_OVERLOAD(equals); REGISTER_REGEX_MATCHER(isExpansionInFileMatching); - REGISTER_REGEX_MATCHER(matchesString); REGISTER_REGEX_MATCHER(matchesName); REGISTER_REGEX_MATCHER(matchesSelector); + REGISTER_REGEX_MATCHER(matchesString); REGISTER_MATCHER(accessSpecDecl); REGISTER_MATCHER(addrLabelExpr); >From 22ad5bff393984cfdf536134dbdb8e5cebdd8ddb Mon Sep 17 00:00:00 2001 From: hehouhua <hehou...@feysh.com> Date: Fri, 23 Aug 2024 09:18:25 +0800 Subject: [PATCH 3/4] use getBytes instead of OutputString --- clang/include/clang/ASTMatchers/ASTMatchers.h | 434 +++++++----------- .../ASTMatchers/ASTMatchersNarrowingTest.cpp | 6 +- 2 files changed, 173 insertions(+), 267 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index bff415294c4561..b17fb22db177ef 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -112,8 +112,7 @@ class BoundNodes { /// /// Returns NULL if there was no node bound to \c ID or if there is a node but /// it cannot be converted to the specified type. - template <typename T> - const T *getNodeAs(StringRef ID) const { + template <typename T> const T *getNodeAs(StringRef ID) const { return MyBoundNodes.getNodeAs<T>(ID); } @@ -123,9 +122,7 @@ class BoundNodes { using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap; /// Retrieve mapping from binding identifiers to bound nodes. - const IDToNodeMap &getMap() const { - return MyBoundNodes.getMap(); - } + const IDToNodeMap &getMap() const { return MyBoundNodes.getMap(); } private: friend class internal::BoundNodesTreeBuilder; @@ -318,13 +315,15 @@ AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro, std::string, MacroName) { // Verifies that the statement' beginning and ending are both expanded from // the same instance of the given macro. - auto& Context = Finder->getASTContext(); + auto &Context = Finder->getASTContext(); std::optional<SourceLocation> B = internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); - if (!B) return false; + if (!B) + return false; std::optional<SourceLocation> E = internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); - if (!E) return false; + if (!E) + return false; return *B == *E; } @@ -690,9 +689,7 @@ AST_POLYMORPHIC_MATCHER(isPrivate, /// \endcode /// fieldDecl(isBitField()) /// matches 'int a;' but not 'int b;'. -AST_MATCHER(FieldDecl, isBitField) { - return Node.isBitField(); -} +AST_MATCHER(FieldDecl, isBitField) { return Node.isBitField(); } /// Matches non-static data members that are bit-fields of the specified /// bit width. @@ -735,9 +732,7 @@ AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>, /// Determines whether the function is "main", which is the entry point /// into an executable program. -AST_MATCHER(FunctionDecl, isMain) { - return Node.isMain(); -} +AST_MATCHER(FunctionDecl, isMain) { return Node.isMain(); } /// Matches the specialized template of a specialization declaration. /// @@ -751,9 +746,8 @@ AST_MATCHER(FunctionDecl, isMain) { /// declaration of 'A' at #1. AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate, internal::Matcher<ClassTemplateDecl>, InnerMatcher) { - const ClassTemplateDecl* Decl = Node.getSpecializedTemplate(); - return (Decl != nullptr && - InnerMatcher.matches(*Decl, Finder, Builder)); + const ClassTemplateDecl *Decl = Node.getSpecializedTemplate(); + return (Decl != nullptr && InnerMatcher.matches(*Decl, Finder, Builder)); } /// Matches an entity that has been implicitly added by the compiler (e.g. @@ -890,8 +884,7 @@ traverse(TraversalKind TK, const internal::MapAnyOfHelper<T...> &InnerMatcher) { /// varDecl(hasInitializer(cxxConstructExpr())) /// \endcode /// only match the declarations for b and c. -AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, - InnerMatcher) { +AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder); } @@ -920,8 +913,7 @@ AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, /// varDecl(hasInitializer(declRefExpr())) /// \endcode /// only match the declarations for a. -AST_MATCHER_P(Expr, ignoringImpCasts, - internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(Expr, ignoringImpCasts, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder); } @@ -967,8 +959,8 @@ AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { /// varDecl(hasInitializer(integerLiteral())) /// varDecl(hasInitializer(declRefExpr())) /// would only match the declaration for a. -AST_MATCHER_P(Expr, ignoringParenImpCasts, - internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(Expr, ignoringParenImpCasts, internal::Matcher<Expr>, + InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder); } @@ -1107,8 +1099,8 @@ AST_POLYMORPHIC_MATCHER_P( /// classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType( /// recordType(hasDeclaration(recordDecl(hasName("X"))))))) /// matches the specialization of \c struct A generated by \c A<X>. -AST_MATCHER_P(TemplateArgument, refersToType, - internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P(TemplateArgument, refersToType, internal::Matcher<QualType>, + InnerMatcher) { if (Node.getKind() != TemplateArgument::Type) return false; return InnerMatcher.matches(Node.getAsType(), Finder, Builder); @@ -1145,8 +1137,8 @@ AST_MATCHER_P(TemplateArgument, refersToTemplate, /// refersToDeclaration(fieldDecl(hasName("next"))))) /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching /// \c B::next -AST_MATCHER_P(TemplateArgument, refersToDeclaration, - internal::Matcher<Decl>, InnerMatcher) { +AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher<Decl>, + InnerMatcher) { if (Node.getKind() == TemplateArgument::Declaration) return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder); return false; @@ -1216,8 +1208,7 @@ AST_MATCHER_P(TemplateArgument, refersToIntegralType, /// classTemplateSpecializationDecl( /// hasAnyTemplateArgument(equalsIntegralValue("42"))) /// matches the implicit instantiation of C in C<42>. -AST_MATCHER_P(TemplateArgument, equalsIntegralValue, - std::string, Value) { +AST_MATCHER_P(TemplateArgument, equalsIntegralValue, std::string, Value) { if (Node.getKind() != TemplateArgument::Integral) return false; return toString(Node.getAsIntegral(), 10) == Value; @@ -1234,7 +1225,8 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue, /// autoreleasePoolStmt(stmt()) matches the declaration of "x" /// inside the autorelease pool. extern const internal::VariadicDynCastAllOfMatcher<Stmt, - ObjCAutoreleasePoolStmt> autoreleasePoolStmt; + ObjCAutoreleasePoolStmt> + autoreleasePoolStmt; /// Matches any value declaration. /// @@ -1612,8 +1604,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> /// printf("%d", p); /// }) /// \endcode -extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> - blockDecl; +extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> blockDecl; /// Matches Objective-C instance variable declarations. /// @@ -1702,8 +1693,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> /// Matches the syntactic form of init list expressions /// (if expression have it). -AST_MATCHER_P(InitListExpr, hasSyntacticForm, - internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(InitListExpr, hasSyntacticForm, internal::Matcher<Expr>, + InnerMatcher) { const Expr *SyntForm = Node.getSyntacticForm(); return (SyntForm != nullptr && InnerMatcher.matches(*SyntForm, Finder, Builder)); @@ -1982,7 +1973,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> cxxNoexceptExpr; -/// Matches a loop initializing the elements of an array in a number of contexts: +/// Matches a loop initializing the elements of an array in a number of +/// contexts: /// * in the implicit copy/move constructor for a class with an array member /// * when a lambda-expression captures an array by value /// * when a decomposition declaration decomposes an array @@ -1996,16 +1988,16 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> /// }; /// } /// \endcode -/// arrayInitLoopExpr() matches the implicit loop that initializes each element of -/// the implicit array field inside the lambda object, that represents the array `a` -/// captured by value. +/// arrayInitLoopExpr() matches the implicit loop that initializes each element +/// of the implicit array field inside the lambda object, that represents the +/// array `a` captured by value. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitLoopExpr> arrayInitLoopExpr; /// The arrayInitIndexExpr consists of two subexpressions: a common expression -/// (the source array) that is evaluated once up-front, and a per-element initializer -/// that runs once for each array element. Within the per-element initializer, -/// the current index may be obtained via an ArrayInitIndexExpr. +/// (the source array) that is evaluated once up-front, and a per-element +/// initializer that runs once for each array element. Within the per-element +/// initializer, the current index may be obtained via an ArrayInitIndexExpr. /// /// Given /// \code @@ -2161,8 +2153,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; /// \code /// for (x; x < N; ++x) { } /// \endcode -AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, - InnerMatcher) { +AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Increment = Node.getInc(); return (Increment != nullptr && InnerMatcher.matches(*Increment, Finder, Builder)); @@ -2176,8 +2167,7 @@ AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, /// \code /// for (int x = 0; x < N; ++x) { } /// \endcode -AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, - InnerMatcher) { +AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Init = Node.getInit(); return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)); } @@ -2529,8 +2519,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> cxxNullPtrLiteralExpr; /// Matches GNU __builtin_choose_expr. -extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> - chooseExpr; +extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr; /// Matches builtin function __builtin_convertvector. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConvertVectorExpr> @@ -3046,8 +3035,8 @@ AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind) { /// Same as unaryExprOrTypeTraitExpr, but only matching /// alignof. -inline internal::BindableMatcher<Stmt> alignOfExpr( - const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { +inline internal::BindableMatcher<Stmt> +alignOfExpr(const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { return stmt(unaryExprOrTypeTraitExpr( allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)), InnerMatcher))); @@ -3055,10 +3044,10 @@ inline internal::BindableMatcher<Stmt> alignOfExpr( /// Same as unaryExprOrTypeTraitExpr, but only matching /// sizeof. -inline internal::BindableMatcher<Stmt> sizeOfExpr( - const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { - return stmt(unaryExprOrTypeTraitExpr( - allOf(ofKind(UETT_SizeOf), InnerMatcher))); +inline internal::BindableMatcher<Stmt> +sizeOfExpr(const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { + return stmt( + unaryExprOrTypeTraitExpr(allOf(ofKind(UETT_SizeOf), InnerMatcher))); } /// Matches NamedDecl nodes that have the specified name. @@ -3116,7 +3105,8 @@ AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) { return RegExp->match(FullNameString); } -/// Matches string literals that contain a substring matched by the given RegExp. +/// Matches string literals that contain a substring matched by the given +/// RegExp. /// /// Example matches "foo" and "foobar" but not "bar" /// (matcher = stringLiteral(matchesString("foo.*"))) @@ -3128,16 +3118,8 @@ AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) { /// /// Usable as: Matcher<StringLiteral> AST_MATCHER_REGEX(StringLiteral, matchesString, RegExp) { - constexpr unsigned StringLength = 64; - SmallString<StringLength> Str; - llvm::raw_svector_ostream OS(Str); - Node.outputString(OS); - StringRef OSRef = OS.str(); - if (OSRef.size() < 2U) { - return false; - } - OSRef = OSRef.substr(1, OSRef.size() - 2); - return RegExp->match(OSRef); + StringRef Str = Node.getBytes(); + return RegExp->match(Str); } /// Matches overloaded operator names. @@ -3290,10 +3272,10 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode, /// \endcode /// /// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl> -AST_POLYMORPHIC_MATCHER_P( - isDerivedFrom, - AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), - internal::Matcher<NamedDecl>, Base) { +AST_POLYMORPHIC_MATCHER_P(isDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, + ObjCInterfaceDecl), + internal::Matcher<NamedDecl>, Base) { // Check if the node is a C++ struct/union/class. if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); @@ -3478,9 +3460,7 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>, /// /// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of /// \c decltype(x) -AST_MATCHER(CXXRecordDecl, isLambda) { - return Node.isLambda(); -} +AST_MATCHER(CXXRecordDecl, isLambda) { return Node.isLambda(); } /// Matches AST nodes that have child AST nodes that match the /// provided matcher. @@ -3718,15 +3698,13 @@ AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher<NamedDecl>, /// matches `(g()).m()`. /// /// FIXME: Overload to allow directly matching types? -AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, - InnerMatcher) { - const Expr *ExprNode = Node.getImplicitObjectArgument() - ->IgnoreParenImpCasts(); +AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, InnerMatcher) { + const Expr *ExprNode = + Node.getImplicitObjectArgument()->IgnoreParenImpCasts(); return (ExprNode != nullptr && InnerMatcher.matches(*ExprNode, Finder, Builder)); } - /// Matches on the receiver of an ObjectiveC Message expression. /// /// Example @@ -3755,9 +3733,7 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>, /// \code /// @interface I - (void)bar; @end /// \endcode -AST_MATCHER(ObjCMethodDecl, isClassMethod) { - return Node.isClassMethod(); -} +AST_MATCHER(ObjCMethodDecl, isClassMethod) { return Node.isClassMethod(); } /// Returns true when the Objective-C method declaration is an instance method. /// @@ -3788,9 +3764,7 @@ AST_MATCHER(ObjCMethodDecl, isInstanceMethod) { /// NSString *x = @"hello"; /// [x containsString:@"h"]; /// \endcode -AST_MATCHER(ObjCMessageExpr, isClassMessage) { - return Node.isClassMessage(); -} +AST_MATCHER(ObjCMessageExpr, isClassMessage) { return Node.isClassMessage(); } /// Returns true when the Objective-C message is sent to an instance. /// @@ -3850,9 +3824,8 @@ AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { /// [myObj methodB:argB]; /// \endcode extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, - StringRef, - internal::hasAnySelectorFunc> - hasAnySelector; + StringRef, internal::hasAnySelectorFunc> + hasAnySelector; /// Matches ObjC selectors whose name contains /// a substring matched by the given RegExp. @@ -4046,8 +4019,8 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD( /// \endcode /// /// Example matches class Derived -/// (matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")))))) -/// \code +/// (matcher = +/// cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")))))) \code /// class Base {}; /// class Derived : Base {}; /// \endcode @@ -4134,9 +4107,7 @@ AST_MATCHER_P(QualType, asString, std::string, Name) { /// class Y { public: void x(); }; /// void z() { Y *y; y->x(); } /// \endcode -AST_MATCHER_P( - QualType, pointsTo, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(QualType, pointsTo, internal::Matcher<QualType>, InnerMatcher) { return (!Node.isNull() && Node->isAnyPointerType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } @@ -4177,8 +4148,7 @@ AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>, /// } /// }; /// \endcode -AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, InnerMatcher) { return (!Node.isNull() && Node->isReferenceType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } @@ -4252,7 +4222,7 @@ AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument, AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<QualType>, InnerMatcher, 0) { return onImplicitObjectArgument( - anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) + anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } @@ -4260,7 +4230,7 @@ AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<Decl>, InnerMatcher, 1) { return onImplicitObjectArgument( - anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) + anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } @@ -4273,8 +4243,7 @@ AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, /// bool x; /// if (x) {} /// \endcode -AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, - InnerMatcher) { +AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, InnerMatcher) { const Decl *DeclNode = Node.getDecl(); return (DeclNode != nullptr && InnerMatcher.matches(*DeclNode, Finder, Builder)); @@ -4358,9 +4327,7 @@ AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { /// bool y() { return true; } /// bool x = y(); /// \endcode -AST_MATCHER_P( - VarDecl, hasInitializer, internal::Matcher<Expr>, - InnerMatcher) { +AST_MATCHER_P(VarDecl, hasInitializer, internal::Matcher<Expr>, InnerMatcher) { const Expr *Initializer = Node.getAnyInitializer(); return (Initializer != nullptr && InnerMatcher.matches(*Initializer, Finder, Builder)); @@ -4415,9 +4382,7 @@ AST_MATCHER_P(LambdaExpr, forEachLambdaCapture, /// } /// static int z; /// \endcode -AST_MATCHER(VarDecl, isStaticLocal) { - return Node.isStaticLocal(); -} +AST_MATCHER(VarDecl, isStaticLocal) { return Node.isStaticLocal(); } /// Matches a variable declaration that has function scope and is a /// non-static local variable. @@ -4430,9 +4395,7 @@ AST_MATCHER(VarDecl, isStaticLocal) { /// } /// int z; /// \endcode -AST_MATCHER(VarDecl, hasLocalStorage) { - return Node.hasLocalStorage(); -} +AST_MATCHER(VarDecl, hasLocalStorage) { return Node.hasLocalStorage(); } /// Matches a variable declaration that does not have local storage. /// @@ -4444,9 +4407,7 @@ AST_MATCHER(VarDecl, hasLocalStorage) { /// } /// int z; /// \endcode -AST_MATCHER(VarDecl, hasGlobalStorage) { - return Node.hasGlobalStorage(); -} +AST_MATCHER(VarDecl, hasGlobalStorage) { return Node.hasGlobalStorage(); } /// Matches a variable declaration that has automatic storage duration. /// @@ -4511,9 +4472,7 @@ AST_MATCHER(VarDecl, hasThreadStorageDuration) { /// } /// } /// \endcode -AST_MATCHER(VarDecl, isExceptionVariable) { - return Node.isExceptionVariable(); -} +AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); } /// Checks that a call expression or a constructor call expression has /// a specific number of arguments (including absent default arguments). @@ -4710,7 +4669,7 @@ AST_MATCHER(CXXFoldExpr, isBinaryFold) { return Node.getInit() != nullptr; } AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N, internal::Matcher<Expr>, InnerMatcher) { return N < Node.getNumInits() && - InnerMatcher.matches(*Node.getInit(N), Finder, Builder); + InnerMatcher.matches(*Node.getInit(N), Finder, Builder); } /// Matches declaration statements that contain a specific number of @@ -4809,11 +4768,11 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, /// forField(hasName("foo_")))))) /// matches Foo /// with forField matching foo_ -AST_MATCHER_P(CXXCtorInitializer, forField, - internal::Matcher<FieldDecl>, InnerMatcher) { +AST_MATCHER_P(CXXCtorInitializer, forField, internal::Matcher<FieldDecl>, + InnerMatcher) { const FieldDecl *NodeAsDecl = Node.getAnyMember(); return (NodeAsDecl != nullptr && - InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); + InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); } /// Matches the initializer expression of a constructor initializer. @@ -4829,11 +4788,11 @@ AST_MATCHER_P(CXXCtorInitializer, forField, /// withInitializer(integerLiteral(equals(1))))))) /// matches Foo /// with withInitializer matching (1) -AST_MATCHER_P(CXXCtorInitializer, withInitializer, - internal::Matcher<Expr>, InnerMatcher) { - const Expr* NodeAsExpr = Node.getInit(); +AST_MATCHER_P(CXXCtorInitializer, withInitializer, internal::Matcher<Expr>, + InnerMatcher) { + const Expr *NodeAsExpr = Node.getInit(); return (NodeAsExpr != nullptr && - InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); + InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); } /// Matches a constructor initializer if it is explicitly written in @@ -4849,9 +4808,7 @@ AST_MATCHER_P(CXXCtorInitializer, withInitializer, /// \endcode /// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) /// will match Foo(int), but not Foo() -AST_MATCHER(CXXCtorInitializer, isWritten) { - return Node.isWritten(); -} +AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); } /// Matches a constructor initializer if it is initializing a base, as /// opposed to a member. @@ -5048,14 +5005,12 @@ AST_MATCHER(CXXConstructExpr, requiresZeroInitialization) { /// the matcher objcMethodDecl(hasParameter(0, hasName("y"))) /// matches the declaration of method f with hasParameter /// matching y. -AST_POLYMORPHIC_MATCHER_P2(hasParameter, - AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, - ObjCMethodDecl, - BlockDecl), - unsigned, N, internal::Matcher<ParmVarDecl>, - InnerMatcher) { - return (N < Node.parameters().size() - && InnerMatcher.matches(*Node.parameters()[N], Finder, Builder)); +AST_POLYMORPHIC_MATCHER_P2( + hasParameter, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), + unsigned, N, internal::Matcher<ParmVarDecl>, InnerMatcher) { + return (N < Node.parameters().size() && + InnerMatcher.matches(*Node.parameters()[N], Finder, Builder)); } /// Matches if the given method declaration declares a member function with an @@ -5115,8 +5070,8 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam, bool Matched = false; for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) { BoundNodesTreeBuilder ArgMatches(*Builder); - if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), - Finder, &ArgMatches)) { + if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder, + &ArgMatches)) { BoundNodesTreeBuilder ParamMatches(ArgMatches); if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl( hasParameter(ParamIndex, ParamMatcher)))), @@ -5297,8 +5252,7 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyParameter, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), - internal::Matcher<ParmVarDecl>, - InnerMatcher) { + internal::Matcher<ParmVarDecl>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), Node.param_end(), Finder, Builder) != Node.param_end(); @@ -5397,8 +5351,8 @@ AST_MATCHER(FunctionDecl, isNoReturn) { return Node.isNoReturn(); } /// \endcode /// cxxMethodDecl(returns(asString("int"))) /// matches int f() { return 1; } -AST_MATCHER_P(FunctionDecl, returns, - internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P(FunctionDecl, returns, internal::Matcher<QualType>, + InnerMatcher) { return InnerMatcher.matches(Node.getReturnType(), Finder, Builder); } @@ -5451,9 +5405,7 @@ AST_POLYMORPHIC_MATCHER(isStaticStorageClass, /// \endcode /// functionDecl(isDeleted()) /// matches the declaration of DeletedFunc, but not Func. -AST_MATCHER(FunctionDecl, isDeleted) { - return Node.isDeleted(); -} +AST_MATCHER(FunctionDecl, isDeleted) { return Node.isDeleted(); } /// Matches defaulted function declarations. /// @@ -5464,9 +5416,7 @@ AST_MATCHER(FunctionDecl, isDeleted) { /// \endcode /// functionDecl(isDefaulted()) /// matches the declaration of ~B, but not ~A. -AST_MATCHER(FunctionDecl, isDefaulted) { - return Node.isDefaulted(); -} +AST_MATCHER(FunctionDecl, isDefaulted) { return Node.isDefaulted(); } /// Matches weak function declarations. /// @@ -5567,8 +5517,7 @@ AST_POLYMORPHIC_MATCHER(isConsteval, /// ifStmt(isConstexpr()) /// matches the if statement in baz. AST_POLYMORPHIC_MATCHER(isConstexpr, - AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, - FunctionDecl, + AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, FunctionDecl, IfStmt)) { return Node.isConstexpr(); } @@ -5707,8 +5656,8 @@ AST_POLYMORPHIC_MATCHER_P(equalsBoundNode, /// matches 'A* a = GetAPointer()'. AST_MATCHER_P(IfStmt, hasConditionVariableStatement, internal::Matcher<DeclStmt>, InnerMatcher) { - const DeclStmt* const DeclarationStatement = - Node.getConditionVariableDeclStmt(); + const DeclStmt *const DeclarationStatement = + Node.getConditionVariableDeclStmt(); return DeclarationStatement != nullptr && InnerMatcher.matches(*DeclarationStatement, Finder, Builder); } @@ -5722,9 +5671,9 @@ AST_MATCHER_P(IfStmt, hasConditionVariableStatement, /// \endcode /// arraySubscriptExpression(hasIndex(integerLiteral())) /// matches \c i[1] with the \c integerLiteral() matching \c 1 -AST_MATCHER_P(ArraySubscriptExpr, hasIndex, - internal::Matcher<Expr>, InnerMatcher) { - if (const Expr* Expression = Node.getIdx()) +AST_MATCHER_P(ArraySubscriptExpr, hasIndex, internal::Matcher<Expr>, + InnerMatcher) { + if (const Expr *Expression = Node.getIdx()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } @@ -5739,9 +5688,9 @@ AST_MATCHER_P(ArraySubscriptExpr, hasIndex, /// arraySubscriptExpression(hasBase(implicitCastExpr( /// hasSourceExpression(declRefExpr())))) /// matches \c i[1] with the \c declRefExpr() matching \c i -AST_MATCHER_P(ArraySubscriptExpr, hasBase, - internal::Matcher<Expr>, InnerMatcher) { - if (const Expr* Expression = Node.getBase()) +AST_MATCHER_P(ArraySubscriptExpr, hasBase, internal::Matcher<Expr>, + InnerMatcher) { + if (const Expr *Expression = Node.getBase()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } @@ -5798,14 +5747,12 @@ AST_POLYMORPHIC_MATCHER_P( /// with compoundStmt() /// matching '{}' /// but does not match 'void g();' -AST_MATCHER_P(FunctionDecl, hasAnyBody, - internal::Matcher<Stmt>, InnerMatcher) { +AST_MATCHER_P(FunctionDecl, hasAnyBody, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Statement = Node.getBody(); return (Statement != nullptr && InnerMatcher.matches(*Statement, Finder, Builder)); } - /// Matches compound statements where at least one substatement matches /// a given matcher. Also matches StmtExprs that have CompoundStmt as children. /// @@ -5875,32 +5822,31 @@ equals(const ValueT &Value) { Value); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, - CXXBoolLiteralExpr, - IntegerLiteral), - bool, Value, 0) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) - .matchesNode(Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, + IntegerLiteral), + bool, Value, 0) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( + Node); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, - CXXBoolLiteralExpr, - IntegerLiteral), - unsigned, Value, 1) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) - .matchesNode(Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, + IntegerLiteral), + unsigned, Value, 1) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( + Node); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, - CXXBoolLiteralExpr, - FloatingLiteral, - IntegerLiteral), - double, Value, 2) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) - .matchesNode(Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD( + equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, + FloatingLiteral, IntegerLiteral), + double, Value, 2) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( + Node); } /// Matches the operator Name of operator expressions and fold expressions @@ -6114,8 +6060,8 @@ AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) { /// /// (Note: Clang's AST refers to other conversions as "casts" too, and calls /// actual casts "explicit" casts.) -AST_MATCHER_P(ExplicitCastExpr, hasDestinationType, - internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P(ExplicitCastExpr, hasDestinationType, internal::Matcher<QualType>, + InnerMatcher) { const QualType NodeType = Node.getTypeAsWritten(); return InnerMatcher.matches(NodeType, Finder, Builder); } @@ -6136,9 +6082,7 @@ AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType, /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isStruct) { - return Node.isStruct(); -} +AST_MATCHER(TagDecl, isStruct) { return Node.isStruct(); } /// Matches TagDecl object that are spelled with "union." /// @@ -6149,9 +6093,7 @@ AST_MATCHER(TagDecl, isStruct) { /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isUnion) { - return Node.isUnion(); -} +AST_MATCHER(TagDecl, isUnion) { return Node.isUnion(); } /// Matches TagDecl object that are spelled with "class." /// @@ -6162,9 +6104,7 @@ AST_MATCHER(TagDecl, isUnion) { /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isClass) { - return Node.isClass(); -} +AST_MATCHER(TagDecl, isClass) { return Node.isClass(); } /// Matches TagDecl object that are spelled with "enum." /// @@ -6175,9 +6115,7 @@ AST_MATCHER(TagDecl, isClass) { /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isEnum) { - return Node.isEnum(); -} +AST_MATCHER(TagDecl, isEnum) { return Node.isEnum(); } /// Matches the true branch expression of a conditional operator. /// @@ -6249,9 +6187,7 @@ AST_POLYMORPHIC_MATCHER(isDefinition, /// template <typename... Ts> void h(Ts...); /// void i(); /// \endcode -AST_MATCHER(FunctionDecl, isVariadic) { - return Node.isVariadic(); -} +AST_MATCHER(FunctionDecl, isVariadic) { return Node.isVariadic(); } /// Matches the class declaration that the given method declaration /// belongs to. @@ -6270,14 +6206,13 @@ AST_MATCHER(FunctionDecl, isVariadic) { /// }; /// A a = A(); /// \endcode -AST_MATCHER_P(CXXMethodDecl, ofClass, - internal::Matcher<CXXRecordDecl>, InnerMatcher) { +AST_MATCHER_P(CXXMethodDecl, ofClass, internal::Matcher<CXXRecordDecl>, + InnerMatcher) { ASTChildrenNotSpelledInSourceScope RAII(Finder, false); const CXXRecordDecl *Parent = Node.getParent(); - return (Parent != nullptr && - InnerMatcher.matches(*Parent, Finder, Builder)); + return (Parent != nullptr && InnerMatcher.matches(*Parent, Finder, Builder)); } /// Matches each method overridden by the given method. This matcher may @@ -6412,9 +6347,7 @@ AST_MATCHER(CXXMethodDecl, isPure) { return Node.isPureVirtual(); } /// \endcode /// /// cxxMethodDecl(isConst()) matches A::foo() but not A::bar() -AST_MATCHER(CXXMethodDecl, isConst) { - return Node.isConst(); -} +AST_MATCHER(CXXMethodDecl, isConst) { return Node.isConst(); } /// Matches if the given method declaration declares a copy assignment /// operator. @@ -6479,9 +6412,7 @@ AST_MATCHER(CXXMethodDecl, isOverride) { /// }; /// \endcode /// cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. -AST_MATCHER(CXXMethodDecl, isUserProvided) { - return Node.isUserProvided(); -} +AST_MATCHER(CXXMethodDecl, isUserProvided) { return Node.isUserProvided(); } /// Matches member expressions that are called with '->' as opposed /// to '.'. @@ -6523,9 +6454,7 @@ AST_POLYMORPHIC_MATCHER( /// \endcode /// functionDecl(hasAnyParameter(hasType(isInteger()))) /// matches "a(int)", "b(long)", but not "c(double)". -AST_MATCHER(QualType, isInteger) { - return Node->isIntegerType(); -} +AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); } /// Matches QualType nodes that are of unsigned integer type. /// @@ -6538,7 +6467,7 @@ AST_MATCHER(QualType, isInteger) { /// functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) /// matches "b(unsigned long)", but not "a(int)" and "c(double)". AST_MATCHER(QualType, isUnsignedInteger) { - return Node->isUnsignedIntegerType(); + return Node->isUnsignedIntegerType(); } /// Matches QualType nodes that are of signed integer type. @@ -6551,9 +6480,7 @@ AST_MATCHER(QualType, isUnsignedInteger) { /// \endcode /// functionDecl(hasAnyParameter(hasType(isSignedInteger()))) /// matches "a(int)", but not "b(unsigned long)" and "c(double)". -AST_MATCHER(QualType, isSignedInteger) { - return Node->isSignedIntegerType(); -} +AST_MATCHER(QualType, isSignedInteger) { return Node->isSignedIntegerType(); } /// Matches QualType nodes that are of character type. /// @@ -6565,9 +6492,7 @@ AST_MATCHER(QualType, isSignedInteger) { /// \endcode /// functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) /// matches "a(char)", "b(wchar_t)", but not "c(double)". -AST_MATCHER(QualType, isAnyCharacter) { - return Node->isAnyCharacterType(); -} +AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } /// Matches QualType nodes that are of any pointer type; this includes /// the Objective-C object pointer type, which is different despite being @@ -6585,9 +6510,7 @@ AST_MATCHER(QualType, isAnyCharacter) { /// \endcode /// varDecl(hasType(isAnyPointer())) /// matches "int *i" and "Foo *f", but not "int j". -AST_MATCHER(QualType, isAnyPointer) { - return Node->isAnyPointerType(); -} +AST_MATCHER(QualType, isAnyPointer) { return Node->isAnyPointerType(); } /// Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. @@ -6604,9 +6527,7 @@ AST_MATCHER(QualType, isAnyPointer) { /// matches "void b(int const)", "void c(const int)" and /// "void e(int const) {}". It does not match d as there /// is no top-level const on the parameter type "const int *". -AST_MATCHER(QualType, isConstQualified) { - return Node.isConstQualified(); -} +AST_MATCHER(QualType, isConstQualified) { return Node.isConstQualified(); } /// Matches QualType nodes that are volatile-qualified, i.e., that /// include "top-level" volatile. @@ -6640,9 +6561,7 @@ AST_MATCHER(QualType, isVolatileQualified) { /// \endcode /// \c varDecl(hasType(hasLocalQualifiers())) matches only \c j and \c k. /// \c i is const-qualified but the qualifier is not local. -AST_MATCHER(QualType, hasLocalQualifiers) { - return Node.hasLocalQualifiers(); -} +AST_MATCHER(QualType, hasLocalQualifiers) { return Node.hasLocalQualifiers(); } /// Matches a member expression where the member is matched by a /// given matcher. @@ -6656,8 +6575,7 @@ AST_MATCHER(QualType, hasLocalQualifiers) { /// memberExpr(member(hasName("first"))) /// matches second.first /// but not first.second (because the member name there is "second"). -AST_MATCHER_P(MemberExpr, member, - internal::Matcher<ValueDecl>, InnerMatcher) { +AST_MATCHER_P(MemberExpr, member, internal::Matcher<ValueDecl>, InnerMatcher) { return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder); } @@ -6719,8 +6637,8 @@ AST_MATCHER_P(BaseUsingDecl, hasAnyUsingShadowDecl, /// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) /// matches \code using X::b \endcode /// but not \code using X::a \endcode -AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, - internal::Matcher<NamedDecl>, InnerMatcher) { +AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, internal::Matcher<NamedDecl>, + InnerMatcher) { return InnerMatcher.matches(*Node.getTargetDecl(), Finder, Builder); } @@ -7019,9 +6937,7 @@ AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>, /// \endcode /// functionDecl(returns(booleanType())) /// matches "bool func();" -AST_MATCHER(Type, booleanType) { - return Node.isBooleanType(); -} +AST_MATCHER(Type, booleanType) { return Node.isBooleanType(); } /// Matches type \c void. /// @@ -7031,9 +6947,7 @@ AST_MATCHER(Type, booleanType) { /// \endcode /// functionDecl(returns(voidType())) /// matches "void func();" -AST_MATCHER(Type, voidType) { - return Node.isVoidType(); -} +AST_MATCHER(Type, voidType) { return Node.isVoidType(); } template <typename NodeType> using AstTypeMatcher = internal::VariadicDynCastAllOfMatcher<Type, NodeType>; @@ -7083,9 +6997,7 @@ extern const AstTypeMatcher<ComplexType> complexType; /// \endcode /// realFloatingPointType() /// matches "float f" but not "int i" -AST_MATCHER(Type, realFloatingPointType) { - return Node.isRealFloatingType(); -} +AST_MATCHER(Type, realFloatingPointType) { return Node.isRealFloatingType(); } /// Matches arrays and C99 complex types that have a specific element /// type. @@ -7207,8 +7119,8 @@ extern const AstTypeMatcher<VariableArrayType> variableArrayType; /// variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( /// varDecl(hasName("b"))))))) /// matches "int a[b]" -AST_MATCHER_P(VariableArrayType, hasSizeExpr, - internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(VariableArrayType, hasSizeExpr, internal::Matcher<Expr>, + InnerMatcher) { return InnerMatcher.matches(*Node.getSizeExpr(), Finder, Builder); } @@ -7696,7 +7608,8 @@ extern const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; /// Matches decayed type /// Example matches i[] in declaration of f. -/// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) +/// (matcher = +/// valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) /// Example matches i[1]. /// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) /// \code @@ -7728,7 +7641,8 @@ AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher<QualType>, /// declaration of \c class \c D. AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) { const DeclContext *DC = Node.getDeclContext(); - if (!DC) return false; + if (!DC) + return false; return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder); } @@ -7774,8 +7688,8 @@ AST_MATCHER_FUNCTION_P_OVERLOAD( /// hasDeclaration(cxxRecordDecl(hasName("A"))) /// )) /// matches "A::" -AST_MATCHER_P(NestedNameSpecifier, specifiesType, - internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P(NestedNameSpecifier, specifiesType, internal::Matcher<QualType>, + InnerMatcher) { if (!Node.getAsType()) return false; return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder); @@ -7876,20 +7790,20 @@ extern const internal::VariadicAllOfMatcher<Attr> attr; /// Matches if a node equals another node. /// /// \c Decl has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl*, Other, 0) { +AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl *, Other, 0) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Stmt has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt*, Other, 1) { +AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt *, Other, 1) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Type has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type*, Other, 2) { - return &Node == Other; +AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type *, Other, 2) { + return &Node == Other; } /// @} @@ -8061,9 +7975,11 @@ AST_POLYMORPHIC_MATCHER(isExplicit, AST_POLYMORPHIC_SUPPORTED_TYPES( /// S(int) -> S<true> // #5 /// explicit S(double) -> S<false> // #6 /// \endcode -/// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2. -/// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4. -/// cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6. +/// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 +/// and #9, but not #1 or #2. +/// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or +/// #4. cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not +/// match #5 or #6. AST_MATCHER_P(FunctionDecl, hasExplicitSpecifier, internal::Matcher<Expr>, InnerMatcher) { ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(&Node); @@ -8113,9 +8029,7 @@ AST_POLYMORPHIC_MATCHER(isInline, AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl, /// } /// \endcode /// namespaceDecl(isAnonymous()) will match #1 but not ::n. -AST_MATCHER(NamespaceDecl, isAnonymous) { - return Node.isAnonymousNamespace(); -} +AST_MATCHER(NamespaceDecl, isAnonymous) { return Node.isAnonymousNamespace(); } /// Matches declarations in the namespace `std`, but not in nested namespaces. /// @@ -8471,9 +8385,7 @@ AST_MATCHER(NamedDecl, hasExternalFormalLinkage) { /// A matcher such as /// parmVarDecl(hasInitializer(anything())) /// is equivalent to parmVarDecl(hasDefaultArgument()). -AST_MATCHER(ParmVarDecl, hasDefaultArgument) { - return Node.hasDefaultArg(); -} +AST_MATCHER(ParmVarDecl, hasDefaultArgument) { return Node.hasDefaultArg(); } /// Matches array new expressions. /// @@ -8483,9 +8395,7 @@ AST_MATCHER(ParmVarDecl, hasDefaultArgument) { /// \endcode /// cxxNewExpr(isArray()) /// matches the expression 'new MyClass[10]'. -AST_MATCHER(CXXNewExpr, isArray) { - return Node.isArray(); -} +AST_MATCHER(CXXNewExpr, isArray) { return Node.isArray(); } /// Matches placement new expression arguments. /// @@ -8536,9 +8446,7 @@ AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher<Expr>, InnerMatcher) { /// class x {}; /// class y; /// \endcode -AST_MATCHER(CXXRecordDecl, hasDefinition) { - return Node.hasDefinition(); -} +AST_MATCHER(CXXRecordDecl, hasDefinition) { return Node.hasDefinition(); } /// Matches C++11 scoped enum declaration. /// @@ -8547,9 +8455,7 @@ AST_MATCHER(CXXRecordDecl, hasDefinition) { /// enum X {}; /// enum class Y {}; /// \endcode -AST_MATCHER(EnumDecl, isScoped) { - return Node.isScoped(); -} +AST_MATCHER(EnumDecl, isScoped) { return Node.isScoped(); } /// Matches a function declared with a trailing return type. /// diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 2d2b71c5393c58..937f0374db6a11 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2518,11 +2518,11 @@ TEST_P(ASTMatchersTest, MatchesString) { TEST(MatchesString, MatchesStringPrefixed) { StatementMatcher Literal = stringLiteral(matchesString("foo.*")); EXPECT_TRUE(matchesConditionally("const char16_t* a = u\"foo\";", Literal, - true, {"-std=c++11"})); + false, {"-std=c++11"})); EXPECT_TRUE(matchesConditionally("const char32_t* a = U\"foo\";", Literal, - true, {"-std=c++11"})); + false, {"-std=c++11"})); EXPECT_TRUE(matchesConditionally("const wchar_t* a = L\"foo\";", Literal, - true, {"-std=c++11"})); + false, {"-std=c++11"})); } TEST_P(ASTMatchersTest, HasSize) { >From c4b165febb21c7d253e739f56b940eca3cc25423 Mon Sep 17 00:00:00 2001 From: hehouhua <hehou...@feysh.com> Date: Fri, 23 Aug 2024 11:42:48 +0800 Subject: [PATCH 4/4] fix fmt --- clang/include/clang/ASTMatchers/ASTMatchers.h | 422 +++++++++++------- 1 file changed, 254 insertions(+), 168 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index b17fb22db177ef..f4d95fb8bff3bb 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -112,7 +112,8 @@ class BoundNodes { /// /// Returns NULL if there was no node bound to \c ID or if there is a node but /// it cannot be converted to the specified type. - template <typename T> const T *getNodeAs(StringRef ID) const { + template <typename T> + const T *getNodeAs(StringRef ID) const { return MyBoundNodes.getNodeAs<T>(ID); } @@ -122,7 +123,9 @@ class BoundNodes { using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap; /// Retrieve mapping from binding identifiers to bound nodes. - const IDToNodeMap &getMap() const { return MyBoundNodes.getMap(); } + const IDToNodeMap &getMap() const { + return MyBoundNodes.getMap(); + } private: friend class internal::BoundNodesTreeBuilder; @@ -315,15 +318,13 @@ AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro, std::string, MacroName) { // Verifies that the statement' beginning and ending are both expanded from // the same instance of the given macro. - auto &Context = Finder->getASTContext(); + auto& Context = Finder->getASTContext(); std::optional<SourceLocation> B = internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); - if (!B) - return false; + if (!B) return false; std::optional<SourceLocation> E = internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); - if (!E) - return false; + if (!E) return false; return *B == *E; } @@ -689,7 +690,9 @@ AST_POLYMORPHIC_MATCHER(isPrivate, /// \endcode /// fieldDecl(isBitField()) /// matches 'int a;' but not 'int b;'. -AST_MATCHER(FieldDecl, isBitField) { return Node.isBitField(); } +AST_MATCHER(FieldDecl, isBitField) { + return Node.isBitField(); +} /// Matches non-static data members that are bit-fields of the specified /// bit width. @@ -732,7 +735,9 @@ AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>, /// Determines whether the function is "main", which is the entry point /// into an executable program. -AST_MATCHER(FunctionDecl, isMain) { return Node.isMain(); } +AST_MATCHER(FunctionDecl, isMain) { + return Node.isMain(); +} /// Matches the specialized template of a specialization declaration. /// @@ -746,8 +751,9 @@ AST_MATCHER(FunctionDecl, isMain) { return Node.isMain(); } /// declaration of 'A' at #1. AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate, internal::Matcher<ClassTemplateDecl>, InnerMatcher) { - const ClassTemplateDecl *Decl = Node.getSpecializedTemplate(); - return (Decl != nullptr && InnerMatcher.matches(*Decl, Finder, Builder)); + const ClassTemplateDecl* Decl = Node.getSpecializedTemplate(); + return (Decl != nullptr && + InnerMatcher.matches(*Decl, Finder, Builder)); } /// Matches an entity that has been implicitly added by the compiler (e.g. @@ -884,7 +890,8 @@ traverse(TraversalKind TK, const internal::MapAnyOfHelper<T...> &InnerMatcher) { /// varDecl(hasInitializer(cxxConstructExpr())) /// \endcode /// only match the declarations for b and c. -AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, + InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder); } @@ -913,7 +920,8 @@ AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, InnerMatcher) { /// varDecl(hasInitializer(declRefExpr())) /// \endcode /// only match the declarations for a. -AST_MATCHER_P(Expr, ignoringImpCasts, internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P(Expr, ignoringImpCasts, + internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder); } @@ -959,8 +967,8 @@ AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { /// varDecl(hasInitializer(integerLiteral())) /// varDecl(hasInitializer(declRefExpr())) /// would only match the declaration for a. -AST_MATCHER_P(Expr, ignoringParenImpCasts, internal::Matcher<Expr>, - InnerMatcher) { +AST_MATCHER_P(Expr, ignoringParenImpCasts, + internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder); } @@ -1099,8 +1107,8 @@ AST_POLYMORPHIC_MATCHER_P( /// classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType( /// recordType(hasDeclaration(recordDecl(hasName("X"))))))) /// matches the specialization of \c struct A generated by \c A<X>. -AST_MATCHER_P(TemplateArgument, refersToType, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(TemplateArgument, refersToType, + internal::Matcher<QualType>, InnerMatcher) { if (Node.getKind() != TemplateArgument::Type) return false; return InnerMatcher.matches(Node.getAsType(), Finder, Builder); @@ -1137,8 +1145,8 @@ AST_MATCHER_P(TemplateArgument, refersToTemplate, /// refersToDeclaration(fieldDecl(hasName("next"))))) /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching /// \c B::next -AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher<Decl>, - InnerMatcher) { +AST_MATCHER_P(TemplateArgument, refersToDeclaration, + internal::Matcher<Decl>, InnerMatcher) { if (Node.getKind() == TemplateArgument::Declaration) return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder); return false; @@ -1208,7 +1216,8 @@ AST_MATCHER_P(TemplateArgument, refersToIntegralType, /// classTemplateSpecializationDecl( /// hasAnyTemplateArgument(equalsIntegralValue("42"))) /// matches the implicit instantiation of C in C<42>. -AST_MATCHER_P(TemplateArgument, equalsIntegralValue, std::string, Value) { +AST_MATCHER_P(TemplateArgument, equalsIntegralValue, + std::string, Value) { if (Node.getKind() != TemplateArgument::Integral) return false; return toString(Node.getAsIntegral(), 10) == Value; @@ -1225,8 +1234,7 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue, std::string, Value) { /// autoreleasePoolStmt(stmt()) matches the declaration of "x" /// inside the autorelease pool. extern const internal::VariadicDynCastAllOfMatcher<Stmt, - ObjCAutoreleasePoolStmt> - autoreleasePoolStmt; + ObjCAutoreleasePoolStmt> autoreleasePoolStmt; /// Matches any value declaration. /// @@ -1604,7 +1612,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> /// printf("%d", p); /// }) /// \endcode -extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> blockDecl; +extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> + blockDecl; /// Matches Objective-C instance variable declarations. /// @@ -1693,8 +1702,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> /// Matches the syntactic form of init list expressions /// (if expression have it). -AST_MATCHER_P(InitListExpr, hasSyntacticForm, internal::Matcher<Expr>, - InnerMatcher) { +AST_MATCHER_P(InitListExpr, hasSyntacticForm, + internal::Matcher<Expr>, InnerMatcher) { const Expr *SyntForm = Node.getSyntacticForm(); return (SyntForm != nullptr && InnerMatcher.matches(*SyntForm, Finder, Builder)); @@ -1973,8 +1982,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> cxxNoexceptExpr; -/// Matches a loop initializing the elements of an array in a number of -/// contexts: +/// Matches a loop initializing the elements of an array in a number of contexts: /// * in the implicit copy/move constructor for a class with an array member /// * when a lambda-expression captures an array by value /// * when a decomposition declaration decomposes an array @@ -1988,16 +1996,16 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> /// }; /// } /// \endcode -/// arrayInitLoopExpr() matches the implicit loop that initializes each element -/// of the implicit array field inside the lambda object, that represents the -/// array `a` captured by value. +/// arrayInitLoopExpr() matches the implicit loop that initializes each element of +/// the implicit array field inside the lambda object, that represents the array `a` +/// captured by value. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitLoopExpr> arrayInitLoopExpr; /// The arrayInitIndexExpr consists of two subexpressions: a common expression -/// (the source array) that is evaluated once up-front, and a per-element -/// initializer that runs once for each array element. Within the per-element -/// initializer, the current index may be obtained via an ArrayInitIndexExpr. +/// (the source array) that is evaluated once up-front, and a per-element initializer +/// that runs once for each array element. Within the per-element initializer, +/// the current index may be obtained via an ArrayInitIndexExpr. /// /// Given /// \code @@ -2153,7 +2161,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; /// \code /// for (x; x < N; ++x) { } /// \endcode -AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, InnerMatcher) { +AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, + InnerMatcher) { const Stmt *const Increment = Node.getInc(); return (Increment != nullptr && InnerMatcher.matches(*Increment, Finder, Builder)); @@ -2167,7 +2176,8 @@ AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, InnerMatcher) { /// \code /// for (int x = 0; x < N; ++x) { } /// \endcode -AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, InnerMatcher) { +AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, + InnerMatcher) { const Stmt *const Init = Node.getInit(); return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)); } @@ -2519,7 +2529,8 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> cxxNullPtrLiteralExpr; /// Matches GNU __builtin_choose_expr. -extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr; +extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> + chooseExpr; /// Matches builtin function __builtin_convertvector. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConvertVectorExpr> @@ -3035,8 +3046,8 @@ AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind) { /// Same as unaryExprOrTypeTraitExpr, but only matching /// alignof. -inline internal::BindableMatcher<Stmt> -alignOfExpr(const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { +inline internal::BindableMatcher<Stmt> alignOfExpr( + const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { return stmt(unaryExprOrTypeTraitExpr( allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)), InnerMatcher))); @@ -3044,10 +3055,10 @@ alignOfExpr(const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { /// Same as unaryExprOrTypeTraitExpr, but only matching /// sizeof. -inline internal::BindableMatcher<Stmt> -sizeOfExpr(const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { - return stmt( - unaryExprOrTypeTraitExpr(allOf(ofKind(UETT_SizeOf), InnerMatcher))); +inline internal::BindableMatcher<Stmt> sizeOfExpr( + const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { + return stmt(unaryExprOrTypeTraitExpr( + allOf(ofKind(UETT_SizeOf), InnerMatcher))); } /// Matches NamedDecl nodes that have the specified name. @@ -3105,8 +3116,7 @@ AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) { return RegExp->match(FullNameString); } -/// Matches string literals that contain a substring matched by the given -/// RegExp. +/// Matches string literals that contain a substring matched by the given RegExp. /// /// Example matches "foo" and "foobar" but not "bar" /// (matcher = stringLiteral(matchesString("foo.*"))) @@ -3272,10 +3282,10 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode, /// \endcode /// /// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl> -AST_POLYMORPHIC_MATCHER_P(isDerivedFrom, - AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, - ObjCInterfaceDecl), - internal::Matcher<NamedDecl>, Base) { +AST_POLYMORPHIC_MATCHER_P( + isDerivedFrom, + AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), + internal::Matcher<NamedDecl>, Base) { // Check if the node is a C++ struct/union/class. if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); @@ -3460,7 +3470,9 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>, /// /// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of /// \c decltype(x) -AST_MATCHER(CXXRecordDecl, isLambda) { return Node.isLambda(); } +AST_MATCHER(CXXRecordDecl, isLambda) { + return Node.isLambda(); +} /// Matches AST nodes that have child AST nodes that match the /// provided matcher. @@ -3698,13 +3710,15 @@ AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher<NamedDecl>, /// matches `(g()).m()`. /// /// FIXME: Overload to allow directly matching types? -AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, InnerMatcher) { - const Expr *ExprNode = - Node.getImplicitObjectArgument()->IgnoreParenImpCasts(); +AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, + InnerMatcher) { + const Expr *ExprNode = Node.getImplicitObjectArgument() + ->IgnoreParenImpCasts(); return (ExprNode != nullptr && InnerMatcher.matches(*ExprNode, Finder, Builder)); } + /// Matches on the receiver of an ObjectiveC Message expression. /// /// Example @@ -3733,7 +3747,9 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>, /// \code /// @interface I - (void)bar; @end /// \endcode -AST_MATCHER(ObjCMethodDecl, isClassMethod) { return Node.isClassMethod(); } +AST_MATCHER(ObjCMethodDecl, isClassMethod) { + return Node.isClassMethod(); +} /// Returns true when the Objective-C method declaration is an instance method. /// @@ -3764,7 +3780,9 @@ AST_MATCHER(ObjCMethodDecl, isInstanceMethod) { /// NSString *x = @"hello"; /// [x containsString:@"h"]; /// \endcode -AST_MATCHER(ObjCMessageExpr, isClassMessage) { return Node.isClassMessage(); } +AST_MATCHER(ObjCMessageExpr, isClassMessage) { + return Node.isClassMessage(); +} /// Returns true when the Objective-C message is sent to an instance. /// @@ -3824,8 +3842,9 @@ AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { /// [myObj methodB:argB]; /// \endcode extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, - StringRef, internal::hasAnySelectorFunc> - hasAnySelector; + StringRef, + internal::hasAnySelectorFunc> + hasAnySelector; /// Matches ObjC selectors whose name contains /// a substring matched by the given RegExp. @@ -4019,8 +4038,8 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD( /// \endcode /// /// Example matches class Derived -/// (matcher = -/// cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")))))) \code +/// (matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")))))) +/// \code /// class Base {}; /// class Derived : Base {}; /// \endcode @@ -4107,7 +4126,9 @@ AST_MATCHER_P(QualType, asString, std::string, Name) { /// class Y { public: void x(); }; /// void z() { Y *y; y->x(); } /// \endcode -AST_MATCHER_P(QualType, pointsTo, internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P( + QualType, pointsTo, internal::Matcher<QualType>, + InnerMatcher) { return (!Node.isNull() && Node->isAnyPointerType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } @@ -4148,7 +4169,8 @@ AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>, /// } /// }; /// \endcode -AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, InnerMatcher) { +AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, + InnerMatcher) { return (!Node.isNull() && Node->isReferenceType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } @@ -4222,7 +4244,7 @@ AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument, AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<QualType>, InnerMatcher, 0) { return onImplicitObjectArgument( - anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) + anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } @@ -4230,7 +4252,7 @@ AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<Decl>, InnerMatcher, 1) { return onImplicitObjectArgument( - anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) + anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } @@ -4243,7 +4265,8 @@ AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, /// bool x; /// if (x) {} /// \endcode -AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, InnerMatcher) { +AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, + InnerMatcher) { const Decl *DeclNode = Node.getDecl(); return (DeclNode != nullptr && InnerMatcher.matches(*DeclNode, Finder, Builder)); @@ -4327,7 +4350,9 @@ AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { /// bool y() { return true; } /// bool x = y(); /// \endcode -AST_MATCHER_P(VarDecl, hasInitializer, internal::Matcher<Expr>, InnerMatcher) { +AST_MATCHER_P( + VarDecl, hasInitializer, internal::Matcher<Expr>, + InnerMatcher) { const Expr *Initializer = Node.getAnyInitializer(); return (Initializer != nullptr && InnerMatcher.matches(*Initializer, Finder, Builder)); @@ -4382,7 +4407,9 @@ AST_MATCHER_P(LambdaExpr, forEachLambdaCapture, /// } /// static int z; /// \endcode -AST_MATCHER(VarDecl, isStaticLocal) { return Node.isStaticLocal(); } +AST_MATCHER(VarDecl, isStaticLocal) { + return Node.isStaticLocal(); +} /// Matches a variable declaration that has function scope and is a /// non-static local variable. @@ -4395,7 +4422,9 @@ AST_MATCHER(VarDecl, isStaticLocal) { return Node.isStaticLocal(); } /// } /// int z; /// \endcode -AST_MATCHER(VarDecl, hasLocalStorage) { return Node.hasLocalStorage(); } +AST_MATCHER(VarDecl, hasLocalStorage) { + return Node.hasLocalStorage(); +} /// Matches a variable declaration that does not have local storage. /// @@ -4407,7 +4436,9 @@ AST_MATCHER(VarDecl, hasLocalStorage) { return Node.hasLocalStorage(); } /// } /// int z; /// \endcode -AST_MATCHER(VarDecl, hasGlobalStorage) { return Node.hasGlobalStorage(); } +AST_MATCHER(VarDecl, hasGlobalStorage) { + return Node.hasGlobalStorage(); +} /// Matches a variable declaration that has automatic storage duration. /// @@ -4472,7 +4503,9 @@ AST_MATCHER(VarDecl, hasThreadStorageDuration) { /// } /// } /// \endcode -AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); } +AST_MATCHER(VarDecl, isExceptionVariable) { + return Node.isExceptionVariable(); +} /// Checks that a call expression or a constructor call expression has /// a specific number of arguments (including absent default arguments). @@ -4669,7 +4702,7 @@ AST_MATCHER(CXXFoldExpr, isBinaryFold) { return Node.getInit() != nullptr; } AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N, internal::Matcher<Expr>, InnerMatcher) { return N < Node.getNumInits() && - InnerMatcher.matches(*Node.getInit(N), Finder, Builder); + InnerMatcher.matches(*Node.getInit(N), Finder, Builder); } /// Matches declaration statements that contain a specific number of @@ -4768,11 +4801,11 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, /// forField(hasName("foo_")))))) /// matches Foo /// with forField matching foo_ -AST_MATCHER_P(CXXCtorInitializer, forField, internal::Matcher<FieldDecl>, - InnerMatcher) { +AST_MATCHER_P(CXXCtorInitializer, forField, + internal::Matcher<FieldDecl>, InnerMatcher) { const FieldDecl *NodeAsDecl = Node.getAnyMember(); return (NodeAsDecl != nullptr && - InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); + InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); } /// Matches the initializer expression of a constructor initializer. @@ -4788,11 +4821,11 @@ AST_MATCHER_P(CXXCtorInitializer, forField, internal::Matcher<FieldDecl>, /// withInitializer(integerLiteral(equals(1))))))) /// matches Foo /// with withInitializer matching (1) -AST_MATCHER_P(CXXCtorInitializer, withInitializer, internal::Matcher<Expr>, - InnerMatcher) { - const Expr *NodeAsExpr = Node.getInit(); +AST_MATCHER_P(CXXCtorInitializer, withInitializer, + internal::Matcher<Expr>, InnerMatcher) { + const Expr* NodeAsExpr = Node.getInit(); return (NodeAsExpr != nullptr && - InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); + InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); } /// Matches a constructor initializer if it is explicitly written in @@ -4808,7 +4841,9 @@ AST_MATCHER_P(CXXCtorInitializer, withInitializer, internal::Matcher<Expr>, /// \endcode /// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) /// will match Foo(int), but not Foo() -AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); } +AST_MATCHER(CXXCtorInitializer, isWritten) { + return Node.isWritten(); +} /// Matches a constructor initializer if it is initializing a base, as /// opposed to a member. @@ -5005,12 +5040,14 @@ AST_MATCHER(CXXConstructExpr, requiresZeroInitialization) { /// the matcher objcMethodDecl(hasParameter(0, hasName("y"))) /// matches the declaration of method f with hasParameter /// matching y. -AST_POLYMORPHIC_MATCHER_P2( - hasParameter, - AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), - unsigned, N, internal::Matcher<ParmVarDecl>, InnerMatcher) { - return (N < Node.parameters().size() && - InnerMatcher.matches(*Node.parameters()[N], Finder, Builder)); +AST_POLYMORPHIC_MATCHER_P2(hasParameter, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, + ObjCMethodDecl, + BlockDecl), + unsigned, N, internal::Matcher<ParmVarDecl>, + InnerMatcher) { + return (N < Node.parameters().size() + && InnerMatcher.matches(*Node.parameters()[N], Finder, Builder)); } /// Matches if the given method declaration declares a member function with an @@ -5070,8 +5107,8 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam, bool Matched = false; for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) { BoundNodesTreeBuilder ArgMatches(*Builder); - if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder, - &ArgMatches)) { + if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), + Finder, &ArgMatches)) { BoundNodesTreeBuilder ParamMatches(ArgMatches); if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl( hasParameter(ParamIndex, ParamMatcher)))), @@ -5252,7 +5289,8 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyParameter, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), - internal::Matcher<ParmVarDecl>, InnerMatcher) { + internal::Matcher<ParmVarDecl>, + InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), Node.param_end(), Finder, Builder) != Node.param_end(); @@ -5351,8 +5389,8 @@ AST_MATCHER(FunctionDecl, isNoReturn) { return Node.isNoReturn(); } /// \endcode /// cxxMethodDecl(returns(asString("int"))) /// matches int f() { return 1; } -AST_MATCHER_P(FunctionDecl, returns, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(FunctionDecl, returns, + internal::Matcher<QualType>, InnerMatcher) { return InnerMatcher.matches(Node.getReturnType(), Finder, Builder); } @@ -5405,7 +5443,9 @@ AST_POLYMORPHIC_MATCHER(isStaticStorageClass, /// \endcode /// functionDecl(isDeleted()) /// matches the declaration of DeletedFunc, but not Func. -AST_MATCHER(FunctionDecl, isDeleted) { return Node.isDeleted(); } +AST_MATCHER(FunctionDecl, isDeleted) { + return Node.isDeleted(); +} /// Matches defaulted function declarations. /// @@ -5416,7 +5456,9 @@ AST_MATCHER(FunctionDecl, isDeleted) { return Node.isDeleted(); } /// \endcode /// functionDecl(isDefaulted()) /// matches the declaration of ~B, but not ~A. -AST_MATCHER(FunctionDecl, isDefaulted) { return Node.isDefaulted(); } +AST_MATCHER(FunctionDecl, isDefaulted) { + return Node.isDefaulted(); +} /// Matches weak function declarations. /// @@ -5517,7 +5559,8 @@ AST_POLYMORPHIC_MATCHER(isConsteval, /// ifStmt(isConstexpr()) /// matches the if statement in baz. AST_POLYMORPHIC_MATCHER(isConstexpr, - AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, FunctionDecl, + AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, + FunctionDecl, IfStmt)) { return Node.isConstexpr(); } @@ -5656,8 +5699,8 @@ AST_POLYMORPHIC_MATCHER_P(equalsBoundNode, /// matches 'A* a = GetAPointer()'. AST_MATCHER_P(IfStmt, hasConditionVariableStatement, internal::Matcher<DeclStmt>, InnerMatcher) { - const DeclStmt *const DeclarationStatement = - Node.getConditionVariableDeclStmt(); + const DeclStmt* const DeclarationStatement = + Node.getConditionVariableDeclStmt(); return DeclarationStatement != nullptr && InnerMatcher.matches(*DeclarationStatement, Finder, Builder); } @@ -5671,9 +5714,9 @@ AST_MATCHER_P(IfStmt, hasConditionVariableStatement, /// \endcode /// arraySubscriptExpression(hasIndex(integerLiteral())) /// matches \c i[1] with the \c integerLiteral() matching \c 1 -AST_MATCHER_P(ArraySubscriptExpr, hasIndex, internal::Matcher<Expr>, - InnerMatcher) { - if (const Expr *Expression = Node.getIdx()) +AST_MATCHER_P(ArraySubscriptExpr, hasIndex, + internal::Matcher<Expr>, InnerMatcher) { + if (const Expr* Expression = Node.getIdx()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } @@ -5688,9 +5731,9 @@ AST_MATCHER_P(ArraySubscriptExpr, hasIndex, internal::Matcher<Expr>, /// arraySubscriptExpression(hasBase(implicitCastExpr( /// hasSourceExpression(declRefExpr())))) /// matches \c i[1] with the \c declRefExpr() matching \c i -AST_MATCHER_P(ArraySubscriptExpr, hasBase, internal::Matcher<Expr>, - InnerMatcher) { - if (const Expr *Expression = Node.getBase()) +AST_MATCHER_P(ArraySubscriptExpr, hasBase, + internal::Matcher<Expr>, InnerMatcher) { + if (const Expr* Expression = Node.getBase()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } @@ -5747,12 +5790,14 @@ AST_POLYMORPHIC_MATCHER_P( /// with compoundStmt() /// matching '{}' /// but does not match 'void g();' -AST_MATCHER_P(FunctionDecl, hasAnyBody, internal::Matcher<Stmt>, InnerMatcher) { +AST_MATCHER_P(FunctionDecl, hasAnyBody, + internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Statement = Node.getBody(); return (Statement != nullptr && InnerMatcher.matches(*Statement, Finder, Builder)); } + /// Matches compound statements where at least one substatement matches /// a given matcher. Also matches StmtExprs that have CompoundStmt as children. /// @@ -5822,31 +5867,32 @@ equals(const ValueT &Value) { Value); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD( - equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, - IntegerLiteral), - bool, Value, 0) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( - Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, + CXXBoolLiteralExpr, + IntegerLiteral), + bool, Value, 0) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) + .matchesNode(Node); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD( - equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, - IntegerLiteral), - unsigned, Value, 1) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( - Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, + CXXBoolLiteralExpr, + IntegerLiteral), + unsigned, Value, 1) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) + .matchesNode(Node); } -AST_POLYMORPHIC_MATCHER_P_OVERLOAD( - equals, - AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, - FloatingLiteral, IntegerLiteral), - double, Value, 2) { - return internal::ValueEqualsMatcher<NodeType, ParamT>(Value).matchesNode( - Node); +AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, + AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, + CXXBoolLiteralExpr, + FloatingLiteral, + IntegerLiteral), + double, Value, 2) { + return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) + .matchesNode(Node); } /// Matches the operator Name of operator expressions and fold expressions @@ -6060,8 +6106,8 @@ AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) { /// /// (Note: Clang's AST refers to other conversions as "casts" too, and calls /// actual casts "explicit" casts.) -AST_MATCHER_P(ExplicitCastExpr, hasDestinationType, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(ExplicitCastExpr, hasDestinationType, + internal::Matcher<QualType>, InnerMatcher) { const QualType NodeType = Node.getTypeAsWritten(); return InnerMatcher.matches(NodeType, Finder, Builder); } @@ -6082,7 +6128,9 @@ AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType, /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isStruct) { return Node.isStruct(); } +AST_MATCHER(TagDecl, isStruct) { + return Node.isStruct(); +} /// Matches TagDecl object that are spelled with "union." /// @@ -6093,7 +6141,9 @@ AST_MATCHER(TagDecl, isStruct) { return Node.isStruct(); } /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isUnion) { return Node.isUnion(); } +AST_MATCHER(TagDecl, isUnion) { + return Node.isUnion(); +} /// Matches TagDecl object that are spelled with "class." /// @@ -6104,7 +6154,9 @@ AST_MATCHER(TagDecl, isUnion) { return Node.isUnion(); } /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isClass) { return Node.isClass(); } +AST_MATCHER(TagDecl, isClass) { + return Node.isClass(); +} /// Matches TagDecl object that are spelled with "enum." /// @@ -6115,7 +6167,9 @@ AST_MATCHER(TagDecl, isClass) { return Node.isClass(); } /// union U {}; /// enum E {}; /// \endcode -AST_MATCHER(TagDecl, isEnum) { return Node.isEnum(); } +AST_MATCHER(TagDecl, isEnum) { + return Node.isEnum(); +} /// Matches the true branch expression of a conditional operator. /// @@ -6187,7 +6241,9 @@ AST_POLYMORPHIC_MATCHER(isDefinition, /// template <typename... Ts> void h(Ts...); /// void i(); /// \endcode -AST_MATCHER(FunctionDecl, isVariadic) { return Node.isVariadic(); } +AST_MATCHER(FunctionDecl, isVariadic) { + return Node.isVariadic(); +} /// Matches the class declaration that the given method declaration /// belongs to. @@ -6206,13 +6262,14 @@ AST_MATCHER(FunctionDecl, isVariadic) { return Node.isVariadic(); } /// }; /// A a = A(); /// \endcode -AST_MATCHER_P(CXXMethodDecl, ofClass, internal::Matcher<CXXRecordDecl>, - InnerMatcher) { +AST_MATCHER_P(CXXMethodDecl, ofClass, + internal::Matcher<CXXRecordDecl>, InnerMatcher) { ASTChildrenNotSpelledInSourceScope RAII(Finder, false); const CXXRecordDecl *Parent = Node.getParent(); - return (Parent != nullptr && InnerMatcher.matches(*Parent, Finder, Builder)); + return (Parent != nullptr && + InnerMatcher.matches(*Parent, Finder, Builder)); } /// Matches each method overridden by the given method. This matcher may @@ -6347,7 +6404,9 @@ AST_MATCHER(CXXMethodDecl, isPure) { return Node.isPureVirtual(); } /// \endcode /// /// cxxMethodDecl(isConst()) matches A::foo() but not A::bar() -AST_MATCHER(CXXMethodDecl, isConst) { return Node.isConst(); } +AST_MATCHER(CXXMethodDecl, isConst) { + return Node.isConst(); +} /// Matches if the given method declaration declares a copy assignment /// operator. @@ -6412,7 +6471,9 @@ AST_MATCHER(CXXMethodDecl, isOverride) { /// }; /// \endcode /// cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. -AST_MATCHER(CXXMethodDecl, isUserProvided) { return Node.isUserProvided(); } +AST_MATCHER(CXXMethodDecl, isUserProvided) { + return Node.isUserProvided(); +} /// Matches member expressions that are called with '->' as opposed /// to '.'. @@ -6454,7 +6515,9 @@ AST_POLYMORPHIC_MATCHER( /// \endcode /// functionDecl(hasAnyParameter(hasType(isInteger()))) /// matches "a(int)", "b(long)", but not "c(double)". -AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); } +AST_MATCHER(QualType, isInteger) { + return Node->isIntegerType(); +} /// Matches QualType nodes that are of unsigned integer type. /// @@ -6467,7 +6530,7 @@ AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); } /// functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) /// matches "b(unsigned long)", but not "a(int)" and "c(double)". AST_MATCHER(QualType, isUnsignedInteger) { - return Node->isUnsignedIntegerType(); + return Node->isUnsignedIntegerType(); } /// Matches QualType nodes that are of signed integer type. @@ -6480,7 +6543,9 @@ AST_MATCHER(QualType, isUnsignedInteger) { /// \endcode /// functionDecl(hasAnyParameter(hasType(isSignedInteger()))) /// matches "a(int)", but not "b(unsigned long)" and "c(double)". -AST_MATCHER(QualType, isSignedInteger) { return Node->isSignedIntegerType(); } +AST_MATCHER(QualType, isSignedInteger) { + return Node->isSignedIntegerType(); +} /// Matches QualType nodes that are of character type. /// @@ -6492,7 +6557,9 @@ AST_MATCHER(QualType, isSignedInteger) { return Node->isSignedIntegerType(); } /// \endcode /// functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) /// matches "a(char)", "b(wchar_t)", but not "c(double)". -AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } +AST_MATCHER(QualType, isAnyCharacter) { + return Node->isAnyCharacterType(); +} /// Matches QualType nodes that are of any pointer type; this includes /// the Objective-C object pointer type, which is different despite being @@ -6510,7 +6577,9 @@ AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } /// \endcode /// varDecl(hasType(isAnyPointer())) /// matches "int *i" and "Foo *f", but not "int j". -AST_MATCHER(QualType, isAnyPointer) { return Node->isAnyPointerType(); } +AST_MATCHER(QualType, isAnyPointer) { + return Node->isAnyPointerType(); +} /// Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. @@ -6527,7 +6596,9 @@ AST_MATCHER(QualType, isAnyPointer) { return Node->isAnyPointerType(); } /// matches "void b(int const)", "void c(const int)" and /// "void e(int const) {}". It does not match d as there /// is no top-level const on the parameter type "const int *". -AST_MATCHER(QualType, isConstQualified) { return Node.isConstQualified(); } +AST_MATCHER(QualType, isConstQualified) { + return Node.isConstQualified(); +} /// Matches QualType nodes that are volatile-qualified, i.e., that /// include "top-level" volatile. @@ -6561,7 +6632,9 @@ AST_MATCHER(QualType, isVolatileQualified) { /// \endcode /// \c varDecl(hasType(hasLocalQualifiers())) matches only \c j and \c k. /// \c i is const-qualified but the qualifier is not local. -AST_MATCHER(QualType, hasLocalQualifiers) { return Node.hasLocalQualifiers(); } +AST_MATCHER(QualType, hasLocalQualifiers) { + return Node.hasLocalQualifiers(); +} /// Matches a member expression where the member is matched by a /// given matcher. @@ -6575,7 +6648,8 @@ AST_MATCHER(QualType, hasLocalQualifiers) { return Node.hasLocalQualifiers(); } /// memberExpr(member(hasName("first"))) /// matches second.first /// but not first.second (because the member name there is "second"). -AST_MATCHER_P(MemberExpr, member, internal::Matcher<ValueDecl>, InnerMatcher) { +AST_MATCHER_P(MemberExpr, member, + internal::Matcher<ValueDecl>, InnerMatcher) { return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder); } @@ -6637,8 +6711,8 @@ AST_MATCHER_P(BaseUsingDecl, hasAnyUsingShadowDecl, /// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) /// matches \code using X::b \endcode /// but not \code using X::a \endcode -AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, internal::Matcher<NamedDecl>, - InnerMatcher) { +AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, + internal::Matcher<NamedDecl>, InnerMatcher) { return InnerMatcher.matches(*Node.getTargetDecl(), Finder, Builder); } @@ -6937,7 +7011,9 @@ AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>, /// \endcode /// functionDecl(returns(booleanType())) /// matches "bool func();" -AST_MATCHER(Type, booleanType) { return Node.isBooleanType(); } +AST_MATCHER(Type, booleanType) { + return Node.isBooleanType(); +} /// Matches type \c void. /// @@ -6947,7 +7023,9 @@ AST_MATCHER(Type, booleanType) { return Node.isBooleanType(); } /// \endcode /// functionDecl(returns(voidType())) /// matches "void func();" -AST_MATCHER(Type, voidType) { return Node.isVoidType(); } +AST_MATCHER(Type, voidType) { + return Node.isVoidType(); +} template <typename NodeType> using AstTypeMatcher = internal::VariadicDynCastAllOfMatcher<Type, NodeType>; @@ -6997,7 +7075,9 @@ extern const AstTypeMatcher<ComplexType> complexType; /// \endcode /// realFloatingPointType() /// matches "float f" but not "int i" -AST_MATCHER(Type, realFloatingPointType) { return Node.isRealFloatingType(); } +AST_MATCHER(Type, realFloatingPointType) { + return Node.isRealFloatingType(); +} /// Matches arrays and C99 complex types that have a specific element /// type. @@ -7119,8 +7199,8 @@ extern const AstTypeMatcher<VariableArrayType> variableArrayType; /// variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( /// varDecl(hasName("b"))))))) /// matches "int a[b]" -AST_MATCHER_P(VariableArrayType, hasSizeExpr, internal::Matcher<Expr>, - InnerMatcher) { +AST_MATCHER_P(VariableArrayType, hasSizeExpr, + internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.getSizeExpr(), Finder, Builder); } @@ -7608,8 +7688,7 @@ extern const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; /// Matches decayed type /// Example matches i[] in declaration of f. -/// (matcher = -/// valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) +/// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) /// Example matches i[1]. /// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) /// \code @@ -7641,8 +7720,7 @@ AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher<QualType>, /// declaration of \c class \c D. AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) { const DeclContext *DC = Node.getDeclContext(); - if (!DC) - return false; + if (!DC) return false; return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder); } @@ -7688,8 +7766,8 @@ AST_MATCHER_FUNCTION_P_OVERLOAD( /// hasDeclaration(cxxRecordDecl(hasName("A"))) /// )) /// matches "A::" -AST_MATCHER_P(NestedNameSpecifier, specifiesType, internal::Matcher<QualType>, - InnerMatcher) { +AST_MATCHER_P(NestedNameSpecifier, specifiesType, + internal::Matcher<QualType>, InnerMatcher) { if (!Node.getAsType()) return false; return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder); @@ -7790,20 +7868,20 @@ extern const internal::VariadicAllOfMatcher<Attr> attr; /// Matches if a node equals another node. /// /// \c Decl has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl *, Other, 0) { +AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl*, Other, 0) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Stmt has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt *, Other, 1) { +AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt*, Other, 1) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Type has pointer identity in the AST. -AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type *, Other, 2) { - return &Node == Other; +AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type*, Other, 2) { + return &Node == Other; } /// @} @@ -7975,11 +8053,9 @@ AST_POLYMORPHIC_MATCHER(isExplicit, AST_POLYMORPHIC_SUPPORTED_TYPES( /// S(int) -> S<true> // #5 /// explicit S(double) -> S<false> // #6 /// \endcode -/// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 -/// and #9, but not #1 or #2. -/// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or -/// #4. cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not -/// match #5 or #6. +/// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2. +/// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4. +/// cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6. AST_MATCHER_P(FunctionDecl, hasExplicitSpecifier, internal::Matcher<Expr>, InnerMatcher) { ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(&Node); @@ -8029,7 +8105,9 @@ AST_POLYMORPHIC_MATCHER(isInline, AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl, /// } /// \endcode /// namespaceDecl(isAnonymous()) will match #1 but not ::n. -AST_MATCHER(NamespaceDecl, isAnonymous) { return Node.isAnonymousNamespace(); } +AST_MATCHER(NamespaceDecl, isAnonymous) { + return Node.isAnonymousNamespace(); +} /// Matches declarations in the namespace `std`, but not in nested namespaces. /// @@ -8385,7 +8463,9 @@ AST_MATCHER(NamedDecl, hasExternalFormalLinkage) { /// A matcher such as /// parmVarDecl(hasInitializer(anything())) /// is equivalent to parmVarDecl(hasDefaultArgument()). -AST_MATCHER(ParmVarDecl, hasDefaultArgument) { return Node.hasDefaultArg(); } +AST_MATCHER(ParmVarDecl, hasDefaultArgument) { + return Node.hasDefaultArg(); +} /// Matches array new expressions. /// @@ -8395,7 +8475,9 @@ AST_MATCHER(ParmVarDecl, hasDefaultArgument) { return Node.hasDefaultArg(); } /// \endcode /// cxxNewExpr(isArray()) /// matches the expression 'new MyClass[10]'. -AST_MATCHER(CXXNewExpr, isArray) { return Node.isArray(); } +AST_MATCHER(CXXNewExpr, isArray) { + return Node.isArray(); +} /// Matches placement new expression arguments. /// @@ -8446,7 +8528,9 @@ AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher<Expr>, InnerMatcher) { /// class x {}; /// class y; /// \endcode -AST_MATCHER(CXXRecordDecl, hasDefinition) { return Node.hasDefinition(); } +AST_MATCHER(CXXRecordDecl, hasDefinition) { + return Node.hasDefinition(); +} /// Matches C++11 scoped enum declaration. /// @@ -8455,7 +8539,9 @@ AST_MATCHER(CXXRecordDecl, hasDefinition) { return Node.hasDefinition(); } /// enum X {}; /// enum class Y {}; /// \endcode -AST_MATCHER(EnumDecl, isScoped) { return Node.isScoped(); } +AST_MATCHER(EnumDecl, isScoped) { + return Node.isScoped(); +} /// Matches a function declared with a trailing return type. /// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits