blob: 30700d8ae3f778a6f5639f36d65d092d6ef1bb89 [file] [log] [blame]
Steve Naroff2b8ee6c2009-09-01 15:55:40 +00001/* c-index-test.c */
Steve Naroff50398192009-08-28 15:28:48 +00002
3#include "clang-c/Index.h"
Steve Naroff89922f82009-08-31 00:59:03 +00004#include <stdio.h>
5
Steve Naroff2b8ee6c2009-09-01 15:55:40 +00006static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor,
7 CXClientData Filter) {
Steve Naroff2d4d6292009-08-31 14:26:51 +00008 if (clang_isDeclaration(Cursor.kind)) {
Steve Naroff2b8ee6c2009-09-01 15:55:40 +00009 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 Naroff2d4d6292009-08-31 14:26:51 +000016 }
Steve Naroff89922f82009-08-31 00:59:03 +000017}
Steve Naroff50398192009-08-28 15:28:48 +000018
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]);
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000025
26 /* Use client data to only print ObjC interfaces */
27 enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl;
28 clang_loadTranslationUnit(TU, PrintDecls, &filterData);
Steve Naroff50398192009-08-28 15:28:48 +000029 return 1;
30}