Path: blob/main/contrib/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp
35271 views
//===--- ASTSelectionRequirements.cpp - Clang refactoring library ---------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"9#include "clang/AST/Attr.h"10#include <optional>1112using namespace clang;13using namespace tooling;1415Expected<SelectedASTNode>16ASTSelectionRequirement::evaluate(RefactoringRuleContext &Context) const {17// FIXME: Memoize so that selection is evaluated only once.18Expected<SourceRange> Range =19SourceRangeSelectionRequirement::evaluate(Context);20if (!Range)21return Range.takeError();2223std::optional<SelectedASTNode> Selection =24findSelectedASTNodes(Context.getASTContext(), *Range);25if (!Selection)26return Context.createDiagnosticError(27Range->getBegin(), diag::err_refactor_selection_invalid_ast);28return std::move(*Selection);29}3031Expected<CodeRangeASTSelection> CodeRangeASTSelectionRequirement::evaluate(32RefactoringRuleContext &Context) const {33// FIXME: Memoize so that selection is evaluated only once.34Expected<SelectedASTNode> ASTSelection =35ASTSelectionRequirement::evaluate(Context);36if (!ASTSelection)37return ASTSelection.takeError();38std::unique_ptr<SelectedASTNode> StoredSelection =39std::make_unique<SelectedASTNode>(std::move(*ASTSelection));40std::optional<CodeRangeASTSelection> CodeRange =41CodeRangeASTSelection::create(Context.getSelectionRange(),42*StoredSelection);43if (!CodeRange)44return Context.createDiagnosticError(45Context.getSelectionRange().getBegin(),46diag::err_refactor_selection_invalid_ast);47Context.setASTSelection(std::move(StoredSelection));48return std::move(*CodeRange);49}505152