Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84b4784

Browse files
tyomitchmethane
authored andcommitted
use const in graminit.c (GH-12713)
1 parent fb8c7d5 commit 84b4784

3 files changed

Lines changed: 418 additions & 418 deletions

File tree

Include/grammar.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313

1414
typedef struct {
1515
int lb_type;
16-
char *lb_str;
16+
const char *lb_str;
1717
} label;
1818

1919
#define EMPTY 0 /* Label number 0 is by definition the empty label */
@@ -22,7 +22,7 @@ typedef struct {
2222

2323
typedef struct {
2424
int ll_nlabels;
25-
label *ll_label;
25+
const label *ll_label;
2626
} labellist;
2727

2828
/* An arc from one state to another */
@@ -36,7 +36,7 @@ typedef struct {
3636

3737
typedef struct {
3838
int s_narcs;
39-
arc *s_arc; /* Array of arcs */
39+
const arc *s_arc; /* Array of arcs */
4040

4141
/* Optional accelerators */
4242
int s_lower; /* Lowest label index */
@@ -59,8 +59,8 @@ typedef struct {
5959

6060
typedef struct {
6161
int g_ndfas;
62-
dfa *g_dfa; /* Array of DFAs */
63-
labellist g_ll;
62+
const dfa *g_dfa; /* Array of DFAs */
63+
const labellist g_ll;
6464
int g_start; /* Start symbol of the grammar */
6565
int g_accel; /* Set if accelerators present */
6666
} grammar;

Parser/pgen/grammar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def produce_graminit_c(self, writer):
7676

7777
def print_labels(self, writer):
7878
writer(
79-
"static label labels[{n_labels}] = {{\n".format(n_labels=len(self.labels))
79+
"static const label labels[{n_labels}] = {{\n".format(n_labels=len(self.labels))
8080
)
8181
for label, name in self.labels:
8282
label_name = '"{}"'.format(name) if name is not None else 0
@@ -89,7 +89,7 @@ def print_labels(self, writer):
8989

9090
def print_dfas(self, writer):
9191
self.print_states(writer)
92-
writer("static dfa dfas[{}] = {{\n".format(len(self.dfas)))
92+
writer("static const dfa dfas[{}] = {{\n".format(len(self.dfas)))
9393
for dfaindex, dfa_elem in enumerate(self.dfas.items()):
9494
symbol, (dfa, first_sets) = dfa_elem
9595
writer(
@@ -131,7 +131,7 @@ def print_arcs(self, write, dfaindex, states):
131131
for stateindex, state in enumerate(states):
132132
narcs = len(state)
133133
write(
134-
"static arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
134+
"static const arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
135135
dfa_index=dfaindex, state_index=stateindex, n_arcs=narcs
136136
)
137137
)

0 commit comments

Comments
 (0)