[cfe-commits] r83087 - in /cfe/trunk: include/clang/Index/ASTLocation.h lib/Analysis/CallGraph.cpp lib/Index/ASTLocation.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Tue Sep 29 12:39:54 PDT 2009


Author: akirtzidis
Date: Tue Sep 29 14:39:53 2009
New Revision: 83087

URL: http://llvm.org/viewvc/llvm-project?rev=83087&view=rev
Log:
Add more const-goodness to ASTLocation.

Modified:
    cfe/trunk/include/clang/Index/ASTLocation.h
    cfe/trunk/lib/Analysis/CallGraph.cpp
    cfe/trunk/lib/Index/ASTLocation.cpp

Modified: cfe/trunk/include/clang/Index/ASTLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/ASTLocation.h?rev=83087&r1=83086&r2=83087&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Tue Sep 29 14:39:53 2009
@@ -37,22 +37,21 @@
 /// like the declaration context, ASTContext, etc.
 ///
 class ASTLocation {
-  Decl *D;
-  Stmt *Stm;
+  const Decl *D;
+  const Stmt *Stm;
 
 public:
   ASTLocation() : D(0), Stm(0) {}
 
-  explicit ASTLocation(const Decl *d, const Stmt *stm = 0)
-    : D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(stm)) {
+  explicit ASTLocation(const Decl *d, const Stmt *stm = 0) : D(d), Stm(stm) {
     assert((Stm == 0 || isImmediateParent(D, Stm)) &&
            "The Decl is not the immediate parent of the Stmt.");
   }
 
   const Decl *getDecl() const { return D; }
   const Stmt *getStmt() const { return Stm; }
-  Decl *getDecl() { return D; }
-  Stmt *getStmt() { return Stm; }
+  Decl *getDecl() { return const_cast<Decl*>(D); }
+  Stmt *getStmt() { return const_cast<Stmt*>(Stm); }
 
   bool isValid() const { return D != 0; }
   bool isInvalid() const { return !isValid(); }
@@ -72,8 +71,8 @@
   SourceRange getSourceRange() const;
 
   /// \brief Checks that D is the immediate Decl parent of Node.
-  static bool isImmediateParent(Decl *D, Stmt *Node);
-  static Decl *FindImmediateParent(Decl *D, Stmt *Node);
+  static bool isImmediateParent(const Decl *D, const Stmt *Node);
+  static const Decl *FindImmediateParent(const Decl *D, const Stmt *Node);
 
   friend bool operator==(const ASTLocation &L, const ASTLocation &R) {
     return L.D == R.D && L.Stm == R.Stm;

Modified: cfe/trunk/lib/Analysis/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CallGraph.cpp?rev=83087&r1=83086&r2=83087&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CallGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/CallGraph.cpp Tue Sep 29 14:39:53 2009
@@ -52,7 +52,7 @@
     Entity Ent = Entity::get(CalleeDecl, G.getProgram());
     CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
 
-    Decl *Parent = ASTLocation::FindImmediateParent(FD, CE);
+    const Decl *Parent = ASTLocation::FindImmediateParent(FD, CE);
 
     CallerNode->addCallee(ASTLocation(Parent, CE), CalleeNode);
   }

Modified: cfe/trunk/lib/Index/ASTLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTLocation.cpp?rev=83087&r1=83086&r2=83087&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Tue Sep 29 14:39:53 2009
@@ -47,13 +47,13 @@
 }
 
 
-static bool isContainedInStatement(Stmt *Node, Stmt *Parent) {
+static bool isContainedInStatement(const Stmt *Node, const Stmt *Parent) {
   assert(Node && Parent && "Passed null Node or Parent");
 
   if (Node == Parent)
     return true;
 
-  for (Stmt::child_iterator
+  for (Stmt::const_child_iterator
          I = Parent->child_begin(), E = Parent->child_end(); I != E; ++I) {
     if (*I)
       if (isContainedInStatement(Node, *I))
@@ -63,23 +63,23 @@
   return false;
 }
 
-Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
+const Decl *ASTLocation::FindImmediateParent(const Decl *D, const Stmt *Node) {
   assert(D && Node && "Passed null Decl or null Stmt");
 
-  if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    Expr *Init = VD->getInit();
+  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+    const Expr *Init = VD->getInit();
     if (Init == 0)
       return 0;
     return isContainedInStatement(Node, Init) ? D : 0;
   }
 
-  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     if (!FD->isThisDeclarationADefinition())
       return 0;
 
     for (DeclContext::decl_iterator
            I = FD->decls_begin(), E = FD->decls_end(); I != E; ++I) {
-      Decl *Child = FindImmediateParent(*I, Node);
+      const Decl *Child = FindImmediateParent(*I, Node);
       if (Child)
         return Child;
     }
@@ -88,13 +88,13 @@
     return isContainedInStatement(Node, FD->getBody()) ? D : 0;
   }
 
-  if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
+  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
     if (!MD->getBody())
       return 0;
 
     for (DeclContext::decl_iterator
            I = MD->decls_begin(), E = MD->decls_end(); I != E; ++I) {
-      Decl *Child = FindImmediateParent(*I, Node);
+      const Decl *Child = FindImmediateParent(*I, Node);
       if (Child)
         return Child;
     }
@@ -103,10 +103,10 @@
     return isContainedInStatement(Node, MD->getBody()) ? D : 0;
   }
 
-  if (BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
+  if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
     for (DeclContext::decl_iterator
            I = BD->decls_begin(), E = BD->decls_end(); I != E; ++I) {
-      Decl *Child = FindImmediateParent(*I, Node);
+      const Decl *Child = FindImmediateParent(*I, Node);
       if (Child)
         return Child;
     }
@@ -118,7 +118,7 @@
   return 0;
 }
 
-bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) {
+bool ASTLocation::isImmediateParent(const Decl *D, const Stmt *Node) {
   assert(D && Node && "Passed null Decl or null Stmt");
   return D == FindImmediateParent(D, Node);
 }





More information about the cfe-commits mailing list