summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2009-07-17 07:36:20 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2009-07-17 07:36:20 +0000
commit3436f58e40bb92a4dae81355798f1273b2159e2a (patch)
treefab4ecf3d8c1c7c6cff77fdbec2d24d0027c7ab2 /clang
parentfab6cbe6cdf29d198d6d866f4469224fc46982da (diff)
downloadbcm5719-llvm-3436f58e40bb92a4dae81355798f1273b2159e2a.tar.gz
bcm5719-llvm-3436f58e40bb92a4dae81355798f1273b2159e2a.zip
As suggested by Argyrios, revert r76159 and make "FindImmediateParent"
a public static method of ASTLocation. llvm-svn: 76166
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Index/ASTLocation.h7
-rw-r--r--clang/lib/Analysis/CallGraph.cpp5
-rw-r--r--clang/lib/Index/ASTLocation.cpp12
3 files changed, 11 insertions, 13 deletions
diff --git a/clang/include/clang/Index/ASTLocation.h b/clang/include/clang/Index/ASTLocation.h
index 6058623d768..303d95ecc28 100644
--- a/clang/include/clang/Index/ASTLocation.h
+++ b/clang/include/clang/Index/ASTLocation.h
@@ -42,7 +42,11 @@ class ASTLocation {
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 @@ public:
/// \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;
diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp
index d49e8ec11be..2ec6d2014d8 100644
--- a/clang/lib/Analysis/CallGraph.cpp
+++ b/clang/lib/Analysis/CallGraph.cpp
@@ -69,7 +69,10 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) {
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);
}
}
diff --git a/clang/lib/Index/ASTLocation.cpp b/clang/lib/Index/ASTLocation.cpp
index 3beff3f31a8..41846055da0 100644
--- a/clang/lib/Index/ASTLocation.cpp
+++ b/clang/lib/Index/ASTLocation.cpp
@@ -33,7 +33,7 @@ static bool isContainedInStatement(Stmt *Node, Stmt *Parent) {
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 @@ static Decl *FindImmediateParent(Decl *D, Stmt *Node) {
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);
OpenPOWER on IntegriCloud