More work to enable more exhaustive testing of the indexing API.

Next step: Add actual some test cases:-)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index e7043c1..b403863 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -32,6 +32,32 @@
                                       clang_getCursorLine(Cursor),
                                       clang_getCursorColumn(Cursor));
 
+    if (Cursor.kind == CXCursor_FunctionDefn) {
+      const char *startBuf, *endBuf;
+      unsigned startLine, startColumn, endLine, endColumn;
+      clang_getDefinitionSpellingAndExtent(Cursor, &startBuf, &endBuf,
+                                           &startLine, &startColumn,
+                                           &endLine, &endColumn);
+      /* Probe the entire body, looking for "refs". */
+      unsigned curLine = startLine, curColumn = startColumn;
+      while (startBuf <= endBuf) {
+        if (*startBuf == '\n') {
+          startBuf++;
+          curLine++;
+          curColumn = 1;
+        }
+        CXCursor Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor), 
+                                       curLine, curColumn);
+        if (Ref.kind != CXCursor_FunctionDecl) {
+          PrintCursor(Ref);
+          printf("(Context: %s", clang_getDeclSpelling(Ref.decl));
+          printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Ref),
+                                            curLine, curColumn);
+        }
+        startBuf++;
+        curColumn++;
+      }
+    }
     clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
   }
 }