Coverage Report

Created: 2018-07-20 23:04

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