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
Gwenaël Samain
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:
...
@@ -12,10 +12,12 @@ cdef class TreeVisitor:
cdef
_visitchild
(
self
,
child
,
parent
,
attrname
,
idx
)
cdef
_visitchild
(
self
,
child
,
parent
,
attrname
,
idx
)
cdef
dict
_visitchildren
(
self
,
parent
,
attrs
)
cdef
dict
_visitchildren
(
self
,
parent
,
attrs
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cdef
_raise_compiler_error
(
self
,
child
,
e
)
cdef
class
VisitorTransform
(
TreeVisitor
):
cdef
class
VisitorTransform
(
TreeVisitor
):
cdef
dict
_process_children
(
self
,
parent
,
attrs
=*
)
cdef
dict
_process_children
(
self
,
parent
,
attrs
=*
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cdef
list
_flatten_list
(
self
,
list
orig_list
)
cdef
class
CythonTransform
(
VisitorTransform
):
cdef
class
CythonTransform
(
VisitorTransform
):
cdef
public
context
cdef
public
context
...
...
Cython/Compiler/Visitor.py
View file @
2ab4744f
...
@@ -78,7 +78,7 @@ class TreeVisitor(object):
...
@@ -78,7 +78,7 @@ class TreeVisitor(object):
self
.
dispatch_table
=
{}
self
.
dispatch_table
=
{}
self
.
access_path
=
[]
self
.
access_path
=
[]
def
dump_node
(
self
,
node
,
indent
=
0
):
def
dump_node
(
self
,
node
):
ignored
=
list
(
node
.
child_attrs
or
[])
+
[
ignored
=
list
(
node
.
child_attrs
or
[])
+
[
u'child_attrs'
,
u'pos'
,
u'gil_message'
,
u'cpp_message'
,
u'subexprs'
]
u'child_attrs'
,
u'pos'
,
u'gil_message'
,
u'cpp_message'
,
u'subexprs'
]
values
=
[]
values
=
[]
...
@@ -90,7 +90,6 @@ class TreeVisitor(object):
...
@@ -90,7 +90,6 @@ class TreeVisitor(object):
source
=
os
.
path
.
basename
(
source
.
get_description
())
source
=
os
.
path
.
basename
(
source
.
get_description
())
values
.
append
(
u'%s:%s:%s'
%
(
source
,
pos
[
1
],
pos
[
2
]))
values
.
append
(
u'%s:%s:%s'
%
(
source
,
pos
[
1
],
pos
[
2
]))
attribute_names
=
dir
(
node
)
attribute_names
=
dir
(
node
)
attribute_names
.
sort
()
for
attr
in
attribute_names
:
for
attr
in
attribute_names
:
if
attr
in
ignored
:
if
attr
in
ignored
:
continue
continue
...
@@ -156,7 +155,6 @@ class TreeVisitor(object):
...
@@ -156,7 +155,6 @@ class TreeVisitor(object):
cls
=
type
(
obj
)
cls
=
type
(
obj
)
pattern
=
"visit_%s"
pattern
=
"visit_%s"
mro
=
inspect
.
getmro
(
cls
)
mro
=
inspect
.
getmro
(
cls
)
handler_method
=
None
for
mro_cls
in
mro
:
for
mro_cls
in
mro
:
handler_method
=
getattr
(
self
,
pattern
%
mro_cls
.
__name__
,
None
)
handler_method
=
getattr
(
self
,
pattern
%
mro_cls
.
__name__
,
None
)
if
handler_method
is
not
None
:
if
handler_method
is
not
None
:
...
@@ -255,20 +253,23 @@ class VisitorTransform(TreeVisitor):
...
@@ -255,20 +253,23 @@ class VisitorTransform(TreeVisitor):
# fast cdef entry point for calls from Cython subclasses
# fast cdef entry point for calls from Cython subclasses
result
=
self
.
_visitchildren
(
parent
,
attrs
)
result
=
self
.
_visitchildren
(
parent
,
attrs
)
for
attr
,
newnode
in
result
.
items
():
for
attr
,
newnode
in
result
.
items
():
if
type
(
newnode
)
is
not
list
:
if
type
(
newnode
)
is
list
:
setattr
(
parent
,
attr
,
newnode
)
newnode
=
self
.
_flatten_list
(
newnode
)
else
:
setattr
(
parent
,
attr
,
newnode
)
# 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
)
return
result
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
):
def
recurse_to_children
(
self
,
node
):
self
.
_process_children
(
node
)
self
.
_process_children
(
node
)
return
node
return
node
...
@@ -276,6 +277,7 @@ class VisitorTransform(TreeVisitor):
...
@@ -276,6 +277,7 @@ class VisitorTransform(TreeVisitor):
def
__call__
(
self
,
root
):
def
__call__
(
self
,
root
):
return
self
.
_visit
(
root
)
return
self
.
_visit
(
root
)
class
CythonTransform
(
VisitorTransform
):
class
CythonTransform
(
VisitorTransform
):
"""
"""
Certain common conventions and utilities for Cython transforms.
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