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
Xavier Thompson
cython
Commits
9631aff9
Commit
9631aff9
authored
Jun 11, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defer declaration analysis of cpp classes until all bases have been analysed
parent
c95a2257
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
+42
-12
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+35
-11
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+7
-1
No files found.
Cython/Compiler/Nodes.py
View file @
9631aff9
...
...
@@ -1510,6 +1510,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
# decorators [DecoratorNode] or None
decorators
=
None
scope
=
None
template_types
=
None
def
declare
(
self
,
env
):
if
not
env
.
is_cpp
():
...
...
@@ -1522,6 +1524,7 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
num_optional_templates
=
sum
(
not
required
for
_
,
required
in
self
.
templates
)
if
num_optional_templates
and
not
all
(
required
for
_
,
required
in
self
.
templates
[:
-
num_optional_templates
]):
error
(
self
.
pos
,
"Required template parameters must precede optional template parameters."
)
self
.
template_types
=
template_types
self
.
entry
=
env
.
declare_cpp_class
(
self
.
name
,
None
,
self
.
pos
,
self
.
cname
,
base_classes
=
[],
visibility
=
self
.
visibility
,
templates
=
template_types
,
...
...
@@ -1529,37 +1532,55 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
def
analyse_declarations
(
self
,
env
):
if
self
.
templates
is
None
:
template_
types
=
template_
names
=
None
template_names
=
None
else
:
template_names
=
[
template_name
for
template_name
,
_
in
self
.
templates
]
template_types
=
[
PyrexTypes
.
TemplatePlaceholderType
(
template_name
,
not
required
)
if
self
.
template_types
is
None
:
self
.
template_types
=
[
PyrexTypes
.
TemplatePlaceholderType
(
template_name
,
not
required
)
for
template_name
,
required
in
self
.
templates
]
scope
=
None
if
self
.
attributes
is
not
None
:
template_types
=
self
.
template_types
if
self
.
scope
is
None
and
self
.
attributes
is
not
None
:
scope
=
CppClassScope
(
self
.
name
,
env
,
templates
=
template_names
)
self
.
scope
=
scope
scope
=
self
.
scope
def
base_ok
(
base_class
):
if
base_class
.
is_cpp_class
or
base_class
.
is_struct
:
return
True
else
:
error
(
self
.
pos
,
"Base class '%s' not a struct or class."
%
base_class
)
base_types_list
=
[
b
.
analyse
(
scope
or
env
)
for
b
in
self
.
base_classes
]
base_class_types
=
list
(
filter
(
base_ok
,
base_types_list
))
# if this is not just a forward declaration, defer analysis until all base classes are analysed
if
scope
:
for
base_type
in
base_class_types
:
if
not
base_type
.
scope
:
base_type
.
deferred_declarations
.
append
(
lambda
:
self
.
analyse_declarations
(
env
))
return
# add implicit cyobject or acthon base if this cypclass has no explicit cypclass bases
if
self
.
cypclass
:
if
self
.
activable
:
activable_base
=
False
for
base_type
in
base_
types_list
:
for
base_type
in
base_
class_types
:
if
not
base_type
.
activable
:
error
(
self
.
pos
,
"Activable class cannot inherit from not activable one."
)
activable_base
=
activable_base
or
base_type
.
activable
if
not
activable_base
:
from
.
import
Builtin
base_
types_list
.
append
(
Builtin
.
acthon_activable_type
)
base_
class_types
.
append
(
Builtin
.
acthon_activable_type
)
cyobject_base
=
False
for
base_type
in
base_types_list
:
for
base_type
in
base_class_types
:
cyobject_base
=
cyobject_base
or
base_type
.
is_cyp_class
if
not
cyobject_base
:
base_
types_list
.
append
(
cy_object_type
)
base_class_types
=
filter
(
base_ok
,
base_types_list
)
base_
class_types
.
append
(
cy_object_type
)
self
.
entry
=
env
.
declare_cpp_class
(
self
.
name
,
scope
,
self
.
pos
,
self
.
cname
,
base_class_types
,
visibility
=
self
.
visibility
,
templates
=
template_types
,
...
...
@@ -1593,7 +1614,10 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
if
self
.
templates
is
not
None
:
func
.
template_declaration
=
"template <typename %s>"
%
", typename "
.
join
(
template_names
)
self
.
body
=
StatListNode
(
self
.
pos
,
stats
=
defined_funcs
)
self
.
scope
=
scope
# analyse the subclasses that were waiting for this class (their base) to be analysed
for
thunk
in
self
.
entry
.
type
.
deferred_declarations
:
thunk
()
def
analyse_expressions
(
self
,
env
):
self
.
body
=
self
.
body
.
analyse_expressions
(
self
.
entry
.
type
.
scope
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
9631aff9
...
...
@@ -3347,12 +3347,14 @@ class CStructOrUnionType(CType):
# scope StructOrUnionScope, or None if incomplete
# typedef_flag boolean
# packed boolean
# deferred_declarations [thunk] or None Used to declare class hierarchies in order (None when this type is an union)
# entry Entry
is_struct_or_union
=
1
has_attributes
=
1
exception_check
=
True
deferred_declarations
=
None
def
__init__
(
self
,
name
,
kind
,
scope
,
typedef_flag
,
cname
,
packed
=
False
):
self
.
name
=
name
...
...
@@ -3361,6 +3363,8 @@ class CStructOrUnionType(CType):
self
.
scope
=
scope
self
.
typedef_flag
=
typedef_flag
self
.
is_struct
=
kind
==
'struct'
if
self
.
is_struct
:
self
.
deferred_declarations
=
[]
self
.
to_py_function
=
"%s_to_py_%s"
%
(
Naming
.
convert_func_prefix
,
self
.
specialization_name
())
self
.
from_py_function
=
"%s_from_py_%s"
%
(
...
...
@@ -3535,6 +3539,7 @@ class CppClassType(CType):
# cname string
# scope CppClassScope
# templates [string] or None
# deferred_declarations [thunk] Used to declare class hierarchies in order
is_cpp_class
=
1
has_attributes
=
1
...
...
@@ -3553,6 +3558,7 @@ class CppClassType(CType):
self
.
cname
=
cname
self
.
scope
=
scope
self
.
base_classes
=
base_classes
self
.
deferred_declarations
=
[]
self
.
operators
=
[]
self
.
templates
=
templates
self
.
template_type
=
template_type
...
...
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