2009-09-01 23:55:40 +08:00
|
|
|
/* c-index-test.c */
|
2009-08-28 23:28:48 +08:00
|
|
|
|
|
|
|
#include "clang-c/Index.h"
|
2009-08-31 08:59:03 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-09-03 08:32:06 +08:00
|
|
|
static void PrintCursor(CXCursor Cursor) {
|
|
|
|
printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
|
|
|
|
clang_getCursorSpelling(Cursor));
|
|
|
|
printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
|
|
|
|
clang_getCursorLine(Cursor),
|
|
|
|
clang_getCursorColumn(Cursor));
|
|
|
|
}
|
|
|
|
|
2009-09-02 21:28:54 +08:00
|
|
|
static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
|
|
|
|
{
|
2009-09-03 08:32:06 +08:00
|
|
|
printf("%s: ", clang_getDeclSpelling(Dcl));
|
|
|
|
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter))
|
|
|
|
PrintCursor(Cursor);
|
2009-09-02 21:28:54 +08:00
|
|
|
}
|
2009-09-03 08:32:06 +08:00
|
|
|
|
2009-09-02 21:28:54 +08:00
|
|
|
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
|
|
|
|
CXClientData Filter)
|
|
|
|
{
|
2009-09-03 08:32:06 +08:00
|
|
|
printf("%s: ", clang_getTranslationUnitSpelling(Unit));
|
2009-09-02 21:28:54 +08:00
|
|
|
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
|
2009-09-03 08:32:06 +08:00
|
|
|
PrintCursor(Cursor);
|
2009-09-02 21:28:54 +08:00
|
|
|
|
|
|
|
clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
|
2009-08-31 22:26:51 +08:00
|
|
|
}
|
2009-08-31 08:59:03 +08:00
|
|
|
}
|
2009-08-28 23:28:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First sign of life:-)
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
CXIndex Idx = clang_createIndex();
|
|
|
|
CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
|
2009-09-01 23:55:40 +08:00
|
|
|
|
2009-09-02 21:28:54 +08:00
|
|
|
clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
|
2009-08-28 23:28:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|