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
Gwenaël Samain
cython
Commits
685c809c
Commit
685c809c
authored
Mar 13, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow c++ classes to have multiple constructors
parent
fccabc4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
25 deletions
+34
-25
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+34
-25
No files found.
Cython/Compiler/ModuleNode.py
View file @
685c809c
...
...
@@ -919,7 +919,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
attr
.
type
.
is_cfunction
and
attr
.
type
.
is_static_method
:
code
.
put
(
"static "
)
elif
attr
.
name
==
"<init>"
:
constructor
=
attr
#constructor = attr
constructor
=
scope
.
lookup_here
(
"<init>"
)
elif
attr
.
name
==
"<del>"
:
destructor
=
attr
elif
attr
.
type
.
is_cfunction
:
...
...
@@ -927,35 +928,43 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
has_virtual_methods
=
True
code
.
putln
(
"%s;"
%
attr
.
type
.
declaration_code
(
attr
.
cname
))
is_implementing
=
'init_module'
in
code
.
globalstate
.
parts
def
generate_cpp_constructor_code
(
arg_decls
,
arg_names
,
is_implementing
,
py_attrs
,
constructor
):
if
is_implementing
:
code
.
putln
(
"%s(%s) {"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
if
py_attrs
:
code
.
put_ensure_gil
()
for
attr
in
py_attrs
:
code
.
put_init_var_to_py_none
(
attr
,
nanny
=
False
);
if
constructor
:
code
.
putln
(
"%s(%s);"
%
(
constructor
.
cname
,
", "
.
join
(
arg_names
)))
if
py_attrs
:
code
.
put_release_ensured_gil
()
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"%s(%s);"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
if
constructor
or
py_attrs
:
if
constructor
:
arg_decls
=
[]
arg_names
=
[]
for
arg
in
constructor
.
type
.
original_args
[
:
len
(
constructor
.
type
.
args
)
-
constructor
.
type
.
optional_arg_count
]:
arg_decls
.
append
(
arg
.
declaration_code
())
arg_names
.
append
(
arg
.
cname
)
if
constructor
.
type
.
optional_arg_count
:
arg_decls
.
append
(
constructor
.
type
.
op_arg_struct
.
declaration_code
(
Naming
.
optional_args_cname
))
arg_names
.
append
(
Naming
.
optional_args_cname
)
if
not
arg_decls
:
arg_decls
=
[
"void"
]
for
constructor_alternative
in
constructor
.
all_alternatives
():
arg_decls
=
[]
arg_names
=
[]
for
arg
in
constructor_alternative
.
type
.
original_args
[
:
len
(
constructor_alternative
.
type
.
args
)
-
constructor_alternative
.
type
.
optional_arg_count
]:
arg_decls
.
append
(
arg
.
declaration_code
())
arg_names
.
append
(
arg
.
cname
)
if
constructor_alternative
.
type
.
optional_arg_count
:
arg_decls
.
append
(
constructor_alternative
.
type
.
op_arg_struct
.
declaration_code
(
Naming
.
optional_args_cname
))
arg_names
.
append
(
Naming
.
optional_args_cname
)
if
not
arg_decls
:
default_constructor
=
True
arg_decls
=
[
"void"
]
generate_cpp_constructor_code
(
arg_decls
,
arg_names
,
is_implementing
,
py_attrs
,
constructor_alternative
)
else
:
arg_decls
=
[
"void"
]
arg_names
=
[]
if
is_implementing
:
code
.
putln
(
"%s(%s) {"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
if
py_attrs
:
code
.
put_ensure_gil
()
for
attr
in
py_attrs
:
code
.
put_init_var_to_py_none
(
attr
,
nanny
=
False
);
if
constructor
:
code
.
putln
(
"%s(%s);"
%
(
constructor
.
cname
,
", "
.
join
(
arg_names
)))
if
py_attrs
:
code
.
put_release_ensured_gil
()
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"%s(%s);"
%
(
type
.
cname
,
", "
.
join
(
arg_decls
)))
generate_cpp_constructor_code
(
arg_decls
,
arg_names
,
is_implementing
,
py_attrs
,
constructor
)
if
destructor
or
py_attrs
or
has_virtual_methods
:
if
has_virtual_methods
:
code
.
put
(
"virtual "
)
...
...
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