c-index-test.c revision 2b8ee6c2994f738e5162ff46b638974870f51662
1/* c-index-test.c */ 2 3#include "clang-c/Index.h" 4#include <stdio.h> 5 6static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor, 7 CXClientData Filter) { 8 if (clang_isDeclaration(Cursor.kind)) { 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 } 16 } 17} 18 19/* 20 * First sign of life:-) 21 */ 22int main(int argc, char **argv) { 23 CXIndex Idx = clang_createIndex(); 24 CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); 25 26 /* Use client data to only print ObjC interfaces */ 27 enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl; 28 clang_loadTranslationUnit(TU, PrintDecls, &filterData); 29 return 1; 30} 31