1 //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
11 #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
13 #include "clang/Frontend/FrontendAction.h"
21 //===----------------------------------------------------------------------===//
22 // Custom Consumer Actions
23 //===----------------------------------------------------------------------===//
25 class InitOnlyAction : public FrontendAction {
26 virtual void ExecuteAction();
28 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
32 // Don't claim to only use the preprocessor, we want to follow the AST path,
34 virtual bool usesPreprocessorOnly() const { return false; }
37 //===----------------------------------------------------------------------===//
38 // AST Consumer Actions
39 //===----------------------------------------------------------------------===//
41 class ASTPrintAction : public ASTFrontendAction {
43 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
47 class ASTDumpAction : public ASTFrontendAction {
49 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
53 class ASTDeclListAction : public ASTFrontendAction {
55 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
59 class ASTDumpXMLAction : public ASTFrontendAction {
61 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
65 class ASTViewAction : public ASTFrontendAction {
67 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
71 class DeclContextPrintAction : public ASTFrontendAction {
73 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
77 class GeneratePCHAction : public ASTFrontendAction {
79 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
82 virtual TranslationUnitKind getTranslationUnitKind() {
86 virtual bool hasASTFileSupport() const { return false; }
89 /// \brief Compute the AST consumer arguments that will be used to
90 /// create the PCHGenerator instance returned by CreateASTConsumer.
92 /// \returns true if an error occurred, false otherwise.
93 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
96 std::string &OutputFile,
100 class GenerateModuleAction : public ASTFrontendAction {
101 clang::Module *Module;
104 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
107 virtual TranslationUnitKind getTranslationUnitKind() {
111 virtual bool hasASTFileSupport() const { return false; }
114 virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename);
116 /// \brief Compute the AST consumer arguments that will be used to
117 /// create the PCHGenerator instance returned by CreateASTConsumer.
119 /// \returns true if an error occurred, false otherwise.
120 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
122 std::string &Sysroot,
123 std::string &OutputFile,
127 class SyntaxOnlyAction : public ASTFrontendAction {
129 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
133 virtual bool hasCodeCompletionSupport() const { return true; }
136 /// \brief Dump information about the given module file, to be used for
137 /// basic debugging and discovery.
138 class DumpModuleInfoAction : public ASTFrontendAction {
140 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
142 virtual void ExecuteAction();
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; }
152 * \brief Frontend action adaptor that merges ASTs together.
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.
159 class ASTMergeAction : public FrontendAction {
160 /// \brief The action that the merge action adapts.
161 FrontendAction *AdaptedAction;
163 /// \brief The set of AST files to merge.
164 std::vector<std::string> ASTFiles;
167 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
170 virtual bool BeginSourceFileAction(CompilerInstance &CI,
173 virtual void ExecuteAction();
174 virtual void EndSourceFileAction();
177 ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
178 virtual ~ASTMergeAction();
180 virtual bool usesPreprocessorOnly() const;
181 virtual TranslationUnitKind getTranslationUnitKind();
182 virtual bool hasPCHSupport() const;
183 virtual bool hasASTFileSupport() const;
184 virtual bool hasCodeCompletionSupport() const;
187 class PrintPreambleAction : public FrontendAction {
189 void ExecuteAction();
190 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
194 virtual bool usesPreprocessorOnly() const { return true; }
197 //===----------------------------------------------------------------------===//
198 // Preprocessor Actions
199 //===----------------------------------------------------------------------===//
201 class DumpRawTokensAction : public PreprocessorFrontendAction {
203 void ExecuteAction();
206 class DumpTokensAction : public PreprocessorFrontendAction {
208 void ExecuteAction();
211 class GeneratePTHAction : public PreprocessorFrontendAction {
213 void ExecuteAction();
216 class PreprocessOnlyAction : public PreprocessorFrontendAction {
218 void ExecuteAction();
221 class PrintPreprocessedAction : public PreprocessorFrontendAction {
223 void ExecuteAction();
225 virtual bool hasPCHSupport() const { return true; }
228 } // end namespace clang