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
e99f6ac7
Commit
e99f6ac7
authored
May 08, 2012
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mark_forloop_target: backport recent changes to MarkAssignments
parent
e090be97
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
14 deletions
+33
-14
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+33
-14
No files found.
Cython/Compiler/FlowControl.py
View file @
e99f6ac7
...
@@ -9,6 +9,7 @@ import Builtin
...
@@ -9,6 +9,7 @@ import Builtin
import
ExprNodes
import
ExprNodes
import
Nodes
import
Nodes
from
PyrexTypes
import
py_object_type
,
unspecified_type
from
PyrexTypes
import
py_object_type
,
unspecified_type
import
PyrexTypes
from
Visitor
import
TreeVisitor
,
CythonTransform
from
Visitor
import
TreeVisitor
,
CythonTransform
from
Errors
import
error
,
warning
,
InternalError
from
Errors
import
error
,
warning
,
InternalError
...
@@ -857,25 +858,43 @@ class ControlFlowAnalysis(CythonTransform):
...
@@ -857,25 +858,43 @@ class ControlFlowAnalysis(CythonTransform):
# TODO: Remove redundancy with range optimization...
# TODO: Remove redundancy with range optimization...
is_special
=
False
is_special
=
False
sequence
=
node
.
iterator
.
sequence
sequence
=
node
.
iterator
.
sequence
target
=
node
.
target
if
isinstance
(
sequence
,
ExprNodes
.
SimpleCallNode
):
if
isinstance
(
sequence
,
ExprNodes
.
SimpleCallNode
):
function
=
sequence
.
function
function
=
sequence
.
function
if
sequence
.
self
is
None
and
function
.
is_name
:
if
sequence
.
self
is
None
and
function
.
is_name
:
if
function
.
name
==
'reversed'
and
len
(
sequence
.
args
)
==
1
:
entry
=
self
.
env
.
lookup
(
function
.
name
)
sequence
=
sequence
.
args
[
0
]
if
not
entry
or
entry
.
is_builtin
:
if
function
.
name
==
'reversed'
and
len
(
sequence
.
args
)
==
1
:
sequence
=
sequence
.
args
[
0
]
elif
function
.
name
==
'enumerate'
and
len
(
sequence
.
args
)
==
1
:
if
target
.
is_sequence_constructor
and
len
(
target
.
args
)
==
2
:
iterator
=
sequence
.
args
[
0
]
if
iterator
.
is_name
:
iterator_type
=
iterator
.
infer_type
(
self
.
env
)
if
iterator_type
.
is_builtin_type
:
# assume that builtin types have a length within Py_ssize_t
self
.
mark_assignment
(
target
.
args
[
0
],
ExprNodes
.
IntNode
(
target
.
pos
,
value
=
'PY_SSIZE_T_MAX'
,
type
=
PyrexTypes
.
c_py_ssize_t_type
))
target
=
target
.
args
[
1
]
sequence
=
sequence
.
args
[
0
]
if
isinstance
(
sequence
,
ExprNodes
.
SimpleCallNode
):
if
isinstance
(
sequence
,
ExprNodes
.
SimpleCallNode
):
function
=
sequence
.
function
function
=
sequence
.
function
if
sequence
.
self
is
None
and
function
.
is_name
:
if
sequence
.
self
is
None
and
function
.
is_name
:
if
function
.
name
in
(
'range'
,
'xrange'
):
entry
=
self
.
env
.
lookup
(
function
.
name
)
is_special
=
True
if
not
entry
or
entry
.
is_builtin
:
for
arg
in
sequence
.
args
[:
2
]:
if
function
.
name
in
(
'range'
,
'xrange'
):
self
.
mark_assignment
(
node
.
target
,
arg
)
is_special
=
True
if
len
(
sequence
.
args
)
>
2
:
for
arg
in
sequence
.
args
[:
2
]:
self
.
mark_assignment
(
self
.
mark_assignment
(
target
,
arg
)
node
.
target
,
if
len
(
sequence
.
args
)
>
2
:
ExprNodes
.
binop_node
(
node
.
pos
,
self
.
mark_assignment
(
'+'
,
target
,
sequence
.
args
[
0
],
ExprNodes
.
binop_node
(
node
.
pos
,
sequence
.
args
[
2
]))
'+'
,
sequence
.
args
[
0
],
sequence
.
args
[
2
]))
if
not
is_special
:
if
not
is_special
:
# A for-loop basically translates to subsequent calls to
# A for-loop basically translates to subsequent calls to
...
@@ -883,7 +902,7 @@ class ControlFlowAnalysis(CythonTransform):
...
@@ -883,7 +902,7 @@ class ControlFlowAnalysis(CythonTransform):
# naturally infer the base type of pointers, C arrays,
# naturally infer the base type of pointers, C arrays,
# Python strings, etc., while correctly falling back to an
# Python strings, etc., while correctly falling back to an
# object type when the base type cannot be handled.
# object type when the base type cannot be handled.
self
.
mark_assignment
(
node
.
target
,
ExprNodes
.
IndexNode
(
self
.
mark_assignment
(
target
,
ExprNodes
.
IndexNode
(
node
.
pos
,
node
.
pos
,
base
=
sequence
,
base
=
sequence
,
index
=
ExprNodes
.
IntNode
(
node
.
pos
,
value
=
'0'
)))
index
=
ExprNodes
.
IntNode
(
node
.
pos
,
value
=
'0'
)))
...
...
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