25#include "llvm/Support/CrashRecoveryContext.h"
26#include "llvm/Support/TimeProfiler.h"
37class ResetStackCleanup
38 :
public llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup,
41 ResetStackCleanup(llvm::CrashRecoveryContext *Context,
const void *Top)
42 :
llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup, const void>(
44 void recoverResources()
override {
45 llvm::RestorePrettyStackState(resource);
50class PrettyStackTraceParserEntry :
public llvm::PrettyStackTraceEntry {
53 PrettyStackTraceParserEntry(
const Parser &p) :
P(p) {}
54 void print(raw_ostream &OS)
const override;
59void PrettyStackTraceParserEntry::print(raw_ostream &OS)
const {
60 const Token &Tok =
P.getCurToken();
61 if (Tok.
is(tok::eof)) {
62 OS <<
"<eof> parser at end of file\n";
67 OS <<
"<unknown> parser at unknown location\n";
74 OS <<
": at annotation token\n";
83 OS <<
": unknown current parser token\n";
86 OS <<
": current parser token '" << StringRef(Spelling, Length) <<
"'\n";
104 bool SkipFunctionBodies) {
106 std::unique_ptr<Sema> S(
107 new Sema(PP, Ctx, *Consumer, TUKind, CompletionConsumer));
110 llvm::CrashRecoveryContextCleanupRegistrar<Sema> CleanupSema(S.get());
112 ParseAST(*S.get(), PrintStats, SkipFunctionBodies);
123 bool OldCollectStats = PrintStats;
132 std::unique_ptr<Parser> ParseOP(
136 llvm::CrashRecoveryContextCleanupRegistrar<const void, ResetStackCleanup>
137 CleanupPrettyStack(llvm::SavePrettyStackState());
138 PrettyStackTraceParserEntry CrashInfo(
P);
141 llvm::CrashRecoveryContextCleanupRegistrar<Parser>
142 CleanupParser(ParseOP.get());
147 External->StartTranslationUnit(Consumer);
155 llvm::TimeTraceScope TimeScope(
"Frontend");
160 S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
162 for (
bool AtEOF =
P.ParseFirstTopLevelDecl(ADecl, ImportState); !AtEOF;
163 AtEOF =
P.ParseTopLevelDecl(ADecl, ImportState)) {
187 llvm::errs() <<
"\nSTATISTICS:\n";
188 if (HaveLexer)
P.getActions().PrintStats();
Defines the clang::ASTContext interface.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
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 ...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Abstract interface for a consumer of code-completion information.
Decl - This represents one declaration (or definition), e.g.
static void EnableStatistics()
RAII object that enters a new expression evaluation context.
Abstract interface for external sources of AST nodes.
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
SourceManager & getSourceManager() const
Sema - This implements semantic analysis and AST building for C.
Preprocessor & getPreprocessor() const
ASTContext & getASTContext() const
SmallVectorImpl< Decl * > & WeakTopLevelDecls()
WeakTopLevelDeclDecls - access to #pragma weak-generated Decls.
ASTConsumer & getASTConsumer() const
bool CollectStats
Flag indicating whether or not to collect detailed statistics.
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained).
ModuleImportState
An enumeration to represent the transition of states in parsing module fragments and imports.
void print(raw_ostream &OS, const SourceManager &SM) const
This class handles loading and caching of source files into memory.
static void EnableStatistics()
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
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 isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
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.
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
TranslationUnitKind
Describes the kind of translation unit being processed.
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
YAML serialization mapping.