Improve source-location information for CXXNewExpr, by hanging on to
the TypeSourceInfo for the allocated type. Fixes PR7501.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113291 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 5117f2c..c056e48 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -388,7 +388,7 @@
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { return false; }
   // FIXME: CXXTemporaryObjectExpr has poor source-location information.
   // FIXME: CXXScalarValueInitExpr has poor source-location information.
-  // FIXME: CXXNewExpr has poor source-location information
+  bool VisitCXXNewExpr(CXXNewExpr *E);
   bool VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
   // FIXME: UnaryTypeTraitExpr has poor source-location information.
   bool VisitOverloadExpr(OverloadExpr *E);
@@ -1590,6 +1590,29 @@
   return VisitExpr(E);
 }
 
+bool CursorVisitor::VisitCXXNewExpr(CXXNewExpr *E) {
+  // Visit placement arguments.
+  for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I)
+    if (Visit(MakeCXCursor(E->getPlacementArg(I), StmtParent, TU)))
+      return true;
+  
+  // Visit the allocated type.
+  if (TypeSourceInfo *TSInfo = E->getAllocatedTypeSourceInfo())
+    if (Visit(TSInfo->getTypeLoc()))
+      return true;
+  
+  // Visit the array size, if any.
+  if (E->isArray() && Visit(MakeCXCursor(E->getArraySize(), StmtParent, TU)))
+    return true;
+  
+  // Visit the initializer or constructor arguments.
+  for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I)
+    if (Visit(MakeCXCursor(E->getConstructorArg(I), StmtParent, TU)))
+      return true;
+  
+  return false;
+}
+
 bool CursorVisitor::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
   // Visit base expression.
   if (Visit(MakeCXCursor(E->getBase(), StmtParent, TU)))