]> granicus.if.org Git - clang/commitdiff
Factor some code to get the "function level" DeclContext out into a separate function.
authorAnders Carlsson <andersca@mac.com>
Sat, 8 Aug 2009 17:45:02 +0000 (17:45 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 8 Aug 2009 17:45:02 +0000 (17:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78478 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
lib/Sema/Sema.h

index 84d7211555485c3dde2f95598dc2b6f4d99ef6f9..0259a3d18d503de1056a91f227b537593b81b1ed 100644 (file)
@@ -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;
index 4ad7e704ab589e22a2cee98d3ed4ed2fb21d9cc2..4f7ae7ec0d1e427e0d27b7c38f23b6bb6aab7c90 100644 (file)
@@ -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