/src/shaderc/third_party/spirv-tools/source/util/span.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2025 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef SOURCE_UTIL_SPAN_H_ |
16 | | #define SOURCE_UTIL_SPAN_H_ |
17 | | |
18 | | #include <cstddef> |
19 | | #include <iterator> |
20 | | #include <type_traits> |
21 | | |
22 | | namespace spvtools { |
23 | | namespace utils { |
24 | | |
25 | | // Implement a subset of the C++20 std::span, using at most C++17 functionality. |
26 | | // Replace this when SPIRV-Tools can use C++20. |
27 | | template <class T> |
28 | | class Span { |
29 | | public: |
30 | | using element_type = T; |
31 | | using value_type = std::remove_cv_t<T>; |
32 | | using size_type = std::size_t; |
33 | | using difference_type = std::ptrdiff_t; |
34 | | using pointer = T*; |
35 | | using const_pointer = const T*; |
36 | | using reference = T&; |
37 | | using const_reference = const T&; |
38 | | using iterator = T*; |
39 | | using const_iterator = const T*; |
40 | | |
41 | 0 | Span() {} Unexecuted instantiation: spvtools::utils::Span<spv_operand_type_t const>::Span() Unexecuted instantiation: spvtools::utils::Span<char const>::Span() Unexecuted instantiation: spvtools::utils::Span<spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const>::Span() Unexecuted instantiation: spvtools::utils::Span<spv::Capability const>::Span() Unexecuted instantiation: spvtools::utils::Span<spvtools::Extension const>::Span() Unexecuted instantiation: spvtools::utils::Span<spvtools::OperandDesc const>::Span() Unexecuted instantiation: table2.cpp:spvtools::utils::Span<spvtools::(anonymous namespace)::NameIndex const>::Span() Unexecuted instantiation: spvtools::utils::Span<spvtools::ExtInstDesc const>::Span() |
42 | 2.54M | Span(iterator first, size_type count) : first_(first), count_(count) {} spvtools::utils::Span<spv_operand_type_t const>::Span(spv_operand_type_t const*, unsigned long) Line | Count | Source | 42 | 1.09M | Span(iterator first, size_type count) : first_(first), count_(count) {} |
spvtools::utils::Span<char const>::Span(char const*, unsigned long) Line | Count | Source | 42 | 144k | Span(iterator first, size_type count) : first_(first), count_(count) {} |
Unexecuted instantiation: spvtools::utils::Span<spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const>::Span(spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const*, unsigned long) spvtools::utils::Span<spv::Capability const>::Span(spv::Capability const*, unsigned long) Line | Count | Source | 42 | 517k | Span(iterator first, size_type count) : first_(first), count_(count) {} |
spvtools::utils::Span<spvtools::Extension const>::Span(spvtools::Extension const*, unsigned long) Line | Count | Source | 42 | 449k | Span(iterator first, size_type count) : first_(first), count_(count) {} |
spvtools::utils::Span<spvtools::OperandDesc const>::Span(spvtools::OperandDesc const*, unsigned long) Line | Count | Source | 42 | 325k | Span(iterator first, size_type count) : first_(first), count_(count) {} |
Unexecuted instantiation: table2.cpp:spvtools::utils::Span<spvtools::(anonymous namespace)::NameIndex const>::Span(spvtools::(anonymous namespace)::NameIndex const*, unsigned long) spvtools::utils::Span<spvtools::ExtInstDesc const>::Span(spvtools::ExtInstDesc const*, unsigned long) Line | Count | Source | 42 | 8.45k | Span(iterator first, size_type count) : first_(first), count_(count) {} |
|
43 | | |
44 | 834k | iterator begin() const { return first_; } spvtools::utils::Span<spv::Capability const>::begin() const Line | Count | Source | 44 | 276k | iterator begin() const { return first_; } |
spvtools::utils::Span<spvtools::OperandDesc const>::begin() const Line | Count | Source | 44 | 325k | iterator begin() const { return first_; } |
Unexecuted instantiation: table2.cpp:spvtools::utils::Span<spvtools::(anonymous namespace)::NameIndex const>::begin() const spvtools::utils::Span<spvtools::ExtInstDesc const>::begin() const Line | Count | Source | 44 | 8.45k | iterator begin() const { return first_; } |
spvtools::utils::Span<spvtools::Extension const>::begin() const Line | Count | Source | 44 | 223k | iterator begin() const { return first_; } |
|
45 | 892k | iterator end() const { return first_ ? first_ + count_ : nullptr; } spvtools::utils::Span<spvtools::OperandDesc const>::end() const Line | Count | Source | 45 | 651k | iterator end() const { return first_ ? first_ + count_ : nullptr; } |
Unexecuted instantiation: table2.cpp:spvtools::utils::Span<spvtools::(anonymous namespace)::NameIndex const>::end() const spvtools::utils::Span<spvtools::ExtInstDesc const>::end() const Line | Count | Source | 45 | 16.9k | iterator end() const { return first_ ? first_ + count_ : nullptr; } |
spvtools::utils::Span<spvtools::Extension const>::end() const Line | Count | Source | 45 | 223k | iterator end() const { return first_ ? first_ + count_ : nullptr; } |
Unexecuted instantiation: spvtools::utils::Span<spv::Capability const>::end() const |
46 | | const_iterator cbegin() const { return first_; } |
47 | | const_iterator cend() const { return first_ ? first_ + count_ : nullptr; } |
48 | | |
49 | 1.37M | size_type size() const { return count_; } spvtools::utils::Span<spv::Capability const>::size() const Line | Count | Source | 49 | 280k | size_type size() const { return count_; } |
spvtools::utils::Span<spv_operand_type_t const>::size() const Line | Count | Source | 49 | 1.09M | size_type size() const { return count_; } |
|
50 | | size_type size_bytes() const { return count_ * sizeof(T); } |
51 | 228k | bool empty() const { return first_ == nullptr || count_ == 0; } |
52 | | |
53 | | reference front() const { return *first_; } |
54 | | reference back() const { return *(first_ + count_ - 1); } |
55 | 155k | pointer data() const { return first_; } spvtools::utils::Span<char const>::data() const Line | Count | Source | 55 | 144k | pointer data() const { return first_; } |
spvtools::utils::Span<spvtools::Extension const>::data() const Line | Count | Source | 55 | 2.79k | pointer data() const { return first_; } |
spvtools::utils::Span<spv::Capability const>::data() const Line | Count | Source | 55 | 8.23k | pointer data() const { return first_; } |
|
56 | 2.68M | reference operator[](size_type idx) const { return first_[idx]; } |
57 | 596 | Span<T> subspan(size_type offset) const { |
58 | 596 | if (count_ > offset) { |
59 | 596 | return Span(first_ + offset, count_ - offset); |
60 | 596 | } |
61 | 0 | return Span<T>(); |
62 | 596 | } |
63 | | |
64 | | private: |
65 | | T* first_ = nullptr; |
66 | | size_type count_ = 0; |
67 | | }; |
68 | | |
69 | | } // namespace utils |
70 | | } // namespace spvtools |
71 | | |
72 | | #endif // SOURCE_UTIL_SPAN_H_ |