Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 1 | /* c-index-test.c */ |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 2 | |
| 3 | #include "clang-c/Index.h" |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame^] | 6 | static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) |
| 7 | { |
| 8 | if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { |
| 9 | printf("%s => %s", clang_getKindSpelling(Cursor.kind), |
| 10 | clang_getDeclSpelling(Cursor.decl)); |
| 11 | printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), |
| 12 | clang_getCursorLine(Cursor), |
| 13 | clang_getCursorColumn(Cursor)); |
| 14 | } |
| 15 | } |
| 16 | static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, |
| 17 | CXClientData Filter) |
| 18 | { |
| 19 | if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { |
| 20 | printf("%s => %s", clang_getKindSpelling(Cursor.kind), |
| 21 | clang_getDeclSpelling(Cursor.decl)); |
| 22 | printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), |
| 23 | clang_getCursorLine(Cursor), |
| 24 | clang_getCursorColumn(Cursor)); |
| 25 | |
| 26 | enum CXCursorKind filterData = CXCursor_FieldDecl; |
| 27 | clang_loadDeclaration(Cursor.decl, DeclVisitor, 0); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 28 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 29 | } |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * First sign of life:-) |
| 33 | */ |
| 34 | int main(int argc, char **argv) { |
| 35 | CXIndex Idx = clang_createIndex(); |
| 36 | CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 37 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame^] | 38 | enum CXCursorKind filterData = CXCursor_StructDecl; |
| 39 | clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0); |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 40 | return 1; |
| 41 | } |