[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / lib / Tooling / NodeIntrospection.cpp
blobf01bb1cb9c3cab58a1bac0a88f72a57b4e696b6c
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.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Tooling/NodeIntrospection.h"
15 #include "clang/AST/AST.h"
16 #include "llvm/Support/raw_ostream.h"
18 namespace clang {
20 namespace tooling {
22 void LocationCallFormatterCpp::print(const LocationCall &Call,
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 << '.';
32 OS << Call.name() << "()";
35 std::string LocationCallFormatterCpp::format(const LocationCall &Call) {
36 std::string Result;
37 llvm::raw_string_ostream OS(Result);
38 print(Call, OS);
39 OS.flush();
40 return Result;
43 namespace internal {
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());
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())
65 return true;
66 else if (LHS.first.getBegin() != RHS.first.getBegin())
67 return false;
69 if (LHS.first.getEnd() < RHS.first.getEnd())
70 return true;
71 else if (LHS.first.getEnd() != RHS.first.getEnd())
72 return false;
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
86 } // namespace clang
88 #include "clang/Tooling/NodeIntrospection.inc"