r174171 - Use const visitors in ASTDumper.

Alexander Kornienko alexfh at google.com
Fri Feb 1 04:35:51 PST 2013


Author: alexfh
Date: Fri Feb  1 06:35:51 2013
New Revision: 174171

URL: http://llvm.org/viewvc/llvm-project?rev=174171&view=rev
Log:
Use const visitors in ASTDumper.
http://llvm-reviews.chandlerc.com/D355
Patch by Philip Craig!

Modified:
    cfe/trunk/include/clang/AST/DeclVisitor.h
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/ASTDumper.cpp
    cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/DeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclVisitor.h?rev=174171&r1=174170&r2=174171&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DeclVisitor.h Fri Feb  1 06:35:51 2013
@@ -20,15 +20,21 @@
 #include "clang/AST/DeclTemplate.h"
 
 namespace clang {
+namespace declvisitor {
 
-#define DISPATCH(NAME, CLASS) \
-  return static_cast<ImplClass*>(this)-> Visit##NAME(static_cast<CLASS*>(D))
+template <typename T> struct make_ptr       { typedef       T *type; };
+template <typename T> struct make_const_ptr { typedef const T *type; };
 
 /// \brief A simple visitor class that helps create declaration visitors.
-template<typename ImplClass, typename RetTy=void>
-class DeclVisitor {
+template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
+class Base {
 public:
-  RetTy Visit(Decl *D) {
+
+#define PTR(CLASS) typename Ptr<CLASS>::type
+#define DISPATCH(NAME, CLASS) \
+  return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D))
+
+  RetTy Visit(PTR(Decl) D) {
     switch (D->getKind()) {
 #define DECL(DERIVED, BASE) \
       case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
@@ -41,13 +47,31 @@ public:
   // If the implementation chooses not to implement a certain visit
   // method, fall back to the parent.
 #define DECL(DERIVED, BASE) \
-  RetTy Visit##DERIVED##Decl(DERIVED##Decl *D) { DISPATCH(BASE, BASE); }
+  RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); }
 #include "clang/AST/DeclNodes.inc"
 
-  RetTy VisitDecl(Decl *D) { return RetTy(); }
-};
+  RetTy VisitDecl(PTR(Decl) D) { return RetTy(); }
 
+#undef PTR
 #undef DISPATCH
+};
+
+} // end namespace declvisitor
+
+/// \brief A simple visitor class that helps create declaration visitors.
+///
+/// This class does not preserve constness of Decl pointers (see also
+/// ConstDeclVisitor).
+template<typename ImplClass, typename RetTy=void>
+class DeclVisitor
+ : public declvisitor::Base<declvisitor::make_ptr, ImplClass, RetTy> {};
+
+/// \brief A simple visitor class that helps create declaration visitors.
+///
+/// This class preserves constness of Decl pointers (see also DeclVisitor).
+template<typename ImplClass, typename RetTy=void>
+class ConstDeclVisitor
+ : public declvisitor::Base<declvisitor::make_const_ptr, ImplClass, RetTy> {};
 
 }  // end namespace clang
 

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=174171&r1=174170&r2=174171&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Feb  1 06:35:51 2013
@@ -1488,7 +1488,7 @@ public:
                      getByteLength());
   }
 
-  void outputString(raw_ostream &OS);
+  void outputString(raw_ostream &OS) const;
 
   uint32_t getCodeUnit(size_t i) const {
     assert(i < Length && "out of bounds access");

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=174171&r1=174170&r2=174171&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Fri Feb  1 06:35:51 2013
@@ -74,7 +74,7 @@ namespace  {
   static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
 
   class ASTDumper
-      : public DeclVisitor<ASTDumper>, public StmtVisitor<ASTDumper>,
+      : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
         public ConstCommentVisitor<ASTDumper> {
     raw_ostream &OS;
     const CommandTraits *Traits;
@@ -151,8 +151,8 @@ namespace  {
       OS << "\n";
     }
 
-    void dumpDecl(Decl *D);
-    void dumpStmt(Stmt *S);
+    void dumpDecl(const Decl *D);
+    void dumpStmt(const Stmt *S);
     void dumpFullComment(const FullComment *C);
 
     // Formatting
@@ -186,106 +186,106 @@ namespace  {
                               SourceRange R = SourceRange());
 
     // Decls
-    void VisitLabelDecl(LabelDecl *D);
-    void VisitTypedefDecl(TypedefDecl *D);
-    void VisitEnumDecl(EnumDecl *D);
-    void VisitRecordDecl(RecordDecl *D);
-    void VisitEnumConstantDecl(EnumConstantDecl *D);
-    void VisitIndirectFieldDecl(IndirectFieldDecl *D);
-    void VisitFunctionDecl(FunctionDecl *D);
-    void VisitFieldDecl(FieldDecl *D);
-    void VisitVarDecl(VarDecl *D);
-    void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
-    void VisitImportDecl(ImportDecl *D);
+    void VisitLabelDecl(const LabelDecl *D);
+    void VisitTypedefDecl(const TypedefDecl *D);
+    void VisitEnumDecl(const EnumDecl *D);
+    void VisitRecordDecl(const RecordDecl *D);
+    void VisitEnumConstantDecl(const EnumConstantDecl *D);
+    void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
+    void VisitFunctionDecl(const FunctionDecl *D);
+    void VisitFieldDecl(const FieldDecl *D);
+    void VisitVarDecl(const VarDecl *D);
+    void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
+    void VisitImportDecl(const ImportDecl *D);
 
     // C++ Decls
-    void VisitNamespaceDecl(NamespaceDecl *D);
-    void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
-    void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
-    void VisitTypeAliasDecl(TypeAliasDecl *D);
-    void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
-    void VisitCXXRecordDecl(CXXRecordDecl *D);
-    void VisitStaticAssertDecl(StaticAssertDecl *D);
-    void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
-    void VisitClassTemplateDecl(ClassTemplateDecl *D);
+    void VisitNamespaceDecl(const NamespaceDecl *D);
+    void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
+    void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
+    void VisitTypeAliasDecl(const TypeAliasDecl *D);
+    void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
+    void VisitCXXRecordDecl(const CXXRecordDecl *D);
+    void VisitStaticAssertDecl(const StaticAssertDecl *D);
+    void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
+    void VisitClassTemplateDecl(const ClassTemplateDecl *D);
     void VisitClassTemplateSpecializationDecl(
-        ClassTemplateSpecializationDecl *D);
+        const ClassTemplateSpecializationDecl *D);
     void VisitClassTemplatePartialSpecializationDecl(
-        ClassTemplatePartialSpecializationDecl *D);
+        const ClassTemplatePartialSpecializationDecl *D);
     void VisitClassScopeFunctionSpecializationDecl(
-        ClassScopeFunctionSpecializationDecl *D);
-    void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
-    void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
-    void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
-    void VisitUsingDecl(UsingDecl *D);
-    void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
-    void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
-    void VisitUsingShadowDecl(UsingShadowDecl *D);
-    void VisitLinkageSpecDecl(LinkageSpecDecl *D);
-    void VisitAccessSpecDecl(AccessSpecDecl *D);
-    void VisitFriendDecl(FriendDecl *D);
+        const ClassScopeFunctionSpecializationDecl *D);
+    void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
+    void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
+    void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
+    void VisitUsingDecl(const UsingDecl *D);
+    void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
+    void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
+    void VisitUsingShadowDecl(const UsingShadowDecl *D);
+    void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
+    void VisitAccessSpecDecl(const AccessSpecDecl *D);
+    void VisitFriendDecl(const FriendDecl *D);
 
     // ObjC Decls
-    void VisitObjCIvarDecl(ObjCIvarDecl *D);
-    void VisitObjCMethodDecl(ObjCMethodDecl *D);
-    void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
-    void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
-    void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
-    void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
-    void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
-    void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
-    void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
-    void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
-    void VisitBlockDecl(BlockDecl *D);
+    void VisitObjCIvarDecl(const ObjCIvarDecl *D);
+    void VisitObjCMethodDecl(const ObjCMethodDecl *D);
+    void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
+    void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
+    void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
+    void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
+    void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
+    void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
+    void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
+    void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
+    void VisitBlockDecl(const BlockDecl *D);
 
     // Stmts.
-    void VisitStmt(Stmt *Node);
-    void VisitDeclStmt(DeclStmt *Node);
-    void VisitAttributedStmt(AttributedStmt *Node);
-    void VisitLabelStmt(LabelStmt *Node);
-    void VisitGotoStmt(GotoStmt *Node);
+    void VisitStmt(const Stmt *Node);
+    void VisitDeclStmt(const DeclStmt *Node);
+    void VisitAttributedStmt(const AttributedStmt *Node);
+    void VisitLabelStmt(const LabelStmt *Node);
+    void VisitGotoStmt(const GotoStmt *Node);
 
     // Exprs
-    void VisitExpr(Expr *Node);
-    void VisitCastExpr(CastExpr *Node);
-    void VisitDeclRefExpr(DeclRefExpr *Node);
-    void VisitPredefinedExpr(PredefinedExpr *Node);
-    void VisitCharacterLiteral(CharacterLiteral *Node);
-    void VisitIntegerLiteral(IntegerLiteral *Node);
-    void VisitFloatingLiteral(FloatingLiteral *Node);
-    void VisitStringLiteral(StringLiteral *Str);
-    void VisitUnaryOperator(UnaryOperator *Node);
-    void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
-    void VisitMemberExpr(MemberExpr *Node);
-    void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
-    void VisitBinaryOperator(BinaryOperator *Node);
-    void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
-    void VisitAddrLabelExpr(AddrLabelExpr *Node);
-    void VisitBlockExpr(BlockExpr *Node);
-    void VisitOpaqueValueExpr(OpaqueValueExpr *Node);
+    void VisitExpr(const Expr *Node);
+    void VisitCastExpr(const CastExpr *Node);
+    void VisitDeclRefExpr(const DeclRefExpr *Node);
+    void VisitPredefinedExpr(const PredefinedExpr *Node);
+    void VisitCharacterLiteral(const CharacterLiteral *Node);
+    void VisitIntegerLiteral(const IntegerLiteral *Node);
+    void VisitFloatingLiteral(const FloatingLiteral *Node);
+    void VisitStringLiteral(const StringLiteral *Str);
+    void VisitUnaryOperator(const UnaryOperator *Node);
+    void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
+    void VisitMemberExpr(const MemberExpr *Node);
+    void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
+    void VisitBinaryOperator(const BinaryOperator *Node);
+    void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
+    void VisitAddrLabelExpr(const AddrLabelExpr *Node);
+    void VisitBlockExpr(const BlockExpr *Node);
+    void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
 
     // C++
-    void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
-    void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
-    void VisitCXXThisExpr(CXXThisExpr *Node);
-    void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
-    void VisitCXXConstructExpr(CXXConstructExpr *Node);
-    void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
-    void VisitExprWithCleanups(ExprWithCleanups *Node);
-    void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
-    void dumpCXXTemporary(CXXTemporary *Temporary);
+    void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
+    void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
+    void VisitCXXThisExpr(const CXXThisExpr *Node);
+    void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
+    void VisitCXXConstructExpr(const CXXConstructExpr *Node);
+    void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
+    void VisitExprWithCleanups(const ExprWithCleanups *Node);
+    void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
+    void dumpCXXTemporary(const CXXTemporary *Temporary);
 
     // ObjC
-    void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
-    void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
-    void VisitObjCMessageExpr(ObjCMessageExpr *Node);
-    void VisitObjCBoxedExpr(ObjCBoxedExpr *Node);
-    void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
-    void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
-    void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
-    void VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node);
-    void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
-    void VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node);
+    void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
+    void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
+    void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
+    void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
+    void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
+    void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
+    void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
+    void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
+    void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
+    void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
 
     // Comments.
     const char *getCommandName(unsigned CommandID);
@@ -329,8 +329,8 @@ void ASTDumper::indent() {
     OS << "\n";
 
   ColorScope Color(*this, IndentColor);
-  for (llvm::SmallVector<IndentType, 32>::const_iterator I =
-           Indents.begin(), E = Indents.end();
+  for (llvm::SmallVector<IndentType, 32>::const_iterator I = Indents.begin(),
+                                                         E = Indents.end();
        I != E; ++I) {
     switch (*I) {
     case IT_Child:
@@ -625,7 +625,7 @@ void ASTDumper::dumpTemplateArgument(con
 //  Decl dumping methods.
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::dumpDecl(Decl *D) {
+void ASTDumper::dumpDecl(const Decl *D) {
   IndentScope Indent(*this);
 
   if (!D) {
@@ -641,23 +641,21 @@ void ASTDumper::dumpDecl(Decl *D) {
   dumpPointer(D);
   dumpSourceRange(D->getSourceRange());
 
-  bool HasAttrs = D->hasAttrs() && D->getAttrs().begin() != D->getAttrs().end();
+  bool HasAttrs = D->attr_begin() != D->attr_end();
   bool HasComment = D->getASTContext().getCommentForDecl(D, 0);
   // Decls within functions are visited by the body
   bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
                          hasNodes(dyn_cast<DeclContext>(D));
 
   setMoreChildren(HasAttrs || HasComment || HasDeclContext);
-  DeclVisitor<ASTDumper>::Visit(D);
+  ConstDeclVisitor<ASTDumper>::Visit(D);
 
   setMoreChildren(HasComment || HasDeclContext);
-  if (HasAttrs) {
-    for (AttrVec::const_iterator I = D->getAttrs().begin(),
-         E = D->getAttrs().end(); I != E; ++I) {
-      if (I + 1 == E)
-        lastChild();
-      dumpAttr(*I);
-    }
+  for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
+       I != E; ++I) {
+    if (I + 1 == E)
+      lastChild();
+    dumpAttr(*I);
   }
 
   setMoreChildren(HasDeclContext);
@@ -669,18 +667,18 @@ void ASTDumper::dumpDecl(Decl *D) {
     dumpDeclContext(dyn_cast<DeclContext>(D));
 }
 
-void ASTDumper::VisitLabelDecl(LabelDecl *D) {
+void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
   dumpName(D);
 }
 
-void ASTDumper::VisitTypedefDecl(TypedefDecl *D) {
+void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
   dumpName(D);
   dumpType(D->getUnderlyingType());
   if (D->isModulePrivate())
     OS << " __module_private__";
 }
 
-void ASTDumper::VisitEnumDecl(EnumDecl *D) {
+void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
   if (D->isScoped()) {
     if (D->isScopedUsingClassTag())
       OS << " class";
@@ -694,34 +692,35 @@ void ASTDumper::VisitEnumDecl(EnumDecl *
     dumpType(D->getIntegerType());
 }
 
-void ASTDumper::VisitRecordDecl(RecordDecl *D) {
+void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
   OS << ' ' << D->getKindName();
   dumpName(D);
   if (D->isModulePrivate())
     OS << " __module_private__";
 }
 
-void ASTDumper::VisitEnumConstantDecl(EnumConstantDecl *D) {
+void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
   dumpName(D);
   dumpType(D->getType());
-  if (Expr *Init = D->getInitExpr()) {
+  if (const Expr *Init = D->getInitExpr()) {
     lastChild();
     dumpStmt(Init);
   }
 }
 
-void ASTDumper::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
+void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
   dumpName(D);
   dumpType(D->getType());
   for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
-       E = D->chain_end(); I != E; ++I) {
+                                         E = D->chain_end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpDeclRef(*I);
   }
 }
 
-void ASTDumper::VisitFunctionDecl(FunctionDecl *D) {
+void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
   dumpName(D);
   dumpType(D->getType());
 
@@ -750,7 +749,7 @@ void ASTDumper::VisitFunctionDecl(Functi
 
   bool HasFunctionDecls = D->param_begin() != D->param_end();
 
-  CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
+  const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
   bool HasCtorInitializers = C && C->init_begin() != C->init_end();
 
   bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
@@ -773,7 +772,8 @@ void ASTDumper::VisitFunctionDecl(Functi
   }
 
   setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
-  for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end();
+  for (FunctionDecl::param_const_iterator I = D->param_begin(),
+                                          E = D->param_end();
        I != E; ++I) {
     if (I + 1 == E)
       lastChild();
@@ -783,7 +783,8 @@ void ASTDumper::VisitFunctionDecl(Functi
   setMoreChildren(OldMoreChildren || HasDeclarationBody);
   if (HasCtorInitializers)
     for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
-         E = C->init_end(); I != E; ++I) {
+                                                 E = C->init_end();
+         I != E; ++I) {
       if (I + 1 == E)
         lastChild();
       dumpCXXCtorInitializer(*I);
@@ -796,7 +797,7 @@ void ASTDumper::VisitFunctionDecl(Functi
   }
 }
 
-void ASTDumper::VisitFieldDecl(FieldDecl *D) {
+void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
   dumpName(D);
   dumpType(D->getType());
   if (D->isMutable())
@@ -821,7 +822,7 @@ void ASTDumper::VisitFieldDecl(FieldDecl
   }
 }
 
-void ASTDumper::VisitVarDecl(VarDecl *D) {
+void ASTDumper::VisitVarDecl(const VarDecl *D) {
   dumpName(D);
   dumpType(D->getType());
   StorageClass SC = D->getStorageClassAsWritten();
@@ -839,12 +840,12 @@ void ASTDumper::VisitVarDecl(VarDecl *D)
   }
 }
 
-void ASTDumper::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
+void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
   lastChild();
   dumpStmt(D->getAsmString());
 }
 
-void ASTDumper::VisitImportDecl(ImportDecl *D) {
+void ASTDumper::VisitImportDecl(const ImportDecl *D) {
   OS << ' ' << D->getImportedModule()->getFullModuleName();
 }
 
@@ -852,7 +853,7 @@ void ASTDumper::VisitImportDecl(ImportDe
 // C++ Declarations
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::VisitNamespaceDecl(NamespaceDecl *D) {
+void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
   dumpName(D);
   if (D->isInline())
     OS << " inline";
@@ -860,34 +861,35 @@ void ASTDumper::VisitNamespaceDecl(Names
     dumpDeclRef(D->getOriginalNamespace(), "original");
 }
 
-void ASTDumper::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
   OS << ' ';
   dumpBareDeclRef(D->getNominatedNamespace());
 }
 
-void ASTDumper::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
   dumpName(D);
   dumpDeclRef(D->getAliasedNamespace());
 }
 
-void ASTDumper::VisitTypeAliasDecl(TypeAliasDecl *D) {
+void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
   dumpName(D);
   dumpType(D->getUnderlyingType());
 }
 
-void ASTDumper::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
+void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
   dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
   dumpDecl(D->getTemplatedDecl());
 }
 
-void ASTDumper::VisitCXXRecordDecl(CXXRecordDecl *D) {
+void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
   VisitRecordDecl(D);
   if (!D->isCompleteDefinition())
     return;
 
-  for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
-       E = D->bases_end(); I != E; ++I) {
+  for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
+                                                E = D->bases_end();
+       I != E; ++I) {
     IndentScope Indent(*this);
     if (I->isVirtual())
       OS << "virtual ";
@@ -898,18 +900,19 @@ void ASTDumper::VisitCXXRecordDecl(CXXRe
   }
 }
 
-void ASTDumper::VisitStaticAssertDecl(StaticAssertDecl *D) {
+void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
   dumpStmt(D->getAssertExpr());
   lastChild();
   dumpStmt(D->getMessage());
 }
 
-void ASTDumper::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
+void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
   dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
   dumpDecl(D->getTemplatedDecl());
-  for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
-       E = D->spec_end(); I != E; ++I) {
+  for (FunctionTemplateDecl::spec_iterator
+       I = const_cast<FunctionTemplateDecl*>(D)->spec_begin(),
+       E = const_cast<FunctionTemplateDecl*>(D)->spec_end(); I != E; ++I) {
     FunctionTemplateDecl::spec_iterator Next = I;
     ++Next;
     if (Next == E)
@@ -928,15 +931,18 @@ void ASTDumper::VisitFunctionTemplateDec
   }
 }
 
-void ASTDumper::VisitClassTemplateDecl(ClassTemplateDecl *D) {
+void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
   dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
 
-  if (D->spec_begin() == D->spec_end())
+  ClassTemplateDecl::spec_iterator I =
+      const_cast<ClassTemplateDecl*>(D)->spec_begin();
+  ClassTemplateDecl::spec_iterator E =
+      const_cast<ClassTemplateDecl*>(D)->spec_end();
+  if (I == E)
     lastChild();
   dumpDecl(D->getTemplatedDecl());
-  for (ClassTemplateDecl::spec_iterator I = D->spec_begin(), E = D->spec_end();
-       I != E; ++I) {
+  for (; I != E; ++I) {
     ClassTemplateDecl::spec_iterator Next = I;
     ++Next;
     if (Next == E)
@@ -956,25 +962,25 @@ void ASTDumper::VisitClassTemplateDecl(C
 }
 
 void ASTDumper::VisitClassTemplateSpecializationDecl(
-    ClassTemplateSpecializationDecl *D) {
+    const ClassTemplateSpecializationDecl *D) {
   VisitCXXRecordDecl(D);
   dumpTemplateArgumentList(D->getTemplateArgs());
 }
 
 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
-    ClassTemplatePartialSpecializationDecl *D) {
+    const ClassTemplatePartialSpecializationDecl *D) {
   VisitClassTemplateSpecializationDecl(D);
   dumpTemplateParameters(D->getTemplateParameters());
 }
 
 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
-    ClassScopeFunctionSpecializationDecl *D) {
+    const ClassScopeFunctionSpecializationDecl *D) {
   dumpDeclRef(D->getSpecialization());
   if (D->hasExplicitTemplateArgs())
     dumpTemplateArgumentListInfo(D->templateArgs());
 }
 
-void ASTDumper::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
+void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
   if (D->wasDeclaredWithTypename())
     OS << " typename";
   else
@@ -986,7 +992,7 @@ void ASTDumper::VisitTemplateTypeParmDec
     dumpType(D->getDefaultArgument());
 }
 
-void ASTDumper::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
+void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
   dumpType(D->getType());
   if (D->isParameterPack())
     OS << " ...";
@@ -995,7 +1001,8 @@ void ASTDumper::VisitNonTypeTemplateParm
     dumpStmt(D->getDefaultArgument());
 }
 
-void ASTDumper::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
+void ASTDumper::VisitTemplateTemplateParmDecl(
+    const TemplateTemplateParmDecl *D) {
   if (D->isParameterPack())
     OS << " ...";
   dumpName(D);
@@ -1004,44 +1011,44 @@ void ASTDumper::VisitTemplateTemplatePar
     dumpTemplateArgumentLoc(D->getDefaultArgument());
 }
 
-void ASTDumper::VisitUsingDecl(UsingDecl *D) {
+void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
   OS << ' ';
   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
   OS << D->getNameAsString();
 }
 
-void
-ASTDumper::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
+void ASTDumper::VisitUnresolvedUsingTypenameDecl(
+    const UnresolvedUsingTypenameDecl *D) {
   OS << ' ';
   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
   OS << D->getNameAsString();
 }
 
-void ASTDumper::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
+void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
   OS << ' ';
   D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
   OS << D->getNameAsString();
   dumpType(D->getType());
 }
 
-void ASTDumper::VisitUsingShadowDecl(UsingShadowDecl *D) {
+void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
   OS << ' ';
   dumpBareDeclRef(D->getTargetDecl());
 }
 
-void ASTDumper::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
+void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
   switch (D->getLanguage()) {
   case LinkageSpecDecl::lang_c: OS << " C"; break;
   case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
   }
 }
 
-void ASTDumper::VisitAccessSpecDecl(AccessSpecDecl *D) {
+void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
   OS << ' ';
   dumpAccessSpecifier(D->getAccess());
 }
 
-void ASTDumper::VisitFriendDecl(FriendDecl *D) {
+void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
   if (TypeSourceInfo *T = D->getFriendType())
     dumpType(T->getType());
   else
@@ -1052,7 +1059,7 @@ void ASTDumper::VisitFriendDecl(FriendDe
 // Obj-C Declarations
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::VisitObjCIvarDecl(ObjCIvarDecl *D) {
+void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
   dumpName(D);
   dumpType(D->getType());
   if (D->getSynthesize())
@@ -1077,7 +1084,7 @@ void ASTDumper::VisitObjCIvarDecl(ObjCIv
   }
 }
 
-void ASTDumper::VisitObjCMethodDecl(ObjCMethodDecl *D) {
+void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
   if (D->isInstanceMethod())
     OS << " -";
   else
@@ -1094,8 +1101,9 @@ void ASTDumper::VisitObjCMethodDecl(ObjC
     lastChild();
     dumpDeclContext(D);
   } else {
-    for (ObjCMethodDecl::param_iterator I = D->param_begin(),
-         E = D->param_end(); I != E; ++I) {
+    for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
+                                              E = D->param_end();
+         I != E; ++I) {
       if (I + 1 == E)
         lastChild();
       dumpDecl(*I);
@@ -1116,72 +1124,76 @@ void ASTDumper::VisitObjCMethodDecl(ObjC
   }
 }
 
-void ASTDumper::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
+void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
   dumpName(D);
   dumpDeclRef(D->getClassInterface());
   if (D->protocol_begin() == D->protocol_end())
     lastChild();
   dumpDeclRef(D->getImplementation());
   for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
-       E = D->protocol_end(); I != E; ++I) {
+                                           E = D->protocol_end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpDeclRef(*I);
   }
 }
 
-void ASTDumper::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
+void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
   dumpName(D);
   dumpDeclRef(D->getClassInterface());
   lastChild();
   dumpDeclRef(D->getCategoryDecl());
 }
 
-void ASTDumper::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
+void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
   dumpName(D);
   for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
-       E = D->protocol_end(); I != E; ++I) {
+                                           E = D->protocol_end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpDeclRef(*I);
   }
 }
 
-void ASTDumper::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
+void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
   dumpName(D);
   dumpDeclRef(D->getSuperClass(), "super");
   if (D->protocol_begin() == D->protocol_end())
     lastChild();
   dumpDeclRef(D->getImplementation());
   for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
-       E = D->protocol_end(); I != E; ++I) {
+                                            E = D->protocol_end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpDeclRef(*I);
   }
 }
 
-void ASTDumper::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
+void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
   dumpName(D);
   dumpDeclRef(D->getSuperClass(), "super");
   if (D->init_begin() == D->init_end())
     lastChild();
   dumpDeclRef(D->getClassInterface());
-  for (ObjCImplementationDecl::init_iterator I = D->init_begin(),
-       E = D->init_end(); I != E; ++I) {
+  for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
+                                                   E = D->init_end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpCXXCtorInitializer(*I);
   }
 }
 
-void ASTDumper::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
+void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
   dumpName(D);
   lastChild();
   dumpDeclRef(D->getClassInterface());
 }
 
-void ASTDumper::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
+void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
   dumpName(D);
   dumpType(D->getType());
 
@@ -1224,7 +1236,7 @@ void ASTDumper::VisitObjCPropertyDecl(Ob
   }
 }
 
-void ASTDumper::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
+void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
   dumpName(D->getPropertyDecl());
   if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
     OS << " synthesize";
@@ -1235,8 +1247,8 @@ void ASTDumper::VisitObjCPropertyImplDec
   dumpDeclRef(D->getPropertyIvarDecl());
 }
 
-void ASTDumper::VisitBlockDecl(BlockDecl *D) {
-  for (BlockDecl::param_iterator I = D->param_begin(), E = D->param_end();
+void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
+  for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
        I != E; ++I)
     dumpDecl(*I);
 
@@ -1249,8 +1261,8 @@ void ASTDumper::VisitBlockDecl(BlockDecl
     IndentScope Indent(*this);
     OS << "capture this";
   }
-  for (BlockDecl::capture_iterator I = D->capture_begin(),
-       E = D->capture_end(); I != E; ++I) {
+  for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
+       I != E; ++I) {
     IndentScope Indent(*this);
     OS << "capture";
     if (I->isByRef())
@@ -1272,7 +1284,7 @@ void ASTDumper::VisitBlockDecl(BlockDecl
 //  Stmt dumping methods.
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::dumpStmt(Stmt *S) {
+void ASTDumper::dumpStmt(const Stmt *S) {
   IndentScope Indent(*this);
 
   if (!S) {
@@ -1281,16 +1293,16 @@ void ASTDumper::dumpStmt(Stmt *S) {
     return;
   }
 
-  if (DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
+  if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
     VisitDeclStmt(DS);
     return;
   }
 
   setMoreChildren(S->children());
-  StmtVisitor<ASTDumper>::Visit(S);
+  ConstStmtVisitor<ASTDumper>::Visit(S);
   setMoreChildren(false);
-  for (Stmt::child_range CI = S->children(); CI; ++CI) {
-    Stmt::child_range Next = CI;
+  for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
+    Stmt::const_child_range Next = CI;
     ++Next;
     if (!Next)
       lastChild();
@@ -1298,7 +1310,7 @@ void ASTDumper::dumpStmt(Stmt *S) {
   }
 }
 
-void ASTDumper::VisitStmt(Stmt *Node) {
+void ASTDumper::VisitStmt(const Stmt *Node) {
   {   
     ColorScope Color(*this, StmtColor);
     OS << Node->getStmtClassName();
@@ -1307,9 +1319,10 @@ void ASTDumper::VisitStmt(Stmt *Node) {
   dumpSourceRange(Node->getSourceRange());
 }
 
-void ASTDumper::VisitDeclStmt(DeclStmt *Node) {
+void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
   VisitStmt(Node);
-  for (DeclStmt::decl_iterator I = Node->decl_begin(), E = Node->decl_end();
+  for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
+                                     E = Node->decl_end();
        I != E; ++I) {
     if (I + 1 == E)
       lastChild();
@@ -1317,22 +1330,23 @@ void ASTDumper::VisitDeclStmt(DeclStmt *
   }
 }
 
-void ASTDumper::VisitAttributedStmt(AttributedStmt *Node) {
+void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
   VisitStmt(Node);
-  for (ArrayRef<const Attr*>::iterator I = Node->getAttrs().begin(),
-       E = Node->getAttrs().end(); I != E; ++I) {
+  for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
+                                        E = Node->getAttrs().end();
+       I != E; ++I) {
     if (I + 1 == E)
       lastChild();
     dumpAttr(*I);
   }
 }
 
-void ASTDumper::VisitLabelStmt(LabelStmt *Node) {
+void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
   VisitStmt(Node);
   OS << " '" << Node->getName() << "'";
 }
 
-void ASTDumper::VisitGotoStmt(GotoStmt *Node) {
+void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
   VisitStmt(Node);
   OS << " '" << Node->getLabel()->getName() << "'";
   dumpPointer(Node->getLabel());
@@ -1342,7 +1356,7 @@ void ASTDumper::VisitGotoStmt(GotoStmt *
 //  Expr dumping methods.
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::VisitExpr(Expr *Node) {
+void ASTDumper::VisitExpr(const Expr *Node) {
   VisitStmt(Node);
   dumpType(Node->getType());
 
@@ -1381,14 +1395,15 @@ void ASTDumper::VisitExpr(Expr *Node) {
   }
 }
 
-static void dumpBasePath(raw_ostream &OS, CastExpr *Node) {
+static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
   if (Node->path_empty())
     return;
 
   OS << " (";
   bool First = true;
-  for (CastExpr::path_iterator
-         I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
+  for (CastExpr::path_const_iterator I = Node->path_begin(),
+                                     E = Node->path_end();
+       I != E; ++I) {
     const CXXBaseSpecifier *Base = *I;
     if (!First)
       OS << " -> ";
@@ -1405,7 +1420,7 @@ static void dumpBasePath(raw_ostream &OS
   OS << ')';
 }
 
-void ASTDumper::VisitCastExpr(CastExpr *Node) {
+void ASTDumper::VisitCastExpr(const CastExpr *Node) {
   VisitExpr(Node);
   OS << " <";
   {
@@ -1416,7 +1431,7 @@ void ASTDumper::VisitCastExpr(CastExpr *
   OS << ">";
 }
 
-void ASTDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
+void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
   VisitExpr(Node);
 
   OS << " ";
@@ -1428,7 +1443,7 @@ void ASTDumper::VisitDeclRefExpr(DeclRef
   }
 }
 
-void ASTDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
+void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
   VisitExpr(Node);
   OS << " (";
   if (!Node->requiresADL())
@@ -1443,7 +1458,7 @@ void ASTDumper::VisitUnresolvedLookupExp
     dumpPointer(*I);
 }
 
-void ASTDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
+void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
   VisitExpr(Node);
 
   {
@@ -1456,7 +1471,7 @@ void ASTDumper::VisitObjCIvarRefExpr(Obj
     OS << " isFreeIvar";
 }
 
-void ASTDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
+void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
   VisitExpr(Node);
   switch (Node->getIdentType()) {
   default: llvm_unreachable("unknown case");
@@ -1467,13 +1482,13 @@ void ASTDumper::VisitPredefinedExpr(Pred
   }
 }
 
-void ASTDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
+void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
   VisitExpr(Node);
   ColorScope Color(*this, ValueColor);
   OS << " " << Node->getValue();
 }
 
-void ASTDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
+void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
   VisitExpr(Node);
 
   bool isSigned = Node->getType()->isSignedIntegerType();
@@ -1481,26 +1496,27 @@ void ASTDumper::VisitIntegerLiteral(Inte
   OS << " " << Node->getValue().toString(10, isSigned);
 }
 
-void ASTDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
+void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
   VisitExpr(Node);
   ColorScope Color(*this, ValueColor);
   OS << " " << Node->getValueAsApproximateDouble();
 }
 
-void ASTDumper::VisitStringLiteral(StringLiteral *Str) {
+void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
   VisitExpr(Str);
   ColorScope Color(*this, ValueColor);
   OS << " ";
   Str->outputString(OS);
 }
 
-void ASTDumper::VisitUnaryOperator(UnaryOperator *Node) {
+void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
   VisitExpr(Node);
   OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
      << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
 }
 
-void ASTDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
+void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
+    const UnaryExprOrTypeTraitExpr *Node) {
   VisitExpr(Node);
   switch(Node->getKind()) {
   case UETT_SizeOf:
@@ -1517,23 +1533,24 @@ void ASTDumper::VisitUnaryExprOrTypeTrai
     dumpType(Node->getArgumentType());
 }
 
-void ASTDumper::VisitMemberExpr(MemberExpr *Node) {
+void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
   VisitExpr(Node);
   OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
   dumpPointer(Node->getMemberDecl());
 }
 
-void ASTDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
+void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
   VisitExpr(Node);
   OS << " " << Node->getAccessor().getNameStart();
 }
 
-void ASTDumper::VisitBinaryOperator(BinaryOperator *Node) {
+void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
   VisitExpr(Node);
   OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
 }
 
-void ASTDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
+void ASTDumper::VisitCompoundAssignOperator(
+    const CompoundAssignOperator *Node) {
   VisitExpr(Node);
   OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
      << "' ComputeLHSTy=";
@@ -1542,12 +1559,12 @@ void ASTDumper::VisitCompoundAssignOpera
   dumpBareType(Node->getComputationResultType());
 }
 
-void ASTDumper::VisitBlockExpr(BlockExpr *Node) {
+void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
   VisitExpr(Node);
   dumpDecl(Node->getBlockDecl());
 }
 
-void ASTDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) {
+void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
   VisitExpr(Node);
 
   if (Expr *Source = Node->getSourceExpr()) {
@@ -1558,7 +1575,7 @@ void ASTDumper::VisitOpaqueValueExpr(Opa
 
 // GNU extensions.
 
-void ASTDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
+void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
   VisitExpr(Node);
   OS << " " << Node->getLabel()->getName();
   dumpPointer(Node->getLabel());
@@ -1568,7 +1585,7 @@ void ASTDumper::VisitAddrLabelExpr(AddrL
 // C++ Expressions
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
+void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
   VisitExpr(Node);
   OS << " " << Node->getCastName()
      << "<" << Node->getTypeAsWritten().getAsString() << ">"
@@ -1577,23 +1594,23 @@ void ASTDumper::VisitCXXNamedCastExpr(CX
   OS << ">";
 }
 
-void ASTDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
+void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
   VisitExpr(Node);
   OS << " " << (Node->getValue() ? "true" : "false");
 }
 
-void ASTDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
+void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
   VisitExpr(Node);
   OS << " this";
 }
 
-void ASTDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
+void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
   VisitExpr(Node);
   OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
      << " <" << Node->getCastKindName() << ">";
 }
 
-void ASTDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
+void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
   VisitExpr(Node);
   CXXConstructorDecl *Ctor = Node->getConstructor();
   dumpType(Ctor->getType());
@@ -1603,19 +1620,19 @@ void ASTDumper::VisitCXXConstructExpr(CX
     OS << " zeroing";
 }
 
-void ASTDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
+void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
   VisitExpr(Node);
   OS << " ";
   dumpCXXTemporary(Node->getTemporary());
 }
 
-void ASTDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
+void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
   VisitExpr(Node);
   for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
     dumpDeclRef(Node->getObject(i), "cleanup");
 }
 
-void ASTDumper::dumpCXXTemporary(CXXTemporary *Temporary) {
+void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
   OS << "(CXXTemporary";
   dumpPointer(Temporary);
   OS << ")";
@@ -1625,7 +1642,7 @@ void ASTDumper::dumpCXXTemporary(CXXTemp
 // Obj-C Expressions
 //===----------------------------------------------------------------------===//
 
-void ASTDumper::VisitObjCMessageExpr(ObjCMessageExpr *Node) {
+void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
   VisitExpr(Node);
   OS << " selector=" << Node->getSelector().getAsString();
   switch (Node->getReceiverKind()) {
@@ -1647,37 +1664,37 @@ void ASTDumper::VisitObjCMessageExpr(Obj
   }
 }
 
-void ASTDumper::VisitObjCBoxedExpr(ObjCBoxedExpr *Node) {
+void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
   VisitExpr(Node);
   OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
 }
 
-void ASTDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
+void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
   VisitStmt(Node);
-  if (VarDecl *CatchParam = Node->getCatchParamDecl())
+  if (const VarDecl *CatchParam = Node->getCatchParamDecl())
     dumpDecl(CatchParam);
   else
     OS << " catch all";
 }
 
-void ASTDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
+void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
   VisitExpr(Node);
   dumpType(Node->getEncodedType());
 }
 
-void ASTDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
+void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
   VisitExpr(Node);
 
   OS << " " << Node->getSelector().getAsString();
 }
 
-void ASTDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
+void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
   VisitExpr(Node);
 
   OS << ' ' << *Node->getProtocol();
 }
 
-void ASTDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
+void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
   VisitExpr(Node);
   if (Node->isImplicitProperty()) {
     OS << " Kind=MethodRef Getter=\"";
@@ -1708,7 +1725,7 @@ void ASTDumper::VisitObjCPropertyRefExpr
     OS << "Setter";
 }
 
-void ASTDumper::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) {
+void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
   VisitExpr(Node);
   if (Node->isArraySubscriptRefExpr())
     OS << " Kind=ArraySubscript GetterForArray=\"";
@@ -1729,7 +1746,7 @@ void ASTDumper::VisitObjCSubscriptRefExp
     OS << "(null)";
 }
 
-void ASTDumper::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) {
+void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
   VisitExpr(Node);
   OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
 }
@@ -1891,13 +1908,13 @@ void Decl::dump() const {
 void Decl::dump(raw_ostream &OS) const {
   ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
               &getASTContext().getSourceManager());
-  P.dumpDecl(const_cast<Decl*>(this));
+  P.dumpDecl(this);
 }
 
 void Decl::dumpColor() const {
   ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
               &getASTContext().getSourceManager(), /*ShowColors*/true);
-  P.dumpDecl(const_cast<Decl*>(this));
+  P.dumpDecl(this);
 }
 //===----------------------------------------------------------------------===//
 // Stmt method implementations
@@ -1909,17 +1926,17 @@ void Stmt::dump(SourceManager &SM) const
 
 void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
   ASTDumper P(OS, 0, &SM);
-  P.dumpStmt(const_cast<Stmt*>(this));
+  P.dumpStmt(this);
 }
 
 void Stmt::dump() const {
   ASTDumper P(llvm::errs(), 0, 0);
-  P.dumpStmt(const_cast<Stmt*>(this));
+  P.dumpStmt(this);
 }
 
 void Stmt::dumpColor() const {
   ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
-  P.dumpStmt(const_cast<Stmt*>(this));
+  P.dumpStmt(this);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=174171&r1=174170&r2=174171&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Feb  1 06:35:51 2013
@@ -771,7 +771,7 @@ StringLiteral *StringLiteral::CreateEmpt
   return SL;
 }
 
-void StringLiteral::outputString(raw_ostream &OS) {
+void StringLiteral::outputString(raw_ostream &OS) const {
   switch (getKind()) {
   case Ascii: break; // no prefix.
   case Wide:  OS << 'L'; break;





More information about the cfe-commits mailing list