From: Chris Lattner Date: Fri, 27 Mar 2009 19:19:59 +0000 (+0000) Subject: reduce # const_casts, no functionality change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cf2b1990c82121d03a004dafe498ba43bf4b42a;p=clang reduce # const_casts, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67861 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 002bab79df..982da7493e 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -177,15 +177,15 @@ public: Kind getKind() const { return DeclKind; } const char *getDeclKindName() const; - const DeclContext *getDeclContext() const { - return const_cast(this)->getDeclContext(); - } DeclContext *getDeclContext() { if (isInSemaDC()) return getSemanticDC(); return getMultipleDC()->SemanticDC; } - + const DeclContext *getDeclContext() const { + return const_cast(this)->getDeclContext(); + } + void setAccess(AccessSpecifier AS) { Access = AS; CheckAccessDeclContext(); @@ -433,14 +433,13 @@ public: const char *getDeclKindName() const; /// getParent - Returns the containing DeclContext. - const DeclContext *getParent() const { + DeclContext *getParent() { return cast(this)->getDeclContext(); } - DeclContext *getParent() { - return const_cast( - const_cast(this)->getParent()); + const DeclContext *getParent() const { + return const_cast(this)->getParent(); } - + /// getLexicalParent - Returns the containing lexical DeclContext. May be /// different from getParent, e.g.: /// @@ -450,24 +449,20 @@ public: /// struct A::S {}; // getParent() == namespace 'A' /// // getLexicalParent() == translation unit /// - const DeclContext *getLexicalParent() const { - return cast(this)->getLexicalDeclContext(); - } DeclContext *getLexicalParent() { - return const_cast( - const_cast(this)->getLexicalParent()); + return cast(this)->getLexicalDeclContext(); } - + const DeclContext *getLexicalParent() const { + return const_cast(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 @@ public: /// 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( - const_cast(this)->getLookupContext()); + DeclContext *getLookupContext(); + const DeclContext *getLookupContext() const { + return const_cast(this)->getLookupContext(); } - const DeclContext *getLookupContext() const; - + /// \brief Retrieve the nearest enclosing namespace context. DeclContext *getEnclosingNamespaceContext(); const DeclContext *getEnclosingNamespaceContext() const { diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 47059d952c..ef9dc7622f 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -580,8 +580,8 @@ DeclContext::lookup(DeclarationName Name) const { return const_cast(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();