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:-)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84760
91177308-0d34-0410-b5e6-
96231b3b80d8
/*
* 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,
- unsigned line, unsigned column);
+ unsigned line, unsigned column,
+ CXDecl RelativeToDecl);
enum CXCursorKind clang_getCursorKind(CXCursor);
unsigned clang_isDeclaration(enum CXCursorKind);
namespace clang {
class ASTContext;
class SourceLocation;
-
+ class Decl;
+
namespace idx {
class ASTLocation;
///
/// \returns the resolved ASTLocation or an invalid ASTLocation if the source
/// location could not be resolved.
-ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc);
+ASTLocation ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc,
+ Decl *RelativeToDecl = 0);
} // end namespace idx
/// \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())
return ASTLocation();
+ if (RelativeToDecl)
+ return DeclLocResolver(Ctx, Loc).Visit(RelativeToDecl);
return DeclLocResolver(Ctx, Loc).Visit(Ctx.getTranslationUnitDecl());
}
// CXCursor Operations.
//
CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
- unsigned line, unsigned column)
+ unsigned line, unsigned column,
+ CXDecl RelativeToDecl)
{
assert(CTUnit && "Passed null CXTranslationUnit");
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
SourceLocation SLoc =
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();
if (ALoc.isNamedRef())
unsigned curLine = startLine, curColumn = startColumn;
CXCursor Ref;
- while (startBuf <= endBuf) {
+ while (startBuf < endBuf) {
if (*startBuf == '\n') {
startBuf++;
curLine++;
curColumn++;
Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
- curLine, curColumn);
+ curLine, curColumn, Cursor.decl);
if (Ref.kind == CXCursor_NoDeclFound) {
/* Nothing found here; that's fine. */
} else if (Ref.kind != CXCursor_FunctionDecl) {