[cfe-commits] r80673 - in /cfe/trunk: include/clang-c/Index.h tools/CIndex/CIndex.cpp tools/c-index-test/c-index-test.c
Steve Naroff
snaroff at apple.com
Tue Sep 1 08:55:40 PDT 2009
Author: snaroff
Date: Tue Sep 1 10:55:40 2009
New Revision: 80673
URL: http://llvm.org/viewvc/llvm-project?rev=80673&view=rev
Log:
Add explicit "blind" client data to callback function (since we aren't using blocks).
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=80673&r1=80672&r2=80673&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Sep 1 10:55:40 2009
@@ -104,8 +104,11 @@
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
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=80673&r1=80672&r2=80673&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Tue Sep 1 10:55:40 2009
@@ -28,9 +28,16 @@
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 @@
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 @@
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());
}
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=80673&r1=80672&r2=80673&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Sep 1 10:55:40 2009
@@ -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 @@
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;
}
More information about the cfe-commits
mailing list