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"
19 //===----------------------------------------------------------------------===//
20 // Custom Consumer Actions
21 //===----------------------------------------------------------------------===//
23 class InitOnlyAction : public FrontendAction {
24 virtual void ExecuteAction();
26 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
30 // Don't claim to only use the preprocessor, we want to follow the AST path,
32 virtual bool usesPreprocessorOnly() const { return false; }
35 //===----------------------------------------------------------------------===//
36 // AST Consumer Actions
37 //===----------------------------------------------------------------------===//
39 class ASTPrintAction : public ASTFrontendAction {
41 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
45 class ASTDumpAction : public ASTFrontendAction {
47 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
51 class ASTDumpXMLAction : public ASTFrontendAction {
53 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
57 class ASTViewAction : public ASTFrontendAction {
59 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
63 class DeclContextPrintAction : public ASTFrontendAction {
65 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
69 class GeneratePCHAction : public ASTFrontendAction {
73 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
76 virtual TranslationUnitKind getTranslationUnitKind() {
77 return MakeModule? TU_Module : TU_Prefix;
80 virtual bool hasASTFileSupport() const { return false; }
83 /// \brief Create a new action
84 explicit GeneratePCHAction(bool MakeModule) : MakeModule(MakeModule) { }
86 /// \brief Compute the AST consumer arguments that will be used to
87 /// create the PCHGenerator instance returned by CreateASTConsumer.
89 /// \returns true if an error occurred, false otherwise.
90 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
93 std::string &OutputFile,
97 class SyntaxOnlyAction : public ASTFrontendAction {
99 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
103 virtual bool hasCodeCompletionSupport() const { return true; }
107 * \brief Frontend action adaptor that merges ASTs together.
109 * This action takes an existing AST file and "merges" it into the AST
110 * context, producing a merged context. This action is an action
111 * adaptor, which forwards most of its calls to another action that
112 * will consume the merged context.
114 class ASTMergeAction : public FrontendAction {
115 /// \brief The action that the merge action adapts.
116 FrontendAction *AdaptedAction;
118 /// \brief The set of AST files to merge.
119 std::vector<std::string> ASTFiles;
122 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
125 virtual bool BeginSourceFileAction(CompilerInstance &CI,
128 virtual void ExecuteAction();
129 virtual void EndSourceFileAction();
132 ASTMergeAction(FrontendAction *AdaptedAction,
133 std::string *ASTFiles, unsigned NumASTFiles);
134 virtual ~ASTMergeAction();
136 virtual bool usesPreprocessorOnly() const;
137 virtual TranslationUnitKind getTranslationUnitKind();
138 virtual bool hasPCHSupport() const;
139 virtual bool hasASTFileSupport() const;
140 virtual bool hasCodeCompletionSupport() const;
143 class PrintPreambleAction : public FrontendAction {
145 void ExecuteAction();
146 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
150 virtual bool usesPreprocessorOnly() const { return true; }
153 //===----------------------------------------------------------------------===//
154 // Preprocessor Actions
155 //===----------------------------------------------------------------------===//
157 class DumpRawTokensAction : public PreprocessorFrontendAction {
159 void ExecuteAction();
162 class DumpTokensAction : public PreprocessorFrontendAction {
164 void ExecuteAction();
167 class GeneratePTHAction : public PreprocessorFrontendAction {
169 void ExecuteAction();
172 class PreprocessOnlyAction : public PreprocessorFrontendAction {
174 void ExecuteAction();
177 class PrintPreprocessedAction : public PreprocessorFrontendAction {
179 void ExecuteAction();
181 virtual bool hasPCHSupport() const { return true; }
184 } // end namespace clang