Skip to content

Commit fe192d3

Browse files
author
artyomsk
committed
Use static const instead of static in graminit.c
1 parent 89a8944 commit fe192d3

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
@@ -77,7 +77,7 @@ def produce_graminit_c(self, writer):
7777

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

9191
def print_dfas(self, writer):
9292
self.print_states(writer)
93-
writer("static dfa dfas[{}] = {{\n".format(len(self.dfas)))
93+
writer("static const dfa dfas[{}] = {{\n".format(len(self.dfas)))
9494
for dfaindex, dfa_elem in enumerate(self.dfas.items()):
9595
symbol, (dfa, first_sets) = dfa_elem
9696
writer(
@@ -132,7 +132,7 @@ def print_arcs(self, write, dfaindex, states):
132132
for stateindex, state in enumerate(states):
133133
narcs = len(state)
134134
write(
135-
"static arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
135+
"static const arc arcs_{dfa_index}_{state_index}[{n_arcs}] = {{\n".format(
136136
dfa_index=dfaindex, state_index=stateindex, n_arcs=narcs
137137
)
138138
)

0 commit comments

Comments
 (0)