Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Parser/tokenizer/tokenizer.h
Line
Count
Source
1
#ifndef Py_TOKENIZER_H
2
#define Py_TOKENIZER_H
3
4
#include "Python.h"
5
#include "types.h"
6
7
struct tok_state;
8
9
/* Initialize before use. metadata owns a reference released by _PyToken_Free;
10
   a consumer taking that reference must set metadata to NULL. */
11
struct token {
12
    int type;
13
    int level;
14
    int is_raw;
15
    _PyTok_Span span;
16
    _PyTok_Loc start_loc;
17
    _PyTok_Loc end_loc;
18
    PyObject *metadata;
19
};
20
21
typedef struct {
22
    const char *text;
23
    Py_ssize_t length;
24
    _PyTok_Span line_span;
25
    _PyTok_Off end_line_start;
26
    int implicit_newline;
27
    int at_eof;
28
} _PyToken_View;
29
30
/* Supplemental source context for a terminal error. location is the reporting
31
   cursor, independent of the scanner cursor; lineno == 0 means absent.
32
   The text span may cover multiple physical lines. */
33
typedef struct {
34
    _PyTok_Loc location;
35
    _PyTok_Span text_span;
36
} _PyTokenizer_Diagnostic;
37
38
typedef struct {
39
    int status;
40
    _PyTokenizer_Diagnostic diagnostic;
41
    _PyTok_Loc location;
42
    _PyTok_Off cursor;
43
    _PyTok_Span input_span;
44
    _PyTok_Span line_span;
45
    int level;
46
    char delimiter;
47
    _PyTok_Loc delimiter_loc;
48
    int in_formatted_string;
49
    int is_interactive;
50
    int is_file;
51
    PyObject *filename;
52
    PyObject *module;
53
    const char *encoding;
54
} _PyTokenizer_Info;
55
56
/* Get replaces the initialized token, releasing its previous metadata.
57
   Errors are returned as ERRORTOKEN, with or without a Python exception. */
58
void _PyTokenizer_Get(struct tok_state *, struct token *);
59
void _PyTokenizer_Free(struct tok_state *);
60
int _PyTokenizer_Traverse(struct tok_state *, visitproc, void *);
61
void _PyTokenizer_raise_init_error(PyObject *filename);
62
void _PyToken_Init(struct token *);
63
static inline void
64
_PyToken_Free(struct token *token)
65
3.55M
{
66
    Py_CLEAR(token->metadata);
67
3.55M
}
Unexecuted instantiation: errors.c:_PyToken_Free
Unexecuted instantiation: traceback.c:_PyToken_Free
Unexecuted instantiation: peg_api.c:_PyToken_Free
Unexecuted instantiation: reader.c:_PyToken_Free
Unexecuted instantiation: helpers.c:_PyToken_Free
Python-tokenize.c:_PyToken_Free
Line
Count
Source
65
2.06k
{
66
    Py_CLEAR(token->metadata);
67
2.06k
}
pegen.c:_PyToken_Free
Line
Count
Source
65
1.63M
{
66
    Py_CLEAR(token->metadata);
67
1.63M
}
pegen_errors.c:_PyToken_Free
Line
Count
Source
65
50.3k
{
66
    Py_CLEAR(token->metadata);
67
50.3k
}
Unexecuted instantiation: parser.c:_PyToken_Free
lexer.c:_PyToken_Free
Line
Count
Source
65
1.86M
{
66
    Py_CLEAR(token->metadata);
67
1.86M
}
Unexecuted instantiation: layout.c:_PyToken_Free
Unexecuted instantiation: number.c:_PyToken_Free
Unexecuted instantiation: state.c:_PyToken_Free
Unexecuted instantiation: string.c:_PyToken_Free
Unexecuted instantiation: decoder.c:_PyToken_Free
Unexecuted instantiation: api.c:_PyToken_Free
Unexecuted instantiation: action_helpers.c:_PyToken_Free
Unexecuted instantiation: string_parser.c:_PyToken_Free
68
69
/* Views and borrowed snapshot references remain valid until the tokenizer is
70
   mutated or freed. Source spans may be discarded when reading more input. */
71
_PyTokenizer_Info _PyTokenizer_GetInfo(const struct tok_state *);
72
/* An absent token span has a nonnull empty text view. */
73
const char *_PyToken_TextView(
74
    const struct tok_state *, const struct token *, Py_ssize_t *);
75
/* Use the token from the most recent Get. An absent span has nonnull empty text.
76
   line_span covers the token's complete physical line range. end_line_start
77
   is the logical offset of its final physical line. */
78
void _PyToken_GetView(
79
    const struct tok_state *tok, const struct token *token,
80
    _PyToken_View *view);
81
const char *_PyTokenizer_SpanView(
82
    const struct tok_state *, _PyTok_Span, Py_ssize_t *);
83
/* For retained input: 1-based lines clamp to the first or final line.
84
   The view excludes the newline and need not be NUL-terminated. */
85
const char *_PyTokenizer_LineView(
86
    const struct tok_state *, Py_ssize_t, Py_ssize_t *);
87
/* Return NUL-terminated retained input, or NULL without setting an exception
88
   for streaming input or interactive input before its first line. */
89
const char *_PyTokenizer_RetainedSource(const struct tok_state *);
90
void _PyTokenizer_SetContext(
91
    struct tok_state *tok, PyObject *filename, PyObject *module);
92
void _PyTokenizer_SetOptions(
93
    struct tok_state *tok, int extra_tokens, int type_comments);
94
void _PyTokenizer_ImplyDedents(struct tok_state *);
95
int _PyTokenizer_HasTrailingStatement(const struct tok_state *);
96
int _PyTokenizer_IsInteractive(const struct tok_state *);
97
void _PyTokenizer_StopInteractive(struct tok_state *);
98
99
struct tok_state *_PyTokenizer_FromString(
100
    const char *input, int exec_input, int preserve_crlf);
101
struct tok_state *_PyTokenizer_FromUTF8(
102
    const char *input, int exec_input, int preserve_crlf);
103
struct tok_state *_PyTokenizer_FromReadline(
104
    PyObject *readline, const char *encoding);
105
struct tok_state *_PyTokenizer_FromFile(
106
    FILE *fp, const char *encoding, const char *ps1, const char *ps2);
107
/* Return the declared encoding in PyMem-allocated storage, or NULL.
108
   An exception is set on error. */
109
char *_PyTokenizer_FindEncodingFilename(int, PyObject *);
110
111
#endif /* !Py_TOKENIZER_H */