clang
6.0.0
include
clang
Tooling
Refactoring
RefactoringRuleContext.h
Go to the documentation of this file.
1
//===--- RefactoringRuleContext.h - Clang refactoring library -------------===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RULE_CONTEXT_H
11
#define LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RULE_CONTEXT_H
12
13
#include "
clang/Basic/DiagnosticError.h
"
14
#include "
clang/Basic/SourceManager.h
"
15
#include "
clang/Tooling/Refactoring/ASTSelection.h
"
16
17
namespace
clang
{
18
19
class
ASTContext;
20
21
namespace
tooling {
22
23
/// The refactoring rule context stores all of the inputs that might be needed
24
/// by a refactoring action rule. It can create the specialized
25
/// \c ASTRefactoringOperation or \c PreprocessorRefactoringOperation values
26
/// that can be used by the refactoring action rules.
27
///
28
/// The following inputs are stored by the operation:
29
///
30
/// - SourceManager: a reference to a valid source manager.
31
///
32
/// - SelectionRange: an optional source selection ranges that can be used
33
/// to represent a selection in an editor.
34
class
RefactoringRuleContext
{
35
public
:
36
RefactoringRuleContext
(
const
SourceManager
&SM) : SM(SM) {}
37
38
const
SourceManager
&
getSources
()
const
{
return
SM; }
39
40
/// Returns the current source selection range as set by the
41
/// refactoring engine. Can be invalid.
42
SourceRange
getSelectionRange
()
const
{
return
SelectionRange; }
43
44
void
setSelectionRange
(
SourceRange
R) { SelectionRange = R; }
45
46
bool
hasASTContext
()
const
{
return
AST; }
47
48
ASTContext
&
getASTContext
()
const
{
49
assert(AST &&
"no AST!"
);
50
return
*AST;
51
}
52
53
void
setASTContext
(
ASTContext
&Context) { AST = &Context; }
54
55
/// Creates an llvm::Error value that contains a diagnostic.
56
///
57
/// The errors should not outlive the context.
58
llvm::Error
createDiagnosticError
(
SourceLocation
Loc,
unsigned
DiagID) {
59
return
DiagnosticError::create
(Loc,
PartialDiagnostic
(DiagID, DiagStorage));
60
}
61
62
llvm::Error
createDiagnosticError
(
unsigned
DiagID) {
63
return
createDiagnosticError
(
SourceLocation
(), DiagID);
64
}
65
66
void
setASTSelection
(std::unique_ptr<SelectedASTNode>
Node
) {
67
ASTNodeSelection = std::move(Node);
68
}
69
70
private
:
71
/// The source manager for the translation unit / file on which a refactoring
72
/// action might operate on.
73
const
SourceManager
&SM;
74
/// An optional source selection range that's commonly used to represent
75
/// a selection in an editor.
76
SourceRange
SelectionRange;
77
/// An optional AST for the translation unit on which a refactoring action
78
/// might operate on.
79
ASTContext
*AST =
nullptr
;
80
/// The allocator for diagnostics.
81
PartialDiagnostic::StorageAllocator
DiagStorage;
82
83
// FIXME: Remove when memoized.
84
std::unique_ptr<SelectedASTNode> ASTNodeSelection;
85
};
86
87
}
// end namespace tooling
88
}
// end namespace clang
89
90
#endif // LLVM_CLANG_TOOLING_REFACTOR_REFACTORING_RULE_CONTEXT_H
SourceManager.h
Defines the SourceManager interface.
clang::PartialDiagnostic
Definition:
PartialDiagnostic.h:28
clang::tooling::RefactoringRuleContext::getSelectionRange
SourceRange getSelectionRange() const
Returns the current source selection range as set by the refactoring engine.
Definition:
RefactoringRuleContext.h:42
clang::tooling::RefactoringRuleContext::RefactoringRuleContext
RefactoringRuleContext(const SourceManager &SM)
Definition:
RefactoringRuleContext.h:36
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:149
clang::tooling::RefactoringRuleContext::createDiagnosticError
llvm::Error createDiagnosticError(SourceLocation Loc, unsigned DiagID)
Creates an llvm::Error value that contains a diagnostic.
Definition:
RefactoringRuleContext.h:58
clang::tooling::RefactoringRuleContext::setASTSelection
void setASTSelection(std::unique_ptr< SelectedASTNode > Node)
Definition:
RefactoringRuleContext.h:66
clang::tooling::RefactoringRuleContext
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
Definition:
RefactoringRuleContext.h:34
clang::PartialDiagnostic::StorageAllocator
An allocator for Storage objects, which uses a small cache to objects, used to reduce malloc()/free()...
Definition:
PartialDiagnostic.h:78
clang::DiagnosticLevelMask::Error
clang::SourceLocation
Encodes a location in the source.
Definition:
SourceLocation.h:87
clang::tooling::RefactoringRuleContext::getSources
const SourceManager & getSources() const
Definition:
RefactoringRuleContext.h:38
clang::tooling::RefactoringRuleContext::setASTContext
void setASTContext(ASTContext &Context)
Definition:
RefactoringRuleContext.h:53
clang::tooling::RefactoringRuleContext::getASTContext
ASTContext & getASTContext() const
Definition:
RefactoringRuleContext.h:48
clang::tooling::RefactoringRuleContext::createDiagnosticError
llvm::Error createDiagnosticError(unsigned DiagID)
Definition:
RefactoringRuleContext.h:62
Node
ast_type_traits::DynTypedNode Node
Definition:
ASTMatchFinder.cpp:61
DiagnosticError.h
clang
Dataflow Directional Tag Classes.
Definition:
CFGReachabilityAnalysis.h:22
clang::tooling::RefactoringRuleContext::hasASTContext
bool hasASTContext() const
Definition:
RefactoringRuleContext.h:46
ASTSelection.h
clang::DiagnosticError::create
static llvm::Error create(SourceLocation Loc, PartialDiagnostic Diag)
Creates a new DiagnosticError that contains the given diagnostic at the given location.
Definition:
DiagnosticError.h:32
clang::tooling::RefactoringRuleContext::setSelectionRange
void setSelectionRange(SourceRange R)
Definition:
RefactoringRuleContext.h:44
clang::SourceRange
A trivial tuple used to represent a source range.
Definition:
SourceLocation.h:195
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition:
SourceManager.h:559
Generated on Thu Feb 8 2018 09:14:07 for clang by
1.8.13