]> granicus.if.org Git - clang/commitdiff
Split clang_getCursor() into clang_getCursor() and clang_getCursorWithHint().
authorTed Kremenek <kremenek@apple.com>
Thu, 22 Oct 2009 17:22:53 +0000 (17:22 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 22 Oct 2009 17:22:53 +0000 (17:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84873 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/CIndex/CIndex.cpp
tools/CIndex/CIndex.exports
tools/c-index-test/c-index-test.c

index 644b2e29412e61e4b65a5dd18e9fb0c7b4c21db7..44cbe0efff814d8d626d3ffde0c2490ec8b61ec2 100644 (file)
@@ -251,13 +251,24 @@ const char *clang_getDeclSource(CXDecl);
 /**
    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, 
-                         CXDecl RelativeToDecl);
+                         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, 
+                                 CXLookupHint *hint);
+
+void clang_initCXLookupHint(CXLookupHint *hint);
 
 enum CXCursorKind clang_getCursorKind(CXCursor);
 unsigned clang_isDeclaration(enum CXCursorKind);
index e6e63b8ef180586001af209f739d4daca18da76b..cbc3085a27eb07abfc381a4cfa64389387c4efe5 100644 (file)
@@ -695,13 +695,26 @@ static enum CXCursorKind TranslateKind(Decl *D) {
 //
 // CXCursor Operations.
 //
+void clang_initCXLookupHint(CXLookupHint *hint) {
+  memset(hint, 0, sizeof(*hint));
+}
+
 CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name, 
-                         unsigned line, unsigned column, 
-                         CXDecl RelativeToDecl)
+                         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, 
+                                 CXLookupHint *hint)
 {
   assert(CTUnit && "Passed null CXTranslationUnit");
   ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
   
+  // FIXME: Make this better.
+  CXDecl RelativeToDecl = hint ? hint->decl : NULL;
+  
   FileManager &FMgr = CXXUnit->getFileManager();
   const FileEntry *File = FMgr.getFile(source_name, 
                                        source_name+strlen(source_name));  
index ea647b46a628229486b7cfdda6c01e38fb194040..e9d44a0dc918f4fcf0d19921aa87191ad4f5050d 100644 (file)
@@ -7,6 +7,7 @@ _clang_getCursorFromDecl
 _clang_getCursorKind
 _clang_getCursorLine
 _clang_getCursorSource
+_clang_getCursorWithHint
 _clang_getDeclarationName
 _clang_getDeclSpelling
 _clang_getDeclLine
@@ -20,6 +21,7 @@ _clang_loadTranslationUnit
 _clang_createTranslationUnit
 _clang_createTranslationUnitFromSourceFile
 _clang_disposeTranslationUnit
+_clang_initCXLookupHint
 _clang_isDeclaration
 _clang_isReference
 _clang_isDefinition
index b458216f70d6391dd25076ea61c4624316aed12d..5cbc2fae53f49f7f1413e790e435c71bfad79552 100644 (file)
@@ -60,9 +60,13 @@ static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
             curColumn = 1;
           } else if (*startBuf != '\t')
             curColumn++;
+          
+          CXLookupHint hint;
+          clang_initCXLookupHint(&hint);
+          hint.decl = Cursor.decl;
 
-          Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor),
-                                curLine, curColumn, Cursor.decl);
+          Ref = clang_getCursorWithHint(Unit, clang_getCursorSource(Cursor),
+                                        curLine, curColumn, &hint);
           if (Ref.kind == CXCursor_NoDeclFound) {
             /* Nothing found here; that's fine. */
           } else if (Ref.kind != CXCursor_FunctionDecl) {