summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2010-11-03 14:12:26 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2010-11-03 14:12:26 +0000
commitb2aa0ef310b08b1ea99768d2ee7757bb9c64dc86 (patch)
treea961ebe5b036842d552d6ddfa5fba576f2e800a8 /clang/tools/libclang
parent14627770176bf9a85a672908ba47ca488acc3f05 (diff)
downloadbcm5719-llvm-b2aa0ef310b08b1ea99768d2ee7757bb9c64dc86.tar.gz
bcm5719-llvm-b2aa0ef310b08b1ea99768d2ee7757bb9c64dc86.zip
Added cursor visitor that takes a block as an argument. Tested compiling
libclang with both clang -fblocks and gcc (no blocks support). Only exposed in the header to compilers that do have blocks support. llvm-svn: 118170
Diffstat (limited to 'clang/tools/libclang')
-rw-r--r--clang/tools/libclang/CIndex.cpp35
-rw-r--r--clang/tools/libclang/libclang.exports1
2 files changed, 36 insertions, 0 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index e07c25d77a2..ac57a6941c3 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2467,6 +2467,41 @@ unsigned clang_visitChildren(CXCursor parent,
return CursorVis.VisitChildren(parent);
}
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+#if __has_feature(blocks)
+typedef enum CXChildVisitResult
+ (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
+
+static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
+ CXClientData client_data) {
+ CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
+ return block(cursor, parent);
+}
+#else
+// If we are compiled with a compiler that doesn't have native blocks support,
+// define and call the block manually, so the
+typedef struct _CXChildVisitResult
+{
+ void *isa;
+ int flags;
+ int reserved;
+ enum CXChildVisitResult(*invoke)(struct _CXChildVisitResult*, CXCursor, CXCursor);
+} *CXCursorVisitorBlock;
+
+static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
+ CXClientData client_data) {
+ CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
+ return block->invoke(block, cursor, parent);
+}
+#endif
+
+
+unsigned clang_visitChildrenWithBlock(CXCursor parent, CXCursorVisitorBlock block) {
+ return clang_visitChildren(parent, visitWithBlock, block);
+}
+
static CXString getDeclSpelling(Decl *D) {
NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D);
if (!ND)
diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
index 9935a584b9b..fd96be35b29 100644
--- a/clang/tools/libclang/libclang.exports
+++ b/clang/tools/libclang/libclang.exports
@@ -113,3 +113,4 @@ clang_saveTranslationUnit
clang_sortCodeCompletionResults
clang_tokenize
clang_visitChildren
+clang_visitChildrenWithBlock
OpenPOWER on IntegriCloud