clang-tags
C/C++ source code indexing tool based on libclang
 All Classes Functions Variables Typedefs Groups Pages
Public Member Functions | List of all members
LibClang::Visitor< VISITOR > Class Template Reference

Base class for AST visitors. More...

#include <visitor.hxx>

Public Member Functions

unsigned int visitChildren (const Cursor &top)
 visit an AST
virtual CXChildVisitResult visit (Cursor cursor, LibClang::Cursor parent)=0
 visit a cursor in the AST and decide what to do next

Detailed Description

template<typename VISITOR>
class LibClang::Visitor< VISITOR >

Base class for AST visitors.

This class provides the needed interface for visiting an Abstract Syntax Tree (AST). Every functor used to visit ASTs should derive from this using a CRTP, and specialize the visit() method.

Below is an example of a visitor functor printing the USR of all visited nodes:

// Define the visitor class
class MyVisitor : public LibClang::Visitor<MyVisitor> {
public:
MyVisitor () { }
CXChildVisitResult visit (LibClang::Cursor cursor,
{
std::cerr << cursor.USR();
return CXChildVisit_Recurse;
}
};
// Use it to traverse a TranslationUnit
MyVisitor visitor;
TranslationUnit tu;
visitor.visitChildren (tu.cursor());

Member Function Documentation

template<typename VISITOR>
virtual CXChildVisitResult LibClang::Visitor< VISITOR >::visit ( Cursor  cursor,
LibClang::Cursor  parent 
)
pure virtual

visit a cursor in the AST and decide what to do next

This method visits a Cursor in the AST, and returns a code indicating which action should be taken next:

  • CXChildVisit_Recurse: continue recursively visiting the AST
  • CXChildVisit_Continue: continue visiting the AST, but don't recurse into the current cursors children
  • CXChildVisit_Break: stop traversing the AST
Parameters
cursor
parent
Returns
a code indicating what to do next

Implemented in FindDefinition, and Indexer.

template<typename VISITOR>
unsigned int LibClang::Visitor< VISITOR >::visitChildren ( const Cursor top)
inline

visit an AST

Visit an Abastract Syntax Tree (AST), starting from a top Cursor and recursively visiting its children. The visiting strategy and actions taken for each Cursor in the AST are defined by the visit() method.

Parameters
topa Cursor representing the AST to visit
Returns
non-zero if the traversal was ended prematurely

The documentation for this class was generated from the following file: