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
4610ff37
Commit
4610ff37
authored
Sep 14, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect const-overloading of cypclass methods
parent
c32a402e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+38
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+10
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
4610ff37
...
@@ -3160,6 +3160,27 @@ class CFuncType(CType):
...
@@ -3160,6 +3160,27 @@ class CFuncType(CType):
return
0
return
0
return
1
return
1
def
same_ptr_args_without_cv_with
(
self
,
other_type
,
as_cmethod
=
0
):
return
self
.
same_ptr_args_without_cv_with_resolved_type
(
other_type
.
resolve
(),
as_cmethod
)
def
same_ptr_args_without_cv_with_resolved_type
(
self
,
other_type
,
as_cmethod
=
0
):
if
other_type
is
error_type
:
return
1
if
not
other_type
.
is_cfunction
:
return
0
nargs
=
len
(
self
.
args
)
if
nargs
!=
len
(
other_type
.
args
):
return
0
for
i
in
range
(
as_cmethod
,
nargs
):
if
not
ptr_to_same_without_cv
(
self
.
args
[
i
].
type
,
other_type
.
args
[
i
].
type
):
if
not
self
.
args
[
i
].
type
.
same_as
(
other_type
.
args
[
i
].
type
):
return
0
if
self
.
has_varargs
!=
other_type
.
has_varargs
:
return
0
if
self
.
optional_arg_count
!=
other_type
.
optional_arg_count
:
return
0
return
1
def
narrower_or_larger_arguments_than
(
self
,
other_type
,
as_cmethod
=
0
):
def
narrower_or_larger_arguments_than
(
self
,
other_type
,
as_cmethod
=
0
):
return
self
.
narrower_or_larger_arguments_than_resolved_type
(
other_type
.
resolve
(),
as_cmethod
)
return
self
.
narrower_or_larger_arguments_than_resolved_type
(
other_type
.
resolve
(),
as_cmethod
)
...
@@ -5539,6 +5560,23 @@ def ptr_to_subtype_of(type1, type2):
...
@@ -5539,6 +5560,23 @@ def ptr_to_subtype_of(type1, type2):
return
type1
.
base_type
.
subtype_of
(
type2
.
base_type
)
return
type1
.
base_type
.
subtype_of
(
type2
.
base_type
)
return
0
return
0
def
ptr_to_same_without_cv
(
type1
,
type2
):
if
type1
.
is_cyp_class
and
type2
.
is_cyp_class
:
if
type1
.
is_const_cyp_class
:
type1
=
type1
.
const_base_type
if
type2
.
is_const_cyp_class
:
type2
=
type2
.
const_base_type
return
same_type
(
type1
,
type2
)
elif
type1
.
is_ptr
and
type2
.
is_ptr
:
type1
=
type1
.
base_type
type1
=
type2
.
base_type
if
type1
.
is_cv_qualified
:
type1
=
type1
.
base_type
if
type2
.
is_cv_qualified
:
type2
=
type2
.
base_type
return
same_type
(
type1
,
type2
)
return
0
def
typecast
(
to_type
,
from_type
,
expr_code
):
def
typecast
(
to_type
,
from_type
,
expr_code
):
# Return expr_code cast to a C type which can be
# Return expr_code cast to a C type which can be
# assigned to to_type, assuming its existing C type
# assigned to to_type, assuming its existing C type
...
...
Cython/Compiler/Symtab.py
View file @
4610ff37
...
@@ -547,6 +547,12 @@ class Scope(object):
...
@@ -547,6 +547,12 @@ class Scope(object):
cpp_override_allowed
=
True
cpp_override_allowed
=
True
continue
continue
# allow const overloads
if
alt_type
.
is_const_method
!=
type
.
is_const_method
:
error
(
pos
,
"Cypclass method const-overloads another method: not supported yet"
)
cpp_override_allowed
=
True
continue
elif
alt_entry
.
is_inherited
:
elif
alt_entry
.
is_inherited
:
# if the arguments are compatible, then the signatures need to actually be the
# if the arguments are compatible, then the signatures need to actually be the
...
@@ -579,6 +585,10 @@ class Scope(object):
...
@@ -579,6 +585,10 @@ class Scope(object):
# stop if cpp_override_allowed is False for the current alternative
# stop if cpp_override_allowed is False for the current alternative
break
break
# allow const overloads
elif
type
.
same_ptr_args_without_cv_with
(
alt_type
):
error
(
pos
,
"Cypclass method const-overloads another method: not supported yet"
)
# if an overloaded alternative has narrower argument types than another, then the method
# if an overloaded alternative has narrower argument types than another, then the method
# actually called will depend on the static type of the arguments
# actually called will depend on the static type of the arguments
# we actually also disallow methods where each argument is either narrower or larger
# we actually also disallow methods where each argument is either narrower or larger
...
...
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