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
b8860831
Commit
b8860831
authored
Jul 14, 2009
by
DaniloFreitas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
general best_match and analyse_cpp_operation
parent
9ffea24c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
32 deletions
+22
-32
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+22
-32
No files found.
Cython/Compiler/ExprNodes.py
View file @
b8860831
...
...
@@ -4302,6 +4302,22 @@ class NumBinopNode(BinopNode):
self
.
operand1
=
self
.
operand1
.
coerce_to
(
self
.
type
,
env
)
self
.
operand2
=
self
.
operand2
.
coerce_to
(
self
.
type
,
env
)
def
analyse_cpp_operation
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
type1
.
is_ptr
:
type1
=
type1
.
base_type
if
type2
.
is_ptr
:
type2
=
type2
.
base_type
entry
=
env
.
lookup
(
type1
.
name
)
function
=
entry
.
type
.
scope
.
lookup
(
self
.
operators
[
self
.
operator
])
if
not
function
:
error
(
self
.
pos
,
"'%s' operator not defined for '%s %s %s'"
%
(
self
.
operator
,
type1
,
type2
,
self
.
operator
))
self
.
type_error
()
return
self
.
type
=
self
.
best_match
(
function
)
def
compute_c_result_type
(
self
,
type1
,
type2
):
if
self
.
c_types_okay
(
type1
,
type2
):
return
PyrexTypes
.
widest_numeric_type
(
type1
,
type2
)
...
...
@@ -4391,6 +4407,12 @@ class NumBinopNode(BinopNode):
"**"
:
"PyNumber_Power"
}
operators
=
{
"+"
:
u"__add__"
,
"-"
:
u"__sub__"
,
"*"
:
u"__mul__"
}
#for now
class
IntBinopNode
(
NumBinopNode
):
# Binary operation taking integer arguments.
...
...
@@ -4404,22 +4426,6 @@ class IntBinopNode(NumBinopNode):
class
AddNode
(
NumBinopNode
):
# '+' operator.
def
analyse_cpp_operation
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
type1
.
is_ptr
:
type1
=
type1
.
base_type
if
type2
.
is_ptr
:
type2
=
type2
.
base_type
entry
=
env
.
lookup
(
type1
.
name
)
function
=
entry
.
type
.
scope
.
lookup
(
u'__add__'
)
if
not
function
:
error
(
self
.
pos
,
"'+' operator not defined for '%s + %s'"
%
(
type1
,
type2
))
self
.
type_error
()
return
self
.
type
=
self
.
best_match
(
function
)
def
is_py_operation
(
self
):
if
self
.
operand1
.
type
.
is_string
\
and
self
.
operand2
.
type
.
is_string
:
...
...
@@ -4441,22 +4447,6 @@ class AddNode(NumBinopNode):
class
SubNode
(
NumBinopNode
):
# '-' operator.
def
analyse_cpp_operation
(
self
,
env
):
type1
=
self
.
operand1
.
type
type2
=
self
.
operand2
.
type
if
type1
.
is_ptr
:
type1
=
type1
.
base_type
if
type2
.
is_ptr
:
type2
=
type2
.
base_type
entry
=
env
.
lookup
(
type1
.
name
)
function
=
entry
.
type
.
scope
.
lookup
(
u'__sub__'
)
if
not
function
:
error
(
self
.
pos
,
"'-' operator not defined for '%s - %s'"
%
(
type1
,
type2
))
self
.
type_error
()
return
self
.
type
=
self
.
best_match
(
function
)
def
compute_c_result_type
(
self
,
type1
,
type2
):
if
(
type1
.
is_ptr
or
type1
.
is_array
)
and
(
type2
.
is_int
or
type2
.
is_enum
):
return
type1
...
...
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