summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-08-08 17:45:02 +0000
committerAnders Carlsson <andersca@mac.com>2009-08-08 17:45:02 +0000
commitb26ab816a2ae0bef9dfedc44ed40f37ce7dab9e6 (patch)
treefe242152d311a2e6f7a9aca68971913b0eb33dac /clang/lib/Sema
parent3b5008e23abb2f6fbe85e32670a5437dc3b05a93 (diff)
downloadbcm5719-llvm-b26ab816a2ae0bef9dfedc44ed40f37ce7dab9e6.tar.gz
bcm5719-llvm-b26ab816a2ae0bef9dfedc44ed40f37ce7dab9e6.zip
Factor some code to get the "function level" DeclContext out into a separate function.
llvm-svn: 78478
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.cpp20
-rw-r--r--clang/lib/Sema/Sema.h1
2 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 84d72115554..0259a3d18d5 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -309,27 +309,29 @@ void Sema::ActOnEndOfTranslationUnit() {
// Helper functions.
//===----------------------------------------------------------------------===//
+DeclContext *Sema::getFunctionLevelDeclContext() {
+ DeclContext *DC = CurContext;
+ while (isa<BlockDecl>(DC))
+ DC = DC->getParent();
+
+ return DC;
+}
+
/// 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();
+ DeclContext *DC = getFunctionLevelDeclContext();
return dyn_cast<FunctionDecl>(DC);
}
ObjCMethodDecl *Sema::getCurMethodDecl() {
- DeclContext *DC = CurContext;
- while (isa<BlockDecl>(DC))
- DC = DC->getParent();
+ DeclContext *DC = getFunctionLevelDeclContext();
return dyn_cast<ObjCMethodDecl>(DC);
}
NamedDecl *Sema::getCurFunctionOrMethodDecl() {
- DeclContext *DC = CurContext;
- while (isa<BlockDecl>(DC))
- DC = DC->getParent();
+ DeclContext *DC = getFunctionLevelDeclContext();
if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
return cast<NamedDecl>(DC);
return 0;
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 4ad7e704ab5..4f7ae7ec0d1 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -633,6 +633,7 @@ public:
void EnterDeclaratorContext(Scope *S, DeclContext *DC);
void ExitDeclaratorContext(Scope *S);
+ DeclContext *getFunctionLevelDeclContext();
/// getCurFunctionDecl - If inside of a function body, this returns a pointer
/// to the function decl for the function being parsed. If we're currently
OpenPOWER on IntegriCloud