forked from OSchip/llvm-project
Extend clang_getCursor() to take a 'relativeDecl' argument (so speed up searching). Without a 'relativeDecl', the algorithm is n-squared. For example, running the following command on 'Large.m' takes hours without a 'relatvieDecl'.
snaroff% time ../../Debug/bin/c-index-test Large.ast all > Large.out snaroff% cat Large.m #import <Cocoa/Cocoa.h> #import <QuickTime/QuickTime.h> #import <OpenGL/OpenGL.h> With a 'relativeDecl', it takes <30 seconds:-) llvm-svn: 84760
This commit is contained in:
parent
45f99d6621
commit
20bad0b7c6
|
@ -240,8 +240,16 @@ const char *clang_getDeclSource(CXDecl);
|
||||||
/*
|
/*
|
||||||
* CXCursor Operations.
|
* CXCursor Operations.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
Usage: clang_getCursor() will translate a source/line/column position
|
||||||
|
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);
|
unsigned line, unsigned column,
|
||||||
|
CXDecl RelativeToDecl);
|
||||||
|
|
||||||
enum CXCursorKind clang_getCursorKind(CXCursor);
|
enum CXCursorKind clang_getCursorKind(CXCursor);
|
||||||
unsigned clang_isDeclaration(enum CXCursorKind);
|
unsigned clang_isDeclaration(enum CXCursorKind);
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
namespace clang {
|
namespace clang {
|
||||||
class ASTContext;
|
class ASTContext;
|
||||||
class SourceLocation;
|
class SourceLocation;
|
||||||
|
class Decl;
|
||||||
|
|
||||||
namespace idx {
|
namespace idx {
|
||||||
class ASTLocation;
|
class ASTLocation;
|
||||||
|
|
||||||
|
@ -26,7 +27,8 @@ namespace idx {
|
||||||
///
|
///
|
||||||
/// \returns the resolved ASTLocation or an invalid ASTLocation if the source
|
/// \returns the resolved ASTLocation or an invalid ASTLocation if the source
|
||||||
/// location could not be resolved.
|
/// location could not be resolved.
|
||||||
ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc);
|
ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc,
|
||||||
|
Decl *RelativeToDecl = 0);
|
||||||
|
|
||||||
} // end namespace idx
|
} // end namespace idx
|
||||||
|
|
||||||
|
|
|
@ -497,9 +497,12 @@ void LocResolverBase::print(Stmt *Node) {
|
||||||
|
|
||||||
/// \brief Returns the AST node that a source location points to.
|
/// \brief Returns the AST node that a source location points to.
|
||||||
///
|
///
|
||||||
ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) {
|
ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc,
|
||||||
|
Decl *RelativeToDecl) {
|
||||||
if (Loc.isInvalid())
|
if (Loc.isInvalid())
|
||||||
return ASTLocation();
|
return ASTLocation();
|
||||||
|
|
||||||
|
if (RelativeToDecl)
|
||||||
|
return DeclLocResolver(Ctx, Loc).Visit(RelativeToDecl);
|
||||||
return DeclLocResolver(Ctx, Loc).Visit(Ctx.getTranslationUnitDecl());
|
return DeclLocResolver(Ctx, Loc).Visit(Ctx.getTranslationUnitDecl());
|
||||||
}
|
}
|
||||||
|
|
|
@ -655,7 +655,8 @@ static enum CXCursorKind TranslateKind(Decl *D) {
|
||||||
// CXCursor Operations.
|
// CXCursor Operations.
|
||||||
//
|
//
|
||||||
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
|
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
|
||||||
unsigned line, unsigned column)
|
unsigned line, unsigned column,
|
||||||
|
CXDecl RelativeToDecl)
|
||||||
{
|
{
|
||||||
assert(CTUnit && "Passed null CXTranslationUnit");
|
assert(CTUnit && "Passed null CXTranslationUnit");
|
||||||
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
||||||
|
@ -670,7 +671,8 @@ CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
|
||||||
SourceLocation SLoc =
|
SourceLocation SLoc =
|
||||||
CXXUnit->getSourceManager().getLocation(File, line, column);
|
CXXUnit->getSourceManager().getLocation(File, line, column);
|
||||||
|
|
||||||
ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc);
|
ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc,
|
||||||
|
static_cast<NamedDecl *>(RelativeToDecl));
|
||||||
|
|
||||||
Decl *Dcl = ALoc.getParentDecl();
|
Decl *Dcl = ALoc.getParentDecl();
|
||||||
if (ALoc.isNamedRef())
|
if (ALoc.isNamedRef())
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
|
||||||
unsigned curLine = startLine, curColumn = startColumn;
|
unsigned curLine = startLine, curColumn = startColumn;
|
||||||
CXCursor Ref;
|
CXCursor Ref;
|
||||||
|
|
||||||
while (startBuf <= endBuf) {
|
while (startBuf < endBuf) {
|
||||||
if (*startBuf == '\n') {
|
if (*startBuf == '\n') {
|
||||||
startBuf++;
|
startBuf++;
|
||||||
curLine++;
|
curLine++;
|
||||||
|
@ -62,7 +62,7 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
|
||||||
curColumn++;
|
curColumn++;
|
||||||
|
|
||||||
Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
|
Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
|
||||||
curLine, curColumn);
|
curLine, curColumn, Cursor.decl);
|
||||||
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