diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-10-12 18:40:01 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-10-12 18:40:01 +0000 |
commit | d2595ecce5f8350e485c83bfe767549a522b2802 (patch) | |
tree | 80331aca2907d4c4f8d8d6dd27a40a5b82dc459e | |
parent | 42220c5432c141d47cc8ce786e472b49dc907378 (diff) |
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
-rw-r--r-- | include/clang/AST/Decl.h | 8 | ||||
-rw-r--r-- | include/clang/AST/DeclBase.h | 5 | ||||
-rw-r--r-- | lib/AST/DeclBase.cpp | 6 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 3 |
4 files changed, 14 insertions, 8 deletions
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<ParmVarDecl*, 8>::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<DeclContext*>(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<ScopedDecl>(this)) +DeclContext *DeclContext::getParent() { + if (ScopedDecl *SD = dyn_cast<ScopedDecl>(this)) return SD->getDeclContext(); - else if (const BlockDecl *BD = dyn_cast<BlockDecl>(this)) + else if (BlockDecl *BD = dyn_cast<BlockDecl>(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<CXXRecordDecl>(getParent())); + QualType ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>( + cast<CXXRecordDecl>(getParent()))); QualType ThisTy = C.getPointerType(ClassTy); ThisTy.addConst(); return ThisTy; |