diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-08 17:45:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-08 17:45:02 +0000 |
commit | 8517d9b731f065cdfc55ec0f3ddf5d564d988648 (patch) | |
tree | bde0070ac099e65a0c761de690bfd92cf797c1c4 /lib/Sema/Sema.cpp | |
parent | 0f44b5a85e612e1644d688be93151b22f08604a7 (diff) |
Factor some code to get the "function level" DeclContext out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78478 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 84d7211555..0259a3d18d 100644 --- a/lib/Sema/Sema.cpp +++ b/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; |