Skip to content

Commit

Permalink
use const in graminit.c (pythonGH-12713)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyomitch authored and methane committed Apr 23, 2019
1 parent fb8c7d5 commit 84b4784
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 418 deletions.
10 changes: 5 additions & 5 deletions Include/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {

typedef struct {
int lb_type;
char *lb_str;
const char *lb_str;
} label;

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

typedef struct {
int ll_nlabels;
label *ll_label;
const label *ll_label;
} labellist;

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

typedef struct {
int s_narcs;
arc *s_arc; /* Array of arcs */
const arc *s_arc; /* Array of arcs */

/* Optional accelerators */
int s_lower; /* Lowest label index */
Expand All @@ -59,8 +59,8 @@ typedef struct {

typedef struct {
int g_ndfas;
dfa *g_dfa; /* Array of DFAs */
labellist g_ll;
const dfa *g_dfa; /* Array of DFAs */
const labellist g_ll;
int g_start; /* Start symbol of the grammar */
int g_accel; /* Set if accelerators present */
} grammar;
Expand Down
6 changes: 3 additions & 3 deletions Parser/pgen/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def produce_graminit_c(self, writer):

def print_labels(self, 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:
label_name = '"{}"'.format(name) if name is not None else 0
Expand All @@ -89,7 +89,7 @@ def print_labels(self, writer):

def print_dfas(self, 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()):
symbol, (dfa, first_sets) = dfa_elem
writer(
Expand Down Expand Up @@ -131,7 +131,7 @@ def print_arcs(self, write, dfaindex, states):
for stateindex, state in enumerate(states):
narcs = len(state)
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
)
)
Expand Down
Loading

0 comments on commit 84b4784

Please sign in to comment.