Blender V5.3
mtl_shader_log.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_string_ref.hh"
10
11#include "GPU_platform.hh"
12
13#include "mtl_shader_log.hh"
14
15namespace blender::gpu {
16
17const char *MTLLogParser::parse_line(const char *source_combined,
18 const char *log_line,
19 GPULogItem &log_item)
20{
21 const char *name_start = log_line;
22 log_line = skip_name(log_line);
23 const char *name_end = log_line;
24 log_line = skip_separators(log_line, ":");
25
26 /* Parse error line & char numbers. */
27 if (at_number(log_line)) {
28 /* Reset skip line if two errors follow. */
29 parsed_error_ = false;
30 wrapper_error_ = false;
31
32 const char *error_line_number_end;
33
34 log_item.cursor.row = parse_number(log_line, &error_line_number_end);
35 log_line = error_line_number_end;
36 log_line = skip_separators(log_line, ": ");
37 log_item.cursor.column = parse_number(log_line, &error_line_number_end);
38 log_line = error_line_number_end;
39 /* Simply copy the start of the error line since it is already in the format we want. */
40 log_item.cursor.file_name_and_error_line = StringRef(name_start, error_line_number_end);
41
42 StringRef source_name(name_start, name_end);
43 if (log_item.cursor.row != -1) {
44 /* Get to the wanted line. */
45 size_t line_start_character = line_start_get(source_combined, log_item.cursor.row);
46 if (line_start_character != -1) {
47 StringRef filename = filename_get(source_combined, line_start_character);
48 size_t line_number = source_line_get(source_combined, line_start_character);
49 log_item.cursor.file_name_and_error_line = std::string(filename) + ':' +
50 std::to_string(line_number);
51 }
52 if (log_item.cursor.column != -1) {
53 log_item.cursor.file_name_and_error_line += ':' + std::to_string(log_item.cursor.column);
54 log_item.cursor.column -= 1; /* Caret printing expect 0 based index. */
55 }
56 parsed_error_ = true;
57 }
58 return log_line;
59 }
60
61 if (parsed_error_) {
62 /* Skip the redundant lines that we be outputted above the error. */
63 return skip_line(log_line);
64 }
65
66 if (wrapper_error_) {
67 /* Display full lines of error in case of wrapper (non parsed) errors.
68 * Avoids weirdly aligned '^' and underlined suggestions. */
69 return name_start;
70 }
71 log_line = skip_separators(log_line, ": ");
72
73 /* Skip to message. Avoid redundant info. */
74 log_line = skip_severity_keyword(log_line, log_item);
75 log_line = skip_separators(log_line, ": ");
76
77 return log_line;
78}
79
80const char *MTLLogParser::skip_name(const char *log_line)
81{
82 return skip_until(log_line, ':');
83}
84
85const char *MTLLogParser::skip_severity_keyword(const char *log_line, GPULogItem &log_item)
86{
87 return skip_severity(log_line, log_item, "error", "warning", "note");
88}
89
90const char *MTLLogParser::skip_line(const char *cursor) const
91{
92 while (!ELEM(cursor[0], '\n', '\0')) {
93 cursor++;
94 }
95 return cursor;
96}
97
98} // namespace blender::gpu
#define ELEM(...)
constexpr StringRef()
static size_t line_start_get(StringRefNull source_combined, size_t target_line)
static StringRef filename_get(StringRefNull source_combined, size_t pos)
int parse_number(const char *log_line, const char **r_new_position) const
const char * skip_separators(const char *log_line, const StringRef separators) const
bool at_number(const char *log_line) const
static size_t source_line_get(StringRefNull source_combined, size_t pos)
const char * skip_until(const char *log_line, char stop_char) const
const char * skip_severity(const char *log_line, GPULogItem &log_item, const char *error_msg, const char *warning_msg, const char *note_msg) const
const char * parse_line(const char *source_combined, const char *log_line, GPULogItem &log_item) override
const char * skip_line(const char *cursor) const
const char * skip_name(const char *log_line)
const char * skip_severity_keyword(const char *log_line, GPULogItem &log_item)
size_t line_number(const std::string_view &str, size_t pos)
std::string filename(const std::string_view &str, size_t pos)