forked from OSchip/llvm-project
Split clang_getCursor() into clang_getCursor() and clang_getCursorWithHint().
llvm-svn: 84873
This commit is contained in:
parent
8de31d0e80
commit
a96b72a4ca
|
@ -251,13 +251,24 @@ const char *clang_getDeclSource(CXDecl);
|
||||||
/**
|
/**
|
||||||
Usage: clang_getCursor() will translate a source/line/column position
|
Usage: clang_getCursor() will translate a source/line/column position
|
||||||
into an AST cursor (to derive semantic information from the source code).
|
into an AST cursor (to derive semantic information from the source code).
|
||||||
If 'RelativeToDecl' is NULL, the entire translation unit will be searched.
|
|
||||||
Note that searching the entire translation unit can be slow.
|
|
||||||
Otherwise, the "search" for the AST cursor will start at 'RelativeToDecl'.
|
|
||||||
*/
|
*/
|
||||||
CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
|
CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
|
||||||
|
unsigned line, unsigned column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Usage: clang_getCursorWithHint() provides the same functionality as
|
||||||
|
clang_getCursor() except that it takes an option 'hint' argument.
|
||||||
|
The 'hint' is a temporary CXLookupHint object (whose lifetime is managed by
|
||||||
|
the caller) that should be initialized with clang_initCXLookupHint().
|
||||||
|
|
||||||
|
FIXME: Add a better comment once getCursorWithHint() has more functionality.
|
||||||
|
*/
|
||||||
|
typedef CXCursor CXLookupHint;
|
||||||
|
CXCursor clang_getCursorWithHint(CXTranslationUnit, const char *source_name,
|
||||||
unsigned line, unsigned column,
|
unsigned line, unsigned column,
|
||||||
CXDecl RelativeToDecl);
|
CXLookupHint *hint);
|
||||||
|
|
||||||
|
void clang_initCXLookupHint(CXLookupHint *hint);
|
||||||
|
|
||||||
enum CXCursorKind clang_getCursorKind(CXCursor);
|
enum CXCursorKind clang_getCursorKind(CXCursor);
|
||||||
unsigned clang_isDeclaration(enum CXCursorKind);
|
unsigned clang_isDeclaration(enum CXCursorKind);
|
||||||
|
|
|
@ -695,13 +695,26 @@ static enum CXCursorKind TranslateKind(Decl *D) {
|
||||||
//
|
//
|
||||||
// CXCursor Operations.
|
// CXCursor Operations.
|
||||||
//
|
//
|
||||||
|
void clang_initCXLookupHint(CXLookupHint *hint) {
|
||||||
|
memset(hint, 0, sizeof(*hint));
|
||||||
|
}
|
||||||
|
|
||||||
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
|
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
|
||||||
|
unsigned line, unsigned column) {
|
||||||
|
return clang_getCursorWithHint(CTUnit, source_name, line, column, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
CXCursor clang_getCursorWithHint(CXTranslationUnit CTUnit,
|
||||||
|
const char *source_name,
|
||||||
unsigned line, unsigned column,
|
unsigned line, unsigned column,
|
||||||
CXDecl RelativeToDecl)
|
CXLookupHint *hint)
|
||||||
{
|
{
|
||||||
assert(CTUnit && "Passed null CXTranslationUnit");
|
assert(CTUnit && "Passed null CXTranslationUnit");
|
||||||
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
||||||
|
|
||||||
|
// FIXME: Make this better.
|
||||||
|
CXDecl RelativeToDecl = hint ? hint->decl : NULL;
|
||||||
|
|
||||||
FileManager &FMgr = CXXUnit->getFileManager();
|
FileManager &FMgr = CXXUnit->getFileManager();
|
||||||
const FileEntry *File = FMgr.getFile(source_name,
|
const FileEntry *File = FMgr.getFile(source_name,
|
||||||
source_name+strlen(source_name));
|
source_name+strlen(source_name));
|
||||||
|
|
|
@ -7,6 +7,7 @@ _clang_getCursorFromDecl
|
||||||
_clang_getCursorKind
|
_clang_getCursorKind
|
||||||
_clang_getCursorLine
|
_clang_getCursorLine
|
||||||
_clang_getCursorSource
|
_clang_getCursorSource
|
||||||
|
_clang_getCursorWithHint
|
||||||
_clang_getDeclarationName
|
_clang_getDeclarationName
|
||||||
_clang_getDeclSpelling
|
_clang_getDeclSpelling
|
||||||
_clang_getDeclLine
|
_clang_getDeclLine
|
||||||
|
@ -20,6 +21,7 @@ _clang_loadTranslationUnit
|
||||||
_clang_createTranslationUnit
|
_clang_createTranslationUnit
|
||||||
_clang_createTranslationUnitFromSourceFile
|
_clang_createTranslationUnitFromSourceFile
|
||||||
_clang_disposeTranslationUnit
|
_clang_disposeTranslationUnit
|
||||||
|
_clang_initCXLookupHint
|
||||||
_clang_isDeclaration
|
_clang_isDeclaration
|
||||||
_clang_isReference
|
_clang_isReference
|
||||||
_clang_isDefinition
|
_clang_isDefinition
|
||||||
|
|
|
@ -61,8 +61,12 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
|
||||||
} else if (*startBuf != '\t')
|
} else if (*startBuf != '\t')
|
||||||
curColumn++;
|
curColumn++;
|
||||||
|
|
||||||
Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
|
CXLookupHint hint;
|
||||||
curLine, curColumn, Cursor.decl);
|
clang_initCXLookupHint(&hint);
|
||||||
|
hint.decl = Cursor.decl;
|
||||||
|
|
||||||
|
Ref = clang_getCursorWithHint(Unit, clang_getCursorSource(Cursor),
|
||||||
|
curLine, curColumn, &hint);
|
||||||
if (Ref.kind == CXCursor_NoDeclFound) {
|
if (Ref.kind == CXCursor_NoDeclFound) {
|
||||||
/* Nothing found here; that's fine. */
|
/* Nothing found here; that's fine. */
|
||||||
} else if (Ref.kind != CXCursor_FunctionDecl) {
|
} else if (Ref.kind != CXCursor_FunctionDecl) {
|
||||||
|
|
Loading…
Reference in New Issue