24 #include "llvm/Support/CrashRecoveryContext.h"
28 using namespace clang;
35 class ResetStackCleanup
36 :
public llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup,
39 ResetStackCleanup(llvm::CrashRecoveryContext *
Context,
const void *Top)
40 : llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup, const void>(
42 void recoverResources()
override {
43 llvm::RestorePrettyStackState(resource);
48 class PrettyStackTraceParserEntry :
public llvm::PrettyStackTraceEntry {
51 PrettyStackTraceParserEntry(
const Parser &p) :
P(p) {}
52 void print(raw_ostream &OS)
const override;
57 void PrettyStackTraceParserEntry::print(raw_ostream &OS)
const {
58 const Token &Tok =
P.getCurToken();
60 OS <<
"<eof> parser at end of file\n";
65 OS <<
"<unknown> parser at unknown location\n";
72 OS <<
": at annotation token\n";
81 OS <<
": unknown current parser token\n";
84 OS <<
": current parser token '" << StringRef(Spelling, Length) <<
"'\n";
102 bool SkipFunctionBodies) {
104 std::unique_ptr<Sema>
S(
105 new Sema(PP, Ctx, *Consumer, TUKind, CompletionConsumer));
108 llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(S.get());
110 ParseAST(*S.get(), PrintStats, SkipFunctionBodies);
116 Decl::EnableStatistics();
117 Stmt::EnableStatistics();
121 bool OldCollectStats = PrintStats;
126 std::unique_ptr<Parser> ParseOP(
130 llvm::CrashRecoveryContextCleanupRegistrar<const void, ResetStackCleanup>
131 CleanupPrettyStack(llvm::SavePrettyStackState());
132 PrettyStackTraceParserEntry CrashInfo(P);
135 llvm::CrashRecoveryContextCleanupRegistrar<Parser>
136 CleanupParser(ParseOP.get());
152 P.
Diag(diag::ext_empty_translation_unit);
171 llvm::errs() <<
"\nSTATISTICS:\n";
SourceManager & getSourceManager() const
Defines the clang::ASTContext interface.
SmallVectorImpl< Decl * > & WeakTopLevelDecls()
WeakTopLevelDeclDecls - access to #pragma weak-generated Decls.
void Initialize()
Initialize - Warm up the parser.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
const LangOptions & getLangOpts() const
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
virtual void PrintStats()
PrintStats - If desired, print any statistics.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Token - This structure provides full information about a lexed token.
Sema - This implements semantic analysis and AST building for C.
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Abstract interface for external sources of AST nodes.
void print(raw_ostream &OS, const SourceManager &SM) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
ASTContext & getASTContext() const
void ParseAST(Preprocessor &pp, ASTConsumer *C, ASTContext &Ctx, bool PrintStats=false, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr, bool SkipFunctionBodies=false)
Parse the entire file specified, notifying the ASTConsumer as the file is parsed. ...
ASTConsumer & getASTConsumer() const
bool CollectStats
Flag indicating whether or not to collect detailed statistics.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
bool ParseTopLevelDecl(DeclGroupPtrTy &Result)
ParseTopLevelDecl - Parse one top-level declaration.
Abstract interface for a consumer of code-completion information.
Sema & getActions() const
virtual void StartTranslationUnit(ASTConsumer *Consumer)
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
TranslationUnitKind
Describes the kind of translation unit being processed.
void PrintStats() const
Print out statistics about the semantic analysis.
unsigned getLength() const
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
This class handles loading and caching of source files into memory.
Preprocessor & getPreprocessor() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.