clang  6.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 
38 //===----------------------------------------------------------------------===//
39 // AST Consumer Actions
40 //===----------------------------------------------------------------------===//
41 
43 protected:
44  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
45  StringRef InFile) override;
46 };
47 
49 protected:
50  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
51  StringRef InFile) override;
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 
78  return TU_Prefix;
79  }
80 
81  bool hasASTFileSupport() const override { return false; }
82 
83  bool shouldEraseOutputFiles() override;
84 
85 public:
86  /// \brief Compute the AST consumer arguments that will be used to
87  /// create the PCHGenerator instance returned by CreateASTConsumer.
88  ///
89  /// \returns false if an error occurred, true otherwise.
90  static bool ComputeASTConsumerArguments(CompilerInstance &CI,
91  std::string &Sysroot);
92 
93  /// \brief Creates file to write the PCH into and returns a stream to write it
94  /// into. On error, returns null.
95  static std::unique_ptr<llvm::raw_pwrite_stream>
96  CreateOutputFile(CompilerInstance &CI, StringRef InFile,
97  std::string &OutputFile);
98 
99  bool BeginSourceFileAction(CompilerInstance &CI) override;
100 };
101 
103  virtual std::unique_ptr<raw_pwrite_stream>
104  CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
105 
106 protected:
107  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
108  StringRef InFile) override;
109 
111  return TU_Module;
112  }
113 
114  bool hasASTFileSupport() const override { return false; }
115 };
116 
118 private:
119  bool BeginSourceFileAction(CompilerInstance &CI) override;
120 
121  std::unique_ptr<raw_pwrite_stream>
122  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
123 };
124 
126 private:
127  bool BeginSourceFileAction(CompilerInstance &CI) override;
128 
129  std::unique_ptr<raw_pwrite_stream>
130  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
131 };
132 
134 protected:
135  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
136  StringRef InFile) override;
137 
138 public:
139  ~SyntaxOnlyAction() override;
140  bool hasCodeCompletionSupport() const override { return true; }
141 };
142 
143 /// \brief Dump information about the given module file, to be used for
144 /// basic debugging and discovery.
146 protected:
147  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
148  StringRef InFile) override;
149  bool BeginInvocation(CompilerInstance &CI) override;
150  void ExecuteAction() override;
151 
152 public:
153  bool hasPCHSupport() const override { return false; }
154  bool hasASTFileSupport() const override { return true; }
155  bool hasIRSupport() const override { return false; }
156  bool hasCodeCompletionSupport() const override { return false; }
157 };
158 
160 protected:
161  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
162  StringRef InFile) override;
163 
164  void ExecuteAction() override;
165 
166 public:
167  bool hasCodeCompletionSupport() const override { return false; }
168 };
169 
170 /**
171  * \brief Frontend action adaptor that merges ASTs together.
172  *
173  * This action takes an existing AST file and "merges" it into the AST
174  * context, producing a merged context. This action is an action
175  * adaptor, which forwards most of its calls to another action that
176  * will consume the merged context.
177  */
179  /// \brief The action that the merge action adapts.
180  std::unique_ptr<FrontendAction> AdaptedAction;
181 
182  /// \brief The set of AST files to merge.
183  std::vector<std::string> ASTFiles;
184 
185 protected:
186  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
187  StringRef InFile) override;
188 
189  bool BeginSourceFileAction(CompilerInstance &CI) override;
190 
191  void ExecuteAction() override;
192  void EndSourceFileAction() override;
193 
194 public:
195  ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
196  ArrayRef<std::string> ASTFiles);
197  ~ASTMergeAction() override;
198 
199  bool usesPreprocessorOnly() const override;
201  bool hasPCHSupport() const override;
202  bool hasASTFileSupport() const override;
203  bool hasCodeCompletionSupport() const override;
204 };
205 
207 protected:
208  void ExecuteAction() override;
209  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
210  StringRef) override {
211  return nullptr;
212  }
213 
214  bool usesPreprocessorOnly() const override { return true; }
215 };
216 
217 //===----------------------------------------------------------------------===//
218 // Preprocessor Actions
219 //===----------------------------------------------------------------------===//
220 
222 protected:
223  void ExecuteAction() override;
224 };
225 
227 protected:
228  void ExecuteAction() override;
229 };
230 
232 protected:
233  void ExecuteAction() override;
234 };
235 
237 protected:
238  void ExecuteAction() override;
239 };
240 
242 protected:
243  void ExecuteAction() override;
244 
245  bool hasPCHSupport() const override { return true; }
246 };
247 
248 } // end namespace clang
249 
250 #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:247
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.
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:242
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:249