clang API Documentation

Typedefs | Enumerations | Functions
Traversing the AST with cursors
libclang: C Interface to Clang
Collaboration diagram for Traversing the AST with cursors:

Typedefs

typedef enum CXChildVisitResult(* CXCursorVisitor )(CXCursor cursor, CXCursor parent, CXClientData client_data)
 Visitor invoked for each cursor found by a traversal.

Enumerations

enum  CXChildVisitResult { CXChildVisit_Break, CXChildVisit_Continue, CXChildVisit_Recurse }
 Describes how the traversal of the children of a particular cursor should proceed after visiting a particular child cursor. More...

Functions

CINDEX_LINKAGE unsigned clang_visitChildren (CXCursor parent, CXCursorVisitor visitor, CXClientData client_data)
 Visit the children of a particular cursor.

Detailed Description

These routines provide the ability to traverse the abstract syntax tree using cursors.


Typedef Documentation

typedef enum CXChildVisitResult(* CXCursorVisitor)(CXCursor cursor, CXCursor parent, CXClientData client_data)

Visitor invoked for each cursor found by a traversal.

This visitor function will be invoked for each cursor found by clang_visitCursorChildren(). Its first argument is the cursor being visited, its second argument is the parent visitor for that cursor, and its third argument is the client data provided to clang_visitCursorChildren().

The visitor should return one of the CXChildVisitResult values to direct clang_visitCursorChildren().

Definition at line 3464 of file Index.h.


Enumeration Type Documentation

Describes how the traversal of the children of a particular cursor should proceed after visiting a particular child cursor.

A value of this enumeration type should be returned by each CXCursorVisitor to indicate how clang_visitChildren() proceed.

Enumerator:
CXChildVisit_Break 

Terminates the cursor traversal.

CXChildVisit_Continue 

Continues the cursor traversal with the next sibling of the cursor just visited, without visiting its children.

CXChildVisit_Recurse 

Recursively traverse the children of this cursor, using the same visitor and client data.

Definition at line 3435 of file Index.h.


Function Documentation

Visit the children of a particular cursor.

This function visits all the direct children of the given cursor, invoking the given visitor function with the cursors of each visited child. The traversal may be recursive, if the visitor returns CXChildVisit_Recurse. The traversal may also be ended prematurely, if the visitor returns CXChildVisit_Break.

Parameters:
parentthe cursor whose child may be visited. All kinds of cursors can be visited, including invalid cursors (which, by definition, have no children).
visitorthe visitor function that will be invoked for each child of parent.
client_datapointer data supplied by the client, which will be passed to the visitor each time it is invoked.
Returns:
a non-zero value if the traversal was terminated prematurely by the visitor returning CXChildVisit_Break.