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