clang  14.0.0git
NodeIntrospection.cpp
Go to the documentation of this file.
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 
14 
15 #include "clang/AST/AST.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 namespace clang {
19 
20 namespace tooling {
21 
23  llvm::raw_ostream &OS) {
24  if (const LocationCall *On = Call.on()) {
25  print(*On, OS);
26  if (On->returnsPointer())
27  OS << "->";
28  else
29  OS << '.';
30  }
31 
32  OS << Call.name() << "()";
33 }
34 
36  std::string Result;
37  llvm::raw_string_ostream OS(Result);
38  print(Call, OS);
39  OS.flush();
40  return Result;
41 }
42 
43 namespace internal {
44 
45 static bool locationCallLessThan(const LocationCall *LHS,
46  const LocationCall *RHS) {
47  if (!LHS && !RHS)
48  return false;
49  if (LHS && !RHS)
50  return true;
51  if (!LHS && RHS)
52  return false;
53  auto compareResult = LHS->name().compare(RHS->name());
54  if (compareResult < 0)
55  return true;
56  if (compareResult > 0)
57  return false;
58  return locationCallLessThan(LHS->on(), RHS->on());
59 }
60 
62  std::pair<SourceRange, SharedLocationCall> const &LHS,
63  std::pair<SourceRange, SharedLocationCall> const &RHS) const {
64  if (LHS.first.getBegin() < RHS.first.getBegin())
65  return true;
66  else if (LHS.first.getBegin() != RHS.first.getBegin())
67  return false;
68 
69  if (LHS.first.getEnd() < RHS.first.getEnd())
70  return true;
71  else if (LHS.first.getEnd() != RHS.first.getEnd())
72  return false;
73 
74  return locationCallLessThan(LHS.second.get(), RHS.second.get());
75 }
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;
82 }
83 } // namespace internal
84 
85 } // namespace tooling
86 } // namespace clang
87 
88 #include "clang/Tooling/NodeIntrospection.inc"
NodeIntrospection.h
clang::tooling::LocationCall::name
StringRef name() const
Definition: NodeIntrospection.h:44
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::tooling::internal::RangeLessThan::operator()
bool operator()(std::pair< SourceRange, SharedLocationCall > const &LHS, std::pair< SourceRange, SharedLocationCall > const &RHS) const
Definition: NodeIntrospection.cpp:61
clang::tooling::LocationCall::on
LocationCall * on() const
Definition: NodeIntrospection.h:43
clang::tooling::internal::locationCallLessThan
static bool locationCallLessThan(const LocationCall *LHS, const LocationCall *RHS)
Definition: NodeIntrospection.cpp:45
clang::tooling::LocationCallFormatterCpp::print
static void print(const LocationCall &Call, llvm::raw_ostream &OS)
Definition: NodeIntrospection.cpp:22
clang::tooling::LocationCallFormatterCpp::format
static std::string format(const LocationCall &Call)
Definition: NodeIntrospection.cpp:35
clang
Definition: CalledOnceCheck.h:17
clang::tooling::LocationCall
Definition: NodeIntrospection.h:36
AST.h