1 //===- NodeIntrospection.h -----------------------------------*- C++ -*----===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the implementation of the NodeIntrospection.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Tooling/NodeIntrospection.h"
15 #include "clang/AST/AST.h"
16 #include "llvm/Support/raw_ostream.h"
22 void LocationCallFormatterCpp::print(const LocationCall
&Call
,
23 llvm::raw_ostream
&OS
) {
24 if (const LocationCall
*On
= Call
.on()) {
26 if (On
->returnsPointer())
32 OS
<< Call
.name() << "()";
35 std::string
LocationCallFormatterCpp::format(const LocationCall
&Call
) {
37 llvm::raw_string_ostream
OS(Result
);
45 static bool locationCallLessThan(const LocationCall
*LHS
,
46 const LocationCall
*RHS
) {
53 auto compareResult
= LHS
->name().compare(RHS
->name());
54 if (compareResult
< 0)
56 if (compareResult
> 0)
58 return locationCallLessThan(LHS
->on(), RHS
->on());
61 bool RangeLessThan::operator()(
62 std::pair
<SourceRange
, SharedLocationCall
> const &LHS
,
63 std::pair
<SourceRange
, SharedLocationCall
> const &RHS
) const {
64 if (LHS
.first
.getBegin() < RHS
.first
.getBegin())
66 else if (LHS
.first
.getBegin() != RHS
.first
.getBegin())
69 if (LHS
.first
.getEnd() < RHS
.first
.getEnd())
71 else if (LHS
.first
.getEnd() != RHS
.first
.getEnd())
74 return locationCallLessThan(LHS
.second
.get(), RHS
.second
.get());
76 bool RangeLessThan::operator()(
77 std::pair
<SourceLocation
, SharedLocationCall
> const &LHS
,
78 std::pair
<SourceLocation
, SharedLocationCall
> const &RHS
) const {
79 if (LHS
.first
== RHS
.first
)
80 return locationCallLessThan(LHS
.second
.get(), RHS
.second
.get());
81 return LHS
.first
< RHS
.first
;
83 } // namespace internal
85 } // namespace tooling
88 #include "clang/Tooling/NodeIntrospection.inc"