clang  6.0.0svn
ASTSelectionRequirements.cpp
Go to the documentation of this file.
1 //===--- ASTSelectionRequirements.cpp - 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 
11 
12 using namespace clang;
13 using namespace tooling;
14 
17  // FIXME: Memoize so that selection is evaluated only once.
20  if (!Range)
21  return Range.takeError();
22 
23  Optional<SelectedASTNode> Selection =
24  findSelectedASTNodes(Context.getASTContext(), *Range);
25  if (!Selection)
26  return Context.createDiagnosticError(
27  Range->getBegin(), diag::err_refactor_selection_invalid_ast);
28  return std::move(*Selection);
29 }
30 
32  RefactoringRuleContext &Context) const {
33  // FIXME: Memoize so that selection is evaluated only once.
34  Expected<SelectedASTNode> ASTSelection =
36  if (!ASTSelection)
37  return ASTSelection.takeError();
38  std::unique_ptr<SelectedASTNode> StoredSelection =
39  llvm::make_unique<SelectedASTNode>(std::move(*ASTSelection));
41  Context.getSelectionRange(), *StoredSelection);
42  if (!CodeRange)
43  return Context.createDiagnosticError(
44  Context.getSelectionRange().getBegin(),
45  diag::err_refactor_selection_invalid_ast);
46  Context.setASTSelection(std::move(StoredSelection));
47  return std::move(*CodeRange);
48 }
SourceRange getSelectionRange() const
Returns the current source selection range as set by the refactoring engine.
Expected< CodeRangeASTSelection > evaluate(RefactoringRuleContext &Context) const
llvm::Error createDiagnosticError(SourceLocation Loc, unsigned DiagID)
Creates an llvm::Error value that contains a diagnostic.
Optional< SelectedASTNode > findSelectedASTNodes(const ASTContext &Context, SourceRange SelectionRange)
Traverses the given ASTContext and creates a tree of selected AST nodes.
Expected< SelectedASTNode > evaluate(RefactoringRuleContext &Context) const
void setASTSelection(std::unique_ptr< SelectedASTNode > Node)
A source range independent of the SourceManager.
Definition: Replacement.h:42
The refactoring rule context stores all of the inputs that might be needed by a refactoring action ru...
Dataflow Directional Tag Classes.
static Optional< CodeRangeASTSelection > create(SourceRange SelectionRange, const SelectedASTNode &ASTSelection)
Expected< SourceRange > evaluate(RefactoringRuleContext &Context) const
SourceLocation getBegin() const