Coverage Report

Created: 2024-09-14 07:19

/src/skia/src/sksl/SkSLErrorReporter.h
Line
Count
Source
1
/*
2
 * Copyright 2021 Google LLC.
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#ifndef SKSL_ERROR_REPORTER
9
#define SKSL_ERROR_REPORTER
10
11
#include "include/core/SkTypes.h"
12
13
#include <string_view>
14
15
namespace SkSL {
16
17
class Position;
18
19
/**
20
 * Class which is notified in the event of an error.
21
 */
22
class ErrorReporter {
23
public:
24
44.4k
    ErrorReporter() {}
25
26
44.4k
    virtual ~ErrorReporter() {}
27
28
    void error(Position position, std::string_view msg);
29
30
250k
    std::string_view source() const { return fSource; }
31
32
16.9k
    void setSource(std::string_view source) { fSource = source; }
33
34
75.2k
    int errorCount() const {
35
75.2k
        return fErrorCount;
36
75.2k
    }
37
38
16.6k
    void resetErrorCount() {
39
16.6k
        fErrorCount = 0;
40
16.6k
    }
41
42
protected:
43
    /**
44
     * Called when an error is reported.
45
     */
46
    virtual void handleError(std::string_view msg, Position position) = 0;
47
48
private:
49
    Position position(int offset) const;
50
51
    std::string_view fSource;
52
    int fErrorCount = 0;
53
};
54
55
/**
56
 * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported.
57
 */
58
class TestingOnly_AbortErrorReporter : public ErrorReporter {
59
public:
60
    void handleError(std::string_view msg, Position pos) override;
61
};
62
63
} // namespace SkSL
64
65
#endif