diff options
-rw-r--r-- | include/clang/AST/DeclBase.h | 50 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 4 |
2 files changed, 24 insertions, 30 deletions
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<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 @@ public: 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 @@ public: /// 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 @@ 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<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 { 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<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(); |