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 
17 namespace clang {
18 
19 namespace tooling {
20 
21 std::string LocationCallFormatterCpp::format(LocationCall *Call) {
22   SmallVector<LocationCall *> vec;
23   while (Call) {
24     vec.push_back(Call);
25     Call = Call->on();
26   }
27   std::string result;
28   for (auto *VecCall : llvm::reverse(llvm::makeArrayRef(vec).drop_front())) {
29     result +=
30         (VecCall->name() + "()" + (VecCall->returnsPointer() ? "->" : "."))
31             .str();
32   }
33   result += (vec.back()->name() + "()").str();
34   return result;
35 }
36 
37 namespace internal {
38 bool RangeLessThan::operator()(
39     std::pair<SourceRange, std::shared_ptr<LocationCall>> const &LHS,
40     std::pair<SourceRange, std::shared_ptr<LocationCall>> const &RHS) const {
41   if (!LHS.first.isValid() || !RHS.first.isValid())
42     return false;
43 
44   if (LHS.first.getBegin() < RHS.first.getBegin())
45     return true;
46   else if (LHS.first.getBegin() != RHS.first.getBegin())
47     return false;
48 
49   if (LHS.first.getEnd() < RHS.first.getEnd())
50     return true;
51   else if (LHS.first.getEnd() != RHS.first.getEnd())
52     return false;
53 
54   return LHS.second->name() < RHS.second->name();
55 }
56 } // namespace internal
57 
58 } // namespace tooling
59 } // namespace clang
60 
61 #include "clang/Tooling/NodeIntrospection.inc"
62