c-index-test.c revision 2b8ee6c2994f738e5162ff46b638974870f51662
12b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff/* c-index-test.c */ 250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff 350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff#include "clang-c/Index.h" 489922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff#include <stdio.h> 589922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff 62b8ee6c2994f738e5162ff46b638974870f51662Steve Naroffstatic void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor, 72b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff CXClientData Filter) { 82d4d629d8a0de5112c7ae9d05c03ddbf6dcd956aSteve Naroff if (clang_isDeclaration(Cursor.kind)) { 92b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff if (Cursor.kind == *(enum CXCursorKind *)Filter) { 102b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff printf("%s => %s", clang_getKindSpelling(Cursor.kind), 112b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff clang_getDeclSpelling(Cursor.decl)); 122b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor), 132b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff clang_getCursorLine(Cursor), 142b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff clang_getCursorColumn(Cursor)); 152b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff } 162d4d629d8a0de5112c7ae9d05c03ddbf6dcd956aSteve Naroff } 1789922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff} 1850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff 1950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/* 2050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * First sign of life:-) 2150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */ 2250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroffint main(int argc, char **argv) { 2350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff CXIndex Idx = clang_createIndex(); 2450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); 252b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff 262b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff /* Use client data to only print ObjC interfaces */ 272b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl; 282b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff clang_loadTranslationUnit(TU, PrintDecls, &filterData); 2950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff return 1; 3050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff} 31