diff options
-rw-r--r-- | include/clang/Index/ASTLocation.h | 6 | ||||
-rw-r--r-- | lib/Index/ASTLocation.cpp | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/include/clang/Index/ASTLocation.h b/include/clang/Index/ASTLocation.h index 26c3f31281..6058623d76 100644 --- a/include/clang/Index/ASTLocation.h +++ b/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/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index 3cd657b9b9..3beff3f31a 100644 --- a/lib/Index/ASTLocation.cpp +++ b/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); |