Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/NodeIntrospection.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- NodeIntrospection.h -----------------------------------*- C++ -*----===//
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
//  This file contains the implementation of the NodeIntrospection.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Tooling/NodeIntrospection.h"
14
15
#include "clang/AST/AST.h"
16
#include "llvm/Support/raw_ostream.h"
17
18
namespace clang {
19
20
namespace tooling {
21
22
void LocationCallFormatterCpp::print(const LocationCall &Call,
23
6
                                     llvm::raw_ostream &OS) {
24
6
  if (const LocationCall *On = Call.on()) {
25
4
    print(*On, OS);
26
4
    if (On->returnsPointer())
27
1
      OS << "->";
28
3
    else
29
3
      OS << '.';
30
4
  }
31
32
6
  OS << Call.name() << "()";
33
6
}
34
35
2
std::string LocationCallFormatterCpp::format(const LocationCall &Call) {
36
2
  std::string Result;
37
2
  llvm::raw_string_ostream OS(Result);
38
2
  print(Call, OS);
39
2
  OS.flush();
40
2
  return Result;
41
2
}
42
43
namespace internal {
44
45
static bool locationCallLessThan(const LocationCall *LHS,
46
4
                                 const LocationCall *RHS) {
47
4
  if (!LHS && 
!RHS0
)
48
0
    return false;
49
4
  if (LHS && !RHS)
50
1
    return true;
51
3
  if (!LHS && 
RHS0
)
52
0
    return false;
53
3
  auto compareResult = LHS->name().compare(RHS->name());
54
3
  if (compareResult < 0)
55
1
    return true;
56
2
  if (compareResult > 0)
57
1
    return false;
58
1
  return locationCallLessThan(LHS->on(), RHS->on());
59
2
}
60
61
bool RangeLessThan::operator()(
62
    std::pair<SourceRange, SharedLocationCall> const &LHS,
63
2
    std::pair<SourceRange, SharedLocationCall> const &RHS) const {
64
2
  if (LHS.first.getBegin() < RHS.first.getBegin())
65
0
    return true;
66
2
  else if (LHS.first.getBegin() != RHS.first.getBegin())
67
0
    return false;
68
69
2
  if (LHS.first.getEnd() < RHS.first.getEnd())
70
0
    return true;
71
2
  else if (LHS.first.getEnd() != RHS.first.getEnd())
72
0
    return false;
73
74
2
  return locationCallLessThan(LHS.second.get(), RHS.second.get());
75
2
}
76
bool RangeLessThan::operator()(
77
    std::pair<SourceLocation, SharedLocationCall> const &LHS,
78
1
    std::pair<SourceLocation, SharedLocationCall> const &RHS) const {
79
1
  if (LHS.first == RHS.first)
80
1
    return locationCallLessThan(LHS.second.get(), RHS.second.get());
81
0
  return LHS.first < RHS.first;
82
1
}
83
} // namespace internal
84
85
} // namespace tooling
86
} // namespace clang
87
88
#include "clang/Tooling/NodeIntrospection.inc"