]> granicus.if.org Git - clang/commitdiff
Remove const_casts by making spec_begin()/spec_end() const
authorDmitri Gribenko <gribozavr@gmail.com>
Thu, 14 Feb 2013 13:20:36 +0000 (13:20 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Thu, 14 Feb 2013 13:20:36 +0000 (13:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175159 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclTemplate.h
lib/AST/ASTDumper.cpp
lib/AST/DeclTemplate.cpp

index 547490dea3795b0e18404952e0aa369a07fbc87f..979827a525840e90ae4d9115e87e78ce8ece20d4 100644 (file)
@@ -552,7 +552,7 @@ protected:
   };
 
   template <typename EntryType>
-  SpecIterator<EntryType>
+  static SpecIterator<EntryType>
   makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
     return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
   }
@@ -731,7 +731,7 @@ protected:
 
   CommonBase *newCommon(ASTContext &C) const;
 
-  Common *getCommonPtr() {
+  Common *getCommonPtr() const {
     return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
   }
 
@@ -740,7 +740,7 @@ protected:
   /// \brief Retrieve the set of function template specializations of this
   /// function template.
   llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
-  getSpecializations() {
+  getSpecializations() const {
     return getCommonPtr()->Specializations;
   }
 
@@ -798,11 +798,11 @@ public:
 
   typedef SpecIterator<FunctionTemplateSpecializationInfo> 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<ClassTemplateSpecializationDecl> &getSpecializations();
+  llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
+  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<Common *>(RedeclarableTemplateDecl::getCommonPtr());
   }
 
@@ -1923,11 +1924,11 @@ public:
 
   typedef SpecIterator<ClassTemplateSpecializationDecl> 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);
   }
 
index 3f221a7cde3dc34c432c90a58703b1fcfca71bb6..cdc96b6e01616064148e0d3daa2a7bc6f5095162 100644 (file)
@@ -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<FunctionTemplateDecl*>(D)->spec_begin(),
-       E = const_cast<FunctionTemplateDecl*>(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<ClassTemplateDecl*>(D)->spec_begin();
-  ClassTemplateDecl::spec_iterator E =
-      const_cast<ClassTemplateDecl*>(D)->spec_end();
+  ClassTemplateDecl::spec_iterator I = D->spec_begin();
+  ClassTemplateDecl::spec_iterator E = D->spec_end();
   if (I == E)
     lastChild();
   dumpDecl(D->getTemplatedDecl());
index 42929aa71d4bbc7f62da51f9b6eddc39315ad160..c262e3ff88dd3a76be88cc2aed48e17161f56987 100644 (file)
@@ -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<ClassTemplateSpecializationDecl> &
-ClassTemplateDecl::getSpecializations() {
+ClassTemplateDecl::getSpecializations() const {
   LoadLazySpecializations();
   return getCommonPtr()->Specializations;
 }