]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendActions.h
Update to ELF Tool Chain snapshot at r3561
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / FrontendActions.h
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
13 #include "clang/Frontend/FrontendAction.h"
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
26 class InitOnlyAction : public FrontendAction {
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
42 class ASTPrintAction : public ASTFrontendAction {
43 protected:
44   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
45                                                  StringRef InFile) override;
46 };
47
48 class ASTDumpAction : public ASTFrontendAction {
49 protected:
50   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
51                                                  StringRef InFile) override;
52 };
53
54 class ASTDeclListAction : public ASTFrontendAction {
55 protected:
56   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
57                                                  StringRef InFile) override;
58 };
59
60 class ASTViewAction : public ASTFrontendAction {
61 protected:
62   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
63                                                  StringRef InFile) override;
64 };
65
66 class DeclContextPrintAction : public ASTFrontendAction {
67 protected:
68   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
69                                                  StringRef InFile) override;
70 };
71
72 class GeneratePCHAction : public ASTFrontendAction {
73 protected:
74   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
75                                                  StringRef InFile) override;
76
77   TranslationUnitKind getTranslationUnitKind() override {
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   bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
93 };
94
95 class GenerateModuleAction : public ASTFrontendAction {
96   virtual std::unique_ptr<raw_pwrite_stream>
97   CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
98
99 protected:
100   bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
101
102   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
103                                                  StringRef InFile) override;
104
105   TranslationUnitKind getTranslationUnitKind() override {
106     return TU_Module;
107   }
108
109   bool hasASTFileSupport() const override { return false; }
110 };
111
112 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
113   clang::Module *Module = nullptr;
114   const FileEntry *ModuleMapForUniquing = nullptr;
115   bool IsSystem = false;
116
117 private:
118   bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
119
120   std::unique_ptr<raw_pwrite_stream>
121   CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
122
123 public:
124   GenerateModuleFromModuleMapAction() {}
125   GenerateModuleFromModuleMapAction(const FileEntry *ModuleMap, bool IsSystem)
126       : ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem) {}
127 };
128
129 class GenerateModuleInterfaceAction : public GenerateModuleAction {
130 private:
131   bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
132
133   std::unique_ptr<raw_pwrite_stream>
134   CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
135 };
136
137 class SyntaxOnlyAction : public ASTFrontendAction {
138 protected:
139   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
140                                                  StringRef InFile) override;
141
142 public:
143   ~SyntaxOnlyAction() override;
144   bool hasCodeCompletionSupport() const override { return true; }
145 };
146
147 /// \brief Dump information about the given module file, to be used for
148 /// basic debugging and discovery.
149 class DumpModuleInfoAction : public ASTFrontendAction {
150 protected:
151   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
152                                                  StringRef InFile) override;
153   bool BeginInvocation(CompilerInstance &CI) override;
154   void ExecuteAction() override;
155
156 public:
157   bool hasPCHSupport() const override { return false; }
158   bool hasASTFileSupport() const override { return true; }
159   bool hasIRSupport() const override { return false; }
160   bool hasCodeCompletionSupport() const override { return false; }
161 };
162
163 class VerifyPCHAction : public ASTFrontendAction {
164 protected:
165   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
166                                                  StringRef InFile) override;
167
168   void ExecuteAction() override;
169
170 public:
171   bool hasCodeCompletionSupport() const override { return false; }
172 };
173
174 /**
175  * \brief Frontend action adaptor that merges ASTs together.
176  *
177  * This action takes an existing AST file and "merges" it into the AST
178  * context, producing a merged context. This action is an action
179  * adaptor, which forwards most of its calls to another action that
180  * will consume the merged context.
181  */
182 class ASTMergeAction : public FrontendAction {
183   /// \brief The action that the merge action adapts.
184   std::unique_ptr<FrontendAction> AdaptedAction;
185   
186   /// \brief The set of AST files to merge.
187   std::vector<std::string> ASTFiles;
188
189 protected:
190   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
191                                                  StringRef InFile) override;
192
193   bool BeginSourceFileAction(CompilerInstance &CI,
194                              StringRef Filename) override;
195
196   void ExecuteAction() override;
197   void EndSourceFileAction() override;
198
199 public:
200   ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
201                  ArrayRef<std::string> ASTFiles);
202   ~ASTMergeAction() override;
203
204   bool usesPreprocessorOnly() const override;
205   TranslationUnitKind getTranslationUnitKind() override;
206   bool hasPCHSupport() const override;
207   bool hasASTFileSupport() const override;
208   bool hasCodeCompletionSupport() const override;
209 };
210
211 class PrintPreambleAction : public FrontendAction {
212 protected:
213   void ExecuteAction() override;
214   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
215                                                  StringRef) override {
216     return nullptr;
217   }
218
219   bool usesPreprocessorOnly() const override { return true; }
220 };
221   
222 //===----------------------------------------------------------------------===//
223 // Preprocessor Actions
224 //===----------------------------------------------------------------------===//
225
226 class DumpRawTokensAction : public PreprocessorFrontendAction {
227 protected:
228   void ExecuteAction() override;
229 };
230
231 class DumpTokensAction : public PreprocessorFrontendAction {
232 protected:
233   void ExecuteAction() override;
234 };
235
236 class GeneratePTHAction : public PreprocessorFrontendAction {
237 protected:
238   void ExecuteAction() override;
239 };
240
241 class PreprocessOnlyAction : public PreprocessorFrontendAction {
242 protected:
243   void ExecuteAction() override;
244 };
245
246 class PrintPreprocessedAction : public PreprocessorFrontendAction {
247 protected:
248   void ExecuteAction() override;
249
250   bool hasPCHSupport() const override { return true; }
251 };
252   
253 }  // end namespace clang
254
255 #endif