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 ASTViewAction : public ASTFrontendAction {
61 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
65 class DeclContextPrintAction : public ASTFrontendAction {
67 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
71 class GeneratePCHAction : public ASTFrontendAction {
73 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
76 virtual TranslationUnitKind getTranslationUnitKind() {
80 virtual bool hasASTFileSupport() const { return false; }
83 /// \brief Compute the AST consumer arguments that will be used to
84 /// create the PCHGenerator instance returned by CreateASTConsumer.
86 /// \returns true if an error occurred, false otherwise.
87 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
90 std::string &OutputFile,
94 class GenerateModuleAction : public ASTFrontendAction {
95 clang::Module *Module;
99 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
102 virtual TranslationUnitKind getTranslationUnitKind() {
106 virtual bool hasASTFileSupport() const { return false; }
109 explicit GenerateModuleAction(bool IsSystem = false)
110 : ASTFrontendAction(), IsSystem(IsSystem) { }
112 virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename);
114 /// \brief Compute the AST consumer arguments that will be used to
115 /// create the PCHGenerator instance returned by CreateASTConsumer.
117 /// \returns true if an error occurred, false otherwise.
118 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
120 std::string &Sysroot,
121 std::string &OutputFile,
125 class SyntaxOnlyAction : public ASTFrontendAction {
127 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
131 virtual bool hasCodeCompletionSupport() const { return true; }
134 /// \brief Dump information about the given module file, to be used for
135 /// basic debugging and discovery.
136 class DumpModuleInfoAction : public ASTFrontendAction {
138 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
140 virtual void ExecuteAction();
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; }
150 * \brief Frontend action adaptor that merges ASTs together.
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.
157 class ASTMergeAction : public FrontendAction {
158 /// \brief The action that the merge action adapts.
159 FrontendAction *AdaptedAction;
161 /// \brief The set of AST files to merge.
162 std::vector<std::string> ASTFiles;
165 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
168 virtual bool BeginSourceFileAction(CompilerInstance &CI,
171 virtual void ExecuteAction();
172 virtual void EndSourceFileAction();
175 ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
176 virtual ~ASTMergeAction();
178 virtual bool usesPreprocessorOnly() const;
179 virtual TranslationUnitKind getTranslationUnitKind();
180 virtual bool hasPCHSupport() const;
181 virtual bool hasASTFileSupport() const;
182 virtual bool hasCodeCompletionSupport() const;
185 class PrintPreambleAction : public FrontendAction {
187 void ExecuteAction();
188 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
192 virtual bool usesPreprocessorOnly() const { return true; }
195 //===----------------------------------------------------------------------===//
196 // Preprocessor Actions
197 //===----------------------------------------------------------------------===//
199 class DumpRawTokensAction : public PreprocessorFrontendAction {
201 void ExecuteAction();
204 class DumpTokensAction : public PreprocessorFrontendAction {
206 void ExecuteAction();
209 class GeneratePTHAction : public PreprocessorFrontendAction {
211 void ExecuteAction();
214 class PreprocessOnlyAction : public PreprocessorFrontendAction {
216 void ExecuteAction();
219 class PrintPreprocessedAction : public PreprocessorFrontendAction {
221 void ExecuteAction();
223 virtual bool hasPCHSupport() const { return true; }
226 } // end namespace clang