[cfe-commits] r173577 - libclang: make getCursorStmt() and getCursorExpr() return const pointers

Dmitri Gribenko gribozavr at gmail.com
Sat Jan 26 07:29:09 PST 2013


Author: gribozavr
Date: Sat Jan 26 09:29:08 2013
New Revision: 173577

URL: http://llvm.org/viewvc/llvm-project?rev=173577&view=rev
Log:
libclang: make getCursorStmt() and getCursorExpr() return const pointers

Also change EnqueueVisitor to use ConstStmtVisitor as a consequence.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CXCursor.cpp
    cfe/trunk/tools/libclang/CXCursor.h
    cfe/trunk/tools/libclang/CursorVisitor.h

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=173577&r1=173576&r2=173577&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sat Jan 26 09:29:08 2013
@@ -471,14 +471,14 @@ bool CursorVisitor::VisitChildren(CXCurs
   }
 
   if (clang_isStatement(Cursor.kind)) {
-    if (Stmt *S = getCursorStmt(Cursor))
+    if (const Stmt *S = getCursorStmt(Cursor))
       return Visit(S);
 
     return false;
   }
 
   if (clang_isExpression(Cursor.kind)) {
-    if (Expr *E = getCursorExpr(Cursor))
+    if (const Expr *E = getCursorExpr(Cursor))
       return Visit(E);
 
     return false;
@@ -1660,9 +1660,10 @@ namespace {
 #define DEF_JOB(NAME, DATA, KIND)\
 class NAME : public VisitorJob {\
 public:\
-  NAME(DATA *d, CXCursor parent) : VisitorJob(parent, VisitorJob::KIND, d) {} \
+  NAME(const DATA *d, CXCursor parent) : \
+      VisitorJob(parent, VisitorJob::KIND, d) {} \
   static bool classof(const VisitorJob *VJ) { return VJ->getKind() == KIND; }\
-  DATA *get() const { return static_cast<DATA*>(data[0]); }\
+  const DATA *get() const { return static_cast<const DATA*>(data[0]); }\
 };
 
 DEF_JOB(StmtVisit, Stmt, StmtVisitKind)
@@ -1678,13 +1679,13 @@ DEF_JOB(PostChildrenVisit, void, PostChi
 
 class DeclVisit : public VisitorJob {
 public:
-  DeclVisit(Decl *d, CXCursor parent, bool isFirst) :
+  DeclVisit(const Decl *D, CXCursor parent, bool isFirst) :
     VisitorJob(parent, VisitorJob::DeclVisitKind,
-               d, isFirst ? (void*) 1 : (void*) 0) {}
+               const_cast<Decl *>(D), isFirst ? (void*) 1 : (void*) 0) {}
   static bool classof(const VisitorJob *VJ) {
     return VJ->getKind() == DeclVisitKind;
   }
-  Decl *get() const { return static_cast<Decl*>(data[0]); }
+  const Decl *get() const { return static_cast<const Decl *>(data[0]); }
   bool isFirst() const { return data[1] ? true : false; }
 };
 class TypeLocVisit : public VisitorJob {
@@ -1699,7 +1700,7 @@ public:
 
   TypeLoc get() const { 
     QualType T = QualType::getFromOpaquePtr(data[0]);
-    return TypeLoc(T, data[1]);
+    return TypeLoc(T, const_cast<void *>(data[1]));
   }
 };
 
@@ -1712,7 +1713,9 @@ public:
   static bool classof(const VisitorJob *VJ) {
     return VJ->getKind() == VisitorJob::LabelRefVisitKind;
   }
-  LabelDecl *get() const { return static_cast<LabelDecl*>(data[0]); }
+  const LabelDecl *get() const {
+    return static_cast<const LabelDecl *>(data[0]);
+  }
   SourceLocation getLoc() const { 
     return SourceLocation::getFromPtrEncoding(data[1]); }
 };
@@ -1729,20 +1732,23 @@ public:
   }
   
   NestedNameSpecifierLoc get() const {
-    return NestedNameSpecifierLoc(static_cast<NestedNameSpecifier*>(data[0]), 
-                                  data[1]);
+    return NestedNameSpecifierLoc(
+            const_cast<NestedNameSpecifier *>(
+              static_cast<const NestedNameSpecifier *>(data[0])),
+            const_cast<void *>(data[1]));
   }
 };
   
 class DeclarationNameInfoVisit : public VisitorJob {
 public:
-  DeclarationNameInfoVisit(Stmt *S, CXCursor parent)
-    : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {}
+  DeclarationNameInfoVisit(const Stmt *S, CXCursor parent)
+    : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind,
+                 const_cast<Stmt *>(S)) {}
   static bool classof(const VisitorJob *VJ) {
     return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind;
   }
   DeclarationNameInfo get() const {
-    Stmt *S = static_cast<Stmt*>(data[0]);
+    const Stmt *S = static_cast<const Stmt *>(data[0]);
     switch (S->getStmtClass()) {
     default:
       llvm_unreachable("Unhandled Stmt");
@@ -1757,85 +1763,85 @@ public:
 };
 class MemberRefVisit : public VisitorJob {
 public:
-  MemberRefVisit(FieldDecl *D, SourceLocation L, CXCursor parent)
+  MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent)
     : VisitorJob(parent, VisitorJob::MemberRefVisitKind, D,
                  L.getPtrEncoding()) {}
   static bool classof(const VisitorJob *VJ) {
     return VJ->getKind() == VisitorJob::MemberRefVisitKind;
   }
-  FieldDecl *get() const {
-    return static_cast<FieldDecl*>(data[0]);
+  const FieldDecl *get() const {
+    return static_cast<const FieldDecl *>(data[0]);
   }
   SourceLocation getLoc() const {
     return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) data[1]);
   }
 };
-class EnqueueVisitor : public StmtVisitor<EnqueueVisitor, void> {
+class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
   VisitorWorkList &WL;
   CXCursor Parent;
 public:
   EnqueueVisitor(VisitorWorkList &wl, CXCursor parent)
     : WL(wl), Parent(parent) {}
 
-  void VisitAddrLabelExpr(AddrLabelExpr *E);
-  void VisitBlockExpr(BlockExpr *B);
-  void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
-  void VisitCompoundStmt(CompoundStmt *S);
-  void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { /* Do nothing. */ }
-  void VisitMSDependentExistsStmt(MSDependentExistsStmt *S);
-  void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
-  void VisitCXXNewExpr(CXXNewExpr *E);
-  void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
-  void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
-  void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
-  void VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
-  void VisitCXXTypeidExpr(CXXTypeidExpr *E);
-  void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
-  void VisitCXXUuidofExpr(CXXUuidofExpr *E);
-  void VisitCXXCatchStmt(CXXCatchStmt *S);
-  void VisitDeclRefExpr(DeclRefExpr *D);
-  void VisitDeclStmt(DeclStmt *S);
-  void VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
-  void VisitDesignatedInitExpr(DesignatedInitExpr *E);
-  void VisitExplicitCastExpr(ExplicitCastExpr *E);
-  void VisitForStmt(ForStmt *FS);
-  void VisitGotoStmt(GotoStmt *GS);
-  void VisitIfStmt(IfStmt *If);
-  void VisitInitListExpr(InitListExpr *IE);
-  void VisitMemberExpr(MemberExpr *M);
-  void VisitOffsetOfExpr(OffsetOfExpr *E);
-  void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
-  void VisitObjCMessageExpr(ObjCMessageExpr *M);
-  void VisitOverloadExpr(OverloadExpr *E);
-  void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
-  void VisitStmt(Stmt *S);
-  void VisitSwitchStmt(SwitchStmt *S);
-  void VisitWhileStmt(WhileStmt *W);
-  void VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E);
-  void VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E);
-  void VisitTypeTraitExpr(TypeTraitExpr *E);
-  void VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
-  void VisitExpressionTraitExpr(ExpressionTraitExpr *E);
-  void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *U);
-  void VisitVAArgExpr(VAArgExpr *E);
-  void VisitSizeOfPackExpr(SizeOfPackExpr *E);
-  void VisitPseudoObjectExpr(PseudoObjectExpr *E);
-  void VisitOpaqueValueExpr(OpaqueValueExpr *E);
-  void VisitLambdaExpr(LambdaExpr *E);
-  
+  void VisitAddrLabelExpr(const AddrLabelExpr *E);
+  void VisitBlockExpr(const BlockExpr *B);
+  void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
+  void VisitCompoundStmt(const CompoundStmt *S);
+  void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ }
+  void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S);
+  void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E);
+  void VisitCXXNewExpr(const CXXNewExpr *E);
+  void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
+  void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E);
+  void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E);
+  void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
+  void VisitCXXTypeidExpr(const CXXTypeidExpr *E);
+  void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E);
+  void VisitCXXUuidofExpr(const CXXUuidofExpr *E);
+  void VisitCXXCatchStmt(const CXXCatchStmt *S);
+  void VisitDeclRefExpr(const DeclRefExpr *D);
+  void VisitDeclStmt(const DeclStmt *S);
+  void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E);
+  void VisitDesignatedInitExpr(const DesignatedInitExpr *E);
+  void VisitExplicitCastExpr(const ExplicitCastExpr *E);
+  void VisitForStmt(const ForStmt *FS);
+  void VisitGotoStmt(const GotoStmt *GS);
+  void VisitIfStmt(const IfStmt *If);
+  void VisitInitListExpr(const InitListExpr *IE);
+  void VisitMemberExpr(const MemberExpr *M);
+  void VisitOffsetOfExpr(const OffsetOfExpr *E);
+  void VisitObjCEncodeExpr(const ObjCEncodeExpr *E);
+  void VisitObjCMessageExpr(const ObjCMessageExpr *M);
+  void VisitOverloadExpr(const OverloadExpr *E);
+  void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
+  void VisitStmt(const Stmt *S);
+  void VisitSwitchStmt(const SwitchStmt *S);
+  void VisitWhileStmt(const WhileStmt *W);
+  void VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *E);
+  void VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *E);
+  void VisitTypeTraitExpr(const TypeTraitExpr *E);
+  void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
+  void VisitExpressionTraitExpr(const ExpressionTraitExpr *E);
+  void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U);
+  void VisitVAArgExpr(const VAArgExpr *E);
+  void VisitSizeOfPackExpr(const SizeOfPackExpr *E);
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *E);
+  void VisitOpaqueValueExpr(const OpaqueValueExpr *E);
+  void VisitLambdaExpr(const LambdaExpr *E);
+
 private:
-  void AddDeclarationNameInfo(Stmt *S);
+  void AddDeclarationNameInfo(const Stmt *S);
   void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier);
   void AddExplicitTemplateArgs(const ASTTemplateArgumentListInfo *A);
-  void AddMemberRef(FieldDecl *D, SourceLocation L);
-  void AddStmt(Stmt *S);
-  void AddDecl(Decl *D, bool isFirst = true);
+  void AddMemberRef(const FieldDecl *D, SourceLocation L);
+  void AddStmt(const Stmt *S);
+  void AddDecl(const Decl *D, bool isFirst = true);
   void AddTypeLoc(TypeSourceInfo *TI);
-  void EnqueueChildren(Stmt *S);
+  void EnqueueChildren(const Stmt *S);
 };
 } // end anonyous namespace
 
-void EnqueueVisitor::AddDeclarationNameInfo(Stmt *S) {
+void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) {
   // 'S' should always be non-null, since it comes from the
   // statement we are visiting.
   WL.push_back(DeclarationNameInfoVisit(S, Parent));
@@ -1847,21 +1853,20 @@ EnqueueVisitor::AddNestedNameSpecifierLo
     WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent));
 }
 
-void EnqueueVisitor::AddStmt(Stmt *S) {
+void EnqueueVisitor::AddStmt(const Stmt *S) {
   if (S)
     WL.push_back(StmtVisit(S, Parent));
 }
-void EnqueueVisitor::AddDecl(Decl *D, bool isFirst) {
+void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) {
   if (D)
     WL.push_back(DeclVisit(D, Parent, isFirst));
 }
 void EnqueueVisitor::
   AddExplicitTemplateArgs(const ASTTemplateArgumentListInfo *A) {
   if (A)
-    WL.push_back(ExplicitTemplateArgsVisit(
-                        const_cast<ASTTemplateArgumentListInfo*>(A), Parent));
+    WL.push_back(ExplicitTemplateArgsVisit(A, Parent));
 }
-void EnqueueVisitor::AddMemberRef(FieldDecl *D, SourceLocation L) {
+void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) {
   if (D)
     WL.push_back(MemberRefVisit(D, L, Parent));
 }
@@ -1869,9 +1874,9 @@ void EnqueueVisitor::AddTypeLoc(TypeSour
   if (TI)
     WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent));
  }
-void EnqueueVisitor::EnqueueChildren(Stmt *S) {
+void EnqueueVisitor::EnqueueChildren(const Stmt *S) {
   unsigned size = WL.size();
-  for (Stmt::child_range Child = S->children(); Child; ++Child) {
+  for (Stmt::const_child_range Child = S->children(); Child; ++Child) {
     AddStmt(*Child);
   }
   if (size == WL.size())
@@ -1881,24 +1886,24 @@ void EnqueueVisitor::EnqueueChildren(Stm
   VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
   std::reverse(I, E);
 }
-void EnqueueVisitor::VisitAddrLabelExpr(AddrLabelExpr *E) {
+void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) {
   WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent));
 }
-void EnqueueVisitor::VisitBlockExpr(BlockExpr *B) {
+void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) {
   AddDecl(B->getBlockDecl());
 }
-void EnqueueVisitor::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
+void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
   EnqueueChildren(E);
   AddTypeLoc(E->getTypeSourceInfo());
 }
-void EnqueueVisitor::VisitCompoundStmt(CompoundStmt *S) {
-  for (CompoundStmt::reverse_body_iterator I = S->body_rbegin(),
+void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) {
+  for (CompoundStmt::const_reverse_body_iterator I = S->body_rbegin(),
         E = S->body_rend(); I != E; ++I) {
     AddStmt(*I);
   }
 }
 void EnqueueVisitor::
-VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
+VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
   AddStmt(S->getSubStmt());
   AddDeclarationNameInfo(S);
   if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc())
@@ -1906,7 +1911,7 @@ VisitMSDependentExistsStmt(MSDependentEx
 }
 
 void EnqueueVisitor::
-VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
   AddExplicitTemplateArgs(E->getOptionalExplicitTemplateArgs());
   AddDeclarationNameInfo(E);
   if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
@@ -1914,7 +1919,7 @@ VisitCXXDependentScopeMemberExpr(CXXDepe
   if (!E->isImplicitAccess())
     AddStmt(E->getBase());
 }
-void EnqueueVisitor::VisitCXXNewExpr(CXXNewExpr *E) {
+void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) {
   // Enqueue the initializer , if any.
   AddStmt(E->getInitializer());
   // Enqueue the array size, if any.
@@ -1925,13 +1930,14 @@ void EnqueueVisitor::VisitCXXNewExpr(CXX
   for (unsigned I = E->getNumPlacementArgs(); I > 0; --I)
     AddStmt(E->getPlacementArg(I-1));
 }
-void EnqueueVisitor::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
+void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) {
   for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; --I)
     AddStmt(CE->getArg(I-1));
   AddStmt(CE->getCallee());
   AddStmt(CE->getArg(0));
 }
-void EnqueueVisitor::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
+void EnqueueVisitor::VisitCXXPseudoDestructorExpr(
+                                        const CXXPseudoDestructorExpr *E) {
   // Visit the name of the type being destroyed.
   AddTypeLoc(E->getDestroyedTypeInfo());
   // Visit the scope type that looks disturbingly like the nested-name-specifier
@@ -1943,50 +1949,53 @@ void EnqueueVisitor::VisitCXXPseudoDestr
   // Visit base expression.
   AddStmt(E->getBase());
 }
-void EnqueueVisitor::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
+void EnqueueVisitor::VisitCXXScalarValueInitExpr(
+                                        const CXXScalarValueInitExpr *E) {
   AddTypeLoc(E->getTypeSourceInfo());
 }
-void EnqueueVisitor::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
+void EnqueueVisitor::VisitCXXTemporaryObjectExpr(
+                                        const CXXTemporaryObjectExpr *E) {
   EnqueueChildren(E);
   AddTypeLoc(E->getTypeSourceInfo());
 }
-void EnqueueVisitor::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
+void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
   EnqueueChildren(E);
   if (E->isTypeOperand())
     AddTypeLoc(E->getTypeOperandSourceInfo());
 }
 
-void EnqueueVisitor::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr 
-                                                     *E) {
+void EnqueueVisitor::VisitCXXUnresolvedConstructExpr(
+                                        const CXXUnresolvedConstructExpr *E) {
   EnqueueChildren(E);
   AddTypeLoc(E->getTypeSourceInfo());
 }
-void EnqueueVisitor::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
+void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
   EnqueueChildren(E);
   if (E->isTypeOperand())
     AddTypeLoc(E->getTypeOperandSourceInfo());
 }
 
-void EnqueueVisitor::VisitCXXCatchStmt(CXXCatchStmt *S) {
+void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) {
   EnqueueChildren(S);
   AddDecl(S->getExceptionDecl());
 }
 
-void EnqueueVisitor::VisitDeclRefExpr(DeclRefExpr *DR) {
+void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
   if (DR->hasExplicitTemplateArgs()) {
     AddExplicitTemplateArgs(&DR->getExplicitTemplateArgs());
   }
   WL.push_back(DeclRefExprParts(DR, Parent));
 }
-void EnqueueVisitor::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
+void EnqueueVisitor::VisitDependentScopeDeclRefExpr(
+                                        const DependentScopeDeclRefExpr *E) {
   AddExplicitTemplateArgs(E->getOptionalExplicitTemplateArgs());
   AddDeclarationNameInfo(E);
   AddNestedNameSpecifierLoc(E->getQualifierLoc());
 }
-void EnqueueVisitor::VisitDeclStmt(DeclStmt *S) {
+void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) {
   unsigned size = WL.size();
   bool isFirst = true;
-  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
+  for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
        D != DEnd; ++D) {
     AddDecl(*D, isFirst);
     isFirst = false;
@@ -1998,10 +2007,10 @@ void EnqueueVisitor::VisitDeclStmt(DeclS
   VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
   std::reverse(I, E);
 }
-void EnqueueVisitor::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
+void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
   AddStmt(E->getInit());
   typedef DesignatedInitExpr::Designator Designator;
-  for (DesignatedInitExpr::reverse_designators_iterator
+  for (DesignatedInitExpr::const_reverse_designators_iterator
          D = E->designators_rbegin(), DEnd = E->designators_rend();
          D != DEnd; ++D) {
     if (D->isFieldDesignator()) {
@@ -2018,33 +2027,33 @@ void EnqueueVisitor::VisitDesignatedInit
     AddStmt(E->getArrayRangeStart(*D));
   }
 }
-void EnqueueVisitor::VisitExplicitCastExpr(ExplicitCastExpr *E) {
+void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) {
   EnqueueChildren(E);
   AddTypeLoc(E->getTypeInfoAsWritten());
 }
-void EnqueueVisitor::VisitForStmt(ForStmt *FS) {
+void EnqueueVisitor::VisitForStmt(const ForStmt *FS) {
   AddStmt(FS->getBody());
   AddStmt(FS->getInc());
   AddStmt(FS->getCond());
   AddDecl(FS->getConditionVariable());
   AddStmt(FS->getInit());
 }
-void EnqueueVisitor::VisitGotoStmt(GotoStmt *GS) {
+void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) {
   WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent));
 }
-void EnqueueVisitor::VisitIfStmt(IfStmt *If) {
+void EnqueueVisitor::VisitIfStmt(const IfStmt *If) {
   AddStmt(If->getElse());
   AddStmt(If->getThen());
   AddStmt(If->getCond());
   AddDecl(If->getConditionVariable());
 }
-void EnqueueVisitor::VisitInitListExpr(InitListExpr *IE) {
+void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) {
   // We care about the syntactic form of the initializer list, only.
   if (InitListExpr *Syntactic = IE->getSyntacticForm())
     IE = Syntactic;
   EnqueueChildren(IE);
 }
-void EnqueueVisitor::VisitMemberExpr(MemberExpr *M) {
+void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) {
   WL.push_back(MemberExprParts(M, Parent));
   
   // If the base of the member access expression is an implicit 'this', don't
@@ -2054,14 +2063,14 @@ void EnqueueVisitor::VisitMemberExpr(Mem
   if (!M->isImplicitAccess())
     AddStmt(M->getBase());
 }
-void EnqueueVisitor::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
+void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
   AddTypeLoc(E->getEncodedTypeSourceInfo());
 }
-void EnqueueVisitor::VisitObjCMessageExpr(ObjCMessageExpr *M) {
+void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) {
   EnqueueChildren(M);
   AddTypeLoc(M->getClassReceiverTypeInfo());
 }
-void EnqueueVisitor::VisitOffsetOfExpr(OffsetOfExpr *E) {
+void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) {
   // Visit the components of the offsetof expression.
   for (unsigned N = E->getNumComponents(), I = N; I > 0; --I) {
     typedef OffsetOfExpr::OffsetOfNode OffsetOfNode;
@@ -2081,81 +2090,81 @@ void EnqueueVisitor::VisitOffsetOfExpr(O
   // Visit the type into which we're computing the offset.
   AddTypeLoc(E->getTypeSourceInfo());
 }
-void EnqueueVisitor::VisitOverloadExpr(OverloadExpr *E) {
+void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) {
   AddExplicitTemplateArgs(E->getOptionalExplicitTemplateArgs());
   WL.push_back(OverloadExprParts(E, Parent));
 }
 void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr(
-                                              UnaryExprOrTypeTraitExpr *E) {
+                                        const UnaryExprOrTypeTraitExpr *E) {
   EnqueueChildren(E);
   if (E->isArgumentType())
     AddTypeLoc(E->getArgumentTypeInfo());
 }
-void EnqueueVisitor::VisitStmt(Stmt *S) {
+void EnqueueVisitor::VisitStmt(const Stmt *S) {
   EnqueueChildren(S);
 }
-void EnqueueVisitor::VisitSwitchStmt(SwitchStmt *S) {
+void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) {
   AddStmt(S->getBody());
   AddStmt(S->getCond());
   AddDecl(S->getConditionVariable());
 }
 
-void EnqueueVisitor::VisitWhileStmt(WhileStmt *W) {
+void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) {
   AddStmt(W->getBody());
   AddStmt(W->getCond());
   AddDecl(W->getConditionVariable());
 }
 
-void EnqueueVisitor::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
+void EnqueueVisitor::VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *E) {
   AddTypeLoc(E->getQueriedTypeSourceInfo());
 }
 
-void EnqueueVisitor::VisitBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
+void EnqueueVisitor::VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *E) {
   AddTypeLoc(E->getRhsTypeSourceInfo());
   AddTypeLoc(E->getLhsTypeSourceInfo());
 }
 
-void EnqueueVisitor::VisitTypeTraitExpr(TypeTraitExpr *E) {
+void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) {
   for (unsigned I = E->getNumArgs(); I > 0; --I)
     AddTypeLoc(E->getArg(I-1));
 }
 
-void EnqueueVisitor::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
+void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
   AddTypeLoc(E->getQueriedTypeSourceInfo());
 }
 
-void EnqueueVisitor::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
+void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
   EnqueueChildren(E);
 }
 
-void EnqueueVisitor::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *U) {
+void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) {
   VisitOverloadExpr(U);
   if (!U->isImplicitAccess())
     AddStmt(U->getBase());
 }
-void EnqueueVisitor::VisitVAArgExpr(VAArgExpr *E) {
+void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) {
   AddStmt(E->getSubExpr());
   AddTypeLoc(E->getWrittenTypeInfo());
 }
-void EnqueueVisitor::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
+void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
   WL.push_back(SizeOfPackExprParts(E, Parent));
 }
-void EnqueueVisitor::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
+void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
   // If the opaque value has a source expression, just transparently
   // visit that.  This is useful for (e.g.) pseudo-object expressions.
   if (Expr *SourceExpr = E->getSourceExpr())
     return Visit(SourceExpr);
 }
-void EnqueueVisitor::VisitLambdaExpr(LambdaExpr *E) {
+void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) {
   AddStmt(E->getBody());
   WL.push_back(LambdaExprParts(E, Parent));
 }
-void EnqueueVisitor::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
+void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
   // Treat the expression like its syntactic form.
   Visit(E->getSyntacticForm());
 }
 
-void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, Stmt *S) {
+void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
   EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
 }
 
@@ -2179,7 +2188,7 @@ bool CursorVisitor::RunVisitorWorkList(V
   
     switch (LI.getKind()) {
       case VisitorJob::DeclVisitKind: {
-        Decl *D = cast<DeclVisit>(&LI)->get();
+        const Decl *D = cast<DeclVisit>(&LI)->get();
         if (!D)
           continue;
 
@@ -2208,7 +2217,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         continue;
       }
       case VisitorJob::LabelRefVisitKind: {
-        LabelDecl *LS = cast<LabelRefVisit>(&LI)->get();
+        const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get();
         if (LabelStmt *stmt = LS->getStmt()) {
           if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(),
                                        TU))) {
@@ -2238,7 +2247,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         continue;
       }
       case VisitorJob::StmtVisitKind: {
-        Stmt *S = cast<StmtVisit>(&LI)->get();
+        const Stmt *S = cast<StmtVisit>(&LI)->get();
         if (!S)
           continue;
 
@@ -2259,7 +2268,7 @@ bool CursorVisitor::RunVisitorWorkList(V
       }
       case VisitorJob::MemberExprPartsKind: {
         // Handle the other pieces in the MemberExpr besides the base.
-        MemberExpr *M = cast<MemberExprParts>(&LI)->get();
+        const MemberExpr *M = cast<MemberExprParts>(&LI)->get();
         
         // Visit the nested-name-specifier
         if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc())
@@ -2282,7 +2291,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         continue;
       }
       case VisitorJob::DeclRefExprPartsKind: {
-        DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get();
+        const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get();
         // Visit nested-name-specifier, if present.
         if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc())
           if (VisitNestedNameSpecifierLoc(QualifierLoc))
@@ -2293,7 +2302,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         continue;
       }
       case VisitorJob::OverloadExprPartsKind: {
-        OverloadExpr *O = cast<OverloadExprParts>(&LI)->get();
+        const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get();
         // Visit the nested-name-specifier.
         if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc())
           if (VisitNestedNameSpecifierLoc(QualifierLoc))
@@ -2307,7 +2316,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         continue;
       }
       case VisitorJob::SizeOfPackExprPartsKind: {
-        SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get();
+        const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get();
         NamedDecl *Pack = E->getPack();
         if (isa<TemplateTypeParmDecl>(Pack)) {
           if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack),
@@ -2332,7 +2341,7 @@ bool CursorVisitor::RunVisitorWorkList(V
         
       case VisitorJob::LambdaExprPartsKind: {
         // Visit captures.
-        LambdaExpr *E = cast<LambdaExprParts>(&LI)->get();
+        const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get();
         for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(),
                                        CEnd = E->explicit_capture_end();
              C != CEnd; ++C) {
@@ -2378,7 +2387,7 @@ bool CursorVisitor::RunVisitorWorkList(V
   return false;
 }
 
-bool CursorVisitor::Visit(Stmt *S) {
+bool CursorVisitor::Visit(const Stmt *S) {
   VisitorWorkList *WL = 0;
   if (!WorkListFreeList.empty()) {
     WL = WorkListFreeList.back();
@@ -3029,21 +3038,21 @@ static const Decl *getDeclFromExpr(const
   return 0;
 }
 
-static SourceLocation getLocationFromExpr(Expr *E) {
-  if (ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
+static SourceLocation getLocationFromExpr(const Expr *E) {
+  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
     return getLocationFromExpr(CE->getSubExpr());
 
-  if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
+  if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
     return /*FIXME:*/Msg->getLeftLoc();
-  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
+  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
     return DRE->getLocation();
-  if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
+  if (const MemberExpr *Member = dyn_cast<MemberExpr>(E))
     return Member->getMemberLoc();
-  if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
+  if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
     return Ivar->getLocation();
-  if (SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
+  if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
     return SizeOfPack->getPackLoc();
-  if (ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
+  if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
     return PropRef->getLocation();
   
   return E->getLocStart();
@@ -3227,8 +3236,8 @@ CXString clang_getCursorSpelling(CXCurso
   }
 
   if (clang_isStatement(C.kind)) {
-    Stmt *S = getCursorStmt(C);
-    if (LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
+    const Stmt *S = getCursorStmt(C);
+    if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
       return createCXString(Label->getName());
 
     return createCXString("");
@@ -3270,8 +3279,8 @@ CXSourceRange clang_Cursor_getSpellingNa
   ASTContext &Ctx = getCursorContext(C);
 
   if (clang_isStatement(C.kind)) {
-    Stmt *S = getCursorStmt(C);
-    if (LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) {
+    const Stmt *S = getCursorStmt(C);
+    if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) {
       if (pieceIndex > 0)
         return clang_getNullRange();
       return cxloc::translateSourceRange(Ctx, Label->getIdentLoc());
@@ -3281,7 +3290,7 @@ CXSourceRange clang_Cursor_getSpellingNa
   }
 
   if (C.kind == CXCursor_ObjCMessageExpr) {
-    if (ObjCMessageExpr *
+    if (const ObjCMessageExpr *
           ME = dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) {
       if (pieceIndex >= ME->getNumSelectorLocs())
         return clang_getNullRange();
@@ -4320,8 +4329,8 @@ CXCursor clang_getCursorReferenced(CXCur
   }
 
   if (clang_isStatement(C.kind)) {
-    Stmt *S = getCursorStmt(C);
-    if (GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
+    const Stmt *S = getCursorStmt(C);
+    if (const GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
       if (LabelDecl *label = Goto->getLabel())
         if (LabelStmt *labelS = label->getStmt())
         return MakeCXCursor(labelS, getCursorDecl(C), tu);
@@ -4690,26 +4699,26 @@ CXSourceRange clang_getCursorReferenceNa
   
   switch (C.kind) {
   case CXCursor_MemberRefExpr:
-    if (MemberExpr *E = dyn_cast<MemberExpr>(getCursorExpr(C)))
+    if (const MemberExpr *E = dyn_cast<MemberExpr>(getCursorExpr(C)))
       Pieces = buildPieces(NameFlags, true, E->getMemberNameInfo(),
                            E->getQualifierLoc().getSourceRange());
     break;
   
   case CXCursor_DeclRefExpr:
-    if (DeclRefExpr *E = dyn_cast<DeclRefExpr>(getCursorExpr(C)))
+    if (const DeclRefExpr *E = dyn_cast<DeclRefExpr>(getCursorExpr(C)))
       Pieces = buildPieces(NameFlags, false, E->getNameInfo(), 
                            E->getQualifierLoc().getSourceRange(),
                            E->getOptionalExplicitTemplateArgs());
     break;
     
   case CXCursor_CallExpr:
-    if (CXXOperatorCallExpr *OCE = 
+    if (const CXXOperatorCallExpr *OCE = 
         dyn_cast<CXXOperatorCallExpr>(getCursorExpr(C))) {
-      Expr *Callee = OCE->getCallee();
-      if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
+      const Expr *Callee = OCE->getCallee();
+      if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
         Callee = ICE->getSubExpr();
 
-      if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee))
+      if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee))
         Pieces = buildPieces(NameFlags, false, DRE->getNameInfo(),
                              DRE->getQualifierLoc().getSourceRange());
     }
@@ -5195,7 +5204,7 @@ AnnotateTokensWorker::Visit(CXCursor cur
   // include the variable declaration, e.g.:
   //  MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
   if (clang_isExpression(cursorK)) {
-    Expr *E = getCursorExpr(cursor);
+    const Expr *E = getCursorExpr(cursor);
     if (Decl *D = getCursorParentDecl(cursor)) {
       const unsigned I = NextToken();
       if (E->getLocStart().isValid() && D->getLocation().isValid() &&

Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=173577&r1=173576&r2=173577&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Sat Jan 26 09:29:08 2013
@@ -781,17 +781,17 @@ const Decl *cxcursor::getCursorDecl(CXCu
   return static_cast<const Decl *>(Cursor.data[0]);
 }
 
-Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
+const Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
   return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
 }
 
-Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
+const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
   if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
       Cursor.kind == CXCursor_ObjCProtocolRef ||
       Cursor.kind == CXCursor_ObjCClassRef)
     return 0;
 
-  return static_cast<Stmt*>(const_cast<void*>(Cursor.data[1]));
+  return static_cast<const Stmt *>(Cursor.data[1]);
 }
 
 Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
@@ -882,12 +882,13 @@ CXCursor cxcursor::getTypeRefCursor(CXCu
   if (cursor.xdata == 0)
     return cursor;
 
-  Expr *E = getCursorExpr(cursor);
+  const Expr *E = getCursorExpr(cursor);
   TypeSourceInfo *Type = 0;
-  if (CXXUnresolvedConstructExpr *
+  if (const CXXUnresolvedConstructExpr *
         UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
     Type = UnCtor->getTypeSourceInfo();
-  } else if (CXXTemporaryObjectExpr *Tmp = dyn_cast<CXXTemporaryObjectExpr>(E)){
+  } else if (const CXXTemporaryObjectExpr *Tmp =
+                 dyn_cast<CXXTemporaryObjectExpr>(E)){
     Type = Tmp->getTypeSourceInfo();
   }
 

Modified: cfe/trunk/tools/libclang/CXCursor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.h?rev=173577&r1=173576&r2=173577&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.h (original)
+++ cfe/trunk/tools/libclang/CXCursor.h Sat Jan 26 09:29:08 2013
@@ -242,8 +242,8 @@ std::pair<OverloadedDeclRefStorage, Sour
   getCursorOverloadedDeclRef(CXCursor C);
   
 const Decl *getCursorDecl(CXCursor Cursor);
-Expr *getCursorExpr(CXCursor Cursor);
-Stmt *getCursorStmt(CXCursor Cursor);
+const Expr *getCursorExpr(CXCursor Cursor);
+const Stmt *getCursorStmt(CXCursor Cursor);
 Attr *getCursorAttr(CXCursor Cursor);
 Decl *getCursorParentDecl(CXCursor Cursor);
 

Modified: cfe/trunk/tools/libclang/CursorVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CursorVisitor.h?rev=173577&r1=173576&r2=173577&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CursorVisitor.h (original)
+++ cfe/trunk/tools/libclang/CursorVisitor.h Sat Jan 26 09:29:08 2013
@@ -33,10 +33,11 @@ public:
               MemberRefVisitKind, SizeOfPackExprPartsKind,
               LambdaExprPartsKind, PostChildrenVisitKind };
 protected:
-  void *data[3];
+  const void *data[3];
   CXCursor parent;
   Kind K;
-  VisitorJob(CXCursor C, Kind k, void *d1, void *d2 = 0, void *d3 = 0)
+  VisitorJob(CXCursor C, Kind k, const void *d1, const void *d2 = 0,
+             const void *d3 = 0)
     : parent(C), K(k) {
     data[0] = d1;
     data[1] = d2;
@@ -258,8 +259,8 @@ public:
   // Data-recursive visitor functions.
   bool IsInRegionOfInterest(CXCursor C);
   bool RunVisitorWorkList(VisitorWorkList &WL);
-  void EnqueueWorkList(VisitorWorkList &WL, Stmt *S);
-  LLVM_ATTRIBUTE_NOINLINE bool Visit(Stmt *S);
+  void EnqueueWorkList(VisitorWorkList &WL, const Stmt *S);
+  LLVM_ATTRIBUTE_NOINLINE bool Visit(const Stmt *S);
 };
 
 }





More information about the cfe-commits mailing list