aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-04 23:50:19 +0000
committerChris Lattner <sabre@nondot.org>2008-12-04 23:50:19 +0000
commit371f258e61e1365b951b17931a3c5ac1530fd1a0 (patch)
tree41095e9a128c4e4f966f33753e4317749853ef74 /lib/Sema/Sema.cpp
parentae0ee03fd9d36446ee70e502fdaf5ed5acec269f (diff)
change getCurFunctionDecl to skip through Block contexts to find
the containing block. Introduce a new getCurFunctionOrMethodDecl method to check to see if we're in a function or objc method. Minor cleanups to other related places. This fixes rdar://6405429. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60564 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r--lib/Sema/Sema.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 1a9e5fb30e..13226c0b0e 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -201,9 +201,29 @@ const LangOptions &Sema::getLangOptions() const {
return PP.getLangOptions();
}
+/// getCurFunctionDecl - If inside of a function body, this returns a pointer
+/// to the function decl for the function being parsed. If we're currently
+/// in a 'block', this returns the containing context.
+FunctionDecl *Sema::getCurFunctionDecl() {
+ DeclContext *DC = CurContext;
+ while (isa<BlockDecl>(DC))
+ DC = DC->getParent();
+ return dyn_cast<FunctionDecl>(DC);
+}
+
ObjCMethodDecl *Sema::getCurMethodDecl() {
DeclContext *DC = CurContext;
while (isa<BlockDecl>(DC))
DC = DC->getParent();
return dyn_cast<ObjCMethodDecl>(DC);
}
+
+NamedDecl *Sema::getCurFunctionOrMethodDecl() {
+ DeclContext *DC = CurContext;
+ while (isa<BlockDecl>(DC))
+ DC = DC->getParent();
+ if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
+ return cast<NamedDecl>(DC);
+ return 0;
+}
+