================
@@ -2188,6 +2188,30 @@ class DeclContext {
     }
   }
 
+  /// Test whether we're directly inside a function or method, but ignoring
+  /// any intervening expansion statements.
+  bool isInsideFunctionOrMethod() const {
+    return getEnclosingNonExpansionStatementContext()->isFunctionOrMethod();
+  }
+
+  /// 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());
+  }
----------------
TPPPP72 wrote:

Oh, these functions are helpful

https://github.com/llvm/llvm-project/pull/217110
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to