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
23b3fda7
Commit
23b3fda7
authored
Mar 11, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transform empty comprehensions into empty literals
parent
469db401
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
4 deletions
+14
-4
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+7
-0
tests/run/constant_folding.py
tests/run/constant_folding.py
+5
-3
tests/run/constant_folding_cy.pyx
tests/run/constant_folding_cy.pyx
+2
-1
No files found.
Cython/Compiler/Optimize.py
View file @
23b3fda7
...
...
@@ -3233,6 +3233,13 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
return
base
return
node
def
visit_ComprehensionNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
isinstance
(
node
.
loop
,
Nodes
.
StatListNode
)
and
not
node
.
loop
.
stats
:
# loop was pruned already => transform into literal
return
node
.
target
return
node
def
visit_ForInStatNode
(
self
,
node
):
self
.
visitchildren
(
node
)
sequence
=
node
.
iterator
.
sequence
...
...
tests/run/constant_folding.py
View file @
23b3fda7
...
...
@@ -213,10 +213,11 @@ def for_in_empty_else():
@
cython
.
test_fail_if_path_exists
(
"//ComprehensionNode"
,
"//ForInStatNode"
,
)
@
cython
.
test_assert_path_exists
(
"//
Comprehension
Node"
,
"//
List
Node"
,
)
def
for_in_empty_listcomp
():
"""
...
...
@@ -227,10 +228,11 @@ def for_in_empty_listcomp():
@
cython
.
test_fail_if_path_exists
(
"//ComprehensionNode"
,
"//ForInStatNode"
,
)
@
cython
.
test_assert_path_exists
(
"//
Comprehension
Node"
,
"//
List
Node"
,
)
def
for_in_empty_nested_listcomp
():
"""
...
...
@@ -242,7 +244,7 @@ def for_in_empty_nested_listcomp():
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode//ForInStatNode"
,
)
)
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//ComprehensionNode"
,
...
...
tests/run/constant_folding_cy.pyx
View file @
23b3fda7
...
...
@@ -83,10 +83,11 @@ def unicode_slicing_safe_surrogates2():
@
cython
.
test_fail_if_path_exists
(
"//ComprehensionNode"
,
"//ForInStatNode"
,
)
@
cython
.
test_assert_path_exists
(
"//
Comprehension
Node"
,
"//
Set
Node"
,
)
def
for_in_empty_setcomp
():
"""
...
...
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