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
5d3a0e5e
Commit
5d3a0e5e
authored
Jul 21, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt ctuples to support template-dependent ctuples nested in a templated namespace
parent
31a9ab1e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
13 deletions
+41
-13
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+18
-2
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+23
-11
No files found.
Cython/Compiler/PyrexTypes.py
View file @
5d3a0e5e
...
...
@@ -4470,7 +4470,7 @@ class CTupleType(CType):
is_ctuple
=
True
def
__init__
(
self
,
cname
,
components
):
def
__init__
(
self
,
cname
,
components
,
templated_namespace
=
None
):
self
.
cname
=
cname
self
.
components
=
components
self
.
size
=
len
(
components
)
...
...
@@ -4479,16 +4479,32 @@ class CTupleType(CType):
self
.
exception_check
=
True
self
.
_convert_to_py_code
=
None
self
.
_convert_from_py_code
=
None
self
.
templated_namespace
=
templated_namespace
def
__str__
(
self
):
return
"(%s)"
%
", "
.
join
(
str
(
c
)
for
c
in
self
.
components
)
def
specialize
(
self
,
values
):
specialized_components
=
[
c
.
specialize
(
values
)
for
c
in
self
.
components
]
if
specialized_components
!=
self
.
components
:
ttype
=
CTupleType
(
self
.
cname
,
specialized_components
,
self
.
templated_namespace
.
specialize
(
values
))
# specialise the names of the python conversion functions to avoid collisions
specialised_suffix
=
type_list_identifier
(
specialized_components
)
ttype
.
to_py_function
=
"%s_%s"
%
(
self
.
to_py_function
,
specialised_suffix
)
ttype
.
from_py_function
=
"%s_%s"
%
(
self
.
from_py_function
,
specialised_suffix
)
return
ttype
return
super
(
CTupleType
,
self
).
specialize
(
values
)
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
dll_linkage
=
None
,
pyrex
=
0
):
if
pyrex
or
for_display
:
return
str
(
self
)
else
:
return
self
.
base_declaration_code
(
self
.
cname
,
entity_code
)
base_code
=
self
.
base_declaration_code
(
self
.
cname
,
entity_code
)
if
self
.
templated_namespace
is
not
None
:
return
"%s::%s"
%
(
namespace_declaration_code
(
self
.
templated_namespace
),
base_code
)
else
:
return
base_code
def
can_coerce_to_pyobject
(
self
,
env
):
for
component
in
self
.
components
:
...
...
Cython/Compiler/Symtab.py
View file @
5d3a0e5e
...
...
@@ -961,8 +961,14 @@ class Scope(object):
self
.
sue_entries
.
append
(
entry
)
return
entry
def
declare_tuple_type
(
self
,
pos
,
components
):
return
self
.
outer_scope
.
declare_tuple_type
(
pos
,
components
)
def
declare_tuple_type
(
self
,
pos
,
components
,
templated_namespace
=
None
):
# if the ctuple is nested in a templated cpp namespace it might have templated components
# in order to support that we'll declare the ctuple in the innermost such namespace
if
templated_namespace
is
None
and
self
.
is_cpp_class_scope
and
self
.
parent_type
.
templates
:
# we could declare the ctuple directly in this scope but to avoid redundant code duplication we just
# propagate the innermost templated cpp namespace and let the module scope handle the declaration
templated_namespace
=
self
return
self
.
outer_scope
.
declare_tuple_type
(
pos
,
components
,
templated_namespace
)
def
declare_var
(
self
,
name
,
type
,
pos
,
cname
=
None
,
visibility
=
'private'
,
...
...
@@ -1530,23 +1536,29 @@ class ModuleScope(Scope):
return
self
.
outer_scope
.
lookup
(
name
,
language_level
=
language_level
,
str_is_str
=
str_is_str
)
def
declare_tuple_type
(
self
,
pos
,
components
):
def
declare_tuple_type
(
self
,
pos
,
components
,
templated_namespace
=
None
):
components
=
tuple
(
components
)
if
templated_namespace
is
None
:
try
:
ttype
=
self
.
_cached_tuple_types
[
components
]
except
KeyError
:
ttype
=
self
.
_cached_tuple_types
[
components
]
=
PyrexTypes
.
c_tuple_type
(
components
)
namespace
=
self
# declare the ctuple in the module scope
else
:
namespace
=
templated_namespace
# declare the ctuple in the templated namespace instead
ttype
=
PyrexTypes
.
c_tuple_type
(
components
)
ttype
.
templated_namespace
=
templated_namespace
.
parent_type
cname
=
ttype
.
cname
entry
=
self
.
lookup_here
(
cname
)
entry
=
namespace
.
lookup_here
(
cname
)
if
not
entry
:
scope
=
StructOrUnionScope
(
cname
)
for
ix
,
component
in
enumerate
(
components
):
scope
.
declare_var
(
name
=
"f%s"
%
ix
,
type
=
component
,
pos
=
pos
)
struct_entry
=
self
.
declare_struct_or_union
(
struct_entry
=
namespace
.
declare_struct_or_union
(
cname
+
'_struct'
,
'struct'
,
scope
,
typedef_flag
=
True
,
pos
=
pos
,
cname
=
cname
)
self
.
type_entries
.
remove
(
struct_entry
)
namespace
.
type_entries
.
remove
(
struct_entry
)
ttype
.
struct_entry
=
struct_entry
entry
=
self
.
declare_type
(
cname
,
ttype
,
pos
,
cname
)
entry
=
namespace
.
declare_type
(
cname
,
ttype
,
pos
,
cname
)
ttype
.
entry
=
entry
return
entry
...
...
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