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
a5e49f6e
Commit
a5e49f6e
authored
Aug 08, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix switch transform for in-list tests
parent
7997dd38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+12
-12
tests/run/switch.pyx
tests/run/switch.pyx
+16
-0
No files found.
Cython/Compiler/Optimize.py
View file @
a5e49f6e
...
...
@@ -11,13 +11,9 @@ from StringEncoding import EncodedString
from
ParseTreeTransforms
import
SkipDeclarations
#def unwrap_node(node):
# while isinstance(node, ExprNodes.PersistentNode):
# node = node.arg
# return node
# Temporary hack while PersistentNode is out of order
def
unwrap_node
(
node
):
while
isinstance
(
node
,
UtilNodes
.
ResultRefNode
):
node
=
node
.
expression
return
node
def
is_common_value
(
a
,
b
):
...
...
@@ -301,13 +297,17 @@ class SwitchTransform(Visitor.VisitorTransform):
is common among all clauses and both var and value are ints.
"""
def
extract_conditions
(
self
,
cond
):
if
isinstance
(
cond
,
ExprNodes
.
CoerceToTempNode
):
cond
=
cond
.
arg
while
True
:
if
isinstance
(
cond
,
ExprNodes
.
CoerceToTempNode
):
cond
=
cond
.
arg
elif
isinstance
(
cond
,
UtilNodes
.
EvalWithTempExprNode
):
# this is what we get from the FlattenInListTransform
cond
=
cond
.
subexpression
elif
isinstance
(
cond
,
ExprNodes
.
TypecastNode
):
cond
=
cond
.
operand
else
:
break
if
isinstance
(
cond
,
ExprNodes
.
TypecastNode
):
cond
=
cond
.
operand
if
(
isinstance
(
cond
,
ExprNodes
.
PrimaryCmpNode
)
and
cond
.
cascade
is
None
and
cond
.
operator
==
'=='
...
...
tests/run/switch.pyx
View file @
a5e49f6e
...
...
@@ -74,6 +74,17 @@ __doc__ = u"""
>>> switch_or(4)
0
>>> switch_in(0)
0
>>> switch_in(1)
1
>>> switch_in(2)
0
>>> switch_in(7)
1
>>> switch_in(8)
0
>>> switch_short(0)
0
>>> switch_short(1)
...
...
@@ -161,6 +172,11 @@ def switch_or(int x):
return
0
return
-
1
def
switch_in
(
int
X
):
if
X
in
(
1
,
3
,
5
,
7
):
return
1
return
0
def
switch_short
(
int
x
):
if
x
==
1
:
return
1
...
...
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