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 | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame^] | 6 | static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor, |
| 7 | CXClientData Filter) { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 8 | if (clang_isDeclaration(Cursor.kind)) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame^] | 9 | if (Cursor.kind == *(enum CXCursorKind *)Filter) { |
| 10 | printf("%s => %s", clang_getKindSpelling(Cursor.kind), |
| 11 | clang_getDeclSpelling(Cursor.decl)); |
| 12 | printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), |
| 13 | clang_getCursorLine(Cursor), |
| 14 | clang_getCursorColumn(Cursor)); |
| 15 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 16 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 17 | } |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * First sign of life:-) |
| 21 | */ |
| 22 | int main(int argc, char **argv) { |
| 23 | CXIndex Idx = clang_createIndex(); |
| 24 | CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame^] | 25 | |
| 26 | /* Use client data to only print ObjC interfaces */ |
| 27 | enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl; |
| 28 | clang_loadTranslationUnit(TU, PrintDecls, &filterData); |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 29 | return 1; |
| 30 | } |