]> granicus.if.org Git - clang/blobdiff - include/clang/ASTMatchers/ASTMatchFinder.h
Header guard canonicalization, clang part.
[clang] / include / clang / ASTMatchers / ASTMatchFinder.h
index d2b71d30df700cd3fca50276fad5f0da491a5bcb..75525ad1d62eccb1b8780ed9951bed05958fa16a 100644 (file)
@@ -38,8 +38,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_AST_MATCHERS_AST_MATCH_FINDER_H
-#define LLVM_CLANG_AST_MATCHERS_AST_MATCH_FINDER_H
+#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
+#define LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
 
 #include "clang/ASTMatchers/ASTMatchers.h"
 
@@ -136,8 +136,19 @@ public:
                   MatchCallback *Action);
   /// @}
 
+  /// \brief Adds a matcher to execute when running over the AST.
+  ///
+  /// This is similar to \c addMatcher(), but it uses the dynamic interface. It
+  /// is more flexible, but the lost type information enables a caller to pass
+  /// a matcher that cannot match anything.
+  ///
+  /// \returns \c true if the matcher is a valid top-level matcher, \c false
+  ///   otherwise.
+  bool addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch,
+                         MatchCallback *Action);
+
   /// \brief Creates a clang ASTConsumer that finds all matches.
-  clang::ASTConsumer *newASTConsumer();
+  std::unique_ptr<clang::ASTConsumer> newASTConsumer();
 
   /// \brief Calls the registered callbacks on all matches on the given \p Node.
   ///
@@ -152,6 +163,9 @@ public:
              ASTContext &Context);
   /// @}
 
+  /// \brief Finds all matches in the given AST.
+  void matchAST(ASTContext &Context);
+
   /// \brief Registers a callback to notify the end of parsing.
   ///
   /// The provided closure is called after parsing is done, before the AST is
@@ -162,7 +176,7 @@ public:
 private:
   /// \brief For each \c DynTypedMatcher a \c MatchCallback that will be called
   /// when it matches.
-  std::vector<std::pair<const internal::DynTypedMatcher*, MatchCallback*> >
+  std::vector<std::pair<internal::DynTypedMatcher, MatchCallback *> >
     MatcherCallbackPairs;
 
   /// \brief Called when parsing is done.
@@ -196,25 +210,23 @@ match(MatcherT Matcher, const ast_type_traits::DynTypedNode &Node,
 ///
 /// This is useful in combanation with \c match():
 /// \code
-///   Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"),
-///                                           Node, Context));
+///   const Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"),
+///                                                 Node, Context));
 /// \endcode
 template <typename NodeT>
-NodeT *
+const NodeT *
 selectFirst(StringRef BoundTo, const SmallVectorImpl<BoundNodes> &Results) {
-  for (SmallVectorImpl<BoundNodes>::const_iterator I = Results.begin(),
-                                                   E = Results.end();
-       I != E; ++I) {
-    if (NodeT *Node = I->getNodeAs<NodeT>(BoundTo))
+  for (const BoundNodes &N : Results) {
+    if (const NodeT *Node = N.getNodeAs<NodeT>(BoundTo))
       return Node;
   }
-  return NULL;
+  return nullptr;
 }
 
 namespace internal {
 class CollectMatchesCallback : public MatchFinder::MatchCallback {
 public:
-  virtual void run(const MatchFinder::MatchResult &Result) {
+  void run(const MatchFinder::MatchResult &Result) override {
     Nodes.push_back(Result.Nodes);
   }
   SmallVector<BoundNodes, 1> Nodes;
@@ -241,4 +253,4 @@ match(MatcherT Matcher, const NodeT &Node, ASTContext &Context) {
 } // end namespace ast_matchers
 } // end namespace clang
 
-#endif // LLVM_CLANG_AST_MATCHERS_AST_MATCH_FINDER_H
+#endif