Include information about compound statements when crashing in sema or the
parser.  For example, we now print out:

0.	t.c:5:10: in compound statement {}
1.	t.c:3:12: in compound statement {}
2.	clang t.c -fsyntax-only



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66108 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/SourceLocation.cpp b/lib/Basic/SourceLocation.cpp
index 73e231a..fd90b5a 100644
--- a/lib/Basic/SourceLocation.cpp
+++ b/lib/Basic/SourceLocation.cpp
@@ -13,14 +13,31 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Bitcode/Serialize.h"
 #include "llvm/Bitcode/Deserialize.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cstdio>
-
 using namespace clang;
 
+//===----------------------------------------------------------------------===//
+// PrettyStackTraceLoc
+//===----------------------------------------------------------------------===//
+
+void PrettyStackTraceLoc::print(llvm::raw_ostream &OS) const {
+  if (Loc.isValid()) {
+    Loc.print(OS, SM);
+    OS << ": ";
+  }
+  OS << Message << '\n';
+}
+
+//===----------------------------------------------------------------------===//
+// SourceLocation
+//===----------------------------------------------------------------------===//
+
 void SourceLocation::Emit(llvm::Serializer& S) const {
   S.EmitInt(getRawEncoding());  
 }
@@ -29,28 +46,31 @@
   return SourceLocation::getFromRawEncoding(D.ReadInt());   
 }
 
-void SourceLocation::dump(const SourceManager &SM) const {
+void SourceLocation::print(llvm::raw_ostream &OS, const SourceManager &SM)const{
   if (!isValid()) {
-    fprintf(stderr, "<invalid loc>");
+    OS << "<invalid loc>";
     return;
   }
   
   if (isFileID()) {
     PresumedLoc PLoc = SM.getPresumedLoc(*this);
-    
     // The instantiation and spelling pos is identical for file locs.
-    fprintf(stderr, "%s:%d:%d",
-            PLoc.getFilename(), PLoc.getLine(), PLoc.getColumn());
+    OS << PLoc.getFilename() << ':' << PLoc.getLine()
+       << ':' << PLoc.getColumn();
     return;
   }
   
-  SM.getInstantiationLoc(*this).dump(SM);
-  
-  fprintf(stderr, " <Spelling=");
-  SM.getSpellingLoc(*this).dump(SM);
-  fprintf(stderr, ">");
+  SM.getInstantiationLoc(*this).print(OS, SM);
+
+  OS << " <Spelling=";
+  SM.getSpellingLoc(*this).print(OS, SM);
+  OS << '>';
 }
 
+void SourceLocation::dump(const SourceManager &SM) const {
+  print(llvm::errs(), SM);
+  llvm::errs().flush();
+}
 
 void SourceRange::Emit(llvm::Serializer& S) const {
   B.Emit(S);
@@ -63,6 +83,10 @@
   return SourceRange(A,B);
 }
 
+//===----------------------------------------------------------------------===//
+// FullSourceLoc
+//===----------------------------------------------------------------------===//
+
 FileID FullSourceLoc::getFileID() const {
   assert(isValid());
   return SrcMgr->getFileID(*this);