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 | { |
Daniel Dunbar | bce6f62 | 2009-09-03 05:59:50 +0000 | [diff] [blame^] | 8 | if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { |
| 9 | printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind), |
| 10 | clang_getCursorSpelling(Cursor)); |
| 11 | printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), |
| 12 | clang_getCursorLine(Cursor), |
| 13 | clang_getCursorColumn(Cursor)); |
| 14 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 15 | } |
| 16 | static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor, |
| 17 | CXClientData Filter) |
| 18 | { |
| 19 | if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) { |
Daniel Dunbar | bce6f62 | 2009-09-03 05:59:50 +0000 | [diff] [blame^] | 20 | printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind), |
| 21 | clang_getCursorSpelling(Cursor)); |
| 22 | printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), |
| 23 | clang_getCursorLine(Cursor), |
| 24 | clang_getCursorColumn(Cursor)); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 25 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 26 | clang_loadDeclaration(Cursor.decl, DeclVisitor, 0); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 27 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 28 | } |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * First sign of life:-) |
| 32 | */ |
| 33 | int main(int argc, char **argv) { |
| 34 | CXIndex Idx = clang_createIndex(); |
| 35 | CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 36 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 37 | clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0); |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 38 | return 1; |
| 39 | } |