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