Commit 17e6b1aa authored by Xavier Thompson's avatar Xavier Thompson

Improve synthesis of cypclass method wrappers

parent 589800e3
......@@ -85,11 +85,6 @@ def cypclass_iter_scopes(scope):
for e, s in cypclass_iter_scopes(cypclass_scope):
yield e, s
# cypclass entries that take on a special name: reverse mapping
cycplass_special_entry_names = {
"<init>": "__init__"
}
underlying_name = EncodedString("nogil_cyobject")
#
......
......@@ -1635,30 +1635,27 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
# so their declaration analysis will still occur
self.cyp_wrapper.body.stats.append(py_method_wrapper)
def synthesize_cypclass_method_wrapper(self, cfunc_method):
def synthesize_cypclass_method_wrapper(self, cfunc_method):
if cfunc_method.is_static_method:
return # for now skip static methods
alternatives = cfunc_method.entry.all_alternatives()
if len(alternatives) > 1:
return # for now skip overloaded methods
cfunc_declarator = cfunc_method.cfunc_declarator
# C++ methods have an implict 'this', so the 'self' argument is skipped in the declarator
skipped_self = cfunc_method.cfunc_declarator.skipped_self
skipped_self = cfunc_declarator.skipped_self
if not skipped_self:
return # if this ever happens (?), skip non-static methods without a self argument
from .CypclassWrapper import underlying_name, cycplass_special_entry_names
from .CypclassWrapper import underlying_name
from . import ExprNodes
cfunc_declarator = cfunc_method.cfunc_declarator
# > name of the wrapping method: same name
cfunc_name = cfunc_method.entry.name
# > name of the wrapping method: same name as in the original code
cfunc_name = cfunc_declarator.base.name
py_name = cfunc_name
try:
# transform e.g. <init> back into __init__
py_name = cycplass_special_entry_names[py_name]
except KeyError:
# no need to transform this name
pass
# > self argument of the wrapper method: same name, but type of the wrapper cclass
self_name, self_type, self_pos, self_arg = skipped_self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment