blob: d96468f8c4572d56a6ed3af0b702fcc6369013ef [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{
8 if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
9 printf("%s => %s", clang_getKindSpelling(Cursor.kind),
10 clang_getDeclSpelling(Cursor.decl));
11 printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
12 clang_getCursorLine(Cursor),
13 clang_getCursorColumn(Cursor));
14 }
15}
16static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
17 CXClientData Filter)
18{
19 if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
20 printf("%s => %s", clang_getKindSpelling(Cursor.kind),
21 clang_getDeclSpelling(Cursor.decl));
22 printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
23 clang_getCursorLine(Cursor),
24 clang_getCursorColumn(Cursor));
25
26 enum CXCursorKind filterData = CXCursor_FieldDecl;
27 clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
Steve Naroff2d4d6292009-08-31 14:26:51 +000028 }
Steve Naroff89922f82009-08-31 00:59:03 +000029}
Steve Naroff50398192009-08-28 15:28:48 +000030
31/*
32 * First sign of life:-)
33 */
34int main(int argc, char **argv) {
35 CXIndex Idx = clang_createIndex();
36 CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000037
Steve Naroffc857ea42009-09-02 13:28:54 +000038 enum CXCursorKind filterData = CXCursor_StructDecl;
39 clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
Steve Naroff50398192009-08-28 15:28:48 +000040 return 1;
41}