The last thing done in dump_struct() is to format the structure for printing. That, too, is a separate activity; split it out into its own function. dump_struct() now fits in a single, full-hight editor screen.
Unified · Split
| @@ -739,6 +739,42 @@ class KernelDoc: · 738 unmodified lines | ||
| 739 | 739 | tuples = struct_members.findall(members) |
| 740 | 740 | return members |
| 741 | 741 | |
| 742 | + # | |
| 743 | + # Format the struct declaration into a standard form for inclusion in the | |
| 744 | + # resulting docs. | |
| 745 | + # | |
| 746 | + def format_struct_decl(self, declaration): | |
| 747 | + # | |
| 748 | + # Insert newlines, get rid of extra spaces. | |
| 749 | + # | |
| 750 | + declaration = KernRe(r'([\{;])').sub(r'\1\n', declaration) | |
| 751 | + declaration = KernRe(r'\}\s+;').sub('};', declaration) | |
| 752 | + # | |
| 753 | + # Format inline enums with each member on its own line. | |
| 754 | + # | |
| 755 | + r = KernRe(r'(enum\s+\{[^\}]+),([^\n])') | |
| 756 | + while r.search(declaration): | |
| 757 | + declaration = r.sub(r'\1,\n\2', declaration) | |
| 758 | + # | |
| 759 | + # Now go through and supply the right number of tabs | |
| 760 | + # for each line. | |
| 761 | + # | |
| 762 | + def_args = declaration.split('\n') | |
| 763 | + level = 1 | |
| 764 | + declaration = "" | |
| 765 | + for clause in def_args: | |
| 766 | + clause = KernRe(r'\s+').sub(' ', clause.strip(), count=1) | |
| 767 | + if clause: | |
| 768 | + if '}' in clause and level > 1: | |
| 769 | + level -= 1 | |
| 770 | + if not clause.startswith('#'): | |
| 771 | + declaration += "\t" * level | |
| 772 | + declaration += "\t" + clause + "\n" | |
| 773 | + if "{" in clause and "}" not in clause: | |
| 774 | + level += 1 | |
| 775 | + return declaration | |
| 776 | + | |
| 777 | + | |
| 742 | 778 | def dump_struct(self, ln, proto): |
| 743 | 779 | """ |
| 744 | 780 | Store an entry for an struct or union |
| @@ -777,42 +813,8 @@ class KernelDoc: · 32 unmodified lines | ||
| 777 | 813 | self.create_parameter_list(ln, decl_type, members, ';', |
| 778 | 814 | declaration_name) |
| 779 | 815 | self.check_sections(ln, declaration_name, decl_type) |
| 780 | − | |
| 781 | − # Adjust declaration for better display | |
| 782 | − declaration = KernRe(r'([\{;])').sub(r'\1\n', declaration) | |
| 783 | − declaration = KernRe(r'\}\s+;').sub('};', declaration) | |
| 784 | − | |
| 785 | − # Better handle inlined enums | |
| 786 | − while True: | |
| 787 | − r = KernRe(r'(enum\s+\{[^\}]+),([^\n])') | |
| 788 | − if not r.search(declaration): | |
| 789 | − break | |
| 790 | − | |
| 791 | − declaration = r.sub(r'\1,\n\2', declaration) | |
| 792 | − | |
| 793 | − def_args = declaration.split('\n') | |
| 794 | − level = 1 | |
| 795 | − declaration = "" | |
| 796 | − for clause in def_args: | |
| 797 | − | |
| 798 | − clause = clause.strip() | |
| 799 | − clause = KernRe(r'\s+').sub(' ', clause, count=1) | |
| 800 | − | |
| 801 | − if not clause: | |
| 802 | − continue | |
| 803 | − | |
| 804 | − if '}' in clause and level > 1: | |
| 805 | − level -= 1 | |
| 806 | − | |
| 807 | − if not KernRe(r'^\s*#').match(clause): | |
| 808 | − declaration += "\t" * level | |
| 809 | − | |
| 810 | − declaration += "\t" + clause + "\n" | |
| 811 | − if "{" in clause and "}" not in clause: | |
| 812 | − level += 1 | |
| 813 | − | |
| 814 | 816 | self.output_declaration(decl_type, declaration_name, |
| 815 | − definition=declaration, | |
| 817 | + definition=self.format_struct_decl(declaration), | |
| 816 | 818 | purpose=self.entry.declaration_purpose) |
| 817 | 819 | |
| 818 | 820 | def dump_enum(self, ln, proto): |