Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 1 | //===- ASTMatchersInternal.cpp - Structural query framework ---------------===// |
Manuel Klimek | 04616e4 | 2012-07-06 05:48:52 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implements the base layer of the matcher framework. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Manuel Klimek | 04616e4 | 2012-07-06 05:48:52 +0000 | [diff] [blame] | 14 | #include "clang/ASTMatchers/ASTMatchersInternal.h" |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/ASTTypeTraits.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclTemplate.h" |
| 19 | #include "clang/AST/PrettyPrinter.h" |
| 20 | #include "clang/ASTMatchers/ASTMatchers.h" |
| 21 | #include "clang/Basic/LLVM.h" |
| 22 | #include "llvm/ADT/ArrayRef.h" |
| 23 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 24 | #include "llvm/ADT/None.h" |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallVector.h" |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringRef.h" |
| 28 | #include "llvm/Support/Casting.h" |
| 29 | #include "llvm/Support/ErrorHandling.h" |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ManagedStatic.h" |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 31 | #include "llvm/Support/raw_ostream.h" |
| 32 | #include <algorithm> |
| 33 | #include <cassert> |
| 34 | #include <cstddef> |
| 35 | #include <string> |
| 36 | #include <utility> |
| 37 | #include <vector> |
Manuel Klimek | 04616e4 | 2012-07-06 05:48:52 +0000 | [diff] [blame] | 38 | |
| 39 | namespace clang { |
| 40 | namespace ast_matchers { |
| 41 | namespace internal { |
| 42 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 43 | bool NotUnaryOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 44 | ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, |
| 45 | ArrayRef<DynTypedMatcher> InnerMatchers); |
| 46 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 47 | bool AllOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 48 | ASTMatchFinder *Finder, |
| 49 | BoundNodesTreeBuilder *Builder, |
| 50 | ArrayRef<DynTypedMatcher> InnerMatchers); |
| 51 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 52 | bool EachOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 53 | ASTMatchFinder *Finder, |
| 54 | BoundNodesTreeBuilder *Builder, |
| 55 | ArrayRef<DynTypedMatcher> InnerMatchers); |
| 56 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 57 | bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 58 | ASTMatchFinder *Finder, |
| 59 | BoundNodesTreeBuilder *Builder, |
| 60 | ArrayRef<DynTypedMatcher> InnerMatchers); |
| 61 | |
Manuel Klimek | a0c025f | 2013-06-19 15:42:45 +0000 | [diff] [blame] | 62 | void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) { |
| 63 | if (Bindings.empty()) |
| 64 | Bindings.push_back(BoundNodesMap()); |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 65 | for (BoundNodesMap &Binding : Bindings) { |
| 66 | ResultVisitor->visitMatch(BoundNodes(Binding)); |
Manuel Klimek | 021d56f | 2012-08-28 23:26:39 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 70 | namespace { |
| 71 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 72 | using VariadicOperatorFunction = bool (*)( |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 73 | const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder, |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 74 | BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers); |
| 75 | |
| 76 | template <VariadicOperatorFunction Func> |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 77 | class VariadicMatcher : public DynMatcherInterface { |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 78 | public: |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 79 | VariadicMatcher(std::vector<DynTypedMatcher> InnerMatchers) |
| 80 | : InnerMatchers(std::move(InnerMatchers)) {} |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 81 | |
| 82 | bool dynMatches(const ast_type_traits::DynTypedNode &DynNode, |
| 83 | ASTMatchFinder *Finder, |
| 84 | BoundNodesTreeBuilder *Builder) const override { |
| 85 | return Func(DynNode, Finder, Builder, InnerMatchers); |
| 86 | } |
| 87 | |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 88 | private: |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 89 | std::vector<DynTypedMatcher> InnerMatchers; |
| 90 | }; |
| 91 | |
| 92 | class IdDynMatcher : public DynMatcherInterface { |
Benjamin Kramer | 018b6d4 | 2016-07-21 15:06:51 +0000 | [diff] [blame] | 93 | public: |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 94 | IdDynMatcher(StringRef ID, |
Benjamin Kramer | 018b6d4 | 2016-07-21 15:06:51 +0000 | [diff] [blame] | 95 | IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher) |
| 96 | : ID(ID), InnerMatcher(std::move(InnerMatcher)) {} |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 97 | |
| 98 | bool dynMatches(const ast_type_traits::DynTypedNode &DynNode, |
| 99 | ASTMatchFinder *Finder, |
| 100 | BoundNodesTreeBuilder *Builder) const override { |
| 101 | bool Result = InnerMatcher->dynMatches(DynNode, Finder, Builder); |
| 102 | if (Result) Builder->setBinding(ID, DynNode); |
| 103 | return Result; |
| 104 | } |
| 105 | |
Benjamin Kramer | 018b6d4 | 2016-07-21 15:06:51 +0000 | [diff] [blame] | 106 | private: |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 107 | const std::string ID; |
| 108 | const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher; |
| 109 | }; |
| 110 | |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 111 | /// \brief A matcher that always returns true. |
| 112 | /// |
| 113 | /// We only ever need one instance of this matcher, so we create a global one |
| 114 | /// and reuse it to reduce the overhead of the matcher and increase the chance |
| 115 | /// of cache hits. |
Benjamin Kramer | 967c079 | 2014-10-24 13:29:21 +0000 | [diff] [blame] | 116 | class TrueMatcherImpl : public DynMatcherInterface { |
| 117 | public: |
| 118 | TrueMatcherImpl() { |
| 119 | Retain(); // Reference count will never become zero. |
| 120 | } |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 121 | |
Benjamin Kramer | 967c079 | 2014-10-24 13:29:21 +0000 | [diff] [blame] | 122 | bool dynMatches(const ast_type_traits::DynTypedNode &, ASTMatchFinder *, |
| 123 | BoundNodesTreeBuilder *) const override { |
| 124 | return true; |
| 125 | } |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 126 | }; |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 127 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 128 | } // namespace |
| 129 | |
| 130 | static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance; |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 131 | |
| 132 | DynTypedMatcher DynTypedMatcher::constructVariadic( |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 133 | DynTypedMatcher::VariadicOperator Op, |
Samuel Benzaquen | b063f5c | 2015-07-17 16:05:27 +0000 | [diff] [blame] | 134 | ast_type_traits::ASTNodeKind SupportedKind, |
Samuel Benzaquen | 9743c9d | 2014-11-17 14:55:49 +0000 | [diff] [blame] | 135 | std::vector<DynTypedMatcher> InnerMatchers) { |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 136 | assert(!InnerMatchers.empty() && "Array must not be empty."); |
Samuel Benzaquen | 2009960 | 2014-10-13 17:38:12 +0000 | [diff] [blame] | 137 | assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(), |
Samuel Benzaquen | b063f5c | 2015-07-17 16:05:27 +0000 | [diff] [blame] | 138 | [SupportedKind](const DynTypedMatcher &M) { |
| 139 | return M.canConvertTo(SupportedKind); |
| 140 | }) && |
| 141 | "InnerMatchers must be convertible to SupportedKind!"); |
Samuel Benzaquen | 2009960 | 2014-10-13 17:38:12 +0000 | [diff] [blame] | 142 | |
| 143 | // We must relax the restrict kind here. |
| 144 | // The different operators might deal differently with a mismatch. |
| 145 | // Make it the same as SupportedKind, since that is the broadest type we are |
| 146 | // allowed to accept. |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 147 | auto RestrictKind = SupportedKind; |
| 148 | |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 149 | switch (Op) { |
| 150 | case VO_AllOf: |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 151 | // In the case of allOf() we must pass all the checks, so making |
| 152 | // RestrictKind the most restrictive can save us time. This way we reject |
| 153 | // invalid types earlier and we can elide the kind checks inside the |
| 154 | // matcher. |
| 155 | for (auto &IM : InnerMatchers) { |
| 156 | RestrictKind = ast_type_traits::ASTNodeKind::getMostDerivedType( |
| 157 | RestrictKind, IM.RestrictKind); |
| 158 | } |
| 159 | return DynTypedMatcher( |
| 160 | SupportedKind, RestrictKind, |
| 161 | new VariadicMatcher<AllOfVariadicOperator>(std::move(InnerMatchers))); |
Samuel Benzaquen | 2c15e8c | 2014-11-20 15:45:53 +0000 | [diff] [blame] | 162 | |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 163 | case VO_AnyOf: |
| 164 | return DynTypedMatcher( |
| 165 | SupportedKind, RestrictKind, |
| 166 | new VariadicMatcher<AnyOfVariadicOperator>(std::move(InnerMatchers))); |
| 167 | |
| 168 | case VO_EachOf: |
| 169 | return DynTypedMatcher( |
| 170 | SupportedKind, RestrictKind, |
| 171 | new VariadicMatcher<EachOfVariadicOperator>(std::move(InnerMatchers))); |
| 172 | |
| 173 | case VO_UnaryNot: |
| 174 | // FIXME: Implement the Not operator to take a single matcher instead of a |
| 175 | // vector. |
| 176 | return DynTypedMatcher( |
| 177 | SupportedKind, RestrictKind, |
| 178 | new VariadicMatcher<NotUnaryOperator>(std::move(InnerMatchers))); |
| 179 | } |
| 180 | llvm_unreachable("Invalid Op value."); |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 183 | DynTypedMatcher DynTypedMatcher::trueMatcher( |
| 184 | ast_type_traits::ASTNodeKind NodeKind) { |
Benjamin Kramer | 967c079 | 2014-10-24 13:29:21 +0000 | [diff] [blame] | 185 | return DynTypedMatcher(NodeKind, NodeKind, &*TrueMatcherInstance); |
Samuel Benzaquen | 96039d7 | 2014-10-09 19:28:18 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Samuel Benzaquen | 074bbb6 | 2014-11-24 21:21:09 +0000 | [diff] [blame] | 188 | bool DynTypedMatcher::canMatchNodesOfKind( |
| 189 | ast_type_traits::ASTNodeKind Kind) const { |
| 190 | return RestrictKind.isBaseOf(Kind); |
| 191 | } |
| 192 | |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 193 | DynTypedMatcher DynTypedMatcher::dynCastTo( |
| 194 | const ast_type_traits::ASTNodeKind Kind) const { |
| 195 | auto Copy = *this; |
| 196 | Copy.SupportedKind = Kind; |
Samuel Benzaquen | a117002 | 2014-10-06 13:14:30 +0000 | [diff] [blame] | 197 | Copy.RestrictKind = |
| 198 | ast_type_traits::ASTNodeKind::getMostDerivedType(Kind, RestrictKind); |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 199 | return Copy; |
| 200 | } |
| 201 | |
| 202 | bool DynTypedMatcher::matches(const ast_type_traits::DynTypedNode &DynNode, |
| 203 | ASTMatchFinder *Finder, |
| 204 | BoundNodesTreeBuilder *Builder) const { |
| 205 | if (RestrictKind.isBaseOf(DynNode.getNodeKind()) && |
| 206 | Implementation->dynMatches(DynNode, Finder, Builder)) { |
| 207 | return true; |
| 208 | } |
| 209 | // Delete all bindings when a matcher does not match. |
| 210 | // This prevents unexpected exposure of bound nodes in unmatches |
| 211 | // branches of the match tree. |
| 212 | Builder->removeBindings([](const BoundNodesMap &) { return true; }); |
| 213 | return false; |
| 214 | } |
| 215 | |
Samuel Benzaquen | 074bbb6 | 2014-11-24 21:21:09 +0000 | [diff] [blame] | 216 | bool DynTypedMatcher::matchesNoKindCheck( |
| 217 | const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder, |
| 218 | BoundNodesTreeBuilder *Builder) const { |
| 219 | assert(RestrictKind.isBaseOf(DynNode.getNodeKind())); |
| 220 | if (Implementation->dynMatches(DynNode, Finder, Builder)) { |
| 221 | return true; |
| 222 | } |
| 223 | // Delete all bindings when a matcher does not match. |
| 224 | // This prevents unexpected exposure of bound nodes in unmatches |
| 225 | // branches of the match tree. |
| 226 | Builder->removeBindings([](const BoundNodesMap &) { return true; }); |
| 227 | return false; |
| 228 | } |
| 229 | |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 230 | llvm::Optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const { |
| 231 | if (!AllowBind) return llvm::None; |
| 232 | auto Result = *this; |
Benjamin Kramer | 018b6d4 | 2016-07-21 15:06:51 +0000 | [diff] [blame] | 233 | Result.Implementation = |
| 234 | new IdDynMatcher(ID, std::move(Result.Implementation)); |
| 235 | return std::move(Result); |
Samuel Benzaquen | f28d997 | 2014-10-01 15:08:07 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Samuel Benzaquen | ab005ed | 2014-09-04 14:13:58 +0000 | [diff] [blame] | 238 | bool DynTypedMatcher::canConvertTo(ast_type_traits::ASTNodeKind To) const { |
| 239 | const auto From = getSupportedKind(); |
| 240 | auto QualKind = ast_type_traits::ASTNodeKind::getFromNodeKind<QualType>(); |
| 241 | auto TypeKind = ast_type_traits::ASTNodeKind::getFromNodeKind<Type>(); |
| 242 | /// Mimic the implicit conversions of Matcher<>. |
| 243 | /// - From Matcher<Type> to Matcher<QualType> |
| 244 | if (From.isSame(TypeKind) && To.isSame(QualKind)) return true; |
| 245 | /// - From Matcher<Base> to Matcher<Derived> |
| 246 | return From.isBaseOf(To); |
| 247 | } |
| 248 | |
Manuel Klimek | a0c025f | 2013-06-19 15:42:45 +0000 | [diff] [blame] | 249 | void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder &Other) { |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 250 | Bindings.append(Other.Bindings.begin(), Other.Bindings.end()); |
Manuel Klimek | 021d56f | 2012-08-28 23:26:39 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 253 | bool NotUnaryOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 4d05874 | 2013-11-22 14:41:48 +0000 | [diff] [blame] | 254 | ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, |
| 255 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
| 256 | if (InnerMatchers.size() != 1) |
| 257 | return false; |
| 258 | |
| 259 | // The 'unless' matcher will always discard the result: |
| 260 | // If the inner matcher doesn't match, unless returns true, |
| 261 | // but the inner matcher cannot have bound anything. |
| 262 | // If the inner matcher matches, the result is false, and |
| 263 | // any possible binding will be discarded. |
| 264 | // We still need to hand in all the bound nodes up to this |
| 265 | // point so the inner matcher can depend on bound nodes, |
| 266 | // and we need to actively discard the bound nodes, otherwise |
| 267 | // the inner matcher will reset the bound nodes if it doesn't |
| 268 | // match, but this would be inversed by 'unless'. |
| 269 | BoundNodesTreeBuilder Discard(*Builder); |
| 270 | return !InnerMatchers[0].matches(DynNode, Finder, &Discard); |
| 271 | } |
| 272 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 273 | bool AllOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 274 | ASTMatchFinder *Finder, |
| 275 | BoundNodesTreeBuilder *Builder, |
Samuel Benzaquen | f34ac3e | 2013-10-29 14:37:15 +0000 | [diff] [blame] | 276 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 277 | // allOf leads to one matcher for each alternative in the first |
| 278 | // matcher combined with each alternative in the second matcher. |
| 279 | // Thus, we can reuse the same Builder. |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 280 | for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { |
Samuel Benzaquen | 95636e5 | 2014-12-01 14:46:14 +0000 | [diff] [blame] | 281 | if (!InnerMatcher.matchesNoKindCheck(DynNode, Finder, Builder)) |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 282 | return false; |
| 283 | } |
| 284 | return true; |
| 285 | } |
| 286 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 287 | bool EachOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 288 | ASTMatchFinder *Finder, |
| 289 | BoundNodesTreeBuilder *Builder, |
Samuel Benzaquen | f34ac3e | 2013-10-29 14:37:15 +0000 | [diff] [blame] | 290 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 291 | BoundNodesTreeBuilder Result; |
| 292 | bool Matched = false; |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 293 | for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 294 | BoundNodesTreeBuilder BuilderInner(*Builder); |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 295 | if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) { |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 296 | Matched = true; |
| 297 | Result.addMatch(BuilderInner); |
| 298 | } |
| 299 | } |
Benjamin Kramer | d9c9162 | 2014-08-29 11:22:47 +0000 | [diff] [blame] | 300 | *Builder = std::move(Result); |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 301 | return Matched; |
| 302 | } |
| 303 | |
Hans Wennborg | b27f249 | 2015-07-14 16:50:14 +0000 | [diff] [blame] | 304 | bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 305 | ASTMatchFinder *Finder, |
| 306 | BoundNodesTreeBuilder *Builder, |
Samuel Benzaquen | f34ac3e | 2013-10-29 14:37:15 +0000 | [diff] [blame] | 307 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 308 | for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 309 | BoundNodesTreeBuilder Result = *Builder; |
Benjamin Kramer | 79f1590 | 2014-10-24 13:29:15 +0000 | [diff] [blame] | 310 | if (InnerMatcher.matches(DynNode, Finder, &Result)) { |
Benjamin Kramer | d9c9162 | 2014-08-29 11:22:47 +0000 | [diff] [blame] | 311 | *Builder = std::move(Result); |
Samuel Benzaquen | 85ec25d | 2013-08-27 15:11:16 +0000 | [diff] [blame] | 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | return false; |
| 316 | } |
| 317 | |
George Karpenkov | 88a16a0 | 2018-03-29 00:51:12 +0000 | [diff] [blame^] | 318 | inline static |
| 319 | std::vector<std::string> vectorFromRefs(ArrayRef<const StringRef *> NameRefs) { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 320 | std::vector<std::string> Names; |
| 321 | for (auto *Name : NameRefs) |
| 322 | Names.emplace_back(*Name); |
George Karpenkov | 88a16a0 | 2018-03-29 00:51:12 +0000 | [diff] [blame^] | 323 | return Names; |
| 324 | } |
| 325 | |
| 326 | Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs) { |
| 327 | std::vector<std::string> Names = vectorFromRefs(NameRefs); |
| 328 | return internal::Matcher<NamedDecl>(new internal::HasNameMatcher(Names)); |
| 329 | } |
| 330 | |
| 331 | AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector<std::string>, |
| 332 | Matches) { |
| 333 | std::string SelString = Node.getSelector().getAsString(); |
| 334 | for (const std::string &S : Matches) |
| 335 | if (S == SelString) |
| 336 | return true; |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | Matcher<ObjCMessageExpr> hasAnySelectorFunc( |
| 341 | ArrayRef<const StringRef *> NameRefs) { |
| 342 | return hasAnySelectorMatcher(vectorFromRefs(NameRefs)); |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | HasNameMatcher::HasNameMatcher(std::vector<std::string> N) |
| 346 | : UseUnqualifiedMatch(std::all_of( |
| 347 | N.begin(), N.end(), |
| 348 | [](StringRef Name) { return Name.find("::") == Name.npos; })), |
| 349 | Names(std::move(N)) { |
Alexander Kornienko | 1eeac19 | 2016-02-23 10:29:04 +0000 | [diff] [blame] | 350 | #ifndef NDEBUG |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 351 | for (StringRef Name : Names) |
| 352 | assert(!Name.empty()); |
Alexander Kornienko | 1eeac19 | 2016-02-23 10:29:04 +0000 | [diff] [blame] | 353 | #endif |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 356 | static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 357 | StringRef Name = FullName; |
| 358 | if (!Name.endswith(Suffix)) |
| 359 | return false; |
| 360 | Name = Name.drop_back(Suffix.size()); |
| 361 | if (!Name.empty()) { |
| 362 | if (!Name.endswith("::")) |
| 363 | return false; |
| 364 | Name = Name.drop_back(2); |
Samuel Benzaquen | b6f73bc | 2014-10-16 17:50:19 +0000 | [diff] [blame] | 365 | } |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 366 | FullName = Name; |
| 367 | return true; |
| 368 | } |
| 369 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 370 | static StringRef getNodeName(const NamedDecl &Node, |
| 371 | llvm::SmallString<128> &Scratch) { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 372 | // Simple name. |
| 373 | if (Node.getIdentifier()) |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 374 | return Node.getName(); |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 375 | |
Samuel Benzaquen | b6f73bc | 2014-10-16 17:50:19 +0000 | [diff] [blame] | 376 | if (Node.getDeclName()) { |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 377 | // Name needs to be constructed. |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 378 | Scratch.clear(); |
| 379 | llvm::raw_svector_ostream OS(Scratch); |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 380 | Node.printName(OS); |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 381 | return OS.str(); |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 382 | } |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 383 | |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 384 | return "(anonymous)"; |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 387 | static StringRef getNodeName(const RecordDecl &Node, |
| 388 | llvm::SmallString<128> &Scratch) { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 389 | if (Node.getIdentifier()) { |
| 390 | return Node.getName(); |
| 391 | } |
| 392 | Scratch.clear(); |
| 393 | return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch); |
| 394 | } |
| 395 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 396 | static StringRef getNodeName(const NamespaceDecl &Node, |
| 397 | llvm::SmallString<128> &Scratch) { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 398 | return Node.isAnonymousNamespace() ? "(anonymous namespace)" : Node.getName(); |
| 399 | } |
| 400 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 401 | namespace { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 402 | |
| 403 | class PatternSet { |
| 404 | public: |
| 405 | PatternSet(ArrayRef<std::string> Names) { |
| 406 | for (StringRef Name : Names) |
| 407 | Patterns.push_back({Name, Name.startswith("::")}); |
| 408 | } |
| 409 | |
| 410 | /// Consumes the name suffix from each pattern in the set and removes the ones |
| 411 | /// that didn't match. |
| 412 | /// Return true if there are still any patterns left. |
| 413 | bool consumeNameSuffix(StringRef NodeName, bool CanSkip) { |
| 414 | for (size_t I = 0; I < Patterns.size();) { |
George Karpenkov | 88a16a0 | 2018-03-29 00:51:12 +0000 | [diff] [blame^] | 415 | if (::clang::ast_matchers::internal::consumeNameSuffix(Patterns[I].P, |
| 416 | NodeName) || |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 417 | CanSkip) { |
| 418 | ++I; |
| 419 | } else { |
| 420 | Patterns.erase(Patterns.begin() + I); |
| 421 | } |
| 422 | } |
| 423 | return !Patterns.empty(); |
| 424 | } |
| 425 | |
| 426 | /// Check if any of the patterns are a match. |
| 427 | /// A match will be a pattern that was fully consumed, that also matches the |
| 428 | /// 'fully qualified' requirement. |
| 429 | bool foundMatch(bool AllowFullyQualified) const { |
| 430 | for (auto& P: Patterns) |
Hans Wennborg | 157a5d5 | 2016-02-22 22:21:58 +0000 | [diff] [blame] | 431 | if (P.P.empty() && (AllowFullyQualified || !P.IsFullyQualified)) |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 432 | return true; |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | private: |
| 437 | struct Pattern { |
Hans Wennborg | 157a5d5 | 2016-02-22 22:21:58 +0000 | [diff] [blame] | 438 | StringRef P; |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 439 | bool IsFullyQualified; |
| 440 | }; |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 441 | |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 442 | llvm::SmallVector<Pattern, 8> Patterns; |
| 443 | }; |
| 444 | |
Eugene Zelenko | 06becf8 | 2017-11-01 23:09:49 +0000 | [diff] [blame] | 445 | } // namespace |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 446 | |
| 447 | bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const { |
| 448 | assert(UseUnqualifiedMatch); |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 449 | llvm::SmallString<128> Scratch; |
| 450 | StringRef NodeName = getNodeName(Node, Scratch); |
| 451 | return std::any_of(Names.begin(), Names.end(), [&](StringRef Name) { |
| 452 | return consumeNameSuffix(Name, NodeName) && Name.empty(); |
| 453 | }); |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 457 | PatternSet Patterns(Names); |
| 458 | llvm::SmallString<128> Scratch; |
| 459 | |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 460 | // This function is copied and adapted from NamedDecl::printQualifiedName() |
| 461 | // By matching each part individually we optimize in a couple of ways: |
| 462 | // - We can exit early on the first failure. |
| 463 | // - We can skip inline/anonymous namespaces without another pass. |
| 464 | // - We print one name at a time, reducing the chance of overflowing the |
| 465 | // inlined space of the SmallString. |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 466 | |
| 467 | // First, match the name. |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 468 | if (!Patterns.consumeNameSuffix(getNodeName(Node, Scratch), |
| 469 | /*CanSkip=*/false)) |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 470 | return false; |
| 471 | |
| 472 | // Try to match each declaration context. |
| 473 | // We are allowed to skip anonymous and inline namespaces if they don't match. |
| 474 | const DeclContext *Ctx = Node.getDeclContext(); |
| 475 | |
| 476 | if (Ctx->isFunctionOrMethod()) |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 477 | return Patterns.foundMatch(/*AllowFullyQualified=*/false); |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 478 | |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 479 | for (; Ctx && isa<NamedDecl>(Ctx); Ctx = Ctx->getParent()) { |
| 480 | if (Patterns.foundMatch(/*AllowFullyQualified=*/false)) |
| 481 | return true; |
| 482 | |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 483 | if (const auto *ND = dyn_cast<NamespaceDecl>(Ctx)) { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 484 | // If it matches (or we can skip it), continue. |
| 485 | if (Patterns.consumeNameSuffix(getNodeName(*ND, Scratch), |
| 486 | /*CanSkip=*/ND->isAnonymousNamespace() || |
| 487 | ND->isInline())) |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 488 | continue; |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 489 | return false; |
| 490 | } |
| 491 | if (const auto *RD = dyn_cast<RecordDecl>(Ctx)) { |
| 492 | if (!isa<ClassTemplateSpecializationDecl>(Ctx)) { |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 493 | if (Patterns.consumeNameSuffix(getNodeName(*RD, Scratch), |
| 494 | /*CanSkip=*/false)) |
| 495 | continue; |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 496 | |
| 497 | return false; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // We don't know how to deal with this DeclContext. |
| 502 | // Fallback to the slow version of the code. |
| 503 | return matchesNodeFullSlow(Node); |
| 504 | } |
| 505 | |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 506 | return Patterns.foundMatch(/*AllowFullyQualified=*/true); |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 510 | const bool SkipUnwrittenCases[] = {false, true}; |
| 511 | for (bool SkipUnwritten : SkipUnwrittenCases) { |
| 512 | llvm::SmallString<128> NodeName = StringRef("::"); |
| 513 | llvm::raw_svector_ostream OS(NodeName); |
| 514 | |
| 515 | if (SkipUnwritten) { |
| 516 | PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy(); |
| 517 | Policy.SuppressUnwrittenScope = true; |
| 518 | Node.printQualifiedName(OS, Policy); |
| 519 | } else { |
| 520 | Node.printQualifiedName(OS); |
| 521 | } |
| 522 | |
| 523 | const StringRef FullName = OS.str(); |
| 524 | |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 525 | for (const StringRef Pattern : Names) { |
| 526 | if (Pattern.startswith("::")) { |
| 527 | if (FullName == Pattern) |
| 528 | return true; |
| 529 | } else if (FullName.endswith(Pattern) && |
| 530 | FullName.drop_back(Pattern.size()).endswith("::")) { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 531 | return true; |
Samuel Benzaquen | 922bef4 | 2016-02-22 21:13:02 +0000 | [diff] [blame] | 532 | } |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Samuel Benzaquen | b6f73bc | 2014-10-16 17:50:19 +0000 | [diff] [blame] | 536 | return false; |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 539 | bool HasNameMatcher::matchesNode(const NamedDecl &Node) const { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 540 | assert(matchesNodeFullFast(Node) == matchesNodeFullSlow(Node)); |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 541 | if (UseUnqualifiedMatch) { |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 542 | assert(matchesNodeUnqualified(Node) == matchesNodeFullFast(Node)); |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 543 | return matchesNodeUnqualified(Node); |
| 544 | } |
Samuel Benzaquen | 8e566f3 | 2016-02-05 18:29:24 +0000 | [diff] [blame] | 545 | return matchesNodeFullFast(Node); |
Samuel Benzaquen | 8513d62 | 2014-10-15 14:58:46 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Manuel Klimek | 04616e4 | 2012-07-06 05:48:52 +0000 | [diff] [blame] | 548 | } // end namespace internal |
David Blaikie | ac7e3d6 | 2017-11-15 16:52:12 +0000 | [diff] [blame] | 549 | |
| 550 | const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl> |
| 551 | translationUnitDecl; |
| 552 | const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl; |
| 553 | const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> |
| 554 | typedefNameDecl; |
| 555 | const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl; |
| 556 | const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> |
| 557 | typeAliasTemplateDecl; |
| 558 | const internal::VariadicAllOfMatcher<Decl> decl; |
| 559 | const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> |
| 560 | linkageSpecDecl; |
| 561 | const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; |
| 562 | const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl; |
| 563 | const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl; |
| 564 | const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl> |
| 565 | namespaceAliasDecl; |
| 566 | const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl; |
| 567 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl; |
| 568 | const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl> |
| 569 | classTemplateDecl; |
| 570 | const internal::VariadicDynCastAllOfMatcher<Decl, |
| 571 | ClassTemplateSpecializationDecl> |
| 572 | classTemplateSpecializationDecl; |
| 573 | const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> |
| 574 | declaratorDecl; |
| 575 | const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl; |
| 576 | const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl> |
| 577 | accessSpecDecl; |
| 578 | const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer; |
| 579 | const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument; |
| 580 | const internal::VariadicAllOfMatcher<TemplateName> templateName; |
| 581 | const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl> |
| 582 | nonTypeTemplateParmDecl; |
| 583 | const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl> |
| 584 | templateTypeParmDecl; |
| 585 | const internal::VariadicAllOfMatcher<QualType> qualType; |
| 586 | const internal::VariadicAllOfMatcher<Type> type; |
| 587 | const internal::VariadicAllOfMatcher<TypeLoc> typeLoc; |
| 588 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr> |
| 589 | unaryExprOrTypeTraitExpr; |
| 590 | const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl; |
| 591 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl> |
| 592 | cxxConstructorDecl; |
| 593 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> |
| 594 | cxxDestructorDecl; |
| 595 | const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; |
| 596 | const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl> |
| 597 | enumConstantDecl; |
| 598 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl; |
| 599 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl> |
| 600 | cxxConversionDecl; |
| 601 | const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; |
| 602 | const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; |
| 603 | const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl; |
| 604 | const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl> |
| 605 | functionTemplateDecl; |
| 606 | const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl; |
| 607 | const internal::VariadicAllOfMatcher<Stmt> stmt; |
| 608 | const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt; |
| 609 | const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; |
| 610 | const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; |
| 611 | const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr; |
| 612 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> |
| 613 | cxxMemberCallExpr; |
| 614 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr> |
| 615 | objcMessageExpr; |
| 616 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl> |
| 617 | objcInterfaceDecl; |
| 618 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl> |
| 619 | objcImplementationDecl; |
| 620 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl> |
| 621 | objcProtocolDecl; |
| 622 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl> |
| 623 | objcCategoryDecl; |
| 624 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl> |
| 625 | objcCategoryImplDecl; |
| 626 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> |
| 627 | objcMethodDecl; |
| 628 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl; |
| 629 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl> |
| 630 | objcPropertyDecl; |
| 631 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt> |
| 632 | objcThrowStmt; |
| 633 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt; |
| 634 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt> |
| 635 | objcCatchStmt; |
| 636 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt> |
| 637 | objcFinallyStmt; |
| 638 | const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> |
| 639 | exprWithCleanups; |
| 640 | const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr; |
| 641 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr> |
| 642 | cxxStdInitializerListExpr; |
| 643 | const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr> |
| 644 | implicitValueInitExpr; |
| 645 | const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr; |
| 646 | const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr> |
| 647 | substNonTypeTemplateParmExpr; |
| 648 | const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; |
| 649 | const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> |
| 650 | usingDirectiveDecl; |
| 651 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr> |
| 652 | unresolvedLookupExpr; |
| 653 | const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl> |
| 654 | unresolvedUsingValueDecl; |
| 655 | const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl> |
| 656 | unresolvedUsingTypenameDecl; |
| 657 | const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr; |
| 658 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr> |
| 659 | cxxConstructExpr; |
| 660 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr> |
| 661 | cxxUnresolvedConstructExpr; |
| 662 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr; |
| 663 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr> |
| 664 | cxxBindTemporaryExpr; |
| 665 | const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr> |
| 666 | materializeTemporaryExpr; |
| 667 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr; |
| 668 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr; |
| 669 | const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr> |
| 670 | arraySubscriptExpr; |
| 671 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr> |
| 672 | cxxDefaultArgExpr; |
| 673 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr> |
| 674 | cxxOperatorCallExpr; |
| 675 | const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; |
| 676 | const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; |
| 677 | const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; |
| 678 | const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; |
| 679 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> |
| 680 | cxxForRangeStmt; |
| 681 | const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; |
| 682 | const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; |
| 683 | const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt; |
| 684 | const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt; |
| 685 | const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt; |
| 686 | const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt; |
| 687 | const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt; |
| 688 | const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr; |
| 689 | const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt; |
| 690 | const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; |
| 691 | const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt; |
| 692 | const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt; |
| 693 | const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt; |
| 694 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt; |
| 695 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt; |
| 696 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr; |
| 697 | const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt; |
| 698 | const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt; |
| 699 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr> |
| 700 | cxxBoolLiteral; |
| 701 | const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral; |
| 702 | const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral> |
| 703 | characterLiteral; |
| 704 | const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> |
| 705 | integerLiteral; |
| 706 | const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; |
| 707 | const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> |
| 708 | userDefinedLiteral; |
| 709 | const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> |
| 710 | compoundLiteralExpr; |
| 711 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> |
| 712 | cxxNullPtrLiteralExpr; |
| 713 | const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr; |
| 714 | const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr; |
| 715 | const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr; |
| 716 | const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator> |
| 717 | binaryOperator; |
| 718 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator; |
| 719 | const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator> |
| 720 | conditionalOperator; |
| 721 | const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator> |
| 722 | binaryConditionalOperator; |
| 723 | const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr> |
| 724 | opaqueValueExpr; |
| 725 | const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl> |
| 726 | staticAssertDecl; |
| 727 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr> |
| 728 | cxxReinterpretCastExpr; |
| 729 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr> |
| 730 | cxxStaticCastExpr; |
| 731 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr> |
| 732 | cxxDynamicCastExpr; |
| 733 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr> |
| 734 | cxxConstCastExpr; |
| 735 | const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr> |
| 736 | cStyleCastExpr; |
| 737 | const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr> |
| 738 | explicitCastExpr; |
| 739 | const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr> |
| 740 | implicitCastExpr; |
| 741 | const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr; |
| 742 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr> |
| 743 | cxxFunctionalCastExpr; |
| 744 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr> |
| 745 | cxxTemporaryObjectExpr; |
| 746 | const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr> |
| 747 | predefinedExpr; |
| 748 | const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr> |
| 749 | designatedInitExpr; |
| 750 | const internal::VariadicOperatorMatcherFunc< |
| 751 | 2, std::numeric_limits<unsigned>::max()> |
| 752 | eachOf = {internal::DynTypedMatcher::VO_EachOf}; |
| 753 | const internal::VariadicOperatorMatcherFunc< |
| 754 | 2, std::numeric_limits<unsigned>::max()> |
| 755 | anyOf = {internal::DynTypedMatcher::VO_AnyOf}; |
| 756 | const internal::VariadicOperatorMatcherFunc< |
| 757 | 2, std::numeric_limits<unsigned>::max()> |
| 758 | allOf = {internal::DynTypedMatcher::VO_AllOf}; |
| 759 | const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef, |
| 760 | internal::hasAnyNameFunc> |
| 761 | hasAnyName = {}; |
| 762 | const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {}; |
| 763 | const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher> |
| 764 | hasDescendant = {}; |
| 765 | const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach = |
| 766 | {}; |
| 767 | const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher> |
| 768 | forEachDescendant = {}; |
| 769 | const internal::ArgumentAdaptingMatcherFunc< |
| 770 | internal::HasParentMatcher, |
| 771 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, |
| 772 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> |
| 773 | hasParent = {}; |
| 774 | const internal::ArgumentAdaptingMatcherFunc< |
| 775 | internal::HasAncestorMatcher, |
| 776 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, |
| 777 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> |
| 778 | hasAncestor = {}; |
| 779 | const internal::VariadicOperatorMatcherFunc<1, 1> unless = { |
| 780 | internal::DynTypedMatcher::VO_UnaryNot}; |
| 781 | const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier; |
| 782 | const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc> |
| 783 | nestedNameSpecifierLoc; |
| 784 | const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> |
| 785 | cudaKernelCallExpr; |
| 786 | const AstTypeMatcher<BuiltinType> builtinType; |
| 787 | const AstTypeMatcher<ArrayType> arrayType; |
| 788 | const AstTypeMatcher<ComplexType> complexType; |
| 789 | const AstTypeMatcher<ConstantArrayType> constantArrayType; |
| 790 | const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType; |
| 791 | const AstTypeMatcher<IncompleteArrayType> incompleteArrayType; |
| 792 | const AstTypeMatcher<VariableArrayType> variableArrayType; |
| 793 | const AstTypeMatcher<AtomicType> atomicType; |
| 794 | const AstTypeMatcher<AutoType> autoType; |
| 795 | const AstTypeMatcher<FunctionType> functionType; |
| 796 | const AstTypeMatcher<FunctionProtoType> functionProtoType; |
| 797 | const AstTypeMatcher<ParenType> parenType; |
| 798 | const AstTypeMatcher<BlockPointerType> blockPointerType; |
| 799 | const AstTypeMatcher<MemberPointerType> memberPointerType; |
| 800 | const AstTypeMatcher<PointerType> pointerType; |
| 801 | const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType; |
| 802 | const AstTypeMatcher<ReferenceType> referenceType; |
| 803 | const AstTypeMatcher<LValueReferenceType> lValueReferenceType; |
| 804 | const AstTypeMatcher<RValueReferenceType> rValueReferenceType; |
| 805 | const AstTypeMatcher<TypedefType> typedefType; |
| 806 | const AstTypeMatcher<EnumType> enumType; |
| 807 | const AstTypeMatcher<TemplateSpecializationType> templateSpecializationType; |
| 808 | const AstTypeMatcher<UnaryTransformType> unaryTransformType; |
| 809 | const AstTypeMatcher<RecordType> recordType; |
| 810 | const AstTypeMatcher<TagType> tagType; |
| 811 | const AstTypeMatcher<ElaboratedType> elaboratedType; |
| 812 | const AstTypeMatcher<SubstTemplateTypeParmType> substTemplateTypeParmType; |
| 813 | const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType; |
| 814 | const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; |
| 815 | const AstTypeMatcher<DecayedType> decayedType; |
David Blaikie | 1de3543 | 2017-11-21 01:09:18 +0000 | [diff] [blame] | 816 | AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType, |
| 817 | AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType, |
| 818 | ComplexType)); |
| 819 | AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasValueType, |
| 820 | AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType)); |
| 821 | AST_TYPELOC_TRAVERSE_MATCHER_DEF( |
| 822 | pointee, |
| 823 | AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType, |
| 824 | PointerType, ReferenceType)); |
David Blaikie | ac7e3d6 | 2017-11-15 16:52:12 +0000 | [diff] [blame] | 825 | |
Manuel Klimek | 04616e4 | 2012-07-06 05:48:52 +0000 | [diff] [blame] | 826 | } // end namespace ast_matchers |
| 827 | } // end namespace clang |