From e252a89fc1560ca4cda9a95e4ae05e2dc03ee78c Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Thu, 14 Feb 2013 13:20:36 +0000 Subject: [PATCH] Remove const_casts by making spec_begin()/spec_end() const git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175159 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclTemplate.h | 21 +++++++++++---------- lib/AST/ASTDumper.cpp | 12 +++++------- lib/AST/DeclTemplate.cpp | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 547490dea3..979827a525 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -552,7 +552,7 @@ protected: }; template - SpecIterator + static SpecIterator makeSpecIterator(llvm::FoldingSetVector &Specs, bool isEnd) { return SpecIterator(isEnd ? Specs.end() : Specs.begin()); } @@ -731,7 +731,7 @@ protected: CommonBase *newCommon(ASTContext &C) const; - Common *getCommonPtr() { + Common *getCommonPtr() const { return static_cast(RedeclarableTemplateDecl::getCommonPtr()); } @@ -740,7 +740,7 @@ protected: /// \brief Retrieve the set of function template specializations of this /// function template. llvm::FoldingSetVector & - getSpecializations() { + getSpecializations() const { return getCommonPtr()->Specializations; } @@ -798,11 +798,11 @@ public: typedef SpecIterator spec_iterator; - spec_iterator spec_begin() { + spec_iterator spec_begin() const { return makeSpecIterator(getSpecializations(), false); } - spec_iterator spec_end() { + spec_iterator spec_end() const { return makeSpecIterator(getSpecializations(), true); } @@ -1778,10 +1778,11 @@ protected: }; /// \brief Load any lazily-loaded specializations from the external source. - void LoadLazySpecializations(); + void LoadLazySpecializations() const; /// \brief Retrieve the set of specializations of this class template. - llvm::FoldingSetVector &getSpecializations(); + llvm::FoldingSetVector & + getSpecializations() const; /// \brief Retrieve the set of partial specializations of this class /// template. @@ -1798,7 +1799,7 @@ protected: CommonBase *newCommon(ASTContext &C) const; - Common *getCommonPtr() { + Common *getCommonPtr() const { return static_cast(RedeclarableTemplateDecl::getCommonPtr()); } @@ -1923,11 +1924,11 @@ public: typedef SpecIterator spec_iterator; - spec_iterator spec_begin() { + spec_iterator spec_begin() const { return makeSpecIterator(getSpecializations(), false); } - spec_iterator spec_end() { + spec_iterator spec_end() const { return makeSpecIterator(getSpecializations(), true); } diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 3f221a7cde..cdc96b6e01 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -935,9 +935,9 @@ void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); dumpDecl(D->getTemplatedDecl()); - for (FunctionTemplateDecl::spec_iterator - I = const_cast(D)->spec_begin(), - E = const_cast(D)->spec_end(); I != E; ++I) { + for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(), + E = D->spec_end(); + I != E; ++I) { FunctionTemplateDecl::spec_iterator Next = I; ++Next; if (Next == E) @@ -960,10 +960,8 @@ void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); - ClassTemplateDecl::spec_iterator I = - const_cast(D)->spec_begin(); - ClassTemplateDecl::spec_iterator E = - const_cast(D)->spec_end(); + ClassTemplateDecl::spec_iterator I = D->spec_begin(); + ClassTemplateDecl::spec_iterator E = D->spec_end(); if (I == E) lastChild(); dumpDecl(D->getTemplatedDecl()); diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 42929aa71d..c262e3ff88 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -304,7 +304,7 @@ ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, return new (Mem) ClassTemplateDecl(EmptyShell()); } -void ClassTemplateDecl::LoadLazySpecializations() { +void ClassTemplateDecl::LoadLazySpecializations() const { Common *CommonPtr = getCommonPtr(); if (CommonPtr->LazySpecializations) { ASTContext &Context = getASTContext(); @@ -316,7 +316,7 @@ void ClassTemplateDecl::LoadLazySpecializations() { } llvm::FoldingSetVector & -ClassTemplateDecl::getSpecializations() { +ClassTemplateDecl::getSpecializations() const { LoadLazySpecializations(); return getCommonPtr()->Specializations; } -- 2.40.0