diff options
author | Nico Weber <nicolasweber@gmx.de> | 2012-11-27 21:57:34 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2012-11-27 21:57:34 +0000 |
commit | f88836d949e42452167d312e57a1425b3859d36b (patch) | |
tree | 68333bacd57e78385b292274275071814a3ef201 /lib/Parse/ParseAST.cpp | |
parent | d1bac8d46740eb00085ec816af0829fd75fb4d5c (diff) |
Move PrettyStackTraceParserEntry to ParseAST.cpp
r128056 moved PrettyStackTraceParserEntry construction from Parser.h
to ParseAST.cpp, so there's no need to keep this class in a header.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseAST.cpp')
-rw-r--r-- | lib/Parse/ParseAST.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp index 7d68e1f37e..560febebc6 100644 --- a/lib/Parse/ParseAST.cpp +++ b/lib/Parse/ParseAST.cpp @@ -29,6 +29,40 @@ using namespace clang; +namespace { + +/// If a crash happens while the parser is active, an entry is printed for it. +class PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry { + const Parser &P; +public: + PrettyStackTraceParserEntry(const Parser &p) : P(p) {} + virtual void print(raw_ostream &OS) const; +}; + +/// If a crash happens while the parser is active, print out a line indicating +/// what the current token is. +void PrettyStackTraceParserEntry::print(raw_ostream &OS) const { + const Token &Tok = P.getCurToken(); + if (Tok.is(tok::eof)) { + OS << "<eof> parser at end of file\n"; + return; + } + + if (Tok.getLocation().isInvalid()) { + OS << "<unknown> parser at unknown location\n"; + return; + } + + const Preprocessor &PP = P.getPreprocessor(); + Tok.getLocation().print(OS, PP.getSourceManager()); + if (Tok.isAnnotation()) + OS << ": at annotation token \n"; + else + OS << ": current parser token '" << PP.getSpelling(Tok) << "'\n"; +} + +} // namespace + //===----------------------------------------------------------------------===// // Public interface to the file //===----------------------------------------------------------------------===// @@ -43,9 +77,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, CodeCompleteConsumer *CompletionConsumer, bool SkipFunctionBodies) { - OwningPtr<Sema> S(new Sema(PP, Ctx, *Consumer, - TUKind, - CompletionConsumer)); + OwningPtr<Sema> S(new Sema(PP, Ctx, *Consumer, TUKind, CompletionConsumer)); // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(S.get()); |