]> granicus.if.org Git - clang/commitdiff
Add more const-goodness to ASTLocation.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Sep 2009 19:39:53 +0000 (19:39 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Sep 2009 19:39:53 +0000 (19:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83087 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Index/ASTLocation.h
lib/Analysis/CallGraph.cpp
lib/Index/ASTLocation.cpp

index 60af9e672c011b04a6d2ba521373d36a9c839f9b..ba213052ab59cc4669963eee3bb3fd53192facbb 100644 (file)
@@ -37,22 +37,21 @@ namespace idx {
 /// 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 @@ public:
   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;
index fdca1dc2f44a5cde77a1dbb1dc555575bd663234..f605bd98f54aeb2a3d8fe655a8e06abaffce1714 100644 (file)
@@ -52,7 +52,7 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) {
     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);
   }
index d6f5cc7cfbaec851829b44b944d3d8474e95c3e3..7bad129d6c69ae3c10f70fc528ca343b94ed0c14 100644 (file)
@@ -47,13 +47,13 @@ Decl *ASTLocation::getReferencedDecl() {
 }
 
 
-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 @@ static bool isContainedInStatement(Stmt *Node, Stmt *Parent) {
   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 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
     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 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
     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 @@ Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
   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);
 }