clang 20.0.0git
Typedefs | Enumerations | Functions
Traversing the AST with cursors

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

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.
 
typedef struct _CXChildVisitResult * CXCursorVisitorBlock
 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.
 
CINDEX_LINKAGE unsigned clang_visitChildrenWithBlock (CXCursor parent, CXCursorVisitorBlock block)
 Visits the children of a cursor using the specified block.
 

Detailed Description

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

Typedef Documentation

◆ CXCursorVisitor

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 3905 of file Index.h.

◆ CXCursorVisitorBlock

typedef struct _CXChildVisitResult* CXCursorVisitorBlock

Visitor invoked for each cursor found by a traversal.

This visitor block will be invoked for each cursor found by clang_visitChildrenWithBlock(). Its first argument is the cursor being visited, its second argument is the parent visitor for that cursor.

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

Definition at line 3999 of file Index.h.

Enumeration Type Documentation

◆ CXChildVisitResult

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 3927 of file Index.h.

Function Documentation

◆ clang_visitChildren()

CINDEX_LINKAGE unsigned clang_visitChildren ( CXCursor  parent,
CXCursorVisitor  visitor,
CXClientData  client_data 
)

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.

◆ clang_visitChildrenWithBlock()

CINDEX_LINKAGE unsigned clang_visitChildrenWithBlock ( CXCursor  parent,
CXCursorVisitorBlock  block 
)

Visits the children of a cursor using the specified block.

Behaves identically to clang_visitChildren() in all other respects.