aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-05 07:24:28 +0000
committerChris Lattner <sabre@nondot.org>2009-03-05 07:24:28 +0000
commit0102c30896c83f70cf6b6519fd5c674cb981c0b5 (patch)
treeedcb5708d29d96daee1d2a29cf94b5cdd7aec501 /lib/Parse/Parser.cpp
parent741e73efbf2ef0b7187358e5f62d79ebd78d21e0 (diff)
When the parser is live, print out the location and spelling of its current token.
For example: Stack dump: 0. Program arguments: clang t.cpp 1. t.cpp:4:8: current parser token: ';' 2. t.cpp:3:1: parsing struct/union/class body 'x' Abort It is weird that the parser is always "underneath" any parse context actions, but the parser is created first. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp38
1 files changed, 16 insertions, 22 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 3cdaab6e88..70a336678c 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -15,12 +15,13 @@
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Scope.h"
+#include "llvm/Support/raw_ostream.h"
#include "ExtensionRAIIObject.h"
#include "ParsePragma.h"
using namespace clang;
Parser::Parser(Preprocessor &pp, Action &actions)
- : PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
+ : CrashInfo(*this), PP(pp), Actions(actions), Diags(PP.getDiagnostics()),
GreaterThanIsOperator(true) {
Tok.setKind(tok::eof);
CurScope = 0;
@@ -38,30 +39,23 @@ Parser::Parser(Preprocessor &pp, Action &actions)
PushTopClassStack();
}
-/// Out-of-line virtual destructor to provide home for Action class.
-ActionBase::~ActionBase() {}
-
-/// Out-of-line virtual destructor to provide home for Action class.
-Action::~Action() {}
-
-// Defined out-of-line here because of dependecy on AttributeList
-Action::DeclTy *Action::ActOnUsingDirective(Scope *CurScope,
- SourceLocation UsingLoc,
- SourceLocation NamespcLoc,
- const CXXScopeSpec &SS,
- SourceLocation IdentLoc,
- IdentifierInfo *NamespcName,
- AttributeList *AttrList) {
-
- // FIXME: Parser seems to assume that Action::ActOn* takes ownership over
- // passed AttributeList, however other actions don't free it, is it
- // temporary state or bug?
- delete AttrList;
- return 0;
+/// If a crash happens while the parser is active, print out a line indicating
+/// what the current token is.
+void PrettyStackTraceParserEntry::print(llvm::raw_ostream &OS) const {
+ const Token &Tok = P.getCurToken();
+ if (Tok.getLocation().isInvalid()) {
+ OS << "<eof> parser at end of file\n";
+ return;
+ }
+
+ const Preprocessor &PP = P.getPreprocessor();
+ Tok.getLocation().print(OS, PP.getSourceManager());
+ OS << ": current parser token '" << PP.getSpelling(Tok) << "'\n";
}
+
DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {
- return Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID);
+ return Diags.Report(FullSourceLoc(Loc, PP.getSourceManager()), DiagID);
}
DiagnosticBuilder Parser::Diag(const Token &Tok, unsigned DiagID) {