]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendActions.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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   
21 //===----------------------------------------------------------------------===//
22 // Custom Consumer Actions
23 //===----------------------------------------------------------------------===//
24
25 class InitOnlyAction : public FrontendAction {
26   virtual void ExecuteAction();
27
28   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
29                                          StringRef InFile);
30
31 public:
32   // Don't claim to only use the preprocessor, we want to follow the AST path,
33   // but do nothing.
34   virtual bool usesPreprocessorOnly() const { return false; }
35 };
36
37 //===----------------------------------------------------------------------===//
38 // AST Consumer Actions
39 //===----------------------------------------------------------------------===//
40
41 class ASTPrintAction : public ASTFrontendAction {
42 protected:
43   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
44                                          StringRef InFile);
45 };
46
47 class ASTDumpAction : public ASTFrontendAction {
48 protected:
49   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
50                                          StringRef InFile);
51 };
52
53 class ASTDeclListAction : public ASTFrontendAction {
54 protected:
55   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
56                                          StringRef InFile);
57 };
58
59 class ASTViewAction : public ASTFrontendAction {
60 protected:
61   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
62                                          StringRef InFile);
63 };
64
65 class DeclContextPrintAction : public ASTFrontendAction {
66 protected:
67   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
68                                          StringRef InFile);
69 };
70
71 class GeneratePCHAction : public ASTFrontendAction {
72 protected:
73   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
74                                          StringRef InFile);
75
76   virtual TranslationUnitKind getTranslationUnitKind() {
77     return TU_Prefix;
78   }
79
80   virtual bool hasASTFileSupport() const { return false; }
81
82 public:
83   /// \brief Compute the AST consumer arguments that will be used to
84   /// create the PCHGenerator instance returned by CreateASTConsumer.
85   ///
86   /// \returns true if an error occurred, false otherwise.
87   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
88                                           StringRef InFile,
89                                           std::string &Sysroot,
90                                           std::string &OutputFile,
91                                           raw_ostream *&OS);
92 };
93
94 class GenerateModuleAction : public ASTFrontendAction {
95   clang::Module *Module;
96   bool IsSystem;
97   
98 protected:
99   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
100                                          StringRef InFile);
101   
102   virtual TranslationUnitKind getTranslationUnitKind() { 
103     return TU_Module;
104   }
105   
106   virtual bool hasASTFileSupport() const { return false; }
107   
108 public:
109   explicit GenerateModuleAction(bool IsSystem = false)
110     : ASTFrontendAction(), IsSystem(IsSystem) { }
111
112   virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename);
113   
114   /// \brief Compute the AST consumer arguments that will be used to
115   /// create the PCHGenerator instance returned by CreateASTConsumer.
116   ///
117   /// \returns true if an error occurred, false otherwise.
118   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
119                                           StringRef InFile,
120                                           std::string &Sysroot,
121                                           std::string &OutputFile,
122                                           raw_ostream *&OS);
123 };
124
125 class SyntaxOnlyAction : public ASTFrontendAction {
126 protected:
127   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
128                                          StringRef InFile);
129
130 public:
131   virtual bool hasCodeCompletionSupport() const { return true; }
132 };
133
134 /// \brief Dump information about the given module file, to be used for
135 /// basic debugging and discovery.
136 class DumpModuleInfoAction : public ASTFrontendAction {
137 protected:
138   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
139                                          StringRef InFile);
140   virtual void ExecuteAction();
141   
142 public:
143   virtual bool hasPCHSupport() const { return false; }
144   virtual bool hasASTFileSupport() const { return true; }
145   virtual bool hasIRSupport() const { return false; }
146   virtual bool hasCodeCompletionSupport() const { return false; }
147 };
148
149 /**
150  * \brief Frontend action adaptor that merges ASTs together.
151  *
152  * This action takes an existing AST file and "merges" it into the AST
153  * context, producing a merged context. This action is an action
154  * adaptor, which forwards most of its calls to another action that
155  * will consume the merged context.
156  */
157 class ASTMergeAction : public FrontendAction {
158   /// \brief The action that the merge action adapts.
159   FrontendAction *AdaptedAction;
160   
161   /// \brief The set of AST files to merge.
162   std::vector<std::string> ASTFiles;
163
164 protected:
165   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
166                                          StringRef InFile);
167
168   virtual bool BeginSourceFileAction(CompilerInstance &CI,
169                                      StringRef Filename);
170
171   virtual void ExecuteAction();
172   virtual void EndSourceFileAction();
173
174 public:
175   ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
176   virtual ~ASTMergeAction();
177
178   virtual bool usesPreprocessorOnly() const;
179   virtual TranslationUnitKind getTranslationUnitKind();
180   virtual bool hasPCHSupport() const;
181   virtual bool hasASTFileSupport() const;
182   virtual bool hasCodeCompletionSupport() const;
183 };
184
185 class PrintPreambleAction : public FrontendAction {
186 protected:
187   void ExecuteAction();
188   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) { 
189     return 0; 
190   }
191   
192   virtual bool usesPreprocessorOnly() const { return true; }
193 };
194   
195 //===----------------------------------------------------------------------===//
196 // Preprocessor Actions
197 //===----------------------------------------------------------------------===//
198
199 class DumpRawTokensAction : public PreprocessorFrontendAction {
200 protected:
201   void ExecuteAction();
202 };
203
204 class DumpTokensAction : public PreprocessorFrontendAction {
205 protected:
206   void ExecuteAction();
207 };
208
209 class GeneratePTHAction : public PreprocessorFrontendAction {
210 protected:
211   void ExecuteAction();
212 };
213
214 class PreprocessOnlyAction : public PreprocessorFrontendAction {
215 protected:
216   void ExecuteAction();
217 };
218
219 class PrintPreprocessedAction : public PreprocessorFrontendAction {
220 protected:
221   void ExecuteAction();
222
223   virtual bool hasPCHSupport() const { return true; }
224 };
225   
226 }  // end namespace clang
227
228 #endif