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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
7837b470
Commit
7837b470
authored
Nov 11, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
another bit less overhead inside of Visitor classes
parent
71b6938a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
Cython/Compiler/Visitor.pxd
Cython/Compiler/Visitor.pxd
+3
-2
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+6
-3
No files found.
Cython/Compiler/Visitor.pxd
View file @
7837b470
...
@@ -3,14 +3,15 @@ cimport cython
...
@@ -3,14 +3,15 @@ cimport cython
cdef
class
BasicVisitor
:
cdef
class
BasicVisitor
:
cdef
dict
dispatch_table
cdef
dict
dispatch_table
cpdef
visit
(
self
,
obj
)
cpdef
visit
(
self
,
obj
)
cpdef
find_handler
(
self
,
obj
)
cdef
_visit
(
self
,
obj
)
cdef
find_handler
(
self
,
obj
)
cdef
class
TreeVisitor
(
BasicVisitor
):
cdef
class
TreeVisitor
(
BasicVisitor
):
cdef
public
list
access_path
cdef
public
list
access_path
cpdef
visitchild
(
self
,
child
,
parent
,
attrname
,
idx
)
cpdef
visitchild
(
self
,
child
,
parent
,
attrname
,
idx
)
@
cython
.
locals
(
idx
=
int
)
@
cython
.
locals
(
idx
=
int
)
cdef
dict
_visitchildren
(
self
,
parent
,
attrs
)
cdef
dict
_visitchildren
(
self
,
parent
,
attrs
)
#
cpdef visitchildren(self, parent, attrs=*)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cdef
class
VisitorTransform
(
TreeVisitor
):
cdef
class
VisitorTransform
(
TreeVisitor
):
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
cpdef
visitchildren
(
self
,
parent
,
attrs
=*
)
...
...
Cython/Compiler/Visitor.py
View file @
7837b470
...
@@ -20,6 +20,9 @@ class BasicVisitor(object):
...
@@ -20,6 +20,9 @@ class BasicVisitor(object):
self
.
dispatch_table
=
{}
self
.
dispatch_table
=
{}
def
visit
(
self
,
obj
):
def
visit
(
self
,
obj
):
return
self
.
_visit
(
obj
)
def
_visit
(
self
,
obj
):
try
:
try
:
handler_method
=
self
.
dispatch_table
[
type
(
obj
)]
handler_method
=
self
.
dispatch_table
[
type
(
obj
)]
except
KeyError
:
except
KeyError
:
...
@@ -176,7 +179,7 @@ class TreeVisitor(BasicVisitor):
...
@@ -176,7 +179,7 @@ class TreeVisitor(BasicVisitor):
def
visitchild
(
self
,
child
,
parent
,
attrname
,
idx
):
def
visitchild
(
self
,
child
,
parent
,
attrname
,
idx
):
self
.
access_path
.
append
((
parent
,
attrname
,
idx
))
self
.
access_path
.
append
((
parent
,
attrname
,
idx
))
try
:
try
:
result
=
self
.
visit
(
child
)
result
=
self
.
_
visit
(
child
)
except
Errors
.
CompileError
:
except
Errors
.
CompileError
:
raise
raise
except
Exception
,
e
:
except
Exception
,
e
:
...
@@ -256,7 +259,7 @@ class VisitorTransform(TreeVisitor):
...
@@ -256,7 +259,7 @@ class VisitorTransform(TreeVisitor):
return
node
return
node
def
__call__
(
self
,
root
):
def
__call__
(
self
,
root
):
return
self
.
visit
(
root
)
return
self
.
_
visit
(
root
)
class
CythonTransform
(
VisitorTransform
):
class
CythonTransform
(
VisitorTransform
):
"""
"""
...
@@ -388,7 +391,7 @@ class PrintTree(TreeVisitor):
...
@@ -388,7 +391,7 @@ class PrintTree(TreeVisitor):
def
__call__
(
self
,
tree
,
phase
=
None
):
def
__call__
(
self
,
tree
,
phase
=
None
):
print
(
"Parse tree dump at phase '%s'"
%
phase
)
print
(
"Parse tree dump at phase '%s'"
%
phase
)
self
.
visit
(
tree
)
self
.
_
visit
(
tree
)
return
tree
return
tree
# Don't do anything about process_list, the defaults gives
# Don't do anything about process_list, the defaults gives
...
...
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