================
@@ -2175,19 +2175,41 @@ class DeclContext {
}
}
+ /// Returns true if this DeclContext is a function, Objective-C method,
+ /// or block, or a DeclContext that can only occur in or is conceptually
+ /// treated like a function.
bool isFunctionOrMethod() const {
switch (getDeclKind()) {
case Decl::Block:
case Decl::Captured:
case Decl::ObjCMethod:
case Decl::TopLevelStmt:
+ case Decl::CXXExpansionStmt:
return true;
default:
return getDeclKind() >= Decl::firstFunction &&
getDeclKind() <= Decl::lastFunction;
}
}
+ /// Cast this to a FunctionDecl if it is one, ignoring any intervening
+ /// expansion statements. Returns nullptr if this is not a function.
+ FunctionDecl *getAsFunctionDecl() {
+ return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+ }
+
+ const FunctionDecl *getAsFunctionDecl() const {
+ return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+ }
+
+ FunctionDecl *castAsFunctionDecl() {
+ return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+ }
+
+ const FunctionDecl *castAsFunctionDecl() const {
+ return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+ }
+
----------------
ojhunt wrote:
(not specific to this PR) Is there a way we can make it more clear that many
places want a functiondecl that is likely the correct approach vs dyn_cast etc?
There are similar problems with things like getAsCXXRecord() etc where it's
more a matter that people know it exists.
https://github.com/llvm/llvm-project/pull/217110
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits