class MatchFinder

Declaration

class MatchFinder { /* full declaration omitted */ };

Description

A class to allow finding matches over the Clang AST. After creation, you can add multiple matchers to the MatchFinder via calls to addMatcher(...). Once all matchers are added, newASTConsumer() returns an ASTConsumer that will trigger the callbacks specified via addMatcher(...) when a match is found. The order of matches is guaranteed to be equivalent to doing a pre-order traversal on the AST, and applying the matchers in the order in which they were added to the MatchFinder. See ASTMatchers.h for more information about how to create matchers. Not intended to be subclassed.

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:68

Member Variables

private clang::ast_matchers::MatchFinder::MatchersByType Matchers
private clang::ast_matchers::MatchFinder:: MatchFinderOptions Options
private clang::ast_matchers::MatchFinder:: ParsingDoneTestCallback* ParsingDone
Called when parsing is done.

Method Overview

  • public MatchFinder(clang::ast_matchers::MatchFinder::MatchFinderOptions Options = clang::ast_matchers::MatchFinder::MatchFinderOptions())
  • public bool addDynamicMatcher(const internal::DynTypedMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::DeclarationMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::TypeMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::StatementMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::NestedNameSpecifierMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::NestedNameSpecifierLocMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::TypeLocMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::CXXCtorInitializerMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::TemplateArgumentLocMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public void addMatcher(const clang::ast_matchers::AttrMatcher & NodeMatch, clang::ast_matchers::MatchFinder::MatchCallback * Action)
  • public template <typename T>void match(const T & Node, clang::ASTContext & Context)
  • public void match(const clang::DynTypedNode & Node, clang::ASTContext & Context)
  • public void matchAST(clang::ASTContext & Context)
  • public std::unique_ptr<clang::ASTConsumer> newASTConsumer()
  • public void registerTestCallbackAfterParsing(clang::ast_matchers::MatchFinder::ParsingDoneTestCallback * ParsingDone)
  • public ~MatchFinder()

Methods

MatchFinder(
    clang::ast_matchers::MatchFinder::
        MatchFinderOptions Options =
            clang::ast_matchers::MatchFinder::
                MatchFinderOptions())

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:143

Parameters

clang::ast_matchers::MatchFinder:: MatchFinderOptions Options = clang::ast_matchers::MatchFinder::MatchFinderOptions()

bool addDynamicMatcher(
    const internal::DynTypedMatcher& NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Description

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.

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:181

Parameters

const internal::DynTypedMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

Returns

\c true if the matcher is a valid top-level matcher, \c false otherwise.

void addMatcher(
    const clang::ast_matchers::DeclarationMatcher&
        NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Description

Adds a matcher to execute when running over the AST. Calls 'Action' with the BoundNodes on every match. Adding more than one 'NodeMatch' allows finding different matches in a single pass over the AST. Does not take ownership of 'Action'. @ {

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:154

Parameters

const clang::ast_matchers::DeclarationMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::TypeMatcher&
        NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:156

Parameters

const clang::ast_matchers::TypeMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::StatementMatcher&
        NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:158

Parameters

const clang::ast_matchers::StatementMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::
        NestedNameSpecifierMatcher& NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:160

Parameters

const clang::ast_matchers:: NestedNameSpecifierMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::
        NestedNameSpecifierLocMatcher& NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:162

Parameters

const clang::ast_matchers:: NestedNameSpecifierLocMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::TypeLocMatcher&
        NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:164

Parameters

const clang::ast_matchers::TypeLocMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::
        CXXCtorInitializerMatcher& NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:166

Parameters

const clang::ast_matchers:: CXXCtorInitializerMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::
        TemplateArgumentLocMatcher& NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:168

Parameters

const clang::ast_matchers:: TemplateArgumentLocMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

void addMatcher(
    const clang::ast_matchers::AttrMatcher&
        NodeMatch,
    clang::ast_matchers::MatchFinder::
        MatchCallback* Action)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:170

Parameters

const clang::ast_matchers::AttrMatcher& NodeMatch
clang::ast_matchers::MatchFinder::MatchCallback* Action

template <typename T>
void match(const T& Node,
           clang::ASTContext& Context)

Description

Calls the registered callbacks on all matches on the given \p Node. Note that there can be multiple matches on a single node, for example when using decl(forEachDescendant(stmt())). @ {

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:193

Templates

T

Parameters

const T& Node
clang::ASTContext& Context

void match(const clang::DynTypedNode& Node,
           clang::ASTContext& Context)

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:196

Parameters

const clang::DynTypedNode& Node
clang::ASTContext& Context

void matchAST(clang::ASTContext& Context)

Description

Finds all matches in the given AST.

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:200

Parameters

clang::ASTContext& Context

std::unique_ptr<clang::ASTConsumer>
newASTConsumer()

Description

Creates a clang ASTConsumer that finds all matches.

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:185

void registerTestCallbackAfterParsing(
    clang::ast_matchers::MatchFinder::
        ParsingDoneTestCallback* ParsingDone)

Description

Registers a callback to notify the end of parsing. The provided closure is called after parsing is done, before the AST is traversed. Useful for benchmarking. Each call to FindAll(...) will call the closure once.

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:207

Parameters

clang::ast_matchers::MatchFinder:: ParsingDoneTestCallback* ParsingDone

~MatchFinder()

Declared at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:144