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