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; }
84 /// \brief Compute the AST consumer arguments that will be used to
85 /// create the PCHGenerator instance returned by CreateASTConsumer.
87 /// \returns true if an error occurred, false otherwise.
88 static std::unique_ptr<raw_pwrite_stream>
89 ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
90 std::string &Sysroot, std::string &OutputFile);
92 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
95 class GenerateModuleAction : public ASTFrontendAction {
96 virtual std::unique_ptr<raw_pwrite_stream>
97 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
100 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
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 {
113 clang::Module *Module = nullptr;
114 const FileEntry *ModuleMapForUniquing = nullptr;
115 bool IsSystem = false;
118 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
120 std::unique_ptr<raw_pwrite_stream>
121 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
124 GenerateModuleFromModuleMapAction() {}
125 GenerateModuleFromModuleMapAction(const FileEntry *ModuleMap, bool IsSystem)
126 : ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem) {}
129 class GenerateModuleInterfaceAction : public GenerateModuleAction {
131 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
133 std::unique_ptr<raw_pwrite_stream>
134 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
137 class SyntaxOnlyAction : public ASTFrontendAction {
139 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
140 StringRef InFile) override;
143 ~SyntaxOnlyAction() override;
144 bool hasCodeCompletionSupport() const override { return true; }
147 /// \brief Dump information about the given module file, to be used for
148 /// basic debugging and discovery.
149 class DumpModuleInfoAction : public ASTFrontendAction {
151 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
152 StringRef InFile) override;
153 bool BeginInvocation(CompilerInstance &CI) override;
154 void ExecuteAction() override;
157 bool hasPCHSupport() const override { return false; }
158 bool hasASTFileSupport() const override { return true; }
159 bool hasIRSupport() const override { return false; }
160 bool hasCodeCompletionSupport() const override { return false; }
163 class VerifyPCHAction : public ASTFrontendAction {
165 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
166 StringRef InFile) override;
168 void ExecuteAction() override;
171 bool hasCodeCompletionSupport() const override { return false; }
175 * \brief Frontend action adaptor that merges ASTs together.
177 * This action takes an existing AST file and "merges" it into the AST
178 * context, producing a merged context. This action is an action
179 * adaptor, which forwards most of its calls to another action that
180 * will consume the merged context.
182 class ASTMergeAction : public FrontendAction {
183 /// \brief The action that the merge action adapts.
184 std::unique_ptr<FrontendAction> AdaptedAction;
186 /// \brief The set of AST files to merge.
187 std::vector<std::string> ASTFiles;
190 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
191 StringRef InFile) override;
193 bool BeginSourceFileAction(CompilerInstance &CI,
194 StringRef Filename) override;
196 void ExecuteAction() override;
197 void EndSourceFileAction() override;
200 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
201 ArrayRef<std::string> ASTFiles);
202 ~ASTMergeAction() override;
204 bool usesPreprocessorOnly() const override;
205 TranslationUnitKind getTranslationUnitKind() override;
206 bool hasPCHSupport() const override;
207 bool hasASTFileSupport() const override;
208 bool hasCodeCompletionSupport() const override;
211 class PrintPreambleAction : public FrontendAction {
213 void ExecuteAction() override;
214 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
215 StringRef) override {
219 bool usesPreprocessorOnly() const override { return true; }
222 //===----------------------------------------------------------------------===//
223 // Preprocessor Actions
224 //===----------------------------------------------------------------------===//
226 class DumpRawTokensAction : public PreprocessorFrontendAction {
228 void ExecuteAction() override;
231 class DumpTokensAction : public PreprocessorFrontendAction {
233 void ExecuteAction() override;
236 class GeneratePTHAction : public PreprocessorFrontendAction {
238 void ExecuteAction() override;
241 class PreprocessOnlyAction : public PreprocessorFrontendAction {
243 void ExecuteAction() override;
246 class PrintPreprocessedAction : public PreprocessorFrontendAction {
248 void ExecuteAction() override;
250 bool hasPCHSupport() const override { return true; }
253 } // end namespace clang