aboutsummaryrefslogtreecommitdiff
path: root/tools/c-index-test/c-index-test.c
blob: 20511ec80158dcd64cb3313151e1c2c28ab140e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* c-index-test.c */

#include "clang-c/Index.h"
#include <stdio.h>

static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
                       clang_getCursorSpelling(Cursor));
    printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
                            clang_getCursorLine(Cursor),
                            clang_getCursorColumn(Cursor));
  }
}
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
                                   CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
                       clang_getCursorSpelling(Cursor));
    printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
                            clang_getCursorLine(Cursor),
                            clang_getCursorColumn(Cursor));

    enum CXCursorKind filterData = CXCursor_FieldDecl;
    clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
  }
}

/*
 * First sign of life:-)
 */
int main(int argc, char **argv) {
  CXIndex Idx = clang_createIndex();
  CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
  
  enum CXCursorKind filterData = CXCursor_StructDecl;
  clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
  return 1;
}