[cfe-commits] r76159 - in /cfe/trunk: include/clang/Index/ASTLocation.h lib/Index/ASTLocation.cpp

Zhongxing Xu xuzhongxing at gmail.com
Thu Jul 16 23:58:30 PDT 2009


Author: zhongxingxu
Date: Fri Jul 17 01:58:08 2009
New Revision: 76159

URL: http://llvm.org/viewvc/llvm-project?rev=76159&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Index/ASTLocation.h
    cfe/trunk/lib/Index/ASTLocation.cpp

Modified: cfe/trunk/include/clang/Index/ASTLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/ASTLocation.h?rev=76159&r1=76158&r2=76159&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Fri Jul 17 01:58:08 2009
@@ -42,11 +42,7 @@
 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; }

Modified: cfe/trunk/lib/Index/ASTLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTLocation.cpp?rev=76159&r1=76158&r2=76159&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Fri Jul 17 01:58:08 2009
@@ -61,6 +61,16 @@
   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);





More information about the cfe-commits mailing list