Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
2ab4744f
Commit
2ab4744f
authored
Aug 31, 2018
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor code simplifications in visitor implementation.
parent
743df03d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
15 deletions
+19
-15
Cython/Compiler/Visitor.pxd
Cython/Compiler/Visitor.pxd
+2
-0
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+17
-15
No files found.
Cython/Compiler/Visitor.pxd
View file @
2ab4744f
...
...
@@ -12,10 +12,12 @@ cdef class TreeVisitor:
cdef
_visitchild
(
self
,
child
,
parent
,
attrname
,
idx
)
cdef
dict
_visitchildren
(
self
,
parent
,
attrs
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cdef
_raise_compiler_error
(
self
,
child
,
e
)
cdef
class
VisitorTransform
(
TreeVisitor
):
cdef
dict
_process_children
(
self
,
parent
,
attrs
=*
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cdef
list
_flatten_list
(
self
,
list
orig_list
)
cdef
class
CythonTransform
(
VisitorTransform
):
cdef
public
context
...
...
Cython/Compiler/Visitor.py
View file @
2ab4744f
...
...
@@ -78,7 +78,7 @@ class TreeVisitor(object):
self
.
dispatch_table
=
{}
self
.
access_path
=
[]
def
dump_node
(
self
,
node
,
indent
=
0
):
def
dump_node
(
self
,
node
):
ignored
=
list
(
node
.
child_attrs
or
[])
+
[
u'child_attrs'
,
u'pos'
,
u'gil_message'
,
u'cpp_message'
,
u'subexprs'
]
values
=
[]
...
...
@@ -90,7 +90,6 @@ class TreeVisitor(object):
source
=
os
.
path
.
basename
(
source
.
get_description
())
values
.
append
(
u'%s:%s:%s'
%
(
source
,
pos
[
1
],
pos
[
2
]))
attribute_names
=
dir
(
node
)
attribute_names
.
sort
()
for
attr
in
attribute_names
:
if
attr
in
ignored
:
continue
...
...
@@ -156,7 +155,6 @@ class TreeVisitor(object):
cls
=
type
(
obj
)
pattern
=
"visit_%s"
mro
=
inspect
.
getmro
(
cls
)
handler_method
=
None
for
mro_cls
in
mro
:
handler_method
=
getattr
(
self
,
pattern
%
mro_cls
.
__name__
,
None
)
if
handler_method
is
not
None
:
...
...
@@ -255,20 +253,23 @@ class VisitorTransform(TreeVisitor):
# fast cdef entry point for calls from Cython subclasses
result
=
self
.
_visitchildren
(
parent
,
attrs
)
for
attr
,
newnode
in
result
.
items
():
if
type
(
newnode
)
is
not
list
:
setattr
(
parent
,
attr
,
newnode
)
else
:
# Flatten the list one level and remove any None
newlist
=
[]
for
x
in
newnode
:
if
x
is
not
None
:
if
type
(
x
)
is
list
:
newlist
+=
x
else
:
newlist
.
append
(
x
)
setattr
(
parent
,
attr
,
newlist
)
if
type
(
newnode
)
is
list
:
newnode
=
self
.
_flatten_list
(
newnode
)
setattr
(
parent
,
attr
,
newnode
)
return
result
@
cython
.
final
def
_flatten_list
(
self
,
orig_list
):
# Flatten the list one level and remove any None
newlist
=
[]
for
x
in
orig_list
:
if
x
is
not
None
:
if
type
(
x
)
is
list
:
newlist
.
extend
(
x
)
else
:
newlist
.
append
(
x
)
return
newlist
def
recurse_to_children
(
self
,
node
):
self
.
_process_children
(
node
)
return
node
...
...
@@ -276,6 +277,7 @@ class VisitorTransform(TreeVisitor):
def
__call__
(
self
,
root
):
return
self
.
_visit
(
root
)
class
CythonTransform
(
VisitorTransform
):
"""
Certain common conventions and utilities for Cython transforms.
...
...
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