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);
93 class GenerateModuleAction : public ASTFrontendAction {
94 virtual std::unique_ptr<raw_pwrite_stream>
95 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
98 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
100 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
101 StringRef InFile) override;
103 TranslationUnitKind getTranslationUnitKind() override {
107 bool hasASTFileSupport() const override { return false; }
110 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
111 clang::Module *Module = nullptr;
112 const FileEntry *ModuleMapForUniquing = nullptr;
113 bool IsSystem = false;
116 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
118 std::unique_ptr<raw_pwrite_stream>
119 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
122 GenerateModuleFromModuleMapAction() {}
123 GenerateModuleFromModuleMapAction(const FileEntry *ModuleMap, bool IsSystem)
124 : ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem) {}
127 class GenerateModuleInterfaceAction : public GenerateModuleAction {
129 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
131 std::unique_ptr<raw_pwrite_stream>
132 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
135 class SyntaxOnlyAction : public ASTFrontendAction {
137 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
138 StringRef InFile) override;
141 ~SyntaxOnlyAction() override;
142 bool hasCodeCompletionSupport() const override { return true; }
145 /// \brief Dump information about the given module file, to be used for
146 /// basic debugging and discovery.
147 class DumpModuleInfoAction : public ASTFrontendAction {
149 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
150 StringRef InFile) override;
151 bool BeginInvocation(CompilerInstance &CI) override;
152 void ExecuteAction() override;
155 bool hasPCHSupport() const override { return false; }
156 bool hasASTFileSupport() const override { return true; }
157 bool hasIRSupport() const override { return false; }
158 bool hasCodeCompletionSupport() const override { return false; }
161 class VerifyPCHAction : public ASTFrontendAction {
163 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
164 StringRef InFile) override;
166 void ExecuteAction() override;
169 bool hasCodeCompletionSupport() const override { return false; }
173 * \brief Frontend action adaptor that merges ASTs together.
175 * This action takes an existing AST file and "merges" it into the AST
176 * context, producing a merged context. This action is an action
177 * adaptor, which forwards most of its calls to another action that
178 * will consume the merged context.
180 class ASTMergeAction : public FrontendAction {
181 /// \brief The action that the merge action adapts.
182 std::unique_ptr<FrontendAction> AdaptedAction;
184 /// \brief The set of AST files to merge.
185 std::vector<std::string> ASTFiles;
188 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
189 StringRef InFile) override;
191 bool BeginSourceFileAction(CompilerInstance &CI,
192 StringRef Filename) override;
194 void ExecuteAction() override;
195 void EndSourceFileAction() override;
198 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
199 ArrayRef<std::string> ASTFiles);
200 ~ASTMergeAction() override;
202 bool usesPreprocessorOnly() const override;
203 TranslationUnitKind getTranslationUnitKind() override;
204 bool hasPCHSupport() const override;
205 bool hasASTFileSupport() const override;
206 bool hasCodeCompletionSupport() const override;
209 class PrintPreambleAction : public FrontendAction {
211 void ExecuteAction() override;
212 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
213 StringRef) override {
217 bool usesPreprocessorOnly() const override { return true; }
220 //===----------------------------------------------------------------------===//
221 // Preprocessor Actions
222 //===----------------------------------------------------------------------===//
224 class DumpRawTokensAction : public PreprocessorFrontendAction {
226 void ExecuteAction() override;
229 class DumpTokensAction : public PreprocessorFrontendAction {
231 void ExecuteAction() override;
234 class GeneratePTHAction : public PreprocessorFrontendAction {
236 void ExecuteAction() override;
239 class PreprocessOnlyAction : public PreprocessorFrontendAction {
241 void ExecuteAction() override;
244 class PrintPreprocessedAction : public PreprocessorFrontendAction {
246 void ExecuteAction() override;
248 bool hasPCHSupport() const override { return true; }
251 } // end namespace clang