From 0325fb8576edbf50ad38636869a953e3e455699c Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Sat, 4 May 2013 02:04:27 +0000 Subject: [PATCH] Added a function to check whether a Decl is in the list of Decls for a given DeclContext. This is useful for LLDB's implementation of FindExternalLexicalDecls. llvm-svn: 181093 --- clang/include/clang/AST/DeclBase.h | 3 +++ clang/lib/AST/DeclBase.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 5d5d45267a58..a4a52e2a78df 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -1412,6 +1412,9 @@ public: /// @brief Removes a declaration from this context. void removeDecl(Decl *D); + + /// @brief Checks whether a declaration is in this context. + bool containsDecl(Decl *D) const; /// lookup_iterator - An iterator that provides access to the results /// of looking up a name within this context. diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index c1fbdb996d37..7b7900640b2a 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1064,6 +1064,11 @@ bool DeclContext::decls_empty() const { return !FirstDecl; } +bool DeclContext::containsDecl(Decl *D) const { + return (D->getLexicalDeclContext() == this && + (D->NextInContextAndBits.getPointer() || D == LastDecl)); +} + void DeclContext::removeDecl(Decl *D) { assert(D->getLexicalDeclContext() == this && "decl being removed from non-lexical context");