]> granicus.if.org Git - clang/commitdiff
Relax the assertion in ASTLocation's ctor: if the decl is not the immediate
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 06:58:08 +0000 (06:58 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 17 Jul 2009 06:58:08 +0000 (06:58 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76159 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Index/ASTLocation.h
lib/Index/ASTLocation.cpp

index 26c3f3128179b403dffc528f025ab8d650f77ebc..6058623d768a1d946733a6533e0c1f5b49b15528 100644 (file)
@@ -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; }
index 3cd657b9b91beb78cd8fd9158230ec8d2d720be2..3beff3f31a8f96de5ff16cbb8e11c07c0142978d 100644 (file)
@@ -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);