Commit eae7af21 authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl-gen: walk nested types in depth

So far we had only created structures for nested types nested
directly in messages (second level of attrs so to speak).
Walk types in depth to support deeper nesting.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 37487f93
...@@ -854,18 +854,26 @@ class Family(SpecFamily): ...@@ -854,18 +854,26 @@ class Family(SpecFamily):
self.root_sets[op['attribute-set']]['reply'].update(rsp_attrs) self.root_sets[op['attribute-set']]['reply'].update(rsp_attrs)
def _load_nested_sets(self): def _load_nested_sets(self):
for root_set, rs_members in self.root_sets.items(): attr_set_queue = list(self.root_sets.keys())
for attr, spec in self.attr_sets[root_set].items(): attr_set_seen = set(self.root_sets.keys())
if 'nested-attributes' in spec:
inherit = set() while len(attr_set_queue):
a_set = attr_set_queue.pop(0)
for attr, spec in self.attr_sets[a_set].items():
if 'nested-attributes' not in spec:
continue
nested = spec['nested-attributes'] nested = spec['nested-attributes']
if nested not in attr_set_seen:
attr_set_queue.append(nested)
attr_set_seen.add(nested)
inherit = set()
if nested not in self.root_sets: if nested not in self.root_sets:
if nested not in self.pure_nested_structs: if nested not in self.pure_nested_structs:
self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit) self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
if attr in rs_members['request']: else:
self.pure_nested_structs[nested].request = True raise Exception(f'Using attr set as root and nested not supported - {nested}')
if attr in rs_members['reply']:
self.pure_nested_structs[nested].reply = True
if 'type-value' in spec: if 'type-value' in spec:
if nested in self.root_sets: if nested in self.root_sets:
...@@ -875,6 +883,15 @@ class Family(SpecFamily): ...@@ -875,6 +883,15 @@ class Family(SpecFamily):
inherit.add('idx') inherit.add('idx')
self.pure_nested_structs[nested].set_inherited(inherit) self.pure_nested_structs[nested].set_inherited(inherit)
for root_set, rs_members in self.root_sets.items():
for attr, spec in self.attr_sets[root_set].items():
if 'nested-attributes' in spec:
nested = spec['nested-attributes']
if attr in rs_members['request']:
self.pure_nested_structs[nested].request = True
if attr in rs_members['reply']:
self.pure_nested_structs[nested].reply = True
# Try to reorder according to dependencies # Try to reorder according to dependencies
pns_key_list = list(self.pure_nested_structs.keys()) pns_key_list = list(self.pure_nested_structs.keys())
pns_key_seen = set() pns_key_seen = set()
......
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