Coverage Report

Created: 2026-10-31 06:21

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.64k
#define MAXINDENT 100       /* Max indentation level */
9
160k
#define MAXLEVEL 200        /* Max parentheses level */
10
21.7k
#define MAXFTSTRINGLEVEL 150
11
76.0k
#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
33.7k
#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
93.7k
{
51
93.7k
    return kind == TSTRING || kind == RAW_TSTRING;
52
93.7k
}
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
6
{
51
6
    return kind == TSTRING || kind == RAW_TSTRING;
52
6
}
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
93.7k
{
51
93.7k
    return kind == TSTRING || kind == RAW_TSTRING;
52
93.7k
}
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
62.2k
{
57
62.2k
    return kind == RAW_FSTRING || kind == RAW_TSTRING;
58
62.2k
}
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
62.2k
{
57
62.2k
    return kind == RAW_FSTRING || kind == RAW_TSTRING;
58
62.2k
}
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.35M
{
115
2.35M
    assert(tok->ftstring_stack != NULL);
116
2.35M
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
2.35M
    if (tok->ftstring_depth == 0) {
118
2.14M
        return NULL;
119
2.14M
    }
120
217k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
2.35M
}
reader.c:_PyLexer_CurrentFTString
Line
Count
Source
114
330k
{
115
330k
    assert(tok->ftstring_stack != NULL);
116
330k
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
330k
    if (tok->ftstring_depth == 0) {
118
326k
        return NULL;
119
326k
    }
120
4.07k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
330k
}
Unexecuted instantiation: helpers.c:_PyLexer_CurrentFTString
Unexecuted instantiation: pegen.c:_PyLexer_CurrentFTString
lexer.c:_PyLexer_CurrentFTString
Line
Count
Source
114
2.01M
{
115
2.01M
    assert(tok->ftstring_stack != NULL);
116
2.01M
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
2.01M
    if (tok->ftstring_depth == 0) {
118
1.81M
        return NULL;
119
1.81M
    }
120
199k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
2.01M
}
Unexecuted instantiation: layout.c:_PyLexer_CurrentFTString
Unexecuted instantiation: number.c:_PyLexer_CurrentFTString
state.c:_PyLexer_CurrentFTString
Line
Count
Source
114
14.4k
{
115
14.4k
    assert(tok->ftstring_stack != NULL);
116
14.4k
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
14.4k
    if (tok->ftstring_depth == 0) {
118
0
        return NULL;
119
0
    }
120
14.4k
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
14.4k
}
string.c:_PyLexer_CurrentFTString
Line
Count
Source
114
414
{
115
414
    assert(tok->ftstring_stack != NULL);
116
414
    assert(tok->ftstring_depth >= 0 && tok->ftstring_depth <= tok->ftstring_capacity);
117
414
    if (tok->ftstring_depth == 0) {
118
367
        return NULL;
119
367
    }
120
47
    return &tok->ftstring_stack[tok->ftstring_depth - 1];
121
414
}
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
450
{
126
450
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
450
}
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
6
{
126
6
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
6
}
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
444
{
126
444
    return _PyLexer_IsTString(kind) ? 't' : 'f';
127
444
}
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
100k
{
133
100k
    return tok->level - state->paren_level;
134
100k
}
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
26.8k
{
133
26.8k
    return tok->level - state->paren_level;
134
26.8k
}
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
73.7k
{
133
73.7k
    return tok->level - state->paren_level;
134
73.7k
}
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
6.14M
{
139
6.14M
    assert(tok->line_start >= 0);
140
6.14M
    assert(tok->cur >= tok->line_start);
141
6.14M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
6.14M
    return (int)column;
144
6.14M
}
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.15M
{
139
4.15M
    assert(tok->line_start >= 0);
140
4.15M
    assert(tok->cur >= tok->line_start);
141
4.15M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
4.15M
    return (int)column;
144
4.15M
}
Unexecuted instantiation: layout.c:_PyLexer_ByteColumn
Unexecuted instantiation: number.c:_PyLexer_ByteColumn
state.c:_PyLexer_ByteColumn
Line
Count
Source
138
1.92M
{
139
1.92M
    assert(tok->line_start >= 0);
140
1.92M
    assert(tok->cur >= tok->line_start);
141
1.92M
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
1.92M
    return (int)column;
144
1.92M
}
string.c:_PyLexer_ByteColumn
Line
Count
Source
138
62.2k
{
139
62.2k
    assert(tok->line_start >= 0);
140
62.2k
    assert(tok->cur >= tok->line_start);
141
62.2k
    Py_ssize_t column = tok->cur - tok->line_start;
142
    assert(column <= INT_MAX);
143
62.2k
    return (int)column;
144
62.2k
}
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