Commit a9056438 authored by Stefan Behnel's avatar Stefan Behnel

another simplification of type inheritance sorting

parent 6965934d
...@@ -257,11 +257,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -257,11 +257,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.find_referenced_modules(imported_module, module_list, modules_seen) self.find_referenced_modules(imported_module, module_list, modules_seen)
module_list.append(env) module_list.append(env)
def collect_inheritance_hierarchies(self, type_dict, getkey): def sort_types_by_inheritance(self, type_dict, getkey):
base_dict = {} # copy the types into a list moving each parent type before
for key, entry in type_dict.items(): # its first child
type_items = type_dict.items()
type_list = []
for i, item in enumerate(type_items):
key, new_entry = item
# collect all base classes to check for children
hierarchy = set() hierarchy = set()
base = entry base = new_entry
while base: while base:
base_type = base.type.base_type base_type = base.type.base_type
if not base_type: if not base_type:
...@@ -269,18 +275,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -269,18 +275,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
base_key = getkey(base_type) base_key = getkey(base_type)
hierarchy.add(base_key) hierarchy.add(base_key)
base = type_dict.get(base_key) base = type_dict.get(base_key)
entry.base_keys = hierarchy new_entry.base_keys = hierarchy
base_dict[key] = entry
return base_dict
def sort_types_by_inheritance(self, base_dict): # find the first (sub-)subclass and insert before that
type_items = base_dict.items()
type_list = []
for i, item in enumerate(type_items):
type_key, new_entry = item
for j in range(i): for j in range(i):
entry = type_list[j] entry = type_list[j]
if type_key in entry.base_keys: if key in entry.base_keys:
type_list.insert(j, new_entry) type_list.insert(j, new_entry)
break break
else: else:
...@@ -306,17 +306,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -306,17 +306,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def vtabstruct_cname(entry_type): def vtabstruct_cname(entry_type):
return entry_type.vtabstruct_cname return entry_type.vtabstruct_cname
vtab_hierarchies = self.sort_types_by_inheritance( vtab_list = self.sort_types_by_inheritance(
self.collect_inheritance_hierarchies( vtab_dict, vtabstruct_cname)
vtab_dict, vtabstruct_cname))
def objstruct_cname(entry_type): def objstruct_cname(entry_type):
return entry_type.objstruct_cname return entry_type.objstruct_cname
vtabslot_hierarchies = self.sort_types_by_inheritance( vtabslot_list = self.sort_types_by_inheritance(
self.collect_inheritance_hierarchies( vtabslot_dict, objstruct_cname)
vtabslot_dict, objstruct_cname))
return (vtab_hierarchies, vtabslot_hierarchies) return (vtab_list, vtabslot_list)
def generate_type_definitions(self, env, modules, vtab_list, vtabslot_list, code): def generate_type_definitions(self, env, modules, vtab_list, vtabslot_list, code):
vtabslot_entries = set(vtabslot_list) vtabslot_entries = set(vtabslot_list)
......
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