[cfe-commits] r67861 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp

Chris Lattner sabre at nondot.org
Fri Mar 27 12:20:00 PDT 2009


Author: lattner
Date: Fri Mar 27 14:19:59 2009
New Revision: 67861

URL: http://llvm.org/viewvc/llvm-project?rev=67861&view=rev
Log:
reduce # const_casts, no functionality change.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=67861&r1=67860&r2=67861&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Fri Mar 27 14:19:59 2009
@@ -177,15 +177,15 @@
   Kind getKind() const { return DeclKind; }
   const char *getDeclKindName() const;
   
-  const DeclContext *getDeclContext() const {
-    return const_cast<Decl*>(this)->getDeclContext();
-  }
   DeclContext *getDeclContext() {
     if (isInSemaDC())
       return getSemanticDC();
     return getMultipleDC()->SemanticDC;
   }
-
+  const DeclContext *getDeclContext() const {
+    return const_cast<Decl*>(this)->getDeclContext();
+  }
+  
   void setAccess(AccessSpecifier AS) {
     Access = AS; 
     CheckAccessDeclContext();
@@ -433,14 +433,13 @@
   const char *getDeclKindName() const;
 
   /// getParent - Returns the containing DeclContext.
-  const DeclContext *getParent() const {
+  DeclContext *getParent() {
     return cast<Decl>(this)->getDeclContext();
   }
-  DeclContext *getParent() {
-    return const_cast<DeclContext*>(
-                             const_cast<const DeclContext*>(this)->getParent());
+  const DeclContext *getParent() const {
+    return const_cast<DeclContext*>(this)->getParent();
   }
-
+  
   /// getLexicalParent - Returns the containing lexical DeclContext. May be
   /// different from getParent, e.g.:
   ///
@@ -450,24 +449,20 @@
   ///   struct A::S {}; // getParent() == namespace 'A'
   ///                   // getLexicalParent() == translation unit
   ///
-  const DeclContext *getLexicalParent() const {
-    return cast<Decl>(this)->getLexicalDeclContext();
-  }    
   DeclContext *getLexicalParent() {
-    return const_cast<DeclContext*>(
-                      const_cast<const DeclContext*>(this)->getLexicalParent());
+    return cast<Decl>(this)->getLexicalDeclContext();
   }
-
+  const DeclContext *getLexicalParent() const {
+    return const_cast<DeclContext*>(this)->getLexicalParent();
+  }    
+  
   bool isFunctionOrMethod() const {
     switch (DeclKind) {
-      case Decl::Block:
-      case Decl::ObjCMethod:
-        return true;
-
-      default:
-       if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast)
-         return true;
-        return false;
+    case Decl::Block:
+    case Decl::ObjCMethod:
+      return true;
+    default:
+      return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast;
     }
   }
 
@@ -524,12 +519,11 @@
   /// context of this context, which corresponds to the innermost
   /// location from which name lookup can find the entities in this
   /// context.
-  DeclContext *getLookupContext() {
-    return const_cast<DeclContext *>(
-             const_cast<const DeclContext *>(this)->getLookupContext());
+  DeclContext *getLookupContext();
+  const DeclContext *getLookupContext() const {
+    return const_cast<DeclContext *>(this)->getLookupContext();
   }
-  const DeclContext *getLookupContext() const;
-
+  
   /// \brief Retrieve the nearest enclosing namespace context.
   DeclContext *getEnclosingNamespaceContext();
   const DeclContext *getEnclosingNamespaceContext() const {

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=67861&r1=67860&r2=67861&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Fri Mar 27 14:19:59 2009
@@ -580,8 +580,8 @@
   return const_cast<DeclContext*>(this)->lookup(Name);
 }
 
-const DeclContext *DeclContext::getLookupContext() const {
-  const DeclContext *Ctx = this;
+DeclContext *DeclContext::getLookupContext() {
+  DeclContext *Ctx = this;
   // Skip through transparent contexts.
   while (Ctx->isTransparentContext())
     Ctx = Ctx->getParent();





More information about the cfe-commits mailing list