| 1 | //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_REWRITE_FRONTEND_FRONTENDACTIONS_H |
| 10 | #define LLVM_CLANG_REWRITE_FRONTEND_FRONTENDACTIONS_H |
| 11 | |
| 12 | #include "clang/Frontend/FrontendAction.h" |
| 13 | #include "llvm/Support/raw_ostream.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | class FixItRewriter; |
| 17 | class FixItOptions; |
| 18 | |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | // AST Consumer Actions |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
| 23 | class HTMLPrintAction : public ASTFrontendAction { |
| 24 | protected: |
| 25 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 26 | StringRef InFile) override; |
| 27 | }; |
| 28 | |
| 29 | class FixItAction : public ASTFrontendAction { |
| 30 | protected: |
| 31 | std::unique_ptr<FixItRewriter> Rewriter; |
| 32 | std::unique_ptr<FixItOptions> FixItOpts; |
| 33 | |
| 34 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 35 | StringRef InFile) override; |
| 36 | |
| 37 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 38 | |
| 39 | void EndSourceFileAction() override; |
| 40 | |
| 41 | bool hasASTFileSupport() const override { return false; } |
| 42 | |
| 43 | public: |
| 44 | FixItAction(); |
| 45 | ~FixItAction() override; |
| 46 | }; |
| 47 | |
| 48 | /// Emits changes to temporary files and uses them for the original |
| 49 | /// frontend action. |
| 50 | class FixItRecompile : public WrapperFrontendAction { |
| 51 | public: |
| 52 | FixItRecompile(std::unique_ptr<FrontendAction> WrappedAction) |
| 53 | : WrapperFrontendAction(std::move(WrappedAction)) {} |
| 54 | |
| 55 | protected: |
| 56 | bool BeginInvocation(CompilerInstance &CI) override; |
| 57 | }; |
| 58 | |
| 59 | class RewriteObjCAction : public ASTFrontendAction { |
| 60 | protected: |
| 61 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 62 | StringRef InFile) override; |
| 63 | }; |
| 64 | |
| 65 | class RewriteMacrosAction : public PreprocessorFrontendAction { |
| 66 | protected: |
| 67 | void ExecuteAction() override; |
| 68 | }; |
| 69 | |
| 70 | class RewriteTestAction : public PreprocessorFrontendAction { |
| 71 | protected: |
| 72 | void ExecuteAction() override; |
| 73 | }; |
| 74 | |
| 75 | class RewriteIncludesAction : public PreprocessorFrontendAction { |
| 76 | std::shared_ptr<raw_ostream> OutputStream; |
| 77 | class RewriteImportsListener; |
| 78 | protected: |
| 79 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 80 | void ExecuteAction() override; |
| 81 | }; |
| 82 | |
| 83 | } // end namespace clang |
| 84 | |
| 85 | #endif |
| 86 |