summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 00:30:33 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 00:30:33 +0000
commitfd51520d5fce0d49d914626f18954aa2e736dbcf (patch)
treeffffbb517e0e8519310f4f649b1dddc03e28cec5 /clang
parentd6e9fa55eba409648503e87f20cde0b3e11c9d71 (diff)
downloadbcm5719-llvm-fd51520d5fce0d49d914626f18954aa2e736dbcf.tar.gz
bcm5719-llvm-fd51520d5fce0d49d914626f18954aa2e736dbcf.zip
[libclang] Refactor the important stuff in clang_getCursor into a cxcursor::getCursor(CXTranslationUnit, SourceLocation) function.
llvm-svn: 140588
Diffstat (limited to 'clang')
-rw-r--r--clang/tools/libclang/CIndex.cpp55
-rw-r--r--clang/tools/libclang/CXCursor.h2
2 files changed, 34 insertions, 23 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index e183de13707..f71f1530558 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3489,32 +3489,10 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
- // Translate the given source location to make it point at the beginning of
- // the token under the cursor.
SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
-
- // Guard against an invalid SourceLocation, or we may assert in one
- // of the following calls.
- if (SLoc.isInvalid())
- return clang_getNullCursor();
+ CXCursor Result = cxcursor::getCursor(TU, SLoc);
bool Logging = getenv("LIBCLANG_LOGGING");
- SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(),
- CXXUnit->getASTContext().getLangOptions());
-
- CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
- if (SLoc.isValid()) {
- // FIXME: Would be great to have a "hint" cursor, then walk from that
- // hint cursor upward until we find a cursor whose source range encloses
- // the region of interest, rather than starting from the translation unit.
- GetCursorData ResultData(CXXUnit->getSourceManager(), SLoc, Result);
- CXCursor Parent = clang_getTranslationUnitCursor(TU);
- CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData,
- /*VisitPreprocessorLast=*/true,
- SourceLocation(SLoc));
- CursorVis.VisitChildren(Parent);
- }
-
if (Logging) {
CXFile SearchFile;
unsigned SearchLine, SearchColumn;
@@ -3749,6 +3727,37 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
} // end extern "C"
+CXCursor cxcursor::getCursor(CXTranslationUnit TU, SourceLocation SLoc) {
+ assert(TU);
+
+ // Guard against an invalid SourceLocation, or we may assert in one
+ // of the following calls.
+ if (SLoc.isInvalid())
+ return clang_getNullCursor();
+
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
+
+ // Translate the given source location to make it point at the beginning of
+ // the token under the cursor.
+ SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(),
+ CXXUnit->getASTContext().getLangOptions());
+
+ CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
+ if (SLoc.isValid()) {
+ // FIXME: Would be great to have a "hint" cursor, then walk from that
+ // hint cursor upward until we find a cursor whose source range encloses
+ // the region of interest, rather than starting from the translation unit.
+ GetCursorData ResultData(CXXUnit->getSourceManager(), SLoc, Result);
+ CXCursor Parent = clang_getTranslationUnitCursor(TU);
+ CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData,
+ /*VisitPreprocessorLast=*/true,
+ SourceLocation(SLoc));
+ CursorVis.VisitChildren(Parent);
+ }
+
+ return Result;
+}
+
static SourceRange getRawCursorExtent(CXCursor C) {
if (clang_isReference(C.kind)) {
switch (C.kind) {
diff --git a/clang/tools/libclang/CXCursor.h b/clang/tools/libclang/CXCursor.h
index 68d09e76c1c..c7051ea2f98 100644
--- a/clang/tools/libclang/CXCursor.h
+++ b/clang/tools/libclang/CXCursor.h
@@ -43,6 +43,8 @@ class TemplateName;
class TypeDecl;
namespace cxcursor {
+
+CXCursor getCursor(CXTranslationUnit, SourceLocation);
CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent,
CXTranslationUnit TU);
OpenPOWER on IntegriCloud