From: Argyrios Kyrtzidis Date: Sun, 12 Oct 2008 18:40:01 +0000 (+0000) Subject: Improve the const-ness of a few methods. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2595ecce5f8350e485c83bfe767549a522b2802;p=clang Improve the const-ness of a few methods. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index a6593778ab..e18cfc59e3 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -99,7 +99,8 @@ protected: : NamedDecl(DK, L, Id), NextDeclarator(PrevDecl), Next(0), DeclCtx(DC) {} public: - DeclContext *getDeclContext() const { return DeclCtx; } + const DeclContext *getDeclContext() const { return DeclCtx; } + DeclContext *getDeclContext() { return DeclCtx; } ScopedDecl *getNext() const { return Next; } void setNext(ScopedDecl *N) { Next = N; } @@ -311,7 +312,7 @@ public: bool isBlockVarDecl() const { if (getKind() != Decl::Var) return false; - if (DeclContext *DC = getDeclContext()) + if (const DeclContext *DC = getDeclContext()) return DC->isFunctionOrMethod(); return false; } @@ -1036,7 +1037,8 @@ public: Args.clear(); Args.insert(Args.begin(), args, args+numargs); } - DeclContext *getParentContext() const { return ParentContext; } + const DeclContext *getParentContext() const { return ParentContext; } + DeclContext *getParentContext() { return ParentContext; } /// arg_iterator - Iterate over the ParmVarDecl's for this block. typedef llvm::SmallVector::const_iterator param_iterator; diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index d8b5b378f3..ac6e19610b 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -299,7 +299,10 @@ protected: public: /// getParent - Returns the containing DeclContext if this is a ScopedDecl, /// else returns NULL. - DeclContext *getParent() const; + DeclContext *getParent(); + const DeclContext *getParent() const { + return const_cast(this)->getParent(); + } bool isFunctionOrMethod() const { switch (DeclKind) { diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 1ea545ba5d..265913ccc0 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -344,10 +344,10 @@ DeclContext *Decl::castToDeclContext(const Decl *D) { // DeclContext Implementation //===----------------------------------------------------------------------===// -DeclContext *DeclContext::getParent() const { - if (const ScopedDecl *SD = dyn_cast(this)) +DeclContext *DeclContext::getParent() { + if (ScopedDecl *SD = dyn_cast(this)) return SD->getDeclContext(); - else if (const BlockDecl *BD = dyn_cast(this)) + else if (BlockDecl *BD = dyn_cast(this)) return BD->getParentContext(); else return NULL; diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 0a65ab34f0..3f937914ad 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -54,7 +54,8 @@ CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, QualType CXXMethodDecl::getThisType(ASTContext &C) const { assert(isInstance() && "No 'this' for static methods!"); - QualType ClassTy = C.getTagDeclType(cast(getParent())); + QualType ClassTy = C.getTagDeclType(const_cast( + cast(getParent()))); QualType ThisTy = C.getPointerType(ClassTy); ThisTy.addConst(); return ThisTy;