aboutsummaryrefslogtreecommitdiff
path: root/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/c-index-test/c-index-test.c')
-rw-r--r--tools/c-index-test/c-index-test.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 30700d8ae3..d96468f8c4 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -3,16 +3,28 @@
#include "clang-c/Index.h"
#include <stdio.h>
-static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor,
- CXClientData Filter) {
- if (clang_isDeclaration(Cursor.kind)) {
- if (Cursor.kind == *(enum CXCursorKind *)Filter) {
- printf("%s => %s", clang_getKindSpelling(Cursor.kind),
- clang_getDeclSpelling(Cursor.decl));
- printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
- clang_getCursorLine(Cursor),
- clang_getCursorColumn(Cursor));
- }
+static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
+{
+ if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
+ printf("%s => %s", clang_getKindSpelling(Cursor.kind),
+ clang_getDeclSpelling(Cursor.decl));
+ printf(" (%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_getKindSpelling(Cursor.kind),
+ clang_getDeclSpelling(Cursor.decl));
+ printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
+ clang_getCursorLine(Cursor),
+ clang_getCursorColumn(Cursor));
+
+ enum CXCursorKind filterData = CXCursor_FieldDecl;
+ clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
}
}
@@ -23,8 +35,7 @@ int main(int argc, char **argv) {
CXIndex Idx = clang_createIndex();
CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
- /* Use client data to only print ObjC interfaces */
- enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl;
- clang_loadTranslationUnit(TU, PrintDecls, &filterData);
+ enum CXCursorKind filterData = CXCursor_StructDecl;
+ clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
return 1;
}