Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Parser/lexer/state.h
Line
Count
Source
1
#ifndef _PY_LEXER_H_
2
#define _PY_LEXER_H_
3
4
#include "object.h"
5
#include "../tokenizer/source.h"
6
#include "../tokenizer/tokenizer.h"
7
8
9.72k
#define MAXINDENT 100       /* Max indentation level */
9
165k
#define MAXLEVEL 200        /* Max parentheses level */
10
22.9k
#define MAXFTSTRINGLEVEL 150
11
67.6k
#define FTSTRING_STACK_INLINE_CAPACITY 1
12
13
typedef enum {
14
    FTSTRING_MODE_MIDDLE,
15
    FTSTRING_MODE_EXPRESSION,
16
    FTSTRING_MODE_FORMAT_SPEC,
17
} ftstring_mode;
18
19
typedef enum {
20
    FSTRING,
21
    RAW_FSTRING,
22
    TSTRING,
23
    RAW_TSTRING,
24
} ftstring_kind;
25
26
34.5k
#define MAX_EXPR_NESTING 3
27
28
typedef struct _tokenizer_comments {
29
    Py_ssize_t count;
30
    Py_ssize_t capacity;
31
    _PyTok_Span spans[];
32
} tokenizer_comments;
33
34
typedef struct _ftstring_state {
35
    ftstring_mode mode;
36
    ftstring_kind kind;
37
    char quote;
38
    unsigned char quote_size;
39
    unsigned char debug_expr;
40
    unsigned char replacement_depth;
41
    int paren_level;
42
    _PyTok_Off start;
43
    _PyTok_Loc start_loc;
44
    _PyTok_Span expr_span;
45
    tokenizer_comments *comments;
46
} ftstring_state;
47
48
static inline int
49
_PyLexer_IsTString(ftstring_kind kind)
50
98.2k
{
51
98.2k
    return kind == TSTRING || kind == RAW_TSTRING;
52
98.2k
}
Unexecuted instantiation: reader.c:_PyLexer_IsTString
Unexecuted instantiation: helpers.c:_PyLexer_IsTString
Unexecuted instantiation: pegen.c:_PyLexer_IsTString
lexer.c:_PyLexer_IsTString
Line
Count
Source
50
5
{
51
5
    return kind == TSTRING || kind == RAW_TSTRING;
52
5
}
Unexecuted instantiation: layout.c:_PyLexer_IsTString
Unexecuted instantiation: number.c:_PyLexer_IsTString
Unexecuted instantiation: state.c:_PyLexer_IsTString
string.c:_PyLexer_IsTString
Line
Count
Source
50
98.2k
{
51
98.2k
    return kind == TSTRING || kind == RAW_TSTRING;
52
98.2k
}
Unexecuted instantiation: decoder.c:_PyLexer_IsTString
Unexecuted instantiation: api.c:_PyLexer_IsTString
Unexecuted instantiation: action_helpers.c:_PyLexer_IsTString
53
54
static inline int
55
_PyLexer_IsRawString(ftstring_kind kind)
56
65.7k
{
57
65.7k
    return kind == RAW_FSTRING || kind == RAW_TSTRING;
58
65.7k
}
Unexecuted instantiation: reader.c:_PyLexer_IsRawString
Unexecuted instantiation: helpers.c:_PyLexer_IsRawString
Unexecuted instantiation: pegen.c:_PyLexer_IsRawString
Unexecuted instantiation: lexer.c:_PyLexer_IsRawString
Unexecuted instantiation: layout.c:_PyLexer_IsRawString
Unexecuted instantiation: number.c:_PyLexer_IsRawString
Unexecuted instantiation: state.c:_PyLexer_IsRawString
string.c:_PyLexer_IsRawString
Line
Count
Source
56
65.7k
{
57
65.7k
    return kind == RAW_FSTRING || kind == RAW_TSTRING;
58
65.7k
}
Unexecuted instantiation: decoder.c:_PyLexer_IsRawString
Unexecuted instantiation: api.c:_PyLexer_IsRawString
Unexecuted instantiation: action_helpers.c:_PyLexer_IsRawString
59
60
typedef struct {
61
    int column;
62
    int alternate_column;
63
} indentation_level;
64
65
typedef struct {
66
    int depth;
67
    int pending;
68
    int at_bol;
69
    int comment_newline;
70
    indentation_level stack[MAXINDENT];
71
} lexer_layout_state;
72
73
/* Tokenizer state */
74
struct tok_state {
75
    _PyTok_Off buf_offset;
76
    _PyTok_Off cur;
77
    _PyTok_Off inp;
78
    _PyTok_Off start;
79
    _PyTok_Off line_start;
80
    _PyTok_SourceText source;
81
    int done;           /* E_OK normally, E_EOF at EOF, otherwise error code */
82
    /* NB If done != E_OK, cur must be == inp!!! */
83
    lexer_layout_state layout;
84
    int lineno;         /* Current line number */
85
    _PyTok_Loc start_loc;
86
    _PyTokenizer_Diagnostic diagnostic;
87
    int level;          /* () [] {} Parentheses nesting level */
88
            /* Used to allow free continuations inside them */
89
    char parenstack[MAXLEVEL];
90
    int parenlinenostack[MAXLEVEL];
91
    int parencolstack[MAXLEVEL];
92
    PyObject *filename;
93
    PyObject *module;
94
    struct _PyTok_Reader *reader;
95
96
    int type_comments;      /* Whether to look for type comments */
97
98
    ftstring_state *ftstring_stack;
99
    ftstring_state ftstring_stack_inline[FTSTRING_STACK_INLINE_CAPACITY];
100
    int ftstring_depth;
101
    int ftstring_capacity;
102
    int tok_extra_tokens;
103
    int implicit_newline;
104
#ifdef Py_DEBUG
105
    int debug;
106
#endif
107
    int barry_as_bdfl;
108
    unsigned char allow_incomplete_input;
109
    unsigned char needs_newline;
110
};
111
112
static inline ftstring_state *
113
_PyLexer_CurrentFTString(struct tok_state *tok)
114
2.28M
{
115
2.28M
    assert(tok->ftstring_stack != NULL);
116
2.28M
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
2.28M
    if (tok->ftstring_depth == 0) {
118
2.05M
        return NULL;
119
2.05M
    }
120
225k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
2.28M
}
reader.c:_PyLexer_CurrentFTString
Line
Count
Source
114
316k
{
115
316k
    assert(tok->ftstring_stack != NULL);
116
316k
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
316k
    if (tok->ftstring_depth == 0) {
118
310k
        return NULL;
119
310k
    }
120
6.28k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
316k
}
Unexecuted instantiation: helpers.c:_PyLexer_CurrentFTString
Unexecuted instantiation: pegen.c:_PyLexer_CurrentFTString
lexer.c:_PyLexer_CurrentFTString
Line
Count
Source
114
1.94M
{
115
1.94M
    assert(tok->ftstring_stack != NULL);
116
1.94M
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
1.94M
    if (tok->ftstring_depth == 0) {
118
1.74M
        return NULL;
119
1.74M
    }
120
203k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
1.94M
}
Unexecuted instantiation: layout.c:_PyLexer_CurrentFTString
Unexecuted instantiation: number.c:_PyLexer_CurrentFTString
state.c:_PyLexer_CurrentFTString
Line
Count
Source
114
15.9k
{
115
15.9k
    assert(tok->ftstring_stack != NULL);
116
15.9k
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
15.9k
    if (tok->ftstring_depth == 0) {
118
0
        return NULL;
119
0
    }
120
15.9k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
15.9k
}
string.c:_PyLexer_CurrentFTString
Line
Count
Source
114
390
{
115
390
    assert(tok->ftstring_stack != NULL);
116
390
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
390
    if (tok->ftstring_depth == 0) {
118
349
        return NULL;
119
349
    }
120
41
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
390
}
Unexecuted instantiation: decoder.c:_PyLexer_CurrentFTString
Unexecuted instantiation: api.c:_PyLexer_CurrentFTString
Unexecuted instantiation: action_helpers.c:_PyLexer_CurrentFTString
122
123
static inline char
124
_PyLexer_StringPrefix(ftstring_kind kind)
125
472
{
126
472
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
472
}
Unexecuted instantiation: reader.c:_PyLexer_StringPrefix
Unexecuted instantiation: helpers.c:_PyLexer_StringPrefix
Unexecuted instantiation: pegen.c:_PyLexer_StringPrefix
lexer.c:_PyLexer_StringPrefix
Line
Count
Source
125
5
{
126
5
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
5
}
Unexecuted instantiation: layout.c:_PyLexer_StringPrefix
Unexecuted instantiation: number.c:_PyLexer_StringPrefix
Unexecuted instantiation: state.c:_PyLexer_StringPrefix
string.c:_PyLexer_StringPrefix
Line
Count
Source
125
467
{
126
467
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
467
}
Unexecuted instantiation: decoder.c:_PyLexer_StringPrefix
Unexecuted instantiation: api.c:_PyLexer_StringPrefix
Unexecuted instantiation: action_helpers.c:_PyLexer_StringPrefix
128
129
static inline int
130
_PyLexer_FTStringBracketDepth(const struct tok_state *tok,
131
                              const ftstring_state *state)
132
105k
{
133
105k
    return tok->level - state->paren_level;
134
105k
}
Unexecuted instantiation: reader.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: helpers.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: pegen.c:_PyLexer_FTStringBracketDepth
lexer.c:_PyLexer_FTStringBracketDepth
Line
Count
Source
132
27.6k
{
133
27.6k
    return tok->level - state->paren_level;
134
27.6k
}
Unexecuted instantiation: layout.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: number.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: state.c:_PyLexer_FTStringBracketDepth
string.c:_PyLexer_FTStringBracketDepth
Line
Count
Source
132
77.4k
{
133
77.4k
    return tok->level - state->paren_level;
134
77.4k
}
Unexecuted instantiation: decoder.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: api.c:_PyLexer_FTStringBracketDepth
Unexecuted instantiation: action_helpers.c:_PyLexer_FTStringBracketDepth
135
136
static inline int
137
_PyLexer_ByteColumn(const struct tok_state *tok)
138
5.95M
{
139
5.95M
    assert(tok->line_start >= 0);
140
5.95M
    assert(tok->cur >= tok->line_start);
141
5.95M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
5.95M
    return (int)column;
144
5.95M
}
Unexecuted instantiation: reader.c:_PyLexer_ByteColumn
Unexecuted instantiation: helpers.c:_PyLexer_ByteColumn
Unexecuted instantiation: pegen.c:_PyLexer_ByteColumn
lexer.c:_PyLexer_ByteColumn
Line
Count
Source
138
4.02M
{
139
4.02M
    assert(tok->line_start >= 0);
140
4.02M
    assert(tok->cur >= tok->line_start);
141
4.02M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
4.02M
    return (int)column;
144
4.02M
}
Unexecuted instantiation: layout.c:_PyLexer_ByteColumn
Unexecuted instantiation: number.c:_PyLexer_ByteColumn
state.c:_PyLexer_ByteColumn
Line
Count
Source
138
1.86M
{
139
1.86M
    assert(tok->line_start >= 0);
140
1.86M
    assert(tok->cur >= tok->line_start);
141
1.86M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
1.86M
    return (int)column;
144
1.86M
}
string.c:_PyLexer_ByteColumn
Line
Count
Source
138
65.7k
{
139
65.7k
    assert(tok->line_start >= 0);
140
65.7k
    assert(tok->cur >= tok->line_start);
141
65.7k
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
65.7k
    return (int)column;
144
65.7k
}
Unexecuted instantiation: decoder.c:_PyLexer_ByteColumn
Unexecuted instantiation: api.c:_PyLexer_ByteColumn
Unexecuted instantiation: action_helpers.c:_PyLexer_ByteColumn
145
146
int _PyLexer_token_setup(struct tok_state *tok, struct token *token, int type, _PyTok_Off start, _PyTok_Off end);
147
148
void _PyLexer_ImplyDedents(struct tok_state *);
149
150
void _PyTokenizer_Free(struct tok_state *);
151
ftstring_state *_PyLexer_PushFTString(struct tok_state *);
152
void _PyLexer_PopFTString(struct tok_state *);
153
154
155
#endif