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
c72daa17
Commit
c72daa17
authored
May 29, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow type conversion special methods to be looked up
parent
74e1c4c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
29 deletions
+45
-29
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+45
-29
No files found.
Cython/Compiler/Symtab.py
View file @
c72daa17
...
...
@@ -2775,6 +2775,43 @@ class CppClassScope(Scope):
activated_method_entry
.
is_cfunction
=
1
activated_method_entry
.
is_variable
=
1
# Return the type declaration string if stripped_name corresponds to a known type, None otherwise.
# The returned string is intended to be used to build an operator of the form "operator <type name>".
def
_as_type_operator
(
self
,
stripped_name
):
as_operator_name
=
None
signed
=
1
longness
=
0
ctypename
=
None
exploded_name
=
stripped_name
.
split
(
'_'
)
for
index
,
token
in
enumerate
(
exploded_name
):
# Basically, it is the same code than Parsing.p_sign_and_longness
if
token
==
'unsigned'
:
signed
=
0
elif
token
==
'signed'
:
signed
=
2
elif
token
==
'short'
:
longness
=
-
1
elif
token
==
'long'
:
longness
+=
1
else
:
ctypename
=
'_'
.
join
(
exploded_name
[
index
:])
break
known_type
=
PyrexTypes
.
simple_c_type
(
signed
,
longness
,
ctypename
)
if
not
known_type
:
if
stripped_name
==
"bool"
:
# This one is hardcoded because it is declared as an int
# in PyrexTypes
as_operator_name
=
'bool'
else
:
known_type
=
self
.
lookup_type
(
stripped_name
)
if
known_type
:
as_operator_name
=
known_type
.
declaration_code
(
''
)
return
as_operator_name
def
declare_cfunction
(
self
,
name
,
type
,
pos
,
cname
=
None
,
visibility
=
'extern'
,
api
=
0
,
in_pxd
=
0
,
defining
=
0
,
modifiers
=
(),
utility_code
=
None
,
overridable
=
False
,
inheriting
=
0
):
...
...
@@ -2840,36 +2877,10 @@ class CppClassScope(Scope):
name
=
'operator'
+
operator
elif
name
.
startswith
(
'__'
)
and
name
.
endswith
(
'__'
):
stripped_name
=
name
[
2
:
-
2
]
signed
=
1
longness
=
0
ctypename
=
None
exploded_name
=
stripped_name
.
split
(
'_'
)
for
index
,
token
in
enumerate
(
exploded_name
):
# Basically, it is the same code than Parsing.p_sign_and_longness
if
token
==
'unsigned'
:
signed
=
0
elif
token
==
'signed'
:
signed
=
2
elif
token
==
'short'
:
longness
=
-
1
elif
token
==
'long'
:
longness
+=
1
else
:
ctypename
=
'_'
.
join
(
exploded_name
[
index
:])
break
known_type
=
PyrexTypes
.
simple_c_type
(
signed
,
longness
,
ctypename
)
if
not
known_type
:
if
stripped_name
==
"bool"
:
reify
=
False
# This one is hardcoded because it is declared as an int
# in PyrexTypes
name
=
'operator bool'
type
.
args
=
[]
else
:
known_type
=
self
.
lookup_type
(
stripped_name
)
if
known_type
:
as_operator_name
=
self
.
_as_type_operator
(
stripped_name
)
if
as_operator_name
:
reify
=
False
name
=
'operator '
+
known_type
.
declaration_code
(
''
)
name
=
'operator '
+
as_operator_name
type
.
args
=
[]
if
name
in
(
'<init>'
,
'<del>'
)
and
type
.
nogil
:
...
...
@@ -3018,6 +3029,11 @@ class CppClassScope(Scope):
operator
=
self
.
operator_table
.
get
(
name
,
None
)
if
operator
:
name
=
'operator'
+
operator
elif
name
.
startswith
(
'__'
)
and
name
.
endswith
(
'__'
):
stripped_name
=
name
[
2
:
-
2
]
as_operator_name
=
self
.
_as_type_operator
(
stripped_name
)
if
as_operator_name
:
name
=
'operator '
+
as_operator_name
return
super
(
CppClassScope
,
self
).
lookup_here
(
name
)
...
...
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