clang  10.0.0svn
ASTSelectionRequirements.cpp
Go to the documentation of this file.
1 //===--- ASTSelectionRequirements.cpp - Clang refactoring library ---------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 using namespace clang;
12 using namespace tooling;
13 
16  // FIXME: Memoize so that selection is evaluated only once.
19  if (!Range)
20  return Range.takeError();
21 
22  Optional<SelectedASTNode> Selection =
23  findSelectedASTNodes(Context.getASTContext(), *Range);
24  if (!Selection)
25  return Context.createDiagnosticError(
26  Range->getBegin(), diag::err_refactor_selection_invalid_ast);
27  return std::move(*Selection);
28 }
29 
31  RefactoringRuleContext &Context) const {
32  // FIXME: Memoize so that selection is evaluated only once.
33  Expected<SelectedASTNode> ASTSelection =
35  if (!ASTSelection)
36  return ASTSelection.takeError();
37  std::unique_ptr<SelectedASTNode> StoredSelection =
38  std::make_unique<SelectedASTNode>(std::move(*ASTSelection));
40  Context.getSelectionRange(), *StoredSelection);
41  if (!CodeRange)
42  return Context.createDiagnosticError(
43  Context.getSelectionRange().getBegin(),
44  diag::err_refactor_selection_invalid_ast);
45  Context.setASTSelection(std::move(StoredSelection));
46  return std::move(*CodeRange);
47 }
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:44
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