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

Zhongxing Xu xuzhongxing at gmail.com
Fri Jul 17 00:36:23 PDT 2009


Author: zhongxingxu
Date: Fri Jul 17 02:36:20 2009
New Revision: 76166

URL: http://llvm.org/viewvc/llvm-project?rev=76166&view=rev
Log:
As suggested by Argyrios, revert r76159 and make "FindImmediateParent" 
a public static method of 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=76166&r1=76165&r2=76166&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Fri Jul 17 02:36:20 2009
@@ -42,7 +42,11 @@
 public:
   ASTLocation() : D(0), Stm(0) {}
 
-  explicit ASTLocation(const Decl *d, const Stmt *stm = 0);
+  explicit ASTLocation(const Decl *d, const Stmt *stm = 0)
+    : D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(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; }
@@ -58,6 +62,7 @@
 
   /// \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);
 
   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=76166&r1=76165&r2=76166&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CallGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/CallGraph.cpp Fri Jul 17 02:36:20 2009
@@ -69,7 +69,10 @@
   if (FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
     Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
     CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
-    CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
+
+    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=76166&r1=76165&r2=76166&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Fri Jul 17 02:36:20 2009
@@ -33,7 +33,7 @@
   return false;
 }
 
-static Decl *FindImmediateParent(Decl *D, Stmt *Node) {
+Decl *ASTLocation::FindImmediateParent(Decl *D, Stmt *Node) {
   assert(D && Node && "Passed null Decl or null Stmt");
 
   if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
@@ -61,16 +61,6 @@
   return 0;
 }
 
-ASTLocation::ASTLocation(const Decl *d, const Stmt *stm)
-  : D(const_cast<Decl*>(d)), Stm(const_cast<Stmt*>(stm)) {
-  if (Stm) {
-    Decl *Parent = FindImmediateParent(D, Stm);
-    assert(Parent);
-    D = Parent;
-  }
-}
-
-
 bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) {
   assert(D && Node && "Passed null Decl or null Stmt");
   return D == FindImmediateParent(D, Node);





More information about the cfe-commits mailing list