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
4a3646d1
Commit
4a3646d1
authored
Jun 05, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose the same name for cypclass wrappers as for the underlying cypclass
parent
df9da2f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+12
-7
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+10
-6
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
4a3646d1
...
...
@@ -152,21 +152,25 @@ class CypclassWrapperInjection(CythonTransform):
# whether the is declared with ':' and a suite, or just a forward declaration
node_has_suite
=
node
.
attributes
is
not
None
nested_names
=
[
node
.
name
for
node
in
self
.
nesting_stack
]
nested_names
.
append
(
node
.
name
)
qualified_name
=
"."
.
join
(
nested_names
)
qualified_name
=
EncodedString
(
qualified_name
)
# if a wrapper for this cypclass entry has already been declared, use the same name
# (only happens when there are forward declarations for the cypclass itself)
if
node
.
entry
in
self
.
cypclass_entries_to_wrapper_names
:
cclass_name
=
self
.
cypclass_entries_to_wrapper_names
[
node
.
entry
]
# otherwise derive a unique name that avoid collisions with user-defined names
# otherwise derive a unique name that avoid
s
collisions with user-defined names
else
:
qualifying_names
=
[
node
.
name
for
node
in
self
.
nesting_stack
]
qualifying_names
.
append
(
node
.
name
)
qualified_name
=
"_"
.
join
(
qualifying_names
)
cclass_nested_name
=
"_"
.
join
(
nested_names
)
suffix_name
=
"__cyp_wrapper"
cclass_name
=
"%s%s"
%
(
qualifi
ed_name
,
suffix_name
)
cclass_name
=
"%s%s"
%
(
cclass_nest
ed_name
,
suffix_name
)
while
cclass_name
in
self
.
module_scope
.
entries
:
suffix_name
=
"%s__cyp_wrapper"
%
"_"
cclass_name
=
"%s%s"
%
(
qualifi
ed_name
,
suffix_name
)
cclass_name
=
"%s%s"
%
(
cclass_nest
ed_name
,
suffix_name
)
cclass_name
=
EncodedString
(
cclass_name
)
# determine if the wrapper has a base class
...
...
@@ -199,7 +203,7 @@ class CypclassWrapperInjection(CythonTransform):
stats
.
append
(
underlying_cyobject
)
cclass_body
=
Nodes
.
StatListNode
(
pos
=
node
.
pos
,
stats
=
stats
)
cclass_doc
=
EncodedString
(
"Python Object wrapper for underlying cypclass %s"
%
node
.
name
)
cclass_doc
=
EncodedString
(
"Python Object wrapper for underlying cypclass %s"
%
qualified_
name
)
else
:
cclass_body
=
cclass_doc
=
None
...
...
@@ -220,6 +224,7 @@ class CypclassWrapperInjection(CythonTransform):
doc
=
cclass_doc
,
body
=
cclass_body
,
wrapped_cypclass
=
node
,
wrapped_nested_name
=
qualified_name
)
# indicate that the cypclass will have a wrapper
...
...
Cython/Compiler/Nodes.py
View file @
4a3646d1
...
...
@@ -5266,10 +5266,17 @@ class CClassDefNode(ClassDefNode):
home_scope
.
lookup
(
self
.
class_name
).
as_variable
=
self
.
entry
if
home_scope
is
not
env
and
self
.
visibility
==
'extern'
:
env
.
add_imported_entry
(
self
.
class_name
,
self
.
entry
,
self
.
pos
)
self
.
scope
=
scope
=
self
.
entry
.
type
.
scope
if
scope
is
not
None
:
scope
.
directives
=
env
.
directives
if
scope
is
not
None
and
self
.
is_cyp_wrapper
:
# > correct a cypclass wrapper scope's name
# scope.name = self.wrapped_cypclass.name
scope
.
qualified_name
=
scope
.
qualifying_scope
().
qualify_name
(
self
.
wrapped_nested_name
)
scope
.
class_name
=
self
.
wrapped_nested_name
if
self
.
doc
and
Options
.
docstrings
:
scope
.
doc
=
embed_position
(
self
.
pos
,
self
.
doc
)
...
...
@@ -5560,6 +5567,7 @@ class CClassDefNode(ClassDefNode):
class
CypclassWrapperDefNode
(
CClassDefNode
):
# wrapped_cypclass CppClassNode The wrapped cypclass
# wrapped_nested_name string The nesting-qualified name of the underlying cypclass
is_cyp_wrapper
=
1
...
...
@@ -5570,16 +5578,12 @@ class CypclassWrapperDefNode(CClassDefNode):
self
.
entry
.
type
.
is_cyp_wrapper
=
1
# > associate the wrapper type to the wrapped type
self
.
wrapped_cypclass
.
entry
.
type
.
wrapper_type
=
self
.
entry
.
type
# > remember the cname of the wrapped type
self
.
entry
.
type
.
wrapped_decl
=
self
.
wrapped_cypclass
.
entry
.
type
.
empty_declaration_code
()
def
analyse_declarations
(
self
,
env
):
# > analyse declarations before inserting methods
super
(
CypclassWrapperDefNode
,
self
).
analyse_declarations
(
env
)
# > mark the wrapper type as such
self
.
entry
.
type
.
is_cyp_wrapper
=
1
# > associate the wrapper type to the wrapped type
self
.
wrapped_cypclass
.
entry
.
type
.
wrapper_type
=
self
.
entry
.
type
# > remember the cname of the wrapped type
self
.
entry
.
type
.
wrapped_decl
=
self
.
wrapped_cypclass
.
entry
.
type
.
empty_declaration_code
()
# > insert and analyse each method wrapper
self
.
insert_cypclass_method_wrappers
(
env
)
...
...
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