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 true if an error occurred, false otherwise.
90  static std::unique_ptr<raw_pwrite_stream>
91  ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
92  std::string &Sysroot, std::string &OutputFile);
93 
94  bool BeginSourceFileAction(CompilerInstance &CI) override;
95 };
96 
98  virtual std::unique_ptr<raw_pwrite_stream>
99  CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
100 
101 protected:
102  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
103  StringRef InFile) override;
104 
106  return TU_Module;
107  }
108 
109  bool hasASTFileSupport() const override { return false; }
110 };
111 
113 private:
114  bool BeginSourceFileAction(CompilerInstance &CI) override;
115 
116  std::unique_ptr<raw_pwrite_stream>
117  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
118 };
119 
121 private:
122  bool BeginSourceFileAction(CompilerInstance &CI) override;
123 
124  std::unique_ptr<raw_pwrite_stream>
125  CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
126 };
127 
129 protected:
130  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
131  StringRef InFile) override;
132 
133 public:
134  ~SyntaxOnlyAction() override;
135  bool hasCodeCompletionSupport() const override { return true; }
136 };
137 
138 /// \brief Dump information about the given module file, to be used for
139 /// basic debugging and discovery.
141 protected:
142  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
143  StringRef InFile) override;
144  bool BeginInvocation(CompilerInstance &CI) override;
145  void ExecuteAction() override;
146 
147 public:
148  bool hasPCHSupport() const override { return false; }
149  bool hasASTFileSupport() const override { return true; }
150  bool hasIRSupport() const override { return false; }
151  bool hasCodeCompletionSupport() const override { return false; }
152 };
153 
155 protected:
156  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
157  StringRef InFile) override;
158 
159  void ExecuteAction() override;
160 
161 public:
162  bool hasCodeCompletionSupport() const override { return false; }
163 };
164 
165 /**
166  * \brief Frontend action adaptor that merges ASTs together.
167  *
168  * This action takes an existing AST file and "merges" it into the AST
169  * context, producing a merged context. This action is an action
170  * adaptor, which forwards most of its calls to another action that
171  * will consume the merged context.
172  */
174  /// \brief The action that the merge action adapts.
175  std::unique_ptr<FrontendAction> AdaptedAction;
176 
177  /// \brief The set of AST files to merge.
178  std::vector<std::string> ASTFiles;
179 
180 protected:
181  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
182  StringRef InFile) override;
183 
184  bool BeginSourceFileAction(CompilerInstance &CI) override;
185 
186  void ExecuteAction() override;
187  void EndSourceFileAction() override;
188 
189 public:
190  ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
191  ArrayRef<std::string> ASTFiles);
192  ~ASTMergeAction() override;
193 
194  bool usesPreprocessorOnly() const override;
196  bool hasPCHSupport() const override;
197  bool hasASTFileSupport() const override;
198  bool hasCodeCompletionSupport() const override;
199 };
200 
202 protected:
203  void ExecuteAction() override;
204  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
205  StringRef) override {
206  return nullptr;
207  }
208 
209  bool usesPreprocessorOnly() const override { return true; }
210 };
211 
212 //===----------------------------------------------------------------------===//
213 // Preprocessor Actions
214 //===----------------------------------------------------------------------===//
215 
217 protected:
218  void ExecuteAction() override;
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  bool hasPCHSupport() const override { return true; }
241 };
242 
243 } // end namespace clang
244 
245 #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:246
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:241
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:248