clang-tags
C/C++ source code indexing tool based on libclang
|
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) |
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.
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.
tu | the 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.
tu | the TranslationUnit of the source code location |
fileName | the file name of the source file in the translation unit |
offset | the position in the file, expressed in characters since the file beginning |
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.
bool LibClang::Cursor::isDeclaration | ( | ) | const |
Determine whether 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.
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.
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:
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.
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.
std::string LibClang::Cursor::spelling | ( | ) | const |
Get the name of the entity referred to.
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.