From: Anders Carlsson Date: Sat, 8 Aug 2009 17:45:02 +0000 (+0000) Subject: Factor some code to get the "function level" DeclContext out into a separate function. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8517d9b731f065cdfc55ec0f3ddf5d564d988648;p=clang 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 --- 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(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(DC)) - DC = DC->getParent(); + DeclContext *DC = getFunctionLevelDeclContext(); return dyn_cast(DC); } ObjCMethodDecl *Sema::getCurMethodDecl() { - DeclContext *DC = CurContext; - while (isa(DC)) - DC = DC->getParent(); + DeclContext *DC = getFunctionLevelDeclContext(); return dyn_cast(DC); } NamedDecl *Sema::getCurFunctionOrMethodDecl() { - DeclContext *DC = CurContext; - while (isa(DC)) - DC = DC->getParent(); + DeclContext *DC = getFunctionLevelDeclContext(); if (isa(DC) || isa(DC)) return cast(DC); return 0; diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 4ad7e704ab..4f7ae7ec0d 100644 --- a/lib/Sema/Sema.h +++ b/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