File indexing completed on 2026-05-10 08:37:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGRULECONTEXT_H
0010 #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGRULECONTEXT_H
0011
0012 #include "clang/Basic/DiagnosticError.h"
0013 #include "clang/Basic/SourceManager.h"
0014 #include "clang/Tooling/Refactoring/ASTSelection.h"
0015
0016 namespace clang {
0017
0018 class ASTContext;
0019
0020 namespace tooling {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class RefactoringRuleContext {
0034 public:
0035 RefactoringRuleContext(const SourceManager &SM) : SM(SM) {}
0036
0037 const SourceManager &getSources() const { return SM; }
0038
0039
0040
0041 SourceRange getSelectionRange() const { return SelectionRange; }
0042
0043 void setSelectionRange(SourceRange R) { SelectionRange = R; }
0044
0045 bool hasASTContext() const { return AST; }
0046
0047 ASTContext &getASTContext() const {
0048 assert(AST && "no AST!");
0049 return *AST;
0050 }
0051
0052 void setASTContext(ASTContext &Context) { AST = &Context; }
0053
0054
0055
0056
0057 llvm::Error createDiagnosticError(SourceLocation Loc, unsigned DiagID) {
0058 return DiagnosticError::create(Loc, PartialDiagnostic(DiagID, DiagStorage));
0059 }
0060
0061 llvm::Error createDiagnosticError(unsigned DiagID) {
0062 return createDiagnosticError(SourceLocation(), DiagID);
0063 }
0064
0065 void setASTSelection(std::unique_ptr<SelectedASTNode> Node) {
0066 ASTNodeSelection = std::move(Node);
0067 }
0068
0069 private:
0070
0071
0072 const SourceManager &SM;
0073
0074
0075 SourceRange SelectionRange;
0076
0077
0078 ASTContext *AST = nullptr;
0079
0080 PartialDiagnostic::DiagStorageAllocator DiagStorage;
0081
0082
0083 std::unique_ptr<SelectedASTNode> ASTNodeSelection;
0084 };
0085
0086 }
0087 }
0088
0089 #endif