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"
22 //===----------------------------------------------------------------------===//
23 // Custom Consumer Actions
24 //===----------------------------------------------------------------------===//
26 class InitOnlyAction : public FrontendAction {
27 void ExecuteAction() override;
29 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
30 StringRef InFile) override;
33 // Don't claim to only use the preprocessor, we want to follow the AST path,
35 bool usesPreprocessorOnly() const override { return false; }
38 //===----------------------------------------------------------------------===//
39 // AST Consumer Actions
40 //===----------------------------------------------------------------------===//
42 class ASTPrintAction : public ASTFrontendAction {
44 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
45 StringRef InFile) override;
48 class ASTDumpAction : public ASTFrontendAction {
50 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
51 StringRef InFile) override;
54 class ASTDeclListAction : public ASTFrontendAction {
56 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
57 StringRef InFile) override;
60 class ASTViewAction : public ASTFrontendAction {
62 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
63 StringRef InFile) override;
66 class DeclContextPrintAction : public ASTFrontendAction {
68 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
69 StringRef InFile) override;
72 class GeneratePCHAction : public ASTFrontendAction {
74 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
75 StringRef InFile) override;
77 TranslationUnitKind getTranslationUnitKind() override {
81 bool hasASTFileSupport() const override { return false; }
83 bool shouldEraseOutputFiles() override;
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 std::unique_ptr<raw_pwrite_stream>
91 ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
92 std::string &Sysroot, std::string &OutputFile);
94 bool BeginSourceFileAction(CompilerInstance &CI) override;
97 class GenerateModuleAction : public ASTFrontendAction {
98 virtual std::unique_ptr<raw_pwrite_stream>
99 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
102 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
103 StringRef InFile) override;
105 TranslationUnitKind getTranslationUnitKind() override {
109 bool hasASTFileSupport() const override { return false; }
112 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
114 bool BeginSourceFileAction(CompilerInstance &CI) override;
116 std::unique_ptr<raw_pwrite_stream>
117 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
120 class GenerateModuleInterfaceAction : public GenerateModuleAction {
122 bool BeginSourceFileAction(CompilerInstance &CI) override;
124 std::unique_ptr<raw_pwrite_stream>
125 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
128 class SyntaxOnlyAction : public ASTFrontendAction {
130 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
131 StringRef InFile) override;
134 ~SyntaxOnlyAction() override;
135 bool hasCodeCompletionSupport() const override { return true; }
138 /// \brief Dump information about the given module file, to be used for
139 /// basic debugging and discovery.
140 class DumpModuleInfoAction : public ASTFrontendAction {
142 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
143 StringRef InFile) override;
144 bool BeginInvocation(CompilerInstance &CI) override;
145 void ExecuteAction() override;
148 bool hasPCHSupport() const override { return false; }
149 bool hasASTFileSupport() const override { return true; }
150 bool hasIRSupport() const override { return false; }
151 bool hasCodeCompletionSupport() const override { return false; }
154 class VerifyPCHAction : public ASTFrontendAction {
156 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
157 StringRef InFile) override;
159 void ExecuteAction() override;
162 bool hasCodeCompletionSupport() const override { return false; }
166 * \brief Frontend action adaptor that merges ASTs together.
168 * This action takes an existing AST file and "merges" it into the AST
169 * context, producing a merged context. This action is an action
170 * adaptor, which forwards most of its calls to another action that
171 * will consume the merged context.
173 class ASTMergeAction : public FrontendAction {
174 /// \brief The action that the merge action adapts.
175 std::unique_ptr<FrontendAction> AdaptedAction;
177 /// \brief The set of AST files to merge.
178 std::vector<std::string> ASTFiles;
181 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
182 StringRef InFile) override;
184 bool BeginSourceFileAction(CompilerInstance &CI) override;
186 void ExecuteAction() override;
187 void EndSourceFileAction() override;
190 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
191 ArrayRef<std::string> ASTFiles);
192 ~ASTMergeAction() override;
194 bool usesPreprocessorOnly() const override;
195 TranslationUnitKind getTranslationUnitKind() override;
196 bool hasPCHSupport() const override;
197 bool hasASTFileSupport() const override;
198 bool hasCodeCompletionSupport() const override;
201 class PrintPreambleAction : public FrontendAction {
203 void ExecuteAction() override;
204 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
205 StringRef) override {
209 bool usesPreprocessorOnly() const override { return true; }
212 //===----------------------------------------------------------------------===//
213 // Preprocessor Actions
214 //===----------------------------------------------------------------------===//
216 class DumpRawTokensAction : public PreprocessorFrontendAction {
218 void ExecuteAction() override;
221 class DumpTokensAction : public PreprocessorFrontendAction {
223 void ExecuteAction() override;
226 class GeneratePTHAction : public PreprocessorFrontendAction {
228 void ExecuteAction() override;
231 class PreprocessOnlyAction : public PreprocessorFrontendAction {
233 void ExecuteAction() override;
236 class PrintPreprocessedAction : public PreprocessorFrontendAction {
238 void ExecuteAction() override;
240 bool hasPCHSupport() const override { return true; }
243 } // end namespace clang