[cfe-commits] r78478 - in /cfe/trunk/lib/Sema: Sema.cpp Sema.h

Anders Carlsson andersca at mac.com
Sat Aug 8 10:45:02 PDT 2009


Author: andersca
Date: Sat Aug  8 12:45:02 2009
New Revision: 78478

URL: http://llvm.org/viewvc/llvm-project?rev=78478&view=rev
Log:
Factor some code to get the "function level" DeclContext out into a separate function.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/Sema.h

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=78478&r1=78477&r2=78478&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Aug  8 12:45:02 2009
@@ -309,27 +309,29 @@
 // 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;

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=78478&r1=78477&r2=78478&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Aug  8 12:45:02 2009
@@ -633,6 +633,7 @@
   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





More information about the cfe-commits mailing list