summaryrefslogtreecommitdiffstats
path: root/clang/tools/c-index-test
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-09-03 15:49:00 +0000
committerSteve Naroff <snaroff@apple.com>2009-09-03 15:49:00 +0000
commit38c1a7ba1207ecb5631b2da9a16694b0edd42f38 (patch)
tree692fd1ac60006f06ebe0a6944c64abc35f53b62f /clang/tools/c-index-test
parent22571485b33b3535f8c224d477a4bb4252b2152c (diff)
downloadbcm5719-llvm-38c1a7ba1207ecb5631b2da9a16694b0edd42f38.tar.gz
bcm5719-llvm-38c1a7ba1207ecb5631b2da9a16694b0edd42f38.zip
- Add back some harmless code that part of a reverted commit (r80859). I'll investigate the lifetime snafu (with ASTUnit) separately.
- Traverse category methods, add a "class ref" and make the little test harness a bit more flexible. llvm-svn: 80921
Diffstat (limited to 'clang/tools/c-index-test')
-rw-r--r--clang/tools/c-index-test/c-index-test.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 2d2be158d06..dbf31bea5a9 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -2,26 +2,32 @@
#include "clang-c/Index.h"
#include <stdio.h>
+#include <string.h>
+
+static void PrintCursor(CXCursor Cursor) {
+ printf("%s => %s\n", clang_getCursorKindSpelling(Cursor.kind),
+ clang_getCursorSpelling(Cursor));
+}
static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
{
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
- printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
- clang_getCursorSpelling(Cursor));
- printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
- clang_getCursorLine(Cursor),
- clang_getCursorColumn(Cursor));
+ PrintCursor(Cursor);
+ printf(" Context: %s\n", clang_getDeclSpelling(Dcl));
+ printf(" Source: %s (%d:%d)\n", clang_getCursorSource(Cursor),
+ clang_getCursorLine(Cursor),
+ clang_getCursorColumn(Cursor));
}
}
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
CXClientData Filter)
{
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
- printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
- clang_getCursorSpelling(Cursor));
- printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
- clang_getCursorLine(Cursor),
- clang_getCursorColumn(Cursor));
+ PrintCursor(Cursor);
+ printf(" Context: %s\n", clang_getTranslationUnitSpelling(Unit));
+ printf(" Source: %s (%d:%d)\n", clang_getCursorSource(Cursor),
+ clang_getCursorLine(Cursor),
+ clang_getCursorColumn(Cursor));
clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
}
@@ -34,6 +40,18 @@ int main(int argc, char **argv) {
CXIndex Idx = clang_createIndex();
CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
- clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
+ if (argc == 2)
+ clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
+ else if (argc == 3) {
+ enum CXCursorKind K = CXCursor_Invalid;
+
+ if (!strcmp(argv[2], "category")) K = CXCursor_ObjCCategoryDecl;
+ else if (!strcmp(argv[2], "interface")) K = CXCursor_ObjCInterfaceDecl;
+ else if (!strcmp(argv[2], "protocol")) K = CXCursor_ObjCProtocolDecl;
+ else if (!strcmp(argv[2], "function")) K = CXCursor_FunctionDecl;
+ else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
+
+ clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
+ }
return 1;
}
OpenPOWER on IntegriCloud