[clang] 70c62f4 - [NFC] give getParentFunctionOrMethod a 'Lexical' parameter
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 22 12:53:54 PDT 2022
Author: Erich Keane
Date: 2022-07-22T12:52:26-07:00
New Revision: 70c62f4cadbec132c4ab5f939648d10ca6338b15
URL: https://github.com/llvm/llvm-project/commit/70c62f4cadbec132c4ab5f939648d10ca6338b15
DIFF: https://github.com/llvm/llvm-project/commit/70c62f4cadbec132c4ab5f939648d10ca6338b15.diff
LOG: [NFC] give getParentFunctionOrMethod a 'Lexical' parameter
Split up from the deferred concepts implementation, this function is
useful for determining the containing function of a different function.
However, in some cases it is valuable to instead get the lexical parent.
This adds a parameter to the existing function to allow a 'Lexical'
parameter to instead select the lexical parent.
Added:
Modified:
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 52fe8dd6b1e5..d1193161fd75 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -920,10 +920,12 @@ class alignas(8) Decl {
/// If this decl is defined inside a function/method/block it returns
/// the corresponding DeclContext, otherwise it returns null.
- const DeclContext *getParentFunctionOrMethod() const;
- DeclContext *getParentFunctionOrMethod() {
- return const_cast<DeclContext*>(
- const_cast<const Decl*>(this)->getParentFunctionOrMethod());
+ const DeclContext *
+ getParentFunctionOrMethod(bool LexicalParent = false) const;
+ DeclContext *getParentFunctionOrMethod(bool LexicalParent = false) {
+ return const_cast<DeclContext *>(
+ const_cast<const Decl *>(this)->getParentFunctionOrMethod(
+ LexicalParent));
}
/// Retrieves the "canonical" declaration of the given declaration.
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 13dd6da3f24f..d12330de1500 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -283,8 +283,9 @@ unsigned Decl::getTemplateDepth() const {
return cast<Decl>(DC)->getTemplateDepth();
}
-const DeclContext *Decl::getParentFunctionOrMethod() const {
- for (const DeclContext *DC = getDeclContext();
+const DeclContext *Decl::getParentFunctionOrMethod(bool LexicalParent) const {
+ for (const DeclContext *DC = LexicalParent ? getLexicalDeclContext()
+ : getDeclContext();
DC && !DC->isTranslationUnit() && !DC->isNamespace();
DC = DC->getParent())
if (DC->isFunctionOrMethod())
More information about the cfe-commits
mailing list