summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2009-07-17 06:58:08 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2009-07-17 06:58:08 +0000
commitd25ea831b2bd55aeec3481e690d624fdb229f59a (patch)
tree145c6aed19b221bd0e6f5d59f2f1e3ae842a55e9
parentaeb44a31f6fd67ae4c24c8d1841d15461a581335 (diff)
downloadbcm5719-llvm-d25ea831b2bd55aeec3481e690d624fdb229f59a.tar.gz
bcm5719-llvm-d25ea831b2bd55aeec3481e690d624fdb229f59a.zip
Relax the assertion in ASTLocation's ctor: if the decl is not the immediate
parent of the stmt, find the immediate parent for the stmt. This is because sometimes we cannot get the immediate decl of the stmt when creating the ASTLocation. We can only get a parent of the stmt. llvm-svn: 76159
-rw-r--r--clang/include/clang/Index/ASTLocation.h6
-rw-r--r--clang/lib/Index/ASTLocation.cpp10
2 files changed, 11 insertions, 5 deletions
diff --git a/clang/include/clang/Index/ASTLocation.h b/clang/include/clang/Index/ASTLocation.h
index 26c3f312817..6058623d768 100644
--- a/clang/include/clang/Index/ASTLocation.h
+++ b/clang/include/clang/Index/ASTLocation.h
@@ -42,11 +42,7 @@ class ASTLocation {
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)) {
- assert((Stm == 0 || isImmediateParent(D, Stm)) &&
- "The Decl is not the immediate parent of the Stmt.");
- }
+ explicit ASTLocation(const Decl *d, const Stmt *stm = 0);
const Decl *getDecl() const { return D; }
const Stmt *getStmt() const { return Stm; }
diff --git a/clang/lib/Index/ASTLocation.cpp b/clang/lib/Index/ASTLocation.cpp
index 3cd657b9b91..3beff3f31a8 100644
--- a/clang/lib/Index/ASTLocation.cpp
+++ b/clang/lib/Index/ASTLocation.cpp
@@ -61,6 +61,16 @@ 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