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 raw_pwrite_stream *
89 ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile,
90 std::string &Sysroot, std::string &OutputFile);
93 class GenerateModuleAction : public ASTFrontendAction {
94 clang::Module *Module;
95 const FileEntry *ModuleMapForUniquing;
99 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
100 StringRef InFile) override;
102 TranslationUnitKind getTranslationUnitKind() override {
106 bool hasASTFileSupport() const override { return false; }
109 GenerateModuleAction(const FileEntry *ModuleMap = nullptr,
110 bool IsSystem = false)
111 : ASTFrontendAction(), ModuleMapForUniquing(ModuleMap), IsSystem(IsSystem)
114 bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override;
116 /// \brief Compute the AST consumer arguments that will be used to
117 /// create the PCHGenerator instance returned by CreateASTConsumer.
119 /// \returns true if an error occurred, false otherwise.
120 raw_pwrite_stream *ComputeASTConsumerArguments(CompilerInstance &CI,
122 std::string &Sysroot,
123 std::string &OutputFile);
126 class SyntaxOnlyAction : public ASTFrontendAction {
128 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
129 StringRef InFile) override;
132 bool hasCodeCompletionSupport() const override { return true; }
135 /// \brief Dump information about the given module file, to be used for
136 /// basic debugging and discovery.
137 class DumpModuleInfoAction : public ASTFrontendAction {
139 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
140 StringRef InFile) override;
141 void ExecuteAction() override;
144 bool hasPCHSupport() const override { return false; }
145 bool hasASTFileSupport() const override { return true; }
146 bool hasIRSupport() const override { return false; }
147 bool hasCodeCompletionSupport() const override { return false; }
150 class VerifyPCHAction : public ASTFrontendAction {
152 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
153 StringRef InFile) override;
155 void ExecuteAction() override;
158 bool hasCodeCompletionSupport() const override { return false; }
162 * \brief Frontend action adaptor that merges ASTs together.
164 * This action takes an existing AST file and "merges" it into the AST
165 * context, producing a merged context. This action is an action
166 * adaptor, which forwards most of its calls to another action that
167 * will consume the merged context.
169 class ASTMergeAction : public FrontendAction {
170 /// \brief The action that the merge action adapts.
171 FrontendAction *AdaptedAction;
173 /// \brief The set of AST files to merge.
174 std::vector<std::string> ASTFiles;
177 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
178 StringRef InFile) override;
180 bool BeginSourceFileAction(CompilerInstance &CI,
181 StringRef Filename) override;
183 void ExecuteAction() override;
184 void EndSourceFileAction() override;
187 ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
188 ~ASTMergeAction() override;
190 bool usesPreprocessorOnly() const override;
191 TranslationUnitKind getTranslationUnitKind() override;
192 bool hasPCHSupport() const override;
193 bool hasASTFileSupport() const override;
194 bool hasCodeCompletionSupport() const override;
197 class PrintPreambleAction : public FrontendAction {
199 void ExecuteAction() override;
200 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
201 StringRef) override {
205 bool usesPreprocessorOnly() const override { return true; }
208 //===----------------------------------------------------------------------===//
209 // Preprocessor Actions
210 //===----------------------------------------------------------------------===//
212 class DumpRawTokensAction : public PreprocessorFrontendAction {
214 void ExecuteAction() override;
217 class DumpTokensAction : public PreprocessorFrontendAction {
219 void ExecuteAction() override;
222 class GeneratePTHAction : public PreprocessorFrontendAction {
224 void ExecuteAction() override;
227 class PreprocessOnlyAction : public PreprocessorFrontendAction {
229 void ExecuteAction() override;
232 class PrintPreprocessedAction : public PreprocessorFrontendAction {
234 void ExecuteAction() override;
236 bool hasPCHSupport() const override { return true; }
239 } // end namespace clang