summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceLocation.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-05 00:00:31 +0000
committerChris Lattner <sabre@nondot.org>2009-03-05 00:00:31 +0000
commitbd61a95481aebeaf8e9efec9a17ad5c4b6e6552a (patch)
treeda9bd083a1283bb584697b8fffc32658ff179372 /clang/lib/Basic/SourceLocation.cpp
parent00dfe3040939aea32f1edbfd5e33a1ca6777708d (diff)
downloadbcm5719-llvm-bd61a95481aebeaf8e9efec9a17ad5c4b6e6552a.tar.gz
bcm5719-llvm-bd61a95481aebeaf8e9efec9a17ad5c4b6e6552a.zip
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 llvm-svn: 66108
Diffstat (limited to 'clang/lib/Basic/SourceLocation.cpp')
-rw-r--r--clang/lib/Basic/SourceLocation.cpp46
1 files changed, 35 insertions, 11 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp
index 73e231adc8f..fd90b5a2ce9 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/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 @@ SourceLocation SourceLocation::ReadVal(llvm::Deserializer& D) {
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 @@ SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
return SourceRange(A,B);
}
+//===----------------------------------------------------------------------===//
+// FullSourceLoc
+//===----------------------------------------------------------------------===//
+
FileID FullSourceLoc::getFileID() const {
assert(isValid());
return SrcMgr->getFileID(*this);
OpenPOWER on IntegriCloud