Alex Lorenz | f5ca27c | 2017-10-16 18:28:26 +0000 | [diff] [blame] | 1 | //===--- ToolRefactoringResultConsumer.h - ----------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Alex Lorenz | f5ca27c | 2017-10-16 18:28:26 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H |
| 10 | #define LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H |
| 11 | |
| 12 | #include "clang/AST/ASTContext.h" |
| 13 | #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace refactor { |
| 17 | |
| 18 | /// An interface that subclasses the \c RefactoringResultConsumer interface |
| 19 | /// that stores the reference to the TU-specific diagnostics engine. |
| 20 | class ClangRefactorToolConsumerInterface |
| 21 | : public tooling::RefactoringResultConsumer { |
| 22 | public: |
| 23 | /// Called when a TU is entered. |
| 24 | void beginTU(ASTContext &Context) { |
| 25 | assert(!Diags && "Diags has been set"); |
| 26 | Diags = &Context.getDiagnostics(); |
| 27 | } |
| 28 | |
| 29 | /// Called when the tool is done with a TU. |
| 30 | void endTU() { |
| 31 | assert(Diags && "Diags unset"); |
| 32 | Diags = nullptr; |
| 33 | } |
| 34 | |
| 35 | DiagnosticsEngine &getDiags() const { |
| 36 | assert(Diags && "no diags"); |
| 37 | return *Diags; |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | DiagnosticsEngine *Diags = nullptr; |
| 42 | }; |
| 43 | |
| 44 | } // end namespace refactor |
| 45 | } // end namespace clang |
| 46 | |
| 47 | #endif // LLVM_CLANG_TOOLS_CLANG_REFACTOR_TOOL_REFACTORING_RESULT_CONSUMER_H |