1*e5dd7070Spatrick //===--- ToolRefactoringResultConsumer.h - ----------------------*- C++ -*-===// 2*e5dd7070Spatrick // 3*e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information. 5*e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e5dd7070Spatrick // 7*e5dd7070Spatrick //===----------------------------------------------------------------------===// 8*e5dd7070Spatrick 9*e5dd7070Spatrick #ifndef LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H 10*e5dd7070Spatrick #define LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H 11*e5dd7070Spatrick 12*e5dd7070Spatrick #include "clang/AST/ASTContext.h" 13*e5dd7070Spatrick #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" 14*e5dd7070Spatrick 15*e5dd7070Spatrick namespace clang { 16*e5dd7070Spatrick namespace refactor { 17*e5dd7070Spatrick 18*e5dd7070Spatrick /// An interface that subclasses the \c RefactoringResultConsumer interface 19*e5dd7070Spatrick /// that stores the reference to the TU-specific diagnostics engine. 20*e5dd7070Spatrick class ClangRefactorToolConsumerInterface 21*e5dd7070Spatrick : public tooling::RefactoringResultConsumer { 22*e5dd7070Spatrick public: 23*e5dd7070Spatrick /// Called when a TU is entered. beginTU(ASTContext & Context)24*e5dd7070Spatrick void beginTU(ASTContext &Context) { 25*e5dd7070Spatrick assert(!Diags && "Diags has been set"); 26*e5dd7070Spatrick Diags = &Context.getDiagnostics(); 27*e5dd7070Spatrick } 28*e5dd7070Spatrick 29*e5dd7070Spatrick /// Called when the tool is done with a TU. endTU()30*e5dd7070Spatrick void endTU() { 31*e5dd7070Spatrick assert(Diags && "Diags unset"); 32*e5dd7070Spatrick Diags = nullptr; 33*e5dd7070Spatrick } 34*e5dd7070Spatrick getDiags()35*e5dd7070Spatrick DiagnosticsEngine &getDiags() const { 36*e5dd7070Spatrick assert(Diags && "no diags"); 37*e5dd7070Spatrick return *Diags; 38*e5dd7070Spatrick } 39*e5dd7070Spatrick 40*e5dd7070Spatrick private: 41*e5dd7070Spatrick DiagnosticsEngine *Diags = nullptr; 42*e5dd7070Spatrick }; 43*e5dd7070Spatrick 44*e5dd7070Spatrick } // end namespace refactor 45*e5dd7070Spatrick } // end namespace clang 46*e5dd7070Spatrick 47*e5dd7070Spatrick #endif // LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H 48