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 false if an error occurred, true otherwise.
90 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
91 std::string &Sysroot);
93 /// \brief Creates file to write the PCH into and returns a stream to write it
94 /// into. On error, returns null.
95 static std::unique_ptr<llvm::raw_pwrite_stream>
96 CreateOutputFile(CompilerInstance &CI, StringRef InFile,
97 std::string &OutputFile);
99 bool BeginSourceFileAction(CompilerInstance &CI) override;
102 class GenerateModuleAction : public ASTFrontendAction {
103 virtual std::unique_ptr<raw_pwrite_stream>
104 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
107 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
108 StringRef InFile) override;
110 TranslationUnitKind getTranslationUnitKind() override {
114 bool hasASTFileSupport() const override { return false; }
117 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
119 bool BeginSourceFileAction(CompilerInstance &CI) override;
121 std::unique_ptr<raw_pwrite_stream>
122 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
125 class GenerateModuleInterfaceAction : public GenerateModuleAction {
127 bool BeginSourceFileAction(CompilerInstance &CI) override;
129 std::unique_ptr<raw_pwrite_stream>
130 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
133 class SyntaxOnlyAction : public ASTFrontendAction {
135 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
136 StringRef InFile) override;
139 ~SyntaxOnlyAction() override;
140 bool hasCodeCompletionSupport() const override { return true; }
143 /// \brief Dump information about the given module file, to be used for
144 /// basic debugging and discovery.
145 class DumpModuleInfoAction : public ASTFrontendAction {
147 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
148 StringRef InFile) override;
149 bool BeginInvocation(CompilerInstance &CI) override;
150 void ExecuteAction() override;
153 bool hasPCHSupport() const override { return false; }
154 bool hasASTFileSupport() const override { return true; }
155 bool hasIRSupport() const override { return false; }
156 bool hasCodeCompletionSupport() const override { return false; }
159 class VerifyPCHAction : public ASTFrontendAction {
161 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
162 StringRef InFile) override;
164 void ExecuteAction() override;
167 bool hasCodeCompletionSupport() const override { return false; }
171 * \brief Frontend action adaptor that merges ASTs together.
173 * This action takes an existing AST file and "merges" it into the AST
174 * context, producing a merged context. This action is an action
175 * adaptor, which forwards most of its calls to another action that
176 * will consume the merged context.
178 class ASTMergeAction : public FrontendAction {
179 /// \brief The action that the merge action adapts.
180 std::unique_ptr<FrontendAction> AdaptedAction;
182 /// \brief The set of AST files to merge.
183 std::vector<std::string> ASTFiles;
186 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
187 StringRef InFile) override;
189 bool BeginSourceFileAction(CompilerInstance &CI) override;
191 void ExecuteAction() override;
192 void EndSourceFileAction() override;
195 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
196 ArrayRef<std::string> ASTFiles);
197 ~ASTMergeAction() override;
199 bool usesPreprocessorOnly() const override;
200 TranslationUnitKind getTranslationUnitKind() override;
201 bool hasPCHSupport() const override;
202 bool hasASTFileSupport() const override;
203 bool hasCodeCompletionSupport() const override;
206 class PrintPreambleAction : public FrontendAction {
208 void ExecuteAction() override;
209 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
210 StringRef) override {
214 bool usesPreprocessorOnly() const override { return true; }
217 //===----------------------------------------------------------------------===//
218 // Preprocessor Actions
219 //===----------------------------------------------------------------------===//
221 class DumpRawTokensAction : public PreprocessorFrontendAction {
223 void ExecuteAction() override;
226 class DumpTokensAction : public PreprocessorFrontendAction {
228 void ExecuteAction() override;
231 class GeneratePTHAction : public PreprocessorFrontendAction {
233 void ExecuteAction() override;
236 class PreprocessOnlyAction : public PreprocessorFrontendAction {
238 void ExecuteAction() override;
241 class PrintPreprocessedAction : public PreprocessorFrontendAction {
243 void ExecuteAction() override;
245 bool hasPCHSupport() const override { return true; }
248 } // end namespace clang