]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendActions.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.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 //===----------------------------------------------------------------------===//
20 // Custom Consumer Actions
21 //===----------------------------------------------------------------------===//
22
23 class InitOnlyAction : public FrontendAction {
24   virtual void ExecuteAction();
25
26   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
27                                          llvm::StringRef InFile);
28
29 public:
30   // Don't claim to only use the preprocessor, we want to follow the AST path,
31   // but do nothing.
32   virtual bool usesPreprocessorOnly() const { return false; }
33 };
34
35 //===----------------------------------------------------------------------===//
36 // AST Consumer Actions
37 //===----------------------------------------------------------------------===//
38
39 class ASTPrintAction : public ASTFrontendAction {
40 protected:
41   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
42                                          llvm::StringRef InFile);
43 };
44
45 class ASTDumpAction : public ASTFrontendAction {
46 protected:
47   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
48                                          llvm::StringRef InFile);
49 };
50
51 class ASTDumpXMLAction : public ASTFrontendAction {
52 protected:
53   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
54                                          llvm::StringRef InFile);
55 };
56
57 class ASTViewAction : public ASTFrontendAction {
58 protected:
59   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
60                                          llvm::StringRef InFile);
61 };
62
63 class DeclContextPrintAction : public ASTFrontendAction {
64 protected:
65   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
66                                          llvm::StringRef InFile);
67 };
68
69 class GeneratePCHAction : public ASTFrontendAction {
70 protected:
71   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
72                                          llvm::StringRef InFile);
73
74   virtual bool usesCompleteTranslationUnit() { return false; }
75
76   virtual bool hasASTFileSupport() const { return false; }
77
78 public:
79   /// \brief Compute the AST consumer arguments that will be used to
80   /// create the PCHGenerator instance returned by CreateASTConsumer.
81   ///
82   /// \returns true if an error occurred, false otherwise.
83   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
84                                           llvm::StringRef InFile,
85                                           std::string &Sysroot,
86                                           std::string &OutputFile,
87                                           llvm::raw_ostream *&OS,
88                                           bool &Chaining);
89 };
90
91 class SyntaxOnlyAction : public ASTFrontendAction {
92 protected:
93   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
94                                          llvm::StringRef InFile);
95
96 public:
97   virtual bool hasCodeCompletionSupport() const { return true; }
98 };
99
100 /**
101  * \brief Frontend action adaptor that merges ASTs together.
102  *
103  * This action takes an existing AST file and "merges" it into the AST
104  * context, producing a merged context. This action is an action
105  * adaptor, which forwards most of its calls to another action that
106  * will consume the merged context.
107  */
108 class ASTMergeAction : public FrontendAction {
109   /// \brief The action that the merge action adapts.
110   FrontendAction *AdaptedAction;
111   
112   /// \brief The set of AST files to merge.
113   std::vector<std::string> ASTFiles;
114
115 protected:
116   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
117                                          llvm::StringRef InFile);
118
119   virtual bool BeginSourceFileAction(CompilerInstance &CI,
120                                      llvm::StringRef Filename);
121
122   virtual void ExecuteAction();
123   virtual void EndSourceFileAction();
124
125 public:
126   ASTMergeAction(FrontendAction *AdaptedAction,
127                  std::string *ASTFiles, unsigned NumASTFiles);
128   virtual ~ASTMergeAction();
129
130   virtual bool usesPreprocessorOnly() const;
131   virtual bool usesCompleteTranslationUnit();
132   virtual bool hasPCHSupport() const;
133   virtual bool hasASTFileSupport() const;
134   virtual bool hasCodeCompletionSupport() const;
135 };
136
137 class PrintPreambleAction : public FrontendAction {
138 protected:
139   void ExecuteAction();
140   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, llvm::StringRef) { 
141     return 0; 
142   }
143   
144   virtual bool usesPreprocessorOnly() const { return true; }
145 };
146   
147 //===----------------------------------------------------------------------===//
148 // Preprocessor Actions
149 //===----------------------------------------------------------------------===//
150
151 class DumpRawTokensAction : public PreprocessorFrontendAction {
152 protected:
153   void ExecuteAction();
154 };
155
156 class DumpTokensAction : public PreprocessorFrontendAction {
157 protected:
158   void ExecuteAction();
159 };
160
161 class GeneratePTHAction : public PreprocessorFrontendAction {
162 protected:
163   void ExecuteAction();
164 };
165
166 class PreprocessOnlyAction : public PreprocessorFrontendAction {
167 protected:
168   void ExecuteAction();
169 };
170
171 class PrintPreprocessedAction : public PreprocessorFrontendAction {
172 protected:
173   void ExecuteAction();
174
175   virtual bool hasPCHSupport() const { return true; }
176 };
177   
178 }  // end namespace clang
179
180 #endif