Coverage Report

Created: 2020-02-18 08:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Refactoring/ASTSelectionRequirements.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
10
#include "clang/AST/Attr.h"
11
12
using namespace clang;
13
using namespace tooling;
14
15
Expected<SelectedASTNode>
16
42
ASTSelectionRequirement::evaluate(RefactoringRuleContext &Context) const {
17
42
  // FIXME: Memoize so that selection is evaluated only once.
18
42
  Expected<SourceRange> Range =
19
42
      SourceRangeSelectionRequirement::evaluate(Context);
20
42
  if (!Range)
21
0
    return Range.takeError();
22
42
23
42
  Optional<SelectedASTNode> Selection =
24
42
      findSelectedASTNodes(Context.getASTContext(), *Range);
25
42
  if (!Selection)
26
0
    return Context.createDiagnosticError(
27
0
        Range->getBegin(), diag::err_refactor_selection_invalid_ast);
28
42
  return std::move(*Selection);
29
42
}
30
31
Expected<CodeRangeASTSelection> CodeRangeASTSelectionRequirement::evaluate(
32
42
    RefactoringRuleContext &Context) const {
33
42
  // FIXME: Memoize so that selection is evaluated only once.
34
42
  Expected<SelectedASTNode> ASTSelection =
35
42
      ASTSelectionRequirement::evaluate(Context);
36
42
  if (!ASTSelection)
37
0
    return ASTSelection.takeError();
38
42
  std::unique_ptr<SelectedASTNode> StoredSelection =
39
42
      std::make_unique<SelectedASTNode>(std::move(*ASTSelection));
40
42
  Optional<CodeRangeASTSelection> CodeRange = CodeRangeASTSelection::create(
41
42
      Context.getSelectionRange(), *StoredSelection);
42
42
  if (!CodeRange)
43
1
    return Context.createDiagnosticError(
44
1
        Context.getSelectionRange().getBegin(),
45
1
        diag::err_refactor_selection_invalid_ast);
46
41
  Context.setASTSelection(std::move(StoredSelection));
47
41
  return std::move(*CodeRange);
48
41
}