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