Coverage Report

Created: 2026-12-01 06:09

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.71M
{
19
1.71M
    return source->bytes != NULL ? source->bytes : "";
20
1.71M
}
reader.c:_PyTok_SourceData
Line
Count
Source
18
588k
{
19
588k
    return source->bytes != NULL ? source->bytes : "";
20
588k
}
source.c:_PyTok_SourceData
Line
Count
Source
18
319
{
19
319
    return source->bytes != NULL ? source->bytes : "";
20
319
}
helpers.c:_PyTok_SourceData
Line
Count
Source
18
1.31k
{
19
1.31k
    return source->bytes != NULL ? source->bytes : "";
20
1.31k
}
Unexecuted instantiation: pegen.c:_PyTok_SourceData
lexer.c:_PyTok_SourceData
Line
Count
Source
18
279k
{
19
279k
    return source->bytes != NULL ? source->bytes : "";
20
279k
}
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
15.2k
{
19
15.2k
    return source->bytes != NULL ? source->bytes : "";
20
15.2k
}
decoder.c:_PyTok_SourceData
Line
Count
Source
18
18.8k
{
19
18.8k
    return source->bytes != NULL ? source->bytes : "";
20
18.8k
}
api.c:_PyTok_SourceData
Line
Count
Source
18
814k
{
19
814k
    return source->bytes != NULL ? source->bytes : "";
20
814k
}
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.64M
{
27
1.64M
    assert(offset >= source->base_offset);
28
1.64M
    assert(offset - source->base_offset <= source->len);
29
1.64M
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
1.64M
}
reader.c:_PyTok_SourcePointer
Line
Count
Source
26
532k
{
27
532k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
532k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
532k
}
Unexecuted instantiation: source.c:_PyTok_SourcePointer
helpers.c:_PyTok_SourcePointer
Line
Count
Source
26
1.31k
{
27
1.31k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
1.31k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
1.31k
}
Unexecuted instantiation: pegen.c:_PyTok_SourcePointer
lexer.c:_PyTok_SourcePointer
Line
Count
Source
26
279k
{
27
279k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
279k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
279k
}
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
15.2k
{
27
15.2k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
15.2k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
15.2k
}
Unexecuted instantiation: decoder.c:_PyTok_SourcePointer
api.c:_PyTok_SourcePointer
Line
Count
Source
26
814k
{
27
814k
    assert(offset >= source->base_offset);
28
    assert(offset - source->base_offset <= source->len);
29
814k
    return _PyTok_SourceData(source) + (offset - source->base_offset);
30
814k
}
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.2M
{
35
14.2M
    assert(offset >= source->base_offset);
36
14.2M
    assert(offset - source->base_offset < source->len);
37
14.2M
    return (unsigned char)source->bytes[offset - source->base_offset];
38
14.2M
}
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.5M
{
35
12.5M
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
12.5M
    return (unsigned char)source->bytes[offset - source->base_offset];
38
12.5M
}
layout.c:_PyTok_SourceByte
Line
Count
Source
34
489k
{
35
489k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
489k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
489k
}
number.c:_PyTok_SourceByte
Line
Count
Source
34
538k
{
35
538k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
538k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
538k
}
Unexecuted instantiation: state.c:_PyTok_SourceByte
string.c:_PyTok_SourceByte
Line
Count
Source
34
747k
{
35
747k
    assert(offset >= source->base_offset);
36
    assert(offset - source->base_offset < source->len);
37
747k
    return (unsigned char)source->bytes[offset - source->base_offset];
38
747k
}
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.62M
{
44
1.62M
    assert(length != NULL);
45
1.62M
    assert(_PyTok_SpanIsValid(span));
46
1.62M
    assert(span.end - source->base_offset <= source->len);
47
1.62M
    *length = span.end - span.start;
48
1.62M
    return _PyTok_SourcePointer(source, span.start);
49
1.62M
}
reader.c:_PyTok_SourceSpanView
Line
Count
Source
43
532k
{
44
532k
    assert(length != NULL);
45
532k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
532k
    *length = span.end - span.start;
48
532k
    return _PyTok_SourcePointer(source, span.start);
49
532k
}
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
266k
{
44
266k
    assert(length != NULL);
45
266k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
266k
    *length = span.end - span.start;
48
266k
    return _PyTok_SourcePointer(source, span.start);
49
266k
}
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.5k
{
44
14.5k
    assert(length != NULL);
45
14.5k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
14.5k
    *length = span.end - span.start;
48
14.5k
    return _PyTok_SourcePointer(source, span.start);
49
14.5k
}
Unexecuted instantiation: decoder.c:_PyTok_SourceSpanView
api.c:_PyTok_SourceSpanView
Line
Count
Source
43
814k
{
44
814k
    assert(length != NULL);
45
814k
    assert(_PyTok_SpanIsValid(span));
46
    assert(span.end - source->base_offset <= source->len);
47
814k
    *length = span.end - span.start;
48
814k
    return _PyTok_SourcePointer(source, span.start);
49
814k
}
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
532k
{
56
532k
    Py_ssize_t length;
57
532k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
532k
    const char *found = memchr(data, byte, length);
59
532k
    return found != NULL ? span.start + (found - data) : -1;
60
532k
}
reader.c:_PyTok_SourceFindByte
Line
Count
Source
55
266k
{
56
266k
    Py_ssize_t length;
57
266k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
266k
    const char *found = memchr(data, byte, length);
59
266k
    return found != NULL ? span.start + (found - data) : -1;
60
266k
}
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
266k
{
56
266k
    Py_ssize_t length;
57
266k
    const char *data = _PyTok_SourceSpanView(source, span, &length);
58
266k
    const char *found = memchr(data, byte, length);
59
266k
    return found != NULL ? span.start + (found - data) : -1;
60
266k
}
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