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 class DumpCompilerOptionsAction : public FrontendAction {
39 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
40 StringRef InFile) override {
44 void ExecuteAction() override;
47 bool usesPreprocessorOnly() const override { return true; }
50 //===----------------------------------------------------------------------===//
51 // AST Consumer Actions
52 //===----------------------------------------------------------------------===//
54 class ASTPrintAction : public ASTFrontendAction {
56 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
57 StringRef InFile) override;
60 class ASTDumpAction : public ASTFrontendAction {
62 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
63 StringRef InFile) override;
66 class ASTDeclListAction : public ASTFrontendAction {
68 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
69 StringRef InFile) override;
72 class ASTViewAction : public ASTFrontendAction {
74 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
75 StringRef InFile) override;
78 class DeclContextPrintAction : public ASTFrontendAction {
80 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
81 StringRef InFile) override;
84 class GeneratePCHAction : public ASTFrontendAction {
86 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
87 StringRef InFile) override;
89 TranslationUnitKind getTranslationUnitKind() override {
93 bool hasASTFileSupport() const override { return false; }
95 bool shouldEraseOutputFiles() override;
98 /// Compute the AST consumer arguments that will be used to
99 /// create the PCHGenerator instance returned by CreateASTConsumer.
101 /// \returns false if an error occurred, true otherwise.
102 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
103 std::string &Sysroot);
105 /// Creates file to write the PCH into and returns a stream to write it
106 /// into. On error, returns null.
107 static std::unique_ptr<llvm::raw_pwrite_stream>
108 CreateOutputFile(CompilerInstance &CI, StringRef InFile,
109 std::string &OutputFile);
111 bool BeginSourceFileAction(CompilerInstance &CI) override;
114 class GenerateModuleAction : public ASTFrontendAction {
115 virtual std::unique_ptr<raw_pwrite_stream>
116 CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0;
119 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
120 StringRef InFile) override;
122 TranslationUnitKind getTranslationUnitKind() override {
126 bool hasASTFileSupport() const override { return false; }
129 class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
131 bool BeginSourceFileAction(CompilerInstance &CI) override;
133 std::unique_ptr<raw_pwrite_stream>
134 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
137 class GenerateModuleInterfaceAction : public GenerateModuleAction {
139 bool BeginSourceFileAction(CompilerInstance &CI) override;
141 std::unique_ptr<raw_pwrite_stream>
142 CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
145 class SyntaxOnlyAction : public ASTFrontendAction {
147 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
148 StringRef InFile) override;
151 ~SyntaxOnlyAction() override;
152 bool hasCodeCompletionSupport() const override { return true; }
155 /// Dump information about the given module file, to be used for
156 /// basic debugging and discovery.
157 class DumpModuleInfoAction : public ASTFrontendAction {
159 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
160 StringRef InFile) override;
161 bool BeginInvocation(CompilerInstance &CI) override;
162 void ExecuteAction() override;
165 bool hasPCHSupport() const override { return false; }
166 bool hasASTFileSupport() const override { return true; }
167 bool hasIRSupport() const override { return false; }
168 bool hasCodeCompletionSupport() const override { return false; }
171 class VerifyPCHAction : public ASTFrontendAction {
173 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
174 StringRef InFile) override;
176 void ExecuteAction() override;
179 bool hasCodeCompletionSupport() const override { return false; }
182 class TemplightDumpAction : public ASTFrontendAction {
184 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
185 StringRef InFile) override;
187 void ExecuteAction() override;
191 * Frontend action adaptor that merges ASTs together.
193 * This action takes an existing AST file and "merges" it into the AST
194 * context, producing a merged context. This action is an action
195 * adaptor, which forwards most of its calls to another action that
196 * will consume the merged context.
198 class ASTMergeAction : public FrontendAction {
199 /// The action that the merge action adapts.
200 std::unique_ptr<FrontendAction> AdaptedAction;
202 /// The set of AST files to merge.
203 std::vector<std::string> ASTFiles;
206 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
207 StringRef InFile) override;
209 bool BeginSourceFileAction(CompilerInstance &CI) override;
211 void ExecuteAction() override;
212 void EndSourceFileAction() override;
215 ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction,
216 ArrayRef<std::string> ASTFiles);
217 ~ASTMergeAction() override;
219 bool usesPreprocessorOnly() const override;
220 TranslationUnitKind getTranslationUnitKind() override;
221 bool hasPCHSupport() const override;
222 bool hasASTFileSupport() const override;
223 bool hasCodeCompletionSupport() const override;
226 class PrintPreambleAction : public FrontendAction {
228 void ExecuteAction() override;
229 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
230 StringRef) override {
234 bool usesPreprocessorOnly() const override { return true; }
237 //===----------------------------------------------------------------------===//
238 // Preprocessor Actions
239 //===----------------------------------------------------------------------===//
241 class DumpRawTokensAction : public PreprocessorFrontendAction {
243 void ExecuteAction() override;
246 class DumpTokensAction : public PreprocessorFrontendAction {
248 void ExecuteAction() override;
251 class GeneratePTHAction : public PreprocessorFrontendAction {
253 void ExecuteAction() override;
256 class PreprocessOnlyAction : public PreprocessorFrontendAction {
258 void ExecuteAction() override;
261 class PrintPreprocessedAction : public PreprocessorFrontendAction {
263 void ExecuteAction() override;
265 bool hasPCHSupport() const override { return true; }
268 } // end namespace clang