blob: 2d2be158d0686c1c5ae69178cc3a7a2a87d9e818 [file] [log] [blame]
Steve Naroffb836cb72009-09-01 15:55:40 +00001/* c-index-test.c */
Steve Naroff3ba83e92009-08-28 15:28:48 +00002
3#include "clang-c/Index.h"
Steve Naroffc674c2d2009-08-31 00:59:03 +00004#include <stdio.h>
5
Steve Naroff51366e92009-09-02 13:28:54 +00006static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
7{
Daniel Dunbar172cb432009-09-03 05:59:50 +00008 if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
9 printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
10 clang_getCursorSpelling(Cursor));
11 printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
12 clang_getCursorLine(Cursor),
13 clang_getCursorColumn(Cursor));
14 }
Steve Naroff51366e92009-09-02 13:28:54 +000015}
16static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
17 CXClientData Filter)
18{
19 if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
Daniel Dunbar172cb432009-09-03 05:59:50 +000020 printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
21 clang_getCursorSpelling(Cursor));
22 printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
23 clang_getCursorLine(Cursor),
24 clang_getCursorColumn(Cursor));
Steve Naroff51366e92009-09-02 13:28:54 +000025
Steve Naroff51366e92009-09-02 13:28:54 +000026 clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
Steve Naroff52833ba2009-08-31 14:26:51 +000027 }
Steve Naroffc674c2d2009-08-31 00:59:03 +000028}
Steve Naroff3ba83e92009-08-28 15:28:48 +000029
30/*
31 * First sign of life:-)
32 */
33int main(int argc, char **argv) {
34 CXIndex Idx = clang_createIndex();
35 CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
Steve Naroffb836cb72009-09-01 15:55:40 +000036
Steve Naroff51366e92009-09-02 13:28:54 +000037 clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
Steve Naroff3ba83e92009-08-28 15:28:48 +000038 return 1;
39}