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