clang  7.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 protected:
147  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
148  StringRef InFile) override;
149 
150 public:
151  ~SyntaxOnlyAction() override;
152  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.
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  bool hasPCHSupport() const override { return false; }
166  bool hasASTFileSupport() const override { return true; }
167  bool hasIRSupport() const override { return false; }
168  bool hasCodeCompletionSupport() const override { return false; }
169 };
170 
172 protected:
173  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
174  StringRef InFile) override;
175 
176  void ExecuteAction() override;
177 
178 public:
179  bool hasCodeCompletionSupport() const override { return false; }
180 };
181 
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  */
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;
221  bool hasPCHSupport() const override;
222  bool hasASTFileSupport() const override;
223  bool hasCodeCompletionSupport() const override;
224 };
225 
227 protected:
228  void ExecuteAction() override;
229  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
230  StringRef) override {
231  return nullptr;
232  }
233 
234  bool usesPreprocessorOnly() const override { return true; }
235 };
236 
237 //===----------------------------------------------------------------------===//
238 // Preprocessor Actions
239 //===----------------------------------------------------------------------===//
240 
242 protected:
243  void ExecuteAction() override;
244 };
245 
247 protected:
248  void ExecuteAction() override;
249 };
250 
252 protected:
253  void ExecuteAction() override;
254 };
255 
257 protected:
258  void ExecuteAction() override;
259 };
260 
262 protected:
263  void ExecuteAction() override;
264 
265  bool hasPCHSupport() const override { return true; }
266 };
267 
268 } // end namespace clang
269 
270 #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:307
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.
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:301
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:310