clang  8.0.0svn
FrontendActions.h
Go to the documentation of this file.
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 
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 
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  bool usesPreprocessorOnly() const override { return false; }
36 };
37 
39  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
40  StringRef InFile) override {
41  return nullptr;
42  }
43 
44  void ExecuteAction() override;
45 
46 public:
47  bool usesPreprocessorOnly() const override { return true; }
48 };
49 
50 //===----------------------------------------------------------------------===//
51 // AST Consumer Actions
52 //===----------------------------------------------------------------------===//
53 
55 protected:
56  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
57  StringRef InFile) override;
58 };
59 
61 protected:
62  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
63  StringRef InFile) override;
64 };
65 
67 protected:
68  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
69  StringRef InFile) override;
70 };
71 
73 protected:
74  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
75  StringRef InFile) override;
76 };
77 
79 protected:
80  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
81  StringRef InFile) override;
82 };
83 
85 protected:
86  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
87  StringRef InFile) override;
88 
90  return TU_Prefix;
91  }
92 
93  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 
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 
123  return TU_Module;
124  }
125 
126  bool hasASTFileSupport() const override { return false; }
127 };
128 
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 
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 
146  /// The synthesized module input buffer for the current compilation.
147  std::unique_ptr<llvm::MemoryBuffer> Buffer;
148  std::vector<std::string> ModuleHeaders;
149 
150 private:
151  bool PrepareToExecuteAction(CompilerInstance &CI) override;
152  bool BeginSourceFileAction(CompilerInstance &CI) override;
153 
154  std::unique_ptr<raw_pwrite_stream>
155  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
156 };
157 
159 protected:
160  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
161  StringRef InFile) override;
162 
163 public:
164  ~SyntaxOnlyAction() override;
165  bool hasCodeCompletionSupport() const override { return true; }
166 };
167 
168 /// Dump information about the given module file, to be used for
169 /// basic debugging and discovery.
171 protected:
172  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
173  StringRef InFile) override;
174  bool BeginInvocation(CompilerInstance &CI) override;
175  void ExecuteAction() override;
176 
177 public:
178  bool hasPCHSupport() const override { return false; }
179  bool hasASTFileSupport() const override { return true; }
180  bool hasIRSupport() const override { return false; }
181  bool hasCodeCompletionSupport() const override { return false; }
182 };
183 
185 protected:
186  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
187  StringRef InFile) override;
188 
189  void ExecuteAction() override;
190 
191 public:
192  bool hasCodeCompletionSupport() const override { return false; }
193 };
194 
196 protected:
197  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
198  StringRef InFile) override;
199 
200  void ExecuteAction() override;
201 };
202 
203 /**
204  * Frontend action adaptor that merges ASTs together.
205  *
206  * This action takes an existing AST file and "merges" it into the AST
207  * context, producing a merged context. This action is an action
208  * adaptor, which forwards most of its calls to another action that
209  * will consume the merged context.
210  */
212  /// The action that the merge action adapts.
213  std::unique_ptr<FrontendAction> AdaptedAction;
214 
215  /// The set of AST files to merge.
216  std::vector<std::string> ASTFiles;
217 
218 protected:
219  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
220  StringRef InFile) override;
221 
222  bool BeginSourceFileAction(CompilerInstance &CI) override;
223 
224  void ExecuteAction() override;
225  void EndSourceFileAction() override;
226 
227 public:
228  ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
229  ArrayRef<std::string> ASTFiles);
230  ~ASTMergeAction() override;
231 
232  bool usesPreprocessorOnly() const override;
234  bool hasPCHSupport() const override;
235  bool hasASTFileSupport() const override;
236  bool hasCodeCompletionSupport() const override;
237 };
238 
240 protected:
241  void ExecuteAction() override;
242  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
243  StringRef) override {
244  return nullptr;
245  }
246 
247  bool usesPreprocessorOnly() const override { return true; }
248 };
249 
250 //===----------------------------------------------------------------------===//
251 // Preprocessor Actions
252 //===----------------------------------------------------------------------===//
253 
255 protected:
256  void ExecuteAction() override;
257 };
258 
260 protected:
261  void ExecuteAction() override;
262 };
263 
265 protected:
266  void ExecuteAction() override;
267 };
268 
270 protected:
271  void ExecuteAction() override;
272 };
273 
275 protected:
276  void ExecuteAction() override;
277 
278  bool hasPCHSupport() const override { return true; }
279 };
280 
281 } // end namespace clang
282 
283 #endif
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
Dump information about the given module file, to be used for basic debugging and discovery.
Abstract base class for actions which can be performed by the frontend.
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:335
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we&#39;re handling.
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
bool hasPCHSupport() const override
Does this action support use with PCH?
friend class ASTMergeAction
bool hasIRSupport() const override
Does this action support use with IR files?
bool hasPCHSupport() const override
Does this action support use with PCH?
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &, StringRef) override
Create the AST consumer object for this action, if supported.
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
bool hasASTFileSupport() const override
Does this action support use with AST files?
bool hasASTFileSupport() const override
Does this action support use with AST files?
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
virtual bool hasPCHSupport() const
Does this action support use with PCH?
Frontend action adaptor that merges ASTs together.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we&#39;re handling.
bool hasASTFileSupport() const override
Does this action support use with AST files?
Abstract base class to use for AST consumer-based frontend actions.
virtual bool PrepareToExecuteAction(CompilerInstance &CI)
Prepare to execute the action on the given CompilerInstance.
Abstract base class to use for preprocessor-based frontend actions.
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we&#39;re handling.
Dataflow Directional Tag Classes.
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:329
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
The translation unit is a module.
Definition: LangOptions.h:338