clang API Documentation

Classes | Typedefs | Enumerations | Functions
Cursor manipulations
libclang: C Interface to Clang
Collaboration diagram for Cursor manipulations:

Classes

struct  CXPlatformAvailability

Typedefs

typedef struct
CXPlatformAvailability 
CXPlatformAvailability
typedef struct CXCursorSetImpl * CXCursorSet
 A fast container representing a set of CXCursors.

Enumerations

enum  CXLinkageKind {
  CXLinkage_Invalid, CXLinkage_NoLinkage, CXLinkage_Internal, CXLinkage_UniqueExternal,
  CXLinkage_External
}
 Describe the linkage of the entity referred to by a cursor. More...
enum  CXLanguageKind { CXLanguage_Invalid = 0, CXLanguage_C, CXLanguage_ObjC, CXLanguage_CPlusPlus }
 Describe the "language" of the entity referred to by a cursor. More...

Functions

CINDEX_LINKAGE CXCursor clang_getNullCursor (void)
 Retrieve the NULL cursor, which represents no entity.
CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor (CXTranslationUnit)
 Retrieve the cursor that represents the given translation unit.
CINDEX_LINKAGE unsigned clang_equalCursors (CXCursor, CXCursor)
 Determine whether two cursors are equivalent.
CINDEX_LINKAGE int clang_Cursor_isNull (CXCursor cursor)
 Returns non-zero if cursor is null.
CINDEX_LINKAGE unsigned clang_hashCursor (CXCursor)
 Compute a hash value for the given cursor.
CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind (CXCursor)
 Retrieve the kind of the given cursor.
CINDEX_LINKAGE unsigned clang_isDeclaration (enum CXCursorKind)
 Determine whether the given cursor kind represents a declaration.
CINDEX_LINKAGE unsigned clang_isReference (enum CXCursorKind)
 Determine whether the given cursor kind represents a simple reference.
CINDEX_LINKAGE unsigned clang_isExpression (enum CXCursorKind)
 Determine whether the given cursor kind represents an expression.
CINDEX_LINKAGE unsigned clang_isStatement (enum CXCursorKind)
 Determine whether the given cursor kind represents a statement.
CINDEX_LINKAGE unsigned clang_isAttribute (enum CXCursorKind)
 Determine whether the given cursor kind represents an attribute.
CINDEX_LINKAGE unsigned clang_isInvalid (enum CXCursorKind)
 Determine whether the given cursor kind represents an invalid cursor.
CINDEX_LINKAGE unsigned clang_isTranslationUnit (enum CXCursorKind)
 Determine whether the given cursor kind represents a translation unit.
CINDEX_LINKAGE unsigned clang_isPreprocessing (enum CXCursorKind)
CINDEX_LINKAGE unsigned clang_isUnexposed (enum CXCursorKind)
CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage (CXCursor cursor)
 Determine the linkage of the entity referred to by a given cursor.
CINDEX_LINKAGE enum
CXAvailabilityKind 
clang_getCursorAvailability (CXCursor cursor)
 Determine the availability of the entity that this cursor refers to, taking the current target platform into account.
CINDEX_LINKAGE int clang_getCursorPlatformAvailability (CXCursor cursor, int *always_deprecated, CXString *deprecated_message, int *always_unavailable, CXString *unavailable_message, CXPlatformAvailability *availability, int availability_size)
 Determine the availability of the entity that this cursor refers to on any platforms for which availability information is known.
CINDEX_LINKAGE void clang_disposeCXPlatformAvailability (CXPlatformAvailability *availability)
 Free the memory associated with a CXPlatformAvailability structure.
CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage (CXCursor cursor)
 Determine the "language" of the entity referred to by a given cursor.
CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit (CXCursor)
 Returns the translation unit that a cursor originated from.
CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet (void)
 Creates an empty CXCursorSet.
CINDEX_LINKAGE void clang_disposeCXCursorSet (CXCursorSet cset)
 Disposes a CXCursorSet and releases its associated memory.
CINDEX_LINKAGE unsigned clang_CXCursorSet_contains (CXCursorSet cset, CXCursor cursor)
 Queries a CXCursorSet to see if it contains a specific CXCursor.
CINDEX_LINKAGE unsigned clang_CXCursorSet_insert (CXCursorSet cset, CXCursor cursor)
 Inserts a CXCursor into a CXCursorSet.
CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent (CXCursor cursor)
 Determine the semantic parent of the given cursor.
CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent (CXCursor cursor)
 Determine the lexical parent of the given cursor.
CINDEX_LINKAGE void clang_getOverriddenCursors (CXCursor cursor, CXCursor **overridden, unsigned *num_overridden)
 Determine the set of methods that are overridden by the given method.
CINDEX_LINKAGE void clang_disposeOverriddenCursors (CXCursor *overridden)
 Free the set of overridden cursors returned by clang_getOverriddenCursors().
CINDEX_LINKAGE CXFile clang_getIncludedFile (CXCursor cursor)
 Retrieve the file that is included by the given inclusion directive cursor.

Typedef Documentation

typedef struct CXCursorSetImpl* CXCursorSet

A fast container representing a set of CXCursors.

Definition at line 2548 of file Index.h.

Describes the availability of a given entity on a particular platform, e.g., a particular class might only be available on Mac OS 10.7 or newer.


Enumeration Type Documentation

Describe the "language" of the entity referred to by a cursor.

Enumerator:
CXLanguage_Invalid 
CXLanguage_C 
CXLanguage_ObjC 
CXLanguage_CPlusPlus 

Definition at line 2527 of file Index.h.

Describe the linkage of the entity referred to by a cursor.

Enumerator:
CXLinkage_Invalid 

This value indicates that no linkage information is available for a provided CXCursor.

CXLinkage_NoLinkage 

This is the linkage for variables, parameters, and so on that have automatic storage. This covers normal (non-extern) local variables.

CXLinkage_Internal 

This is the linkage for static variables and static functions.

CXLinkage_UniqueExternal 

This is the linkage for entities with external linkage that live in C++ anonymous namespaces.

CXLinkage_External 

This is the linkage for entities with true, external linkage.

Definition at line 2402 of file Index.h.


Function Documentation

Creates an empty CXCursorSet.

Returns the translation unit that a cursor originated from.

Returns non-zero if cursor is null.

Queries a CXCursorSet to see if it contains a specific CXCursor.

Returns:
non-zero if the set contains the specified cursor.

Inserts a CXCursor into a CXCursorSet.

Returns:
zero if the CXCursor was already in the set, and non-zero otherwise.

Disposes a CXCursorSet and releases its associated memory.

Free the memory associated with a CXPlatformAvailability structure.

Free the set of overridden cursors returned by clang_getOverriddenCursors().

Determine whether two cursors are equivalent.

Determine the availability of the entity that this cursor refers to, taking the current target platform into account.

Parameters:
cursorThe cursor to query.
Returns:
The availability of the cursor.

Retrieve the kind of the given cursor.

Determine the "language" of the entity referred to by a given cursor.

Determine the lexical parent of the given cursor.

The lexical parent of a cursor is the cursor in which the given cursor was actually written. For many declarations, the lexical and semantic parents are equivalent (the semantic parent is returned by clang_getCursorSemanticParent()). They diverge when declarations or definitions are provided out-of-line. For example:

 class C {
  void f();
 };

 void C::f() { }

In the out-of-line definition of C::f, the semantic parent is the class C, of which this function is a member. The lexical parent is the place where the declaration actually occurs in the source code; in this case, the definition occurs in the translation unit. In general, the lexical parent for a given entity can change without affecting the semantics of the program, and the lexical parent of different declarations of the same entity may be different. Changing the semantic parent of a declaration, on the other hand, can have a major impact on semantics, and redeclarations of a particular entity should all have the same semantic context.

In the example above, both declarations of C::f have C as their semantic context, while the lexical context of the first C::f is C and the lexical context of the second C::f is the translation unit.

For declarations written in the global scope, the lexical parent is the translation unit.

Determine the linkage of the entity referred to by a given cursor.

CINDEX_LINKAGE int clang_getCursorPlatformAvailability ( CXCursor  cursor,
int *  always_deprecated,
CXString deprecated_message,
int *  always_unavailable,
CXString unavailable_message,
CXPlatformAvailability availability,
int  availability_size 
)

Determine the availability of the entity that this cursor refers to on any platforms for which availability information is known.

Parameters:
cursorThe cursor to query.
always_deprecatedIf non-NULL, will be set to indicate whether the entity is deprecated on all platforms.
deprecated_messageIf non-NULL, will be set to the message text provided along with the unconditional deprecation of this entity. The client is responsible for deallocating this string.
always_unavailableIf non-NULL, will be set to indicate whether the entity is unavailable on all platforms.
unavailable_messageIf non-NULL, will be set to the message text provided along with the unconditional unavailability of this entity. The client is responsible for deallocating this string.
availabilityIf non-NULL, an array of CXPlatformAvailability instances that will be populated with platform availability information, up to either the number of platforms for which availability information is available (as returned by this function) or availability_size, whichever is smaller.
availability_sizeThe number of elements available in the availability array.
Returns:
The number of platforms (N) for which availability information is available (which is unrelated to availability_size).

Note that the client is responsible for calling clang_disposeCXPlatformAvailability to free each of the platform-availability structures returned. There are min(N, availability_size) such structures.

Determine the semantic parent of the given cursor.

The semantic parent of a cursor is the cursor that semantically contains the given cursor. For many declarations, the lexical and semantic parents are equivalent (the lexical parent is returned by clang_getCursorLexicalParent()). They diverge when declarations or definitions are provided out-of-line. For example:

 class C {
  void f();
 };

 void C::f() { }

In the out-of-line definition of C::f, the semantic parent is the class C, of which this function is a member. The lexical parent is the place where the declaration actually occurs in the source code; in this case, the definition occurs in the translation unit. In general, the lexical parent for a given entity can change without affecting the semantics of the program, and the lexical parent of different declarations of the same entity may be different. Changing the semantic parent of a declaration, on the other hand, can have a major impact on semantics, and redeclarations of a particular entity should all have the same semantic context.

In the example above, both declarations of C::f have C as their semantic context, while the lexical context of the first C::f is C and the lexical context of the second C::f is the translation unit.

For global declarations, the semantic parent is the translation unit.

Retrieve the file that is included by the given inclusion directive cursor.

Retrieve the NULL cursor, which represents no entity.

CINDEX_LINKAGE void clang_getOverriddenCursors ( CXCursor  cursor,
CXCursor **  overridden,
unsigned num_overridden 
)

Determine the set of methods that are overridden by the given method.

In both Objective-C and C++, a method (aka virtual member function, in C++) can override a virtual method in a base class. For Objective-C, a method is said to override any method in the class's base class, its protocols, or its categories' protocols, that has the same selector and is of the same kind (class or instance). If no such method exists, the search continues to the class's superclass, its protocols, and its categories, and so on. A method from an Objective-C implementation is considered to override the same methods as its corresponding method in the interface.

For C++, a virtual member function overrides any virtual member function with the same signature that occurs in its base classes. With multiple inheritance, a virtual member function can override several virtual member functions coming from different base classes.

In all cases, this function determines the immediate overridden method, rather than all of the overridden methods. For example, if a method is originally declared in a class A, then overridden in B (which in inherits from A) and also in C (which inherited from B), then the only overridden method returned from this function when invoked on C's method will be B's method. The client may then invoke this function again, given the previously-found overridden methods, to map out the complete method-override set.

Parameters:
cursorA cursor representing an Objective-C or C++ method. This routine will compute the set of methods that this method overrides.
overriddenA pointer whose pointee will be replaced with a pointer to an array of cursors, representing the set of overridden methods. If there are no overridden methods, the pointee will be set to NULL. The pointee must be freed via a call to clang_disposeOverriddenCursors().
num_overriddenA pointer to the number of overridden functions, will be set to the number of overridden functions in the array pointed to by overridden.

Retrieve the cursor that represents the given translation unit.

The translation unit cursor can be used to start traversing the various declarations within the given translation unit.

Compute a hash value for the given cursor.

CINDEX_LINKAGE unsigned clang_isAttribute ( enum  CXCursorKind)

Determine whether the given cursor kind represents an attribute.

Determine whether the given cursor kind represents a declaration.

CINDEX_LINKAGE unsigned clang_isExpression ( enum  CXCursorKind)

Determine whether the given cursor kind represents an expression.

CINDEX_LINKAGE unsigned clang_isInvalid ( enum  CXCursorKind)

Determine whether the given cursor kind represents an invalid cursor.

CINDEX_LINKAGE unsigned clang_isReference ( enum  CXCursorKind)

Determine whether the given cursor kind represents a simple reference.

Note that other kinds of cursors (such as expressions) can also refer to other cursors. Use clang_getCursorReferenced() to determine whether a particular cursor refers to another entity.

CINDEX_LINKAGE unsigned clang_isStatement ( enum  CXCursorKind)

Determine whether the given cursor kind represents a statement.

Determine whether the given cursor kind represents a translation unit.

CINDEX_LINKAGE unsigned clang_isUnexposed ( enum  CXCursorKind)