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

Node representing an entity in the AST. More...

#include <cursor.hxx>

Public Member Functions

 Cursor (const TranslationUnit &tu)
 Constructor from a translation unit.
 Cursor (const TranslationUnit &tu, const std::string &fileName, const unsigned int offset)
 Constructor from a source location.
bool isNull () const
 Determine whether the cursor is null.
bool isUnexposed () const
 Determine whether the cursor is unexposed.
bool isDeclaration () const
 Determine whether the cursor represents a declaration.
Cursor referenced () const
 Get the cursor referenced.
std::string kindStr () const
 Get the kind of cursor.
std::string spelling () const
 Get the name of the entity referred to.
std::string USR () const
 Get the Unified Symbol Resolution for the entity referenced.
SourceLocation location () const
 Get the source location associated to a cursor.
SourceLocation end () const
 Get the source location associated to a cursor.

Friends

class Visitor
template<typename VISITOR >
CXChildVisitResult visitChildren (CXCursor rawCursor, CXCursor rawParent, CXClientData client_data)

Detailed Description

Node representing an entity in the AST.

This class is a proxy for libclang's CXCursor type. It should provide the same features.

A cursor represents an entity in the Abstract Syntax Tree (AST) of a translation unit: statement, declaration, expressions, ... A cursor is associated to a physical location in the source code, and to an Unified Symbol Resolution (USR), which uniquely identifies the symbol it references across translation units.

Constructor & Destructor Documentation

LibClang::Cursor::Cursor ( const TranslationUnit tu)

Constructor from a translation unit.

Create a cursor representing the whole translation unit. This cursor can be used to start visiting the translation unit.

Parameters
tuthe TranslationUnit
LibClang::Cursor::Cursor ( const TranslationUnit tu,
const std::string &  fileName,
const unsigned int  offset 
)

Constructor from a source location.

Create a cursor to the entity located at a specified location in the source code of a translation unit. The returned cursor represents the most specific entity spanning this location (i.e. a cursor which spans the given location and has no child nodes in the AST).

Creates a null cursor if no such location is found.

Parameters
tuthe TranslationUnit of the source code location
fileNamethe file name of the source file in the translation unit
offsetthe position in the file, expressed in characters since the file beginning

Member Function Documentation

SourceLocation LibClang::Cursor::end ( ) const

Get the source location associated to a cursor.

The location returned corresponds to the last character of the referenced entity in the source code. Use location() to get the location of the first character, and thus the span of the entity in the source code.

Returns
a SourceLocation to the end of the referenced entity
bool LibClang::Cursor::isDeclaration ( ) const

Determine whether the cursor represents a declaration.

Returns
true if the cursor represents a declaration
bool LibClang::Cursor::isNull ( ) const

Determine whether the cursor is null.

A null cursor is used by some functions as a return value for invalid cursors.

Returns
true if the cursor is null
bool LibClang::Cursor::isUnexposed ( ) const

Determine whether the cursor is unexposed.

Some entities in the AST do not (yet) have a specified kind; these are the unexposed entities.

Returns
Determine whether the cursor is unexposed
std::string LibClang::Cursor::kindStr ( ) const

Get the kind of cursor.

Retrieve the kind of entity represented by the cursor, as a string. Cursor kinds include for example:

  • "ClassDecl": a class declaration
  • "CXXMethod": a C++ class method
  • "MemberRefExpr": an expression referring to a member of a class
Returns
the cursor kind, as a string
SourceLocation LibClang::Cursor::location ( ) const

Get the source location associated to a cursor.

The location returned corresponds to the first character of the referenced entity in the source code. Use end() to get the location of the last character, and thus the span of the entity in the source code.

Returns
a SourceLocation to the beginning of the referenced entity
Cursor LibClang::Cursor::referenced ( ) const

Get the cursor referenced.

For cursors which represent references to other entities in the AST, retrieve the referenced cursor. For example, a cursor pointing to the use of a variable refers to the declaration of this variable.

Returns
the referenced Cursor, null if no such cursor can be found
std::string LibClang::Cursor::spelling ( ) const

Get the name of the entity referred to.

Returns
the name of the referenced entity, as a string
std::string LibClang::Cursor::USR ( ) const

Get the Unified Symbol Resolution for the entity referenced.

A Unified Symbol Resolution (USR) is a string that identifies a particular entity (function, class, variable, etc.) within a program. USRs can be compared across translation units to determine, e.g., when references in one translation refer to an entity defined in another translation unit.

Returns
the USR, as a string

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