As suggested by Argyrios, revert r76159 and make "FindImmediateParent"

a public static method of ASTLocation.

llvm-svn: 76166
This commit is contained in:
Zhongxing Xu 2009-07-17 07:36:20 +00:00
parent fab6cbe6cd
commit 3436f58e40
3 changed files with 11 additions and 13 deletions

View File

@ -42,7 +42,11 @@ class ASTLocation {
public: public:
ASTLocation() : D(0), Stm(0) {} 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 Decl *getDecl() const { return D; }
const Stmt *getStmt() const { return Stm; } const Stmt *getStmt() const { return Stm; }
@ -58,6 +62,7 @@ public:
/// \brief Checks that D is the immediate Decl parent of Node. /// \brief Checks that D is the immediate Decl parent of Node.
static bool isImmediateParent(Decl *D, Stmt *Node); static bool isImmediateParent(Decl *D, Stmt *Node);
static Decl *FindImmediateParent(Decl *D, Stmt *Node);
friend bool operator==(const ASTLocation &L, const ASTLocation &R) { friend bool operator==(const ASTLocation &L, const ASTLocation &R) {
return L.D == R.D && L.Stm == R.Stm; return L.D == R.D && L.Stm == R.Stm;

View File

@ -69,7 +69,10 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) {
if (FunctionDecl *CalleeDecl = CE->getDirectCallee()) { if (FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
Entity *Ent = Entity::get(CalleeDecl, G.getProgram()); Entity *Ent = Entity::get(CalleeDecl, G.getProgram());
CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent); CallGraphNode *CalleeNode = G.getOrInsertFunction(Ent);
CallerNode->addCallee(ASTLocation(FD, CE), CalleeNode);
Decl *Parent = ASTLocation::FindImmediateParent(FD, CE);
CallerNode->addCallee(ASTLocation(Parent, CE), CalleeNode);
} }
} }

View File

@ -33,7 +33,7 @@ static bool isContainedInStatement(Stmt *Node, Stmt *Parent) {
return false; 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"); assert(D && Node && "Passed null Decl or null Stmt");
if (VarDecl *VD = dyn_cast<VarDecl>(D)) { if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
@ -61,16 +61,6 @@ static Decl *FindImmediateParent(Decl *D, Stmt *Node) {
return 0; 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) { bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) {
assert(D && Node && "Passed null Decl or null Stmt"); assert(D && Node && "Passed null Decl or null Stmt");
return D == FindImmediateParent(D, Node); return D == FindImmediateParent(D, Node);