119740652SStephen Kelly //===- NodeIntrospection.h -----------------------------------*- C++ -*----===// 219740652SStephen Kelly // 319740652SStephen Kelly // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 419740652SStephen Kelly // See https://llvm.org/LICENSE.txt for license information. 519740652SStephen Kelly // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 619740652SStephen Kelly // 719740652SStephen Kelly //===----------------------------------------------------------------------===// 819740652SStephen Kelly // 919740652SStephen Kelly // This file contains the implementation of the NodeIntrospection. 1019740652SStephen Kelly // 1119740652SStephen Kelly //===----------------------------------------------------------------------===// 1219740652SStephen Kelly 1319740652SStephen Kelly #include "clang/Tooling/NodeIntrospection.h" 1419740652SStephen Kelly 1519740652SStephen Kelly #include "clang/AST/AST.h" 1619740652SStephen Kelly 1719740652SStephen Kelly namespace clang { 1819740652SStephen Kelly 1919740652SStephen Kelly namespace tooling { 2019740652SStephen Kelly 2119740652SStephen Kelly std::string LocationCallFormatterCpp::format(LocationCall *Call) { 2219740652SStephen Kelly SmallVector<LocationCall *> vec; 2319740652SStephen Kelly while (Call) { 2419740652SStephen Kelly vec.push_back(Call); 2519740652SStephen Kelly Call = Call->on(); 2619740652SStephen Kelly } 2719740652SStephen Kelly std::string result; 2819740652SStephen Kelly for (auto *VecCall : llvm::reverse(llvm::makeArrayRef(vec).drop_front())) { 2919740652SStephen Kelly result += 3019740652SStephen Kelly (VecCall->name() + "()" + (VecCall->returnsPointer() ? "->" : ".")) 3119740652SStephen Kelly .str(); 3219740652SStephen Kelly } 3319740652SStephen Kelly result += (vec.back()->name() + "()").str(); 3419740652SStephen Kelly return result; 3519740652SStephen Kelly } 3619740652SStephen Kelly 3719740652SStephen Kelly namespace internal { 3819740652SStephen Kelly bool RangeLessThan::operator()( 39*b23abbeaSNathan James std::pair<SourceRange, SharedLocationCall> const &LHS, 40*b23abbeaSNathan James std::pair<SourceRange, SharedLocationCall> const &RHS) const { 4119740652SStephen Kelly if (!LHS.first.isValid() || !RHS.first.isValid()) 4219740652SStephen Kelly return false; 4319740652SStephen Kelly 4419740652SStephen Kelly if (LHS.first.getBegin() < RHS.first.getBegin()) 4519740652SStephen Kelly return true; 4619740652SStephen Kelly else if (LHS.first.getBegin() != RHS.first.getBegin()) 4719740652SStephen Kelly return false; 4819740652SStephen Kelly 4919740652SStephen Kelly if (LHS.first.getEnd() < RHS.first.getEnd()) 5019740652SStephen Kelly return true; 5119740652SStephen Kelly else if (LHS.first.getEnd() != RHS.first.getEnd()) 5219740652SStephen Kelly return false; 5319740652SStephen Kelly 5419740652SStephen Kelly return LHS.second->name() < RHS.second->name(); 5519740652SStephen Kelly } 56*b23abbeaSNathan James bool RangeLessThan::operator()( 57*b23abbeaSNathan James std::pair<SourceLocation, SharedLocationCall> const &LHS, 58*b23abbeaSNathan James std::pair<SourceLocation, SharedLocationCall> const &RHS) const { 59*b23abbeaSNathan James if (LHS.first == RHS.first) 60*b23abbeaSNathan James return LHS.second->name() < RHS.second->name(); 61*b23abbeaSNathan James return LHS.first < RHS.first; 62*b23abbeaSNathan James } 6319740652SStephen Kelly } // namespace internal 6419740652SStephen Kelly 6519740652SStephen Kelly } // namespace tooling 6619740652SStephen Kelly } // namespace clang 6719740652SStephen Kelly 6819740652SStephen Kelly #include "clang/Tooling/NodeIntrospection.inc" 69