clang: lib/Parse/ParseAST.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

24#include "llvm/Support/CrashRecoveryContext.h"

25#include "llvm/Support/TimeProfiler.h"

26#include

27#include

28

29using namespace clang;

30

31namespace {

32

33

34

35

36class ResetStackCleanup

37 : public llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup,

38 const void> {

39public:

40 ResetStackCleanup(llvm::CrashRecoveryContext *Context, const void *Top)

41 : llvm::CrashRecoveryContextCleanupBase<ResetStackCleanup, const void>(

42 Context, Top) {}

43 void recoverResources() override {

44 llvm::RestorePrettyStackState(resource);

45 }

46};

47

48

49class PrettyStackTraceParserEntry : public llvm::PrettyStackTraceEntry {

50 const Parser &P;

51public:

52 PrettyStackTraceParserEntry(const Parser &p) : P(p) {}

53 void print(raw_ostream &OS) const override;

54};

55

56

57

58void PrettyStackTraceParserEntry::print(raw_ostream &OS) const {

60 if (Tok.is(tok::eof)) {

61 OS << " parser at end of file\n";

62 return;

63 }

64

66 OS << " parser at unknown location\n";

67 return;

68 }

69

73 OS << ": at annotation token\n";

74 } else {

75

76

82 OS << ": unknown current parser token\n";

83 return;

84 }

85 OS << ": current parser token '" << StringRef(Spelling, Length) << "'\n";

86 }

87}

88

89}

90

91

92

93

94

95

96

97

98

103 bool SkipFunctionBodies) {

104

105 std::unique_ptr S(

106 new Sema(PP, Ctx, *Consumer, TUKind, CompletionConsumer));

107

108

109 llvm::CrashRecoveryContextCleanupRegistrar CleanupSema(S.get());

110

111 ParseAST(*S, PrintStats, SkipFunctionBodies);

112}

113

115

116 if (PrintStats) {

119 }

120

121

122 bool OldCollectStats = PrintStats;

124

125

126

128

130

131 std::unique_ptr ParseOP(

133 Parser &P = *ParseOP;

134

135 llvm::CrashRecoveryContextCleanupRegistrar<const void, ResetStackCleanup>

136 CleanupPrettyStack(llvm::SavePrettyStackState());

137 PrettyStackTraceParserEntry CrashInfo(P);

138

139

140 llvm::CrashRecoveryContextCleanupRegistrar

141 CleanupParser(ParseOP.get());

142

146 External->StartTranslationUnit(Consumer);

147

148

149

150

152

153 if (HaveLexer) {

154 llvm::TimeTraceScope TimeScope("Frontend", [&]() {

155 llvm::TimeTraceMetadata M;

156 if (llvm::isTimeTraceVerbose()) {

158 if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))

159 M.File = FE->tryGetRealPathName();

160 }

161 return M;

162 });

168

171

172

173

175 return;

176 }

177 }

178

179

182

184

185

186

187

188

189

191

193 if (PrintStats) {

194 llvm::errs() << "\nSTATISTICS:\n";

200 }

201}

Defines the clang::ASTContext interface.

static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, QualType Ty)

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.

Parser - This implements a parser for the C family of languages.

Preprocessor & getPreprocessor() const

Sema & getActions() const

bool ParseTopLevelDecl(DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState)

ParseTopLevelDecl - Parse one top-level declaration, return whatever the action tells us to.

OpaquePtr< DeclGroupRef > DeclGroupPtrTy

const Token & getCurToken() const

bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result, Sema::ModuleImportState &ImportState)

Parse the first top-level declaration in a translation unit.

void Initialize()

Initialize - Warm up the parser.

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).

SourceManager & getSourceManager() const

ModuleImportState

An enumeration to represent the transition of states in parsing module fragments and imports.

@ PotentiallyEvaluated

The current expression is potentially evaluated at run time, which means that code may be generated t...

void PrintStats() const

Print out statistics about the semantic analysis.

void print(raw_ostream &OS, const SourceManager &SM) const

This class handles loading and caching of source files into memory.

static void EnableStatistics()

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.

@ OS

Indicates that the tracking object is a descendant of a referenced-counted OSObject,...

The JSON file list parser is used to communicate input to InstallAPI.

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.

Definition ParseAST.cpp:99

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)