clang  3.9.0
Frontend/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 public:
84  /// \brief Compute the AST consumer arguments that will be used to
85  /// create the PCHGenerator instance returned by CreateASTConsumer.
86  ///
87  /// \returns true if an error occurred, false otherwise.
88  static std::unique_ptr<raw_pwrite_stream>
89  ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
90  std::string &Sysroot, std::string &OutputFile);
91 };
92 
95  const FileEntry *ModuleMapForUniquing;
96  bool IsSystem;
97 
98 protected:
99  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
100  StringRef InFile) override;
101 
103  return TU_Module;
104  }
105 
106  bool hasASTFileSupport() const override { return false; }
107 
108 public:
110  bool IsSystem = false)
111  : ASTFrontendAction(), ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem)
112  { }
113 
114  bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
115 
116  /// \brief Compute the AST consumer arguments that will be used to
117  /// create the PCHGenerator instance returned by CreateASTConsumer.
118  ///
119  /// \returns true if an error occurred, false otherwise.
120  std::unique_ptr<raw_pwrite_stream>
121  ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
122  std::string &Sysroot, std::string &OutputFile);
123 };
124 
126 protected:
127  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
128  StringRef InFile) override;
129 
130 public:
131  ~SyntaxOnlyAction() override;
132  bool hasCodeCompletionSupport() const override { return true; }
133 };
134 
135 /// \brief Dump information about the given module file, to be used for
136 /// basic debugging and discovery.
138 protected:
139  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
140  StringRef InFile) override;
141  void ExecuteAction() override;
142 
143 public:
144  bool hasPCHSupport() const override { return false; }
145  bool hasASTFileSupport() const override { return true; }
146  bool hasIRSupport() const override { return false; }
147  bool hasCodeCompletionSupport() const override { return false; }
148 };
149 
151 protected:
152  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
153  StringRef InFile) override;
154 
155  void ExecuteAction() override;
156 
157 public:
158  bool hasCodeCompletionSupport() const override { return false; }
159 };
160 
161 /**
162  * \brief Frontend action adaptor that merges ASTs together.
163  *
164  * This action takes an existing AST file and "merges" it into the AST
165  * context, producing a merged context. This action is an action
166  * adaptor, which forwards most of its calls to another action that
167  * will consume the merged context.
168  */
170  /// \brief The action that the merge action adapts.
171  std::unique_ptr<FrontendAction> AdaptedAction;
172 
173  /// \brief The set of AST files to merge.
174  std::vector<std::string> ASTFiles;
175 
176 protected:
177  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
178  StringRef InFile) override;
179 
181  StringRef Filename) override;
182 
183  void ExecuteAction() override;
184  void EndSourceFileAction() override;
185 
186 public:
187  ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
188  ArrayRef<std::string> ASTFiles);
189  ~ASTMergeAction() override;
190 
191  bool usesPreprocessorOnly() const override;
193  bool hasPCHSupport() const override;
194  bool hasASTFileSupport() const override;
195  bool hasCodeCompletionSupport() const override;
196 };
197 
199 protected:
200  void ExecuteAction() override;
201  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
202  StringRef) override {
203  return nullptr;
204  }
205 
206  bool usesPreprocessorOnly() const override { return true; }
207 };
208 
209 //===----------------------------------------------------------------------===//
210 // Preprocessor Actions
211 //===----------------------------------------------------------------------===//
212 
214 protected:
215  void ExecuteAction() override;
216 };
217 
219 protected:
220  void ExecuteAction() override;
221 };
222 
224 protected:
225  void ExecuteAction() override;
226 };
227 
229 protected:
230  void ExecuteAction() override;
231 };
232 
234 protected:
235  void ExecuteAction() override;
236 
237  bool hasPCHSupport() const override { return true; }
238 };
239 
240 } // end namespace clang
241 
242 #endif
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
bool hasPCHSupport() const override
Does this action support use with PCH?
Definition: ASTMerge.cpp:103
bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override
Callback at the start of processing a single input.
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override
Callback at the start of processing a single input.
Definition: ASTMerge.cpp:24
Dump information about the given module file, to be used for basic debugging and discovery.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Abstract base class for actions which can be performed by the frontend.
GenerateModuleAction(const FileEntry *ModuleMap=nullptr, bool IsSystem=false)
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:177
static std::unique_ptr< raw_pwrite_stream > ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Definition: ASTMerge.cpp:20
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
bool hasPCHSupport() const override
Does this action support use with PCH?
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
Definition: ASTMerge.cpp:95
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Describes a module or submodule.
Definition: Basic/Module.h:47
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
Definition: ASTMerge.cpp:111
bool hasIRSupport() const override
Does this action support use with IR files?
bool hasPCHSupport() const override
Does this action support use with PCH?
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
ASTMergeAction(std::unique_ptr< FrontendAction > AdaptedAction, ArrayRef< std::string > ASTFiles)
Definition: ASTMerge.cpp:86
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &, StringRef) override
Create the AST consumer object for this action, if supported.
StringRef Filename
Definition: Format.cpp:1194
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?
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Frontend action adaptor that merges ASTs together.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
~ASTMergeAction() override
Definition: ASTMerge.cpp:92
std::unique_ptr< raw_pwrite_stream > ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile)
Compute the AST consumer arguments that will be used to create the PCHGenerator instance returned by ...
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
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.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
bool hasASTFileSupport() const override
Does this action support use with AST files?
Definition: ASTMerge.cpp:107
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void EndSourceFileAction() override
Callback at the end of processing a single input.
Definition: ASTMerge.cpp:82
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Definition: ASTMerge.cpp:34
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:172
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
Definition: ASTMerge.cpp:99
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
The translation unit is a module.
Definition: LangOptions.h:179