]> granicus.if.org Git - clang/commitdiff
Introduce a utility routine for checking whether a block's captures
authorJohn McCall <rjmccall@apple.com>
Wed, 15 Jun 2011 22:51:16 +0000 (22:51 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 15 Jun 2011 22:51:16 +0000 (22:51 +0000)
include a specific variable.

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

include/clang/AST/Decl.h
lib/AST/Decl.cpp

index d993d345ef967d3ae2029b232f2fbc2661c6b3b2..d3fe6b8c4802f84a71eab3e33be9b55345eddd68 100644 (file)
@@ -2956,6 +2956,8 @@ public:
 
   bool capturesCXXThis() const { return CapturesCXXThis; }
 
+  bool capturesVariable(const VarDecl *var) const;
+
   void setCaptures(ASTContext &Context,
                    const Capture *begin,
                    const Capture *end,
index 12357c07a7948d79677bd4689b5bc6348af4ad61..8661e7405fb359c95b95b6b79c47a7d449484c91 100644 (file)
@@ -2376,6 +2376,16 @@ void BlockDecl::setCaptures(ASTContext &Context,
   Captures = static_cast<Capture*>(buffer);
 }
 
+bool BlockDecl::capturesVariable(const VarDecl *variable) const {
+  for (capture_const_iterator
+         i = capture_begin(), e = capture_end(); i != e; ++i)
+    // Only auto vars can be captured, so no redeclaration worries.
+    if (i->getVariable() == variable)
+      return true;
+
+  return false;
+}
+
 SourceRange BlockDecl::getSourceRange() const {
   return SourceRange(getLocation(), Body? Body->getLocEnd() : getLocation());
 }