]> granicus.if.org Git - clang/commitdiff
Added cursor visitor that takes a block as an argument. Tested compiling
authorDavid Chisnall <csdavec@swan.ac.uk>
Wed, 3 Nov 2010 14:12:26 +0000 (14:12 +0000)
committerDavid Chisnall <csdavec@swan.ac.uk>
Wed, 3 Nov 2010 14:12:26 +0000 (14:12 +0000)
libclang with both clang -fblocks and gcc (no blocks support).  Only exposed in
the header to compilers that do have blocks support.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118170 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/libclang/CIndex.cpp
tools/libclang/libclang.exports

index bb76c564cc948c79c182833a2b5495fab2c3599d..20c8c1199460cbc59b2488797d6807d6c9b3eeb1 100644 (file)
@@ -1828,6 +1828,29 @@ typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
 CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
                                             CXCursorVisitor visitor,
                                             CXClientData client_data);
+#ifdef __has_feature
+#  if __has_feature(blocks)
+/**
+ * \brief Visitor invoked for each cursor found by a traversal.
+ *
+ * This visitor block will be invoked for each cursor found by
+ * clang_visitChildrenWithBlock(). Its first argument is the cursor being
+ * visited, its second argument is the parent visitor for that cursor.
+ *
+ * The visitor should return one of the \c CXChildVisitResult values
+ * to direct clang_visitChildrenWithBlock().
+ */
+typedef enum CXChildVisitResult 
+     (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
+
+/**
+ * Visits the children of a cursor using the specified block.  Behaves
+ * identically to clang_visitChildren() in all other respects.
+ */
+unsigned clang_visitChildrenWithBlock(CXCursor parent,
+                                      CXCursorVisitorBlock block);
+#  endif
+#endif
 
 /**
  * @}
index e07c25d77a25396879b257b391d2d787ac8a4269..ac57a6941c34a8534a9e6af432a294158d71b0b1 100644 (file)
@@ -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)
index 9935a584b9b6d00870b45bb3c97dfdabf0a0edef..fd96be35b2965d2c26a67153bbd25ac44b5a616a 100644 (file)
@@ -113,3 +113,4 @@ clang_saveTranslationUnit
 clang_sortCodeCompletionResults
 clang_tokenize
 clang_visitChildren
+clang_visitChildrenWithBlock