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
632aefa5
Commit
632aefa5
authored
May 04, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RemoveUnreachableCode transform and is_terminator Node flag
parent
efb0837d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+37
-0
No files found.
Cython/Compiler/Nodes.py
View file @
632aefa5
...
...
@@ -129,6 +129,7 @@ class Node(object):
is_name
=
0
is_literal
=
0
is_terminator
=
0
temps
=
None
# All descandants should set child_attrs to a list of the attributes
...
...
@@ -4050,6 +4051,7 @@ class PassStatNode(StatNode):
class
BreakStatNode
(
StatNode
):
child_attrs
=
[]
is_terminator
=
True
def
analyse_expressions
(
self
,
env
):
pass
...
...
@@ -4064,6 +4066,7 @@ class BreakStatNode(StatNode):
class
ContinueStatNode
(
StatNode
):
child_attrs
=
[]
is_terminator
=
True
def
analyse_expressions
(
self
,
env
):
pass
...
...
@@ -4084,6 +4087,7 @@ class ReturnStatNode(StatNode):
# return_type PyrexType
child_attrs
=
[
"value"
]
is_terminator
=
True
def
analyse_expressions
(
self
,
env
):
return_type
=
env
.
return_type
...
...
@@ -4157,6 +4161,7 @@ class RaiseStatNode(StatNode):
# cause ExprNode or None
child_attrs
=
[
"exc_type"
,
"exc_value"
,
"exc_tb"
,
"cause"
]
is_terminator
=
True
def
analyse_expressions
(
self
,
env
):
if
self
.
exc_type
:
...
...
@@ -4251,6 +4256,7 @@ class RaiseStatNode(StatNode):
class
ReraiseStatNode
(
StatNode
):
child_attrs
=
[]
is_terminator
=
True
def
analyse_expressions
(
self
,
env
):
env
.
use_utility_code
(
restore_exception_utility_code
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
632aefa5
...
...
@@ -1407,6 +1407,43 @@ class AlignFunctionDefinitions(CythonTransform):
return
node
class
RemoveUnreachableCode
(
CythonTransform
):
def
visit_Node
(
self
,
node
):
self
.
visitchildren
(
node
)
return
node
def
visit_StatListNode
(
self
,
node
):
if
not
self
.
current_directives
[
'remove_unreachable'
]:
return
node
self
.
visitchildren
(
node
)
for
idx
,
stat
in
enumerate
(
node
.
stats
):
idx
+=
1
if
stat
.
is_terminator
:
if
idx
<
len
(
node
.
stats
):
if
self
.
current_directives
[
'warn.unreachable'
]:
warning
(
node
.
stats
[
idx
].
pos
,
"Unreachable code"
,
2
)
node
.
stats
=
node
.
stats
[:
idx
]
node
.
is_terminator
=
True
break
return
node
def
visit_IfClauseNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
body
.
is_terminator
:
node
.
is_terminator
=
True
return
node
def
visit_IfStatNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
node
.
else_clause
and
node
.
else_clause
.
is_terminator
:
for
clause
in
node
.
if_clauses
:
if
not
clause
.
is_terminator
:
break
else
:
node
.
is_terminator
=
True
return
node
class
YieldNodeCollector
(
TreeVisitor
):
def
__init__
(
self
):
...
...
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