Skip to content

use const in graminit.c #12713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -77,7 +77,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 @@ -90,7 +90,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 @@ -132,7 +132,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