зеркало из https://github.com/microsoft/clang.git
Add explicit "blind" client data to callback function (since we aren't using blocks).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80673 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
c4c65f2b69
Коммит
2b8ee6c299
|
@ -104,8 +104,11 @@ CXTranslationUnit clang_createTranslationUnit(
|
|||
clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
|
||||
}
|
||||
*/
|
||||
typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor);
|
||||
void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator);
|
||||
typedef void *CXClientData;
|
||||
typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
|
||||
CXClientData);
|
||||
void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator,
|
||||
CXClientData);
|
||||
|
||||
/*
|
||||
Usage: clang_loadDeclaration(). Will load the declaration, issuing a
|
||||
|
|
|
@ -28,9 +28,16 @@ namespace {
|
|||
class TUVisitor : public DeclVisitor<TUVisitor> {
|
||||
CXTranslationUnit TUnit;
|
||||
CXTranslationUnitIterator Callback;
|
||||
CXClientData CData;
|
||||
|
||||
void Call(enum CXCursorKind CK, NamedDecl *ND) {
|
||||
CXCursor C = { CK, ND };
|
||||
Callback(TUnit, C, CData);
|
||||
}
|
||||
public:
|
||||
TUVisitor(CXTranslationUnit CTU, CXTranslationUnitIterator cback) :
|
||||
TUnit(CTU), Callback(cback) {}
|
||||
TUVisitor(CXTranslationUnit CTU,
|
||||
CXTranslationUnitIterator cback, CXClientData D) :
|
||||
TUnit(CTU), Callback(cback), CData(D) {}
|
||||
|
||||
void VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
||||
VisitDeclContext(dyn_cast<DeclContext>(D));
|
||||
|
@ -40,29 +47,23 @@ public:
|
|||
I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I)
|
||||
Visit(*I);
|
||||
}
|
||||
void VisitTypedefDecl(TypedefDecl *ND) {
|
||||
CXCursor C = { CXCursor_TypedefDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
void VisitTypedefDecl(TypedefDecl *ND) {
|
||||
Call(CXCursor_TypedefDecl, ND);
|
||||
}
|
||||
void VisitTagDecl(TagDecl *ND) {
|
||||
CXCursor C = { ND->isEnum() ? CXCursor_EnumDecl : CXCursor_RecordDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
Call(ND->isEnum() ? CXCursor_EnumDecl : CXCursor_RecordDecl, ND);
|
||||
}
|
||||
void VisitFunctionDecl(FunctionDecl *ND) {
|
||||
CXCursor C = { CXCursor_FunctionDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
Call(CXCursor_FunctionDecl, ND);
|
||||
}
|
||||
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND) {
|
||||
CXCursor C = { CXCursor_ObjCInterfaceDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
Call(CXCursor_ObjCInterfaceDecl, ND);
|
||||
}
|
||||
void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
|
||||
CXCursor C = { CXCursor_ObjCCategoryDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
Call(CXCursor_ObjCCategoryDecl, ND);
|
||||
}
|
||||
void VisitObjCProtocolDecl(ObjCProtocolDecl *ND) {
|
||||
CXCursor C = { CXCursor_ObjCProtocolDecl, ND };
|
||||
Callback(TUnit, C);
|
||||
Call(CXCursor_ObjCProtocolDecl, ND);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -105,13 +106,14 @@ CXTranslationUnit clang_createTranslationUnit(
|
|||
|
||||
|
||||
void clang_loadTranslationUnit(
|
||||
CXTranslationUnit CTUnit, CXTranslationUnitIterator callback)
|
||||
CXTranslationUnit CTUnit, CXTranslationUnitIterator callback,
|
||||
CXClientData CData)
|
||||
{
|
||||
assert(CTUnit && "Passed null CXTranslationUnit");
|
||||
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
||||
ASTContext &Ctx = CXXUnit->getASTContext();
|
||||
|
||||
TUVisitor DVisit(CTUnit, callback);
|
||||
TUVisitor DVisit(CTUnit, callback, CData);
|
||||
DVisit.Visit(Ctx.getTranslationUnitDecl());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
/* c-index-test.c */
|
||||
|
||||
#include "clang-c/Index.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor) {
|
||||
static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor,
|
||||
CXClientData Filter) {
|
||||
if (clang_isDeclaration(Cursor.kind)) {
|
||||
printf("%s => %s", clang_getKindSpelling(Cursor.kind),
|
||||
clang_getDeclSpelling(Cursor.decl));
|
||||
printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
|
||||
clang_getCursorLine(Cursor),
|
||||
clang_getCursorColumn(Cursor));
|
||||
if (Cursor.kind == *(enum CXCursorKind *)Filter) {
|
||||
printf("%s => %s", clang_getKindSpelling(Cursor.kind),
|
||||
clang_getDeclSpelling(Cursor.decl));
|
||||
printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
|
||||
clang_getCursorLine(Cursor),
|
||||
clang_getCursorColumn(Cursor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +22,9 @@ static void PrintDecls(CXTranslationUnit Unit, CXCursor Cursor) {
|
|||
int main(int argc, char **argv) {
|
||||
CXIndex Idx = clang_createIndex();
|
||||
CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
|
||||
clang_loadTranslationUnit(TU, PrintDecls);
|
||||
|
||||
/* Use client data to only print ObjC interfaces */
|
||||
enum CXCursorKind filterData = CXCursor_ObjCInterfaceDecl;
|
||||
clang_loadTranslationUnit(TU, PrintDecls, &filterData);
|
||||
return 1;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче