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, StringRef Filename) override;
97 class GenerateModuleAction : public ASTFrontendAction {
98 virtual std::unique_ptr<raw_pwrite_stream>
99 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
102 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
104 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
105 StringRef InFile) override;
107 TranslationUnitKind getTranslationUnitKind() override {
111 bool hasASTFileSupport() const override { return false; }
114 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
115 clang::Module *Module = nullptr;
116 const FileEntry *ModuleMapForUniquing = nullptr;
117 bool IsSystem = false;
120 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
122 std::unique_ptr<raw_pwrite_stream>
123 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
126 GenerateModuleFromModuleMapAction() {}
127 GenerateModuleFromModuleMapAction(const FileEntry *ModuleMap, bool IsSystem)
128 : ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem) {}
131 class GenerateModuleInterfaceAction : public GenerateModuleAction {
133 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
135 std::unique_ptr<raw_pwrite_stream>
136 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
139 class SyntaxOnlyAction : public ASTFrontendAction {
141 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
142 StringRef InFile) override;
145 ~SyntaxOnlyAction() override;
146 bool hasCodeCompletionSupport() const override { return true; }
149 /// \brief Dump information about the given module file, to be used for
150 /// basic debugging and discovery.
151 class DumpModuleInfoAction : public ASTFrontendAction {
153 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
154 StringRef InFile) override;
155 bool BeginInvocation(CompilerInstance &CI) override;
156 void ExecuteAction() override;
159 bool hasPCHSupport() const override { return false; }
160 bool hasASTFileSupport() const override { return true; }
161 bool hasIRSupport() const override { return false; }
162 bool hasCodeCompletionSupport() const override { return false; }
165 class VerifyPCHAction : public ASTFrontendAction {
167 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
168 StringRef InFile) override;
170 void ExecuteAction() override;
173 bool hasCodeCompletionSupport() const override { return false; }
177 * \brief Frontend action adaptor that merges ASTs together.
179 * This action takes an existing AST file and "merges" it into the AST
180 * context, producing a merged context. This action is an action
181 * adaptor, which forwards most of its calls to another action that
182 * will consume the merged context.
184 class ASTMergeAction : public FrontendAction {
185 /// \brief The action that the merge action adapts.
186 std::unique_ptr<FrontendAction> AdaptedAction;
188 /// \brief The set of AST files to merge.
189 std::vector<std::string> ASTFiles;
192 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
193 StringRef InFile) override;
195 bool BeginSourceFileAction(CompilerInstance &CI,
196 StringRef Filename) override;
198 void ExecuteAction() override;
199 void EndSourceFileAction() override;
202 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
203 ArrayRef<std::string> ASTFiles);
204 ~ASTMergeAction() override;
206 bool usesPreprocessorOnly() const override;
207 TranslationUnitKind getTranslationUnitKind() override;
208 bool hasPCHSupport() const override;
209 bool hasASTFileSupport() const override;
210 bool hasCodeCompletionSupport() const override;
213 class PrintPreambleAction : public FrontendAction {
215 void ExecuteAction() override;
216 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
217 StringRef) override {
221 bool usesPreprocessorOnly() const override { return true; }
224 //===----------------------------------------------------------------------===//
225 // Preprocessor Actions
226 //===----------------------------------------------------------------------===//
228 class DumpRawTokensAction : public PreprocessorFrontendAction {
230 void ExecuteAction() override;
233 class DumpTokensAction : public PreprocessorFrontendAction {
235 void ExecuteAction() override;
238 class GeneratePTHAction : public PreprocessorFrontendAction {
240 void ExecuteAction() override;
243 class PreprocessOnlyAction : public PreprocessorFrontendAction {
245 void ExecuteAction() override;
248 class PrintPreprocessedAction : public PreprocessorFrontendAction {
250 void ExecuteAction() override;
252 bool hasPCHSupport() const override { return true; }
255 } // end namespace clang