25 #include "llvm/Support/CrashRecoveryContext.h"
29 using namespace clang;
36 class ResetStackCleanup
37 :
public llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup,
40 ResetStackCleanup(llvm::CrashRecoveryContext *
Context,
const void *Top)
41 : llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup, const void>(
43 void recoverResources()
override {
44 llvm::RestorePrettyStackState(resource);
49 class PrettyStackTraceParserEntry :
public llvm::PrettyStackTraceEntry {
52 PrettyStackTraceParserEntry(
const Parser &
p) :
P(p) {}
53 void print(raw_ostream &OS)
const override;
58 void PrettyStackTraceParserEntry::print(raw_ostream &OS)
const {
59 const Token &Tok =
P.getCurToken();
61 OS <<
"<eof> parser at end of file\n";
66 OS <<
"<unknown> parser at unknown location\n";
73 OS <<
": at annotation token\n";
82 OS <<
": unknown current parser token\n";
85 OS <<
": current parser token '" << StringRef(Spelling, Length) <<
"'\n";
103 bool SkipFunctionBodies) {
105 std::unique_ptr<Sema>
S(
106 new Sema(PP, Ctx, *Consumer, TUKind, CompletionConsumer));
109 llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(S.get());
111 ParseAST(*S.get(), PrintStats, SkipFunctionBodies);
118 Stmt::EnableStatistics();
122 bool OldCollectStats = PrintStats;
127 std::unique_ptr<Parser> ParseOP(
131 llvm::CrashRecoveryContextCleanupRegistrar<const void, ResetStackCleanup>
132 CleanupPrettyStack(llvm::SavePrettyStackState());
133 PrettyStackTraceParserEntry CrashInfo(P);
136 llvm::CrashRecoveryContextCleanupRegistrar<Parser>
137 CleanupParser(ParseOP.get());
153 P.
Diag(diag::ext_empty_translation_unit);
172 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
Decl - This represents one declaration (or definition), e.g.
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
static __inline__ uint32_t volatile uint32_t * p
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.
static void EnableStatistics()
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.