Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
84b4784f
Commit
84b4784f
authored
Apr 23, 2019
by
tyomitch
Committed by
Inada Naoki
Apr 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use `const` in graminit.c (GH-12713)
parent
fb8c7d53
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
418 additions
and
418 deletions
+418
-418
Include/grammar.h
Include/grammar.h
+5
-5
Parser/pgen/grammar.py
Parser/pgen/grammar.py
+3
-3
Python/graminit.c
Python/graminit.c
+410
-410
No files found.
Include/grammar.h
View file @
84b4784f
...
...
@@ -13,7 +13,7 @@ extern "C" {
typedef
struct
{
int
lb_type
;
c
har
*
lb_str
;
c
onst
char
*
lb_str
;
}
label
;
#define EMPTY 0
/* Label number 0 is by definition the empty label */
...
...
@@ -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 */
...
...
@@ -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 */
...
...
@@ -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
;
...
...
Parser/pgen/grammar.py
View file @
84b4784f
...
...
@@ -76,7 +76,7 @@ class Grammar:
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
...
...
@@ -89,7 +89,7 @@ class Grammar:
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
(
...
...
@@ -131,7 +131,7 @@ class Grammar:
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
)
)
...
...
Python/graminit.c
View file @
84b4784f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment