Coverage Report

Created: 2019-07-24 05:18

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