Coverage Report

Created: 2026-11-12 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/spirv-tools/source/util/index_range.h
Line
Count
Source
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_INDEX_RANGE_H_
16
#define SOURCE_UTIL_INDEX_RANGE_H_
17
18
#include <cassert>
19
#include <cstddef>
20
#include <cstdint>
21
22
#include "source/util/span.h"
23
24
namespace spvtools {
25
namespace utils {
26
27
// Implement a range of indicies, to index over an array of values of type T,
28
// but whose base pointer is supplied externally.  Think of this as a span
29
// but without the base pointer, which is to be applied later.  Parameterization
30
// by T makes usage more readable and less error-prone.
31
template <typename T, class IndexType = uint32_t, class CountType = IndexType>
32
class IndexRange {
33
 public:
34
  static_assert(std::is_integral<IndexType>::value);
35
  static_assert(std::is_unsigned<IndexType>::value);
36
  static_assert(std::is_integral<CountType>::value);
37
  static_assert(std::is_unsigned<CountType>::value);
38
  using value_type = T;
39
  using index_type = IndexType;
40
  using size_type = CountType;
41
42
840M
  constexpr IndexRange() {}
43
  constexpr IndexRange(index_type first, size_type count)
44
49.4M
      : first_(first), count_(count) {}
45
46
49.9M
  size_type count() const { return count_; }
47
49.4M
  bool empty() const { return count() == size_type(0); }
48
49
9.03M
  IndexType first() const { return first_; }
50
51
  // Returns the span of indexed elements using the given base pointer.
52
  template <typename E>
53
255M
  spvtools::utils::Span<E> apply(E* base) const {
54
255M
    using span_type = spvtools::utils::Span<E>;
55
255M
    return base ? span_type(base + first_, count_) : span_type();
56
255M
  }
spvtools::utils::Span<char const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<char const>(char const*) const
Line
Count
Source
53
45.7M
  spvtools::utils::Span<E> apply(E* base) const {
54
45.7M
    using span_type = spvtools::utils::Span<E>;
55
45.7M
    return base ? span_type(base + first_, count_) : span_type();
56
45.7M
  }
spvtools::utils::Span<spv_operand_type_t const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spv_operand_type_t const>(spv_operand_type_t const*) const
Line
Count
Source
53
100M
  spvtools::utils::Span<E> apply(E* base) const {
54
100M
    using span_type = spvtools::utils::Span<E>;
55
100M
    return base ? span_type(base + first_, count_) : span_type();
56
100M
  }
Unexecuted instantiation: spvtools::utils::Span<spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const>(spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int> const*) const
spvtools::utils::Span<spv::Capability const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spv::Capability const>(spv::Capability const*) const
Line
Count
Source
53
31.3M
  spvtools::utils::Span<E> apply(E* base) const {
54
31.3M
    using span_type = spvtools::utils::Span<E>;
55
31.3M
    return base ? span_type(base + first_, count_) : span_type();
56
31.3M
  }
spvtools::utils::Span<spvtools::Extension const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spvtools::Extension const>(spvtools::Extension const*) const
Line
Count
Source
53
29.0M
  spvtools::utils::Span<E> apply(E* base) const {
54
29.0M
    using span_type = spvtools::utils::Span<E>;
55
29.0M
    return base ? span_type(base + first_, count_) : span_type();
56
29.0M
  }
spvtools::utils::Span<spvtools::OperandDesc const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spvtools::OperandDesc const>(spvtools::OperandDesc const*) const
Line
Count
Source
53
47.6M
  spvtools::utils::Span<E> apply(E* base) const {
54
47.6M
    using span_type = spvtools::utils::Span<E>;
55
47.6M
    return base ? span_type(base + first_, count_) : span_type();
56
47.6M
  }
table2.cpp:spvtools::utils::Span<spvtools::(anonymous namespace)::NameIndex const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spvtools::(anonymous namespace)::NameIndex const>(spvtools::(anonymous namespace)::NameIndex const*) const
Line
Count
Source
53
185k
  spvtools::utils::Span<E> apply(E* base) const {
54
185k
    using span_type = spvtools::utils::Span<E>;
55
185k
    return base ? span_type(base + first_, count_) : span_type();
56
185k
  }
spvtools::utils::Span<spvtools::ExtInstDesc const> spvtools::utils::IndexRange<unsigned int, unsigned int, unsigned int>::apply<spvtools::ExtInstDesc const>(spvtools::ExtInstDesc const*) const
Line
Count
Source
53
602k
  spvtools::utils::Span<E> apply(E* base) const {
54
602k
    using span_type = spvtools::utils::Span<E>;
55
602k
    return base ? span_type(base + first_, count_) : span_type();
56
602k
  }
57
  template <typename E = int>
58
  spvtools::utils::Span<E> apply(std::nullptr_t) const {
59
    using span_type = spvtools::utils::Span<E>;
60
    return span_type();
61
  }
62
63
 private:
64
  index_type first_ = 0;
65
  size_type count_ = 0;
66
};
67
68
}  // namespace utils
69
}  // namespace spvtools
70
71
#endif  // SOURCE_UTIL_INDEX_RANGE_H_