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