tgingold-cern / cheby

GNU General Public License v3.0
8 stars 4 forks source link

Ensure c_sorted_children is consistent after unrolling, add test for #67 #4

Closed stefanlippuner closed 1 year ago

stefanlippuner commented 1 year ago

This MR is supposed to fix an issue when generating documentation for a block that has nested repeat blocks (see https://gitlab.cern.ch/be-cem-edl/common/cheby/-/issues/67 for an example).

The underlying issue is the fact that node.c_sorted_children and node.children are not consistent when the documentation is generated. node.c_sorted_children is generated at the start of the handle_file function in layout.layout_cheby(t), but node.children is updated afterwards in expand_hdl.expand_hdl. Eventually, the HTML/Markdown generation crashes because some nodes don't have the c_name attribute:

  File "python3.10/site-packages/cheby-1.6.dev0-py3.10.egg/cheby/print_markdown.py", line 79, in print_root
  File "python3.10/site-packages/cheby-1.6.dev0-py3.10.egg/cheby/print_markdown.py", line 56, in print_map_summary
AttributeError: 'Block' object has no attribute 'c_name'. Did you mean: 'name'?

To fix this, I've added a function that re-generates the node.c_sorted_children in handle_file after unrolling. It might also make sense to add this call at the end of expand_hdl instead. It was also necessary to allow None for c_address, as this case occurs during the tests (not sure if this is intentional).

@tgingold-cern please let me know what you think.

Changes:

Resolves https://gitlab.cern.ch/be-cem-edl/common/cheby/-/issues/67

tgingold-cern commented 1 year ago

Thanks, I have merged it. I have also slightly simplified it (no need to deal with no c_address if you stops at Reg).

Thanks!

stefanlippuner commented 1 year ago

Nice, makes sense :+1: