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
Kirill Smelkov
cython
Commits
361737c8
Commit
361737c8
authored
Oct 24, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring, use 'notnone=True' in type tests
parent
dabef9db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
13 deletions
+29
-13
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+29
-13
No files found.
Cython/Compiler/Optimize.py
View file @
361737c8
...
@@ -25,6 +25,10 @@ try:
...
@@ -25,6 +25,10 @@ try:
except
NameError
:
except
NameError
:
from
sets
import
Set
as
set
from
sets
import
Set
as
set
class
FakePythonEnv
(
object
):
"A fake environment for creating type test nodes etc."
nogil
=
False
def
unwrap_node
(
node
):
def
unwrap_node
(
node
):
while
isinstance
(
node
,
UtilNodes
.
ResultRefNode
):
while
isinstance
(
node
,
UtilNodes
.
ResultRefNode
):
node
=
node
.
expression
node
=
node
.
expression
...
@@ -297,11 +301,11 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -297,11 +301,11 @@ class IterationTransform(Visitor.VisitorTransform):
tuple_target
=
node
.
target
tuple_target
=
node
.
target
def
coerce_object_to
(
obj_node
,
dest_type
):
def
coerce_object_to
(
obj_node
,
dest_type
):
class
FakeEnv
(
object
):
nogil
=
False
if
dest_type
.
is_pyobject
:
if
dest_type
.
is_pyobject
:
if
dest_type
.
is_extension_type
or
dest_type
.
is_builtin_type
:
if
dest_type
!=
obj_node
.
type
:
obj_node
=
ExprNodes
.
PyTypeTestNode
(
obj_node
,
dest_type
,
FakeEnv
())
if
dest_type
.
is_extension_type
or
dest_type
.
is_builtin_type
:
obj_node
=
ExprNodes
.
PyTypeTestNode
(
obj_node
,
dest_type
,
FakePythonEnv
(),
notnone
=
True
)
result
=
ExprNodes
.
TypecastNode
(
result
=
ExprNodes
.
TypecastNode
(
obj_node
.
pos
,
obj_node
.
pos
,
operand
=
obj_node
,
operand
=
obj_node
,
...
@@ -316,7 +320,7 @@ class IterationTransform(Visitor.VisitorTransform):
...
@@ -316,7 +320,7 @@ class IterationTransform(Visitor.VisitorTransform):
return
temp_result
.
result
()
return
temp_result
.
result
()
def
generate_execution_code
(
self
,
code
):
def
generate_execution_code
(
self
,
code
):
self
.
generate_result_code
(
code
)
self
.
generate_result_code
(
code
)
return
(
temp_result
,
CoercedTempNode
(
dest_type
,
obj_node
,
FakeEnv
()))
return
(
temp_result
,
CoercedTempNode
(
dest_type
,
obj_node
,
Fake
Python
Env
()))
if
isinstance
(
node
.
body
,
Nodes
.
StatListNode
):
if
isinstance
(
node
.
body
,
Nodes
.
StatListNode
):
body
=
node
.
body
body
=
node
.
body
...
@@ -715,6 +719,22 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -715,6 +719,22 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
else
:
else
:
return
node
return
node
def
_error_wrong_arg_count
(
self
,
function_name
,
node
,
args
,
expected
=
None
):
if
not
expected
:
# None or 0
arg_str
=
''
elif
isinstance
(
expected
,
basestring
)
or
expected
>
1
:
arg_str
=
'...'
elif
expected
==
1
:
arg_str
=
'x'
else
:
arg_str
=
''
if
expected
is
not
None
:
expected_str
=
'expected %s, '
%
expected
else
:
expected_str
=
''
error
(
node
.
pos
,
"%s(%s) called with wrong number of args, %sfound %d"
%
(
function_name
,
arg_str
,
expected_str
,
len
(
args
)))
### builtin types
### builtin types
def
_handle_general_function_dict
(
self
,
node
,
pos_args
,
kwargs
):
def
_handle_general_function_dict
(
self
,
node
,
pos_args
,
kwargs
):
...
@@ -848,8 +868,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -848,8 +868,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
is_temp
=
node
.
is_temp
is_temp
=
node
.
is_temp
)
)
else
:
else
:
error
(
node
.
pos
,
"getattr() called with wrong number of args, "
self
.
_error_wrong_arg_count
(
'getattr'
,
node
,
args
,
'2 or 3'
)
"expected 2 or 3, found %d"
%
len
(
args
))
return
node
return
node
Pyx_Type_func_type
=
PyrexTypes
.
CFuncType
(
Pyx_Type_func_type
=
PyrexTypes
.
CFuncType
(
...
@@ -898,8 +917,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -898,8 +917,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
def
_handle_simple_method_list_append
(
self
,
node
,
args
,
is_unbound_method
):
def
_handle_simple_method_list_append
(
self
,
node
,
args
,
is_unbound_method
):
if
len
(
args
)
!=
2
:
if
len
(
args
)
!=
2
:
error
(
node
.
pos
,
"list.append(x) called with wrong number of args, found %d"
%
self
.
_error_wrong_arg_count
(
'list.append'
,
node
,
args
,
2
)
len
(
args
))
return
node
return
node
return
self
.
_substitute_method_call
(
return
self
.
_substitute_method_call
(
node
,
"PyList_Append"
,
self
.
PyList_Append_func_type
,
node
,
"PyList_Append"
,
self
.
PyList_Append_func_type
,
...
@@ -920,8 +938,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -920,8 +938,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
def
_handle_simple_method_list_reverse
(
self
,
node
,
args
,
is_unbound_method
):
def
_handle_simple_method_list_reverse
(
self
,
node
,
args
,
is_unbound_method
):
if
len
(
args
)
!=
1
:
if
len
(
args
)
!=
1
:
error
(
node
.
pos
,
"list.reverse(x) called with wrong number of args, found %d"
%
self
.
_error_wrong_arg_count
(
'list.reverse'
,
node
,
args
,
1
)
len
(
args
))
return
node
return
node
return
self
.
_substitute_method_call
(
return
self
.
_substitute_method_call
(
node
,
"PyList_Reverse"
,
self
.
single_param_func_type
,
node
,
"PyList_Reverse"
,
self
.
single_param_func_type
,
...
@@ -949,8 +966,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
...
@@ -949,8 +966,7 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
def
_handle_simple_method_unicode_encode
(
self
,
node
,
args
,
is_unbound_method
):
def
_handle_simple_method_unicode_encode
(
self
,
node
,
args
,
is_unbound_method
):
if
len
(
args
)
<
1
or
len
(
args
)
>
3
:
if
len
(
args
)
<
1
or
len
(
args
)
>
3
:
error
(
node
.
pos
,
"unicode.encode(...) called with wrong number of args, found %d"
%
self
.
_error_wrong_arg_count
(
'unicode.encode'
,
node
,
args
,
'1-3'
)
len
(
args
))
return
node
return
node
null_node
=
ExprNodes
.
NullNode
(
node
.
pos
)
null_node
=
ExprNodes
.
NullNode
(
node
.
pos
)
...
...
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