mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
use const
in graminit.c (GH-12713)
This commit is contained in:
parent
fb8c7d5332
commit
84b4784f12
3 changed files with 418 additions and 418 deletions
|
@ -13,7 +13,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int lb_type;
|
int lb_type;
|
||||||
char *lb_str;
|
const char *lb_str;
|
||||||
} label;
|
} label;
|
||||||
|
|
||||||
#define EMPTY 0 /* Label number 0 is by definition the empty label */
|
#define EMPTY 0 /* Label number 0 is by definition the empty label */
|
||||||
|
@ -22,7 +22,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int ll_nlabels;
|
int ll_nlabels;
|
||||||
label *ll_label;
|
const label *ll_label;
|
||||||
} labellist;
|
} labellist;
|
||||||
|
|
||||||
/* An arc from one state to another */
|
/* An arc from one state to another */
|
||||||
|
@ -36,7 +36,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int s_narcs;
|
int s_narcs;
|
||||||
arc *s_arc; /* Array of arcs */
|
const arc *s_arc; /* Array of arcs */
|
||||||
|
|
||||||
/* Optional accelerators */
|
/* Optional accelerators */
|
||||||
int s_lower; /* Lowest label index */
|
int s_lower; /* Lowest label index */
|
||||||
|
@ -59,8 +59,8 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int g_ndfas;
|
int g_ndfas;
|
||||||
dfa *g_dfa; /* Array of DFAs */
|
const dfa *g_dfa; /* Array of DFAs */
|
||||||
labellist g_ll;
|
const labellist g_ll;
|
||||||
int g_start; /* Start symbol of the grammar */
|
int g_start; /* Start symbol of the grammar */
|
||||||
int g_accel; /* Set if accelerators present */
|
int g_accel; /* Set if accelerators present */
|
||||||
} grammar;
|
} grammar;
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Grammar:
|
||||||
|
|
||||||
def print_labels(self, writer):
|
def print_labels(self, writer):
|
||||||
writer(
|
writer(
|
||||||
"static label labels[{n_labels}] = {{\n".format(n_labels=len(self.labels))
|
"static const label labels[{n_labels}] = {{\n".format(n_labels=len(self.labels))
|
||||||
)
|
)
|
||||||
for label, name in self.labels:
|
for label, name in self.labels:
|
||||||
label_name = '"{}"'.format(name) if name is not None else 0
|
label_name = '"{}"'.format(name) if name is not None else 0
|
||||||
|
@ -89,7 +89,7 @@ class Grammar:
|
||||||
|
|
||||||
def print_dfas(self, writer):
|
def print_dfas(self, writer):
|
||||||
self.print_states(writer)
|
self.print_states(writer)
|
||||||
writer("static dfa dfas[{}] = {{\n".format(len(self.dfas)))
|
writer("static const dfa dfas[{}] = {{\n".format(len(self.dfas)))
|
||||||
for dfaindex, dfa_elem in enumerate(self.dfas.items()):
|
for dfaindex, dfa_elem in enumerate(self.dfas.items()):
|
||||||
symbol, (dfa, first_sets) = dfa_elem
|
symbol, (dfa, first_sets) = dfa_elem
|
||||||
writer(
|
writer(
|
||||||
|
@ -131,7 +131,7 @@ class Grammar:
|
||||||
for stateindex, state in enumerate(states):
|
for stateindex, state in enumerate(states):
|
||||||
narcs = len(state)
|
narcs = len(state)
|
||||||
write(
|
write(
|
||||||
"static arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
|
"static const arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
|
||||||
dfa_index=dfaindex, state_index=stateindex, n_arcs=narcs
|
dfa_index=dfaindex, state_index=stateindex, n_arcs=narcs
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue