Blender V5.3
gpu/shader_tool/utils.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include <cstddef>
15#include <cstdint>
16#include <optional>
17#include <string>
18#include <vector>
19
21
22struct Token;
23
25 struct Error {
26 /* Contain only the message passed to the report function. */
27 std::string message;
28 /* Contains filename, token location, source line and cursor. */
29 std::string full_report;
30 };
31
32 std::string default_filename;
33 std::optional<Error> err;
34
35 void report(Token tok, std::string_view message);
36 void report(int row, int column, std::string line, std::string_view message);
37 /* Report a series of errors/notes but consider it as a single error. */
38 void report(const std::vector<std::pair<Token, std::string>> &reports);
39
40 void reset()
41 {
42 err.reset();
43 }
44};
45
47struct IndexRange {
50
52
53 bool overlaps(IndexRange other) const
54 {
55 if (start == other.start && size == other.size) {
56 return true;
57 }
58 return ((start < other.start) && (other.start < (start + size))) ||
59 ((other.start < start) && (start < (other.start + other.size)));
60 }
61
62 int64_t last() const
63 {
64 return start + size - 1;
65 }
66};
67
69template<typename T> struct MutableSpan {
72
74 {
75 return data_[index];
76 }
77 const T &operator[](const int64_t index) const
78 {
79 return data_[index];
80 }
81
83 {
84 return data_;
85 }
86
87 uint64_t size() const
88 {
89 return size_;
90 }
91
92 T back() const
93 {
94 return (*this)[size_ - 1];
95 }
96
98 {
99 return data_;
100 }
102 {
103 return data_ + size_;
104 }
105
106 const T *begin() const
107 {
108 return data_;
109 }
110 const T *end() const
111 {
112 return data_ + size_;
113 }
114
119 void shrink(int64_t new_size)
120 {
121 size_ = new_size;
122 }
123};
124
126size_t line_number(const std::string_view &str, size_t pos);
128size_t char_number(const std::string_view &str, size_t pos);
130std::string filename(const std::string_view &str, size_t pos);
132std::string line_str(const std::string_view &str, size_t pos);
133
134/* Return size padded to the given alignment. */
135static inline int pad(int size, int align)
136{
137 return ((size + align - 1) / align) * align;
138}
139
140} // namespace blender::gpu::shader::parser
#define str(s)
#define T
size_t line_number(const std::string_view &str, size_t pos)
std::string filename(const std::string_view &str, size_t pos)
size_t char_number(const std::string_view &str, size_t pos)
std::string line_str(const std::string_view &str, size_t pos)
static int pad(int size, int align)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
void report(Token tok, std::string_view message)
const T & operator[](const int64_t index) const