Commit aac4b717 authored by Xavier Thompson's avatar Xavier Thompson

Expose the same name for cypclass wrappers as for the underlying cypclass

parent 3cdbfd3e
......@@ -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 avoids 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" % (qualified_name, suffix_name)
cclass_name = "%s%s" % (cclass_nested_name, suffix_name)
while cclass_name in self.module_scope.entries:
suffix_name = "%s__cyp_wrapper" % "_"
cclass_name = "%s%s" % (qualified_name, suffix_name)
cclass_name = "%s%s" % (cclass_nested_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
......
......@@ -5110,10 +5110,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)
......@@ -5349,6 +5356,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
......@@ -5359,16 +5367,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)
......
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