Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Frontend/FrontendActions.h
Line
Count
Source (jump to first uncovered line)
1
//===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
10
#define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
11
12
#include "clang/Frontend/FrontendAction.h"
13
#include <string>
14
#include <vector>
15
16
namespace clang {
17
18
//===----------------------------------------------------------------------===//
19
// Custom Consumer Actions
20
//===----------------------------------------------------------------------===//
21
22
class InitOnlyAction : public FrontendAction {
23
  void ExecuteAction() override;
24
25
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
26
                                                 StringRef InFile) override;
27
28
public:
29
  // Don't claim to only use the preprocessor, we want to follow the AST path,
30
  // but do nothing.
31
0
  bool usesPreprocessorOnly() const override { return false; }
32
};
33
34
/// Preprocessor-based frontend action that also loads PCH files.
35
class ReadPCHAndPreprocessAction : public FrontendAction {
36
  void ExecuteAction() override;
37
38
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
39
                                                 StringRef InFile) override;
40
41
public:
42
164
  bool usesPreprocessorOnly() const override { return false; }
43
};
44
45
class DumpCompilerOptionsAction : public FrontendAction {
46
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
47
0
                                                 StringRef InFile) override {
48
0
    return nullptr;
49
0
  }
50
51
  void ExecuteAction() override;
52
53
public:
54
3
  bool usesPreprocessorOnly() const override { return true; }
55
};
56
57
//===----------------------------------------------------------------------===//
58
// AST Consumer Actions
59
//===----------------------------------------------------------------------===//
60
61
class ASTPrintAction : public ASTFrontendAction {
62
protected:
63
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
64
                                                 StringRef InFile) override;
65
};
66
67
class ASTDumpAction : public ASTFrontendAction {
68
protected:
69
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
70
                                                 StringRef InFile) override;
71
};
72
73
class ASTDeclListAction : public ASTFrontendAction {
74
protected:
75
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
76
                                                 StringRef InFile) override;
77
};
78
79
class ASTViewAction : public ASTFrontendAction {
80
protected:
81
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
82
                                                 StringRef InFile) override;
83
};
84
85
class GeneratePCHAction : public ASTFrontendAction {
86
protected:
87
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
88
                                                 StringRef InFile) override;
89
90
6.45k
  TranslationUnitKind getTranslationUnitKind() override {
91
6.45k
    return TU_Prefix;
92
6.45k
  }
93
94
0
  bool hasASTFileSupport() const override { return false; }
95
96
  bool shouldEraseOutputFiles() override;
97
98
public:
99
  /// Compute the AST consumer arguments that will be used to
100
  /// create the PCHGenerator instance returned by CreateASTConsumer.
101
  ///
102
  /// \returns false if an error occurred, true otherwise.
103
  static bool ComputeASTConsumerArguments(CompilerInstance &CI,
104
                                          std::string &Sysroot);
105
106
  /// Creates file to write the PCH into and returns a stream to write it
107
  /// into. On error, returns null.
108
  static std::unique_ptr<llvm::raw_pwrite_stream>
109
  CreateOutputFile(CompilerInstance &CI, StringRef InFile,
110
                   std::string &OutputFile);
111
112
  bool BeginSourceFileAction(CompilerInstance &CI) override;
113
};
114
115
class GenerateModuleAction : public ASTFrontendAction {
116
  virtual std::unique_ptr<raw_pwrite_stream>
117
  CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
118
119
protected:
120
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
121
                                                 StringRef InFile) override;
122
123
4.02k
  TranslationUnitKind getTranslationUnitKind() override {
124
4.02k
    return TU_Module;
125
4.02k
  }
126
127
0
  bool hasASTFileSupport() const override { return false; }
128
129
  bool shouldEraseOutputFiles() override;
130
};
131
132
class GenerateInterfaceStubsAction : public ASTFrontendAction {
133
protected:
134
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
135
                                                 StringRef InFile) override;
136
137
138
  TranslationUnitKind getTranslationUnitKind() override { return TU_Module; }
138
0
  bool hasASTFileSupport() const override { return false; }
139
};
140
141
class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
142
private:
143
  bool BeginSourceFileAction(CompilerInstance &CI) override;
144
145
  std::unique_ptr<raw_pwrite_stream>
146
  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
147
};
148
149
class GenerateModuleInterfaceAction : public GenerateModuleAction {
150
private:
151
  bool BeginSourceFileAction(CompilerInstance &CI) override;
152
153
  std::unique_ptr<raw_pwrite_stream>
154
  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
155
};
156
157
class GenerateHeaderModuleAction : public GenerateModuleAction {
158
  /// The synthesized module input buffer for the current compilation.
159
  std::unique_ptr<llvm::MemoryBuffer> Buffer;
160
  std::vector<std::string> ModuleHeaders;
161
162
private:
163
  bool PrepareToExecuteAction(CompilerInstance &CI) override;
164
  bool BeginSourceFileAction(CompilerInstance &CI) override;
165
166
  std::unique_ptr<raw_pwrite_stream>
167
  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
168
};
169
170
class SyntaxOnlyAction : public ASTFrontendAction {
171
protected:
172
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
173
                                                 StringRef InFile) override;
174
175
public:
176
  ~SyntaxOnlyAction() override;
177
12.5k
  bool hasCodeCompletionSupport() const override { return true; }
178
};
179
180
/// Dump information about the given module file, to be used for
181
/// basic debugging and discovery.
182
class DumpModuleInfoAction : public ASTFrontendAction {
183
protected:
184
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
185
                                                 StringRef InFile) override;
186
  bool BeginInvocation(CompilerInstance &CI) override;
187
  void ExecuteAction() override;
188
189
public:
190
0
  bool hasPCHSupport() const override { return false; }
191
7
  bool hasASTFileSupport() const override { return true; }
192
0
  bool hasIRSupport() const override { return false; }
193
0
  bool hasCodeCompletionSupport() const override { return false; }
194
};
195
196
class VerifyPCHAction : public ASTFrontendAction {
197
protected:
198
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
199
                                                 StringRef InFile) override;
200
201
  void ExecuteAction() override;
202
203
public:
204
0
  bool hasCodeCompletionSupport() const override { return false; }
205
};
206
207
class TemplightDumpAction : public ASTFrontendAction {
208
protected:
209
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
210
                                                 StringRef InFile) override;
211
212
  void ExecuteAction() override;
213
};
214
215
/**
216
 * Frontend action adaptor that merges ASTs together.
217
 *
218
 * This action takes an existing AST file and "merges" it into the AST
219
 * context, producing a merged context. This action is an action
220
 * adaptor, which forwards most of its calls to another action that
221
 * will consume the merged context.
222
 */
223
class ASTMergeAction : public FrontendAction {
224
  /// The action that the merge action adapts.
225
  std::unique_ptr<FrontendAction> AdaptedAction;
226
227
  /// The set of AST files to merge.
228
  std::vector<std::string> ASTFiles;
229
230
protected:
231
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
232
                                                 StringRef InFile) override;
233
234
  bool BeginSourceFileAction(CompilerInstance &CI) override;
235
236
  void ExecuteAction() override;
237
  void EndSourceFileAction() override;
238
239
public:
240
  ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
241
                 ArrayRef<std::string> ASTFiles);
242
  ~ASTMergeAction() override;
243
244
  bool usesPreprocessorOnly() const override;
245
  TranslationUnitKind getTranslationUnitKind() override;
246
  bool hasPCHSupport() const override;
247
  bool hasASTFileSupport() const override;
248
  bool hasCodeCompletionSupport() const override;
249
};
250
251
class PrintPreambleAction : public FrontendAction {
252
protected:
253
  void ExecuteAction() override;
254
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
255
0
                                                 StringRef) override {
256
0
    return nullptr;
257
0
  }
258
259
2
  bool usesPreprocessorOnly() const override { return true; }
260
};
261
262
class PrintDependencyDirectivesSourceMinimizerAction : public FrontendAction {
263
protected:
264
  void ExecuteAction() override;
265
  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
266
0
                                                 StringRef) override {
267
0
    return nullptr;
268
0
  }
269
270
8
  bool usesPreprocessorOnly() const override { return true; }
271
};
272
273
//===----------------------------------------------------------------------===//
274
// Preprocessor Actions
275
//===----------------------------------------------------------------------===//
276
277
class DumpRawTokensAction : public PreprocessorFrontendAction {
278
protected:
279
  void ExecuteAction() override;
280
};
281
282
class DumpTokensAction : public PreprocessorFrontendAction {
283
protected:
284
  void ExecuteAction() override;
285
};
286
287
class PreprocessOnlyAction : public PreprocessorFrontendAction {
288
protected:
289
  void ExecuteAction() override;
290
};
291
292
class PrintPreprocessedAction : public PreprocessorFrontendAction {
293
protected:
294
  void ExecuteAction() override;
295
296
0
  bool hasPCHSupport() const override { return true; }
297
};
298
299
class GetDependenciesByModuleNameAction : public PreprocessOnlyAction {
300
  StringRef ModuleName;
301
  void ExecuteAction() override;
302
303
public:
304
  GetDependenciesByModuleNameAction(StringRef ModuleName)
305
4
      : ModuleName(ModuleName) {}
306
};
307
308
}  // end namespace clang
309
310
#endif