Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Parser/tokenizer/source.h
Line
Count
Source
1
#ifndef Py_TOKENIZER_SOURCE_H
2
#define Py_TOKENIZER_SOURCE_H
3
4
#include "Python.h"
5
6
#include "types.h"
7
8
typedef struct {
9
    char *bytes;
10
    _PyTok_Off base_offset;
11
    _PyTok_Off len;
12
    _PyTok_Off cap;
13
    int nlines;
14
} _PyTok_SourceText;
15
16
static inline const char *
17
_PyTok_SourceData(const _PyTok_SourceText *source)
18
1.76M
{
19
1.76M
    return source->bytes != NULL ? source->bytes : "";
20
1.76M
}
reader.c:_PyTok_SourceData
Line
Count
Source
18
610k
{
19
610k
    return source->bytes != NULL ? source->bytes : "";
20
610k
}
source.c:_PyTok_SourceData
Line
Count
Source
18
310
{
19
310
    return source->bytes != NULL ? source->bytes : "";
20
310
}
helpers.c:_PyTok_SourceData
Line
Count
Source
18
1.30k
{
19
1.30k
    return source->bytes != NULL ? source->bytes : "";
20
1.30k
}
Unexecuted instantiation: pegen.c:_PyTok_SourceData
lexer.c:_PyTok_SourceData
Line
Count
Source
18
286k
{
19
286k
    return source->bytes != NULL ? source->bytes : "";
20
286k
}
Unexecuted instantiation: layout.c:_PyTok_SourceData
Unexecuted instantiation: number.c:_PyTok_SourceData
Unexecuted instantiation: state.c:_PyTok_SourceData
string.c:_PyTok_SourceData
Line
Count
Source
18
14.9k
{
19
14.9k
    return source->bytes != NULL ? source->bytes : "";
20
14.9k
}
decoder.c:_PyTok_SourceData
Line
Count
Source
18
17.7k
{
19
17.7k
    return source->bytes != NULL ? source->bytes : "";
20
17.7k
}
api.c:_PyTok_SourceData
Line
Count
Source
18
830k
{
19
830k
    return source->bytes != NULL ? source->bytes : "";
20
830k
}
Unexecuted instantiation: action_helpers.c:_PyTok_SourceData
21
22
/* Convert positions within the retained source window. Pointers and views
23
   are borrowed; append, discard, and clear invalidate them. */
24
static inline const char *
25
_PyTok_SourcePointer(const _PyTok_SourceText *source, _PyTok_Off offset)
26
1.67M
{
27
1.67M
    assert(offset >= source->base_offset);
28
1.67M
    assert(offset - source->base_offset <= source->len);
29
1.67M
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
1.67M
}
reader.c:_PyTok_SourcePointer
Line
Count
Source
26
545k
{
27
545k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
545k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
545k
}
Unexecuted instantiation: source.c:_PyTok_SourcePointer
helpers.c:_PyTok_SourcePointer
Line
Count
Source
26
1.30k
{
27
1.30k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
1.30k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
1.30k
}
Unexecuted instantiation: pegen.c:_PyTok_SourcePointer
lexer.c:_PyTok_SourcePointer
Line
Count
Source
26
286k
{
27
286k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
286k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
286k
}
Unexecuted instantiation: layout.c:_PyTok_SourcePointer
Unexecuted instantiation: number.c:_PyTok_SourcePointer
Unexecuted instantiation: state.c:_PyTok_SourcePointer
string.c:_PyTok_SourcePointer
Line
Count
Source
26
14.9k
{
27
14.9k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
14.9k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
14.9k
}
Unexecuted instantiation: decoder.c:_PyTok_SourcePointer
api.c:_PyTok_SourcePointer
Line
Count
Source
26
830k
{
27
830k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
830k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
830k
}
Unexecuted instantiation: action_helpers.c:_PyTok_SourcePointer
31
32
static inline unsigned char
33
_PyTok_SourceByte(const _PyTok_SourceText *source, _PyTok_Off offset)
34
14.7M
{
35
14.7M
    assert(offset >= source->base_offset);
36
14.7M
    assert(offset - source->base_offset < source->len);
37
14.7M
    return (unsigned char)source->bytes[offset - source->base_offset];
38
14.7M
}
Unexecuted instantiation: reader.c:_PyTok_SourceByte
Unexecuted instantiation: source.c:_PyTok_SourceByte
Unexecuted instantiation: helpers.c:_PyTok_SourceByte
Unexecuted instantiation: pegen.c:_PyTok_SourceByte
lexer.c:_PyTok_SourceByte
Line
Count
Source
34
12.8M
{
35
12.8M
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
12.8M
    return (unsigned char)source->bytes[offset - source->base_offset];
38
12.8M
}
layout.c:_PyTok_SourceByte
Line
Count
Source
34
515k
{
35
515k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
515k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
515k
}
number.c:_PyTok_SourceByte
Line
Count
Source
34
552k
{
35
552k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
552k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
552k
}
Unexecuted instantiation: state.c:_PyTok_SourceByte
string.c:_PyTok_SourceByte
Line
Count
Source
34
780k
{
35
780k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
780k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
780k
}
Unexecuted instantiation: decoder.c:_PyTok_SourceByte
Unexecuted instantiation: api.c:_PyTok_SourceByte
Unexecuted instantiation: action_helpers.c:_PyTok_SourceByte
39
40
static inline const char *
41
_PyTok_SourceSpanView(const _PyTok_SourceText *source, _PyTok_Span span,
42
                      Py_ssize_t *length)
43
1.66M
{
44
1.66M
    assert(length != NULL);
45
1.66M
    assert(_PyTok_SpanIsValid(span));
46
1.66M
    assert(span.end - source->base_offset <= source->len);
47
1.66M
    *length = span.end - span.start;
48
1.66M
    return _PyTok_SourcePointer(source, span.start);
49
1.66M
}
reader.c:_PyTok_SourceSpanView
Line
Count
Source
43
545k
{
44
545k
    assert(length != NULL);
45
545k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
545k
    *length = span.end - span.start;
48
545k
    return _PyTok_SourcePointer(source, span.start);
49
545k
}
Unexecuted instantiation: source.c:_PyTok_SourceSpanView
Unexecuted instantiation: helpers.c:_PyTok_SourceSpanView
Unexecuted instantiation: pegen.c:_PyTok_SourceSpanView
lexer.c:_PyTok_SourceSpanView
Line
Count
Source
43
272k
{
44
272k
    assert(length != NULL);
45
272k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
272k
    *length = span.end - span.start;
48
272k
    return _PyTok_SourcePointer(source, span.start);
49
272k
}
Unexecuted instantiation: layout.c:_PyTok_SourceSpanView
Unexecuted instantiation: number.c:_PyTok_SourceSpanView
Unexecuted instantiation: state.c:_PyTok_SourceSpanView
string.c:_PyTok_SourceSpanView
Line
Count
Source
43
14.2k
{
44
14.2k
    assert(length != NULL);
45
14.2k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
14.2k
    *length = span.end - span.start;
48
14.2k
    return _PyTok_SourcePointer(source, span.start);
49
14.2k
}
Unexecuted instantiation: decoder.c:_PyTok_SourceSpanView
api.c:_PyTok_SourceSpanView
Line
Count
Source
43
830k
{
44
830k
    assert(length != NULL);
45
830k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
830k
    *length = span.end - span.start;
48
830k
    return _PyTok_SourcePointer(source, span.start);
49
830k
}
Unexecuted instantiation: action_helpers.c:_PyTok_SourceSpanView
50
51
/* Return the first matching offset within span, or -1 if absent. */
52
static inline _PyTok_Off
53
_PyTok_SourceFindByte(const _PyTok_SourceText *source, _PyTok_Span span,
54
                      int byte)
55
545k
{
56
545k
    Py_ssize_t length;
57
545k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
545k
    const char *found = memchr(data, byte, length);
59
545k
    return found != NULL ? span.start + (found - data) : -1;
60
545k
}
reader.c:_PyTok_SourceFindByte
Line
Count
Source
55
272k
{
56
272k
    Py_ssize_t length;
57
272k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
272k
    const char *found = memchr(data, byte, length);
59
272k
    return found != NULL ? span.start + (found - data) : -1;
60
272k
}
Unexecuted instantiation: source.c:_PyTok_SourceFindByte
Unexecuted instantiation: helpers.c:_PyTok_SourceFindByte
Unexecuted instantiation: pegen.c:_PyTok_SourceFindByte
lexer.c:_PyTok_SourceFindByte
Line
Count
Source
55
272k
{
56
272k
    Py_ssize_t length;
57
272k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
272k
    const char *found = memchr(data, byte, length);
59
272k
    return found != NULL ? span.start + (found - data) : -1;
60
272k
}
Unexecuted instantiation: layout.c:_PyTok_SourceFindByte
Unexecuted instantiation: number.c:_PyTok_SourceFindByte
Unexecuted instantiation: state.c:_PyTok_SourceFindByte
Unexecuted instantiation: string.c:_PyTok_SourceFindByte
Unexecuted instantiation: decoder.c:_PyTok_SourceFindByte
Unexecuted instantiation: api.c:_PyTok_SourceFindByte
Unexecuted instantiation: action_helpers.c:_PyTok_SourceFindByte
61
62
PyAPI_FUNC(void) _PyTok_SourceInit(_PyTok_SourceText *);
63
/* Clear invalidates all spans and views for the source. */
64
PyAPI_FUNC(void) _PyTok_SourceClear(_PyTok_SourceText *);
65
/* Discard the retained window and invalidate its spans and views.
66
   Keep its allocation and advance the logical base to the end of the window. */
67
PyAPI_FUNC(void) _PyTok_SourceDiscard(_PyTok_SourceText *);
68
/* Append one nonempty logical line and return its start offset. The input may
69
   contain one newline, as its final byte. An unterminated line must be the
70
   final line. The input must not point into source storage. */
71
PyAPI_FUNC(_PyTok_Off) _PyTok_SourceAppendLine(
72
    _PyTok_SourceText *source, const char *bytes, Py_ssize_t len);
73
/* Append a line payload followed by '\n'. The payload may be empty and must
74
   contain no newline. Other SourceAppendLine constraints still apply. */
75
PyAPI_FUNC(_PyTok_Off) _PyTok_SourceAppendLineWithNewline(
76
    _PyTok_SourceText *source, const char *bytes, Py_ssize_t len);
77
/* Return borrowed bytes excluding '\n', writing the byte length to *len.
78
   Line numbers are 1-based and clamp to the first or final line; a trailing
79
   '\n' adds an empty final line. The view need not be NUL-terminated.
80
   This does not set an exception. Append, discard, and clear invalidate the view. */
81
PyAPI_FUNC(const char *) _PyTok_SourceLineView(
82
    const _PyTok_SourceText *source, Py_ssize_t lineno, Py_ssize_t *len);
83
84
#endif