]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendActions.h
MFV: r333077
[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 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
102 class GenerateModuleAction : public ASTFrontendAction {
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
110   TranslationUnitKind getTranslationUnitKind() override {
111     return TU_Module;
112   }
113
114   bool hasASTFileSupport() const override { return false; }
115 };
116
117 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
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
125 class GenerateModuleInterfaceAction : public GenerateModuleAction {
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
133 class SyntaxOnlyAction : public ASTFrontendAction {
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.
145 class DumpModuleInfoAction : public ASTFrontendAction {
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
159 class VerifyPCHAction : public ASTFrontendAction {
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  */
178 class ASTMergeAction : public FrontendAction {
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;
200   TranslationUnitKind getTranslationUnitKind() override;
201   bool hasPCHSupport() const override;
202   bool hasASTFileSupport() const override;
203   bool hasCodeCompletionSupport() const override;
204 };
205
206 class PrintPreambleAction : public FrontendAction {
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
221 class DumpRawTokensAction : public PreprocessorFrontendAction {
222 protected:
223   void ExecuteAction() override;
224 };
225
226 class DumpTokensAction : public PreprocessorFrontendAction {
227 protected:
228   void ExecuteAction() override;
229 };
230
231 class GeneratePTHAction : public PreprocessorFrontendAction {
232 protected:
233   void ExecuteAction() override;
234 };
235
236 class PreprocessOnlyAction : public PreprocessorFrontendAction {
237 protected:
238   void ExecuteAction() override;
239 };
240
241 class PrintPreprocessedAction : public PreprocessorFrontendAction {
242 protected:
243   void ExecuteAction() override;
244
245   bool hasPCHSupport() const override { return true; }
246 };
247   
248 }  // end namespace clang
249
250 #endif