[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / clang-tools-extra / clangd / unittests / Annotations.cpp
blob32b916d54d8709ab9f29057ed0312fb5f33e920d
1 //===--- Annotations.cpp - Annotated source code for unit tests --*- 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 //===----------------------------------------------------------------------===//
9 #include "Annotations.h"
10 #include "SourceCode.h"
12 namespace clang {
13 namespace clangd {
15 Position Annotations::point(llvm::StringRef Name) const {
16 return pointWithPayload(Name).first;
19 std::pair<Position, llvm::StringRef>
20 Annotations::pointWithPayload(llvm::StringRef Name) const {
21 auto [BasePoint, Payload] = Base::pointWithPayload(Name);
22 return {offsetToPosition(code(), BasePoint), Payload};
25 std::vector<Position> Annotations::points(llvm::StringRef Name) const {
26 auto BasePoints = Base::points(Name);
28 std::vector<Position> Ps;
29 Ps.reserve(BasePoints.size());
30 for (const auto Point : BasePoints)
31 Ps.push_back(offsetToPosition(code(), Point));
33 return Ps;
36 std::vector<std::pair<Position, llvm::StringRef>>
37 Annotations::pointsWithPayload(llvm::StringRef Name) const {
38 auto BasePoints = Base::pointsWithPayload(Name);
40 std::vector<std::pair<Position, llvm::StringRef>> Ps;
41 Ps.reserve(BasePoints.size());
42 for (const auto &[Point, Payload] : BasePoints)
43 Ps.push_back({offsetToPosition(code(), Point), Payload});
45 return Ps;
48 static clangd::Range toLSPRange(llvm::StringRef Code,
49 llvm::Annotations::Range R) {
50 clangd::Range LSPRange;
51 LSPRange.start = offsetToPosition(Code, R.Begin);
52 LSPRange.end = offsetToPosition(Code, R.End);
53 return LSPRange;
56 Range Annotations::range(llvm::StringRef Name) const {
57 return rangeWithPayload(Name).first;
60 std::pair<clangd::Range, llvm::StringRef>
61 Annotations::rangeWithPayload(llvm::StringRef Name) const {
62 auto [BaseRange, Payload] = Base::rangeWithPayload(Name);
63 return {toLSPRange(code(), BaseRange), Payload};
66 std::vector<Range> Annotations::ranges(llvm::StringRef Name) const {
67 auto OffsetRanges = Base::ranges(Name);
69 std::vector<clangd::Range> Rs;
70 Rs.reserve(OffsetRanges.size());
71 for (const auto &R : OffsetRanges)
72 Rs.push_back(toLSPRange(code(), R));
74 return Rs;
77 std::vector<std::pair<clangd::Range, llvm::StringRef>>
78 Annotations::rangesWithPayload(llvm::StringRef Name) const {
79 auto OffsetRanges = Base::rangesWithPayload(Name);
81 std::vector<std::pair<clangd::Range, llvm::StringRef>> Rs;
82 Rs.reserve(OffsetRanges.size());
83 for (const auto &[R, Payload] : OffsetRanges)
84 Rs.push_back({toLSPRange(code(), R), Payload});
86 return Rs;
89 } // namespace clangd
90 } // namespace clang