blob: 2d2be158d0686c1c5ae69178cc3a7a2a87d9e818 [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 Naroffc857ea42009-09-02 13:28:54 +00006static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
7{
Daniel Dunbarbce6f622009-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 Naroffc857ea42009-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 Dunbarbce6f622009-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 Naroffc857ea42009-09-02 13:28:54 +000025
Steve Naroffc857ea42009-09-02 13:28:54 +000026 clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
Steve Naroff2d4d6292009-08-31 14:26:51 +000027 }
Steve Naroff89922f82009-08-31 00:59:03 +000028}
Steve Naroff50398192009-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 Naroff2b8ee6c2009-09-01 15:55:40 +000036
Steve Naroffc857ea42009-09-02 13:28:54 +000037 clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
Steve Naroff50398192009-08-28 15:28:48 +000038 return 1;
39}