Skip to content

Commit 09415ff

Browse files
authored
fix warnings by adding more const (pythonGH-12924)
1 parent 5749134 commit 09415ff

6 files changed

Lines changed: 18 additions & 23 deletions

File tree

Include/grammar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct {
6666
} grammar;
6767

6868
/* FUNCTIONS */
69-
dfa *PyGrammar_FindDFA(grammar *g, int type);
69+
const dfa *PyGrammar_FindDFA(grammar *g, int type);
7070
const char *PyGrammar_LabelRepr(label *lb);
7171
void PyGrammar_AddAccelerators(grammar *g);
7272
void PyGrammar_RemoveAccelerators(grammar *);

Modules/parsermodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ validate_node(node *tree)
644644
{
645645
int type = TYPE(tree);
646646
int nch = NCH(tree);
647-
dfa *nt_dfa;
648647
state *dfa_state;
649648
int pos, arc;
650649

@@ -654,7 +653,7 @@ validate_node(node *tree)
654653
PyErr_Format(parser_error, "Unrecognized node type %d.", TYPE(tree));
655654
return 0;
656655
}
657-
nt_dfa = &_PyParser_Grammar.g_dfa[type];
656+
const dfa *nt_dfa = &_PyParser_Grammar.g_dfa[type];
658657
REQ(tree, nt_dfa->d_type);
659658

660659
/* Run the DFA for this nonterminal. */

Parser/acceler.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
#include "parser.h"
1818

1919
/* Forward references */
20-
static void fixdfa(grammar *, dfa *);
20+
static void fixdfa(grammar *, const dfa *);
2121
static void fixstate(grammar *, state *);
2222

2323
void
2424
PyGrammar_AddAccelerators(grammar *g)
2525
{
26-
dfa *d;
2726
int i;
28-
d = g->g_dfa;
27+
const dfa *d = g->g_dfa;
2928
for (i = g->g_ndfas; --i >= 0; d++)
3029
fixdfa(g, d);
3130
g->g_accel = 1;
@@ -34,10 +33,9 @@ PyGrammar_AddAccelerators(grammar *g)
3433
void
3534
PyGrammar_RemoveAccelerators(grammar *g)
3635
{
37-
dfa *d;
3836
int i;
3937
g->g_accel = 0;
40-
d = g->g_dfa;
38+
const dfa *d = g->g_dfa;
4139
for (i = g->g_ndfas; --i >= 0; d++) {
4240
state *s;
4341
int j;
@@ -51,7 +49,7 @@ PyGrammar_RemoveAccelerators(grammar *g)
5149
}
5250

5351
static void
54-
fixdfa(grammar *g, dfa *d)
52+
fixdfa(grammar *g, const dfa *d)
5553
{
5654
state *s;
5755
int j;
@@ -63,7 +61,7 @@ fixdfa(grammar *g, dfa *d)
6361
static void
6462
fixstate(grammar *g, state *s)
6563
{
66-
arc *a;
64+
const arc *a;
6765
int k;
6866
int *accel;
6967
int nl = g->g_ll.ll_nlabels;
@@ -78,14 +76,14 @@ fixstate(grammar *g, state *s)
7876
a = s->s_arc;
7977
for (k = s->s_narcs; --k >= 0; a++) {
8078
int lbl = a->a_lbl;
81-
label *l = &g->g_ll.ll_label[lbl];
79+
const label *l = &g->g_ll.ll_label[lbl];
8280
int type = l->lb_type;
8381
if (a->a_arrow >= (1 << 7)) {
8482
printf("XXX too many states!\n");
8583
continue;
8684
}
8785
if (ISNONTERMINAL(type)) {
88-
dfa *d1 = PyGrammar_FindDFA(g, type);
86+
const dfa *d1 = PyGrammar_FindDFA(g, type);
8987
int ibit;
9088
if (type - NT_OFFSET >= (1 << 7)) {
9189
printf("XXX too high nonterminal number!\n");

Parser/grammar1.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
/* Return the DFA for the given type */
99

10-
dfa *
10+
const dfa *
1111
PyGrammar_FindDFA(grammar *g, int type)
1212
{
13-
dfa *d;
1413
/* Massive speed-up */
15-
d = &g->g_dfa[type - NT_OFFSET];
14+
const dfa *d = &g->g_dfa[type - NT_OFFSET];
1615
assert(d->d_type == type);
1716
return d;
1817
}

Parser/parser.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ s_reset(stack *s)
3535
#define s_empty(s) ((s)->s_top == &(s)->s_base[MAXSTACK])
3636

3737
static int
38-
s_push(stack *s, dfa *d, node *parent)
38+
s_push(stack *s, const dfa *d, node *parent)
3939
{
4040
stackentry *top;
4141
if (s->s_top == s->s_base) {
@@ -119,7 +119,7 @@ shift(stack *s, int type, char *str, int newstate, int lineno, int col_offset,
119119
}
120120

121121
static int
122-
push(stack *s, int type, dfa *d, int newstate, int lineno, int col_offset,
122+
push(stack *s, int type, const dfa *d, int newstate, int lineno, int col_offset,
123123
int end_lineno, int end_col_offset)
124124
{
125125
int err;
@@ -144,7 +144,7 @@ classify(parser_state *ps, int type, const char *str)
144144
int n = g->g_ll.ll_nlabels;
145145

146146
if (type == NAME) {
147-
label *l = g->g_ll.ll_label;
147+
const label *l = g->g_ll.ll_label;
148148
int i;
149149
for (i = n; i > 0; i--, l++) {
150150
if (l->lb_type != NAME || l->lb_str == NULL ||
@@ -168,7 +168,7 @@ classify(parser_state *ps, int type, const char *str)
168168
}
169169

170170
{
171-
label *l = g->g_ll.ll_label;
171+
const label *l = g->g_ll.ll_label;
172172
int i;
173173
for (i = n; i > 0; i--, l++) {
174174
if (l->lb_type == type && l->lb_str == NULL) {
@@ -246,7 +246,7 @@ PyParser_AddToken(parser_state *ps, int type, char *str,
246246
/* Loop until the token is shifted or an error occurred */
247247
for (;;) {
248248
/* Fetch the current dfa and state */
249-
dfa *d = ps->p_stack.s_top->s_dfa;
249+
const dfa *d = ps->p_stack.s_top->s_dfa;
250250
state *s = &d->d_state[ps->p_stack.s_top->s_state];
251251

252252
D(printf(" DFA '%s', state %d:",
@@ -260,15 +260,14 @@ PyParser_AddToken(parser_state *ps, int type, char *str,
260260
/* Push non-terminal */
261261
int nt = (x >> 8) + NT_OFFSET;
262262
int arrow = x & ((1<<7)-1);
263-
dfa *d1;
264263
if (nt == func_body_suite && !(ps->p_flags & PyCF_TYPE_COMMENTS)) {
265264
/* When parsing type comments is not requested,
266265
we can provide better errors about bad indentation
267266
by using 'suite' for the body of a funcdef */
268267
D(printf(" [switch func_body_suite to suite]"));
269268
nt = suite;
270269
}
271-
d1 = PyGrammar_FindDFA(
270+
const dfa *d1 = PyGrammar_FindDFA(
272271
ps->p_grammar, nt);
273272
if ((err = push(&ps->p_stack, nt, d1,
274273
arrow, lineno, col_offset,

Parser/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111

1212
typedef struct {
1313
int s_state; /* State in current DFA */
14-
dfa *s_dfa; /* Current DFA */
14+
const dfa *s_dfa; /* Current DFA */
1515
struct _node *s_parent; /* Where to add next node */
1616
} stackentry;
1717

0 commit comments

Comments
 (0)