Improve the parser and output plugin to work with macros, adding support for the common pattern of using DEFINE_* to create variables.
Showing the changes to tools/lib/python (2 of 2 files). Show all
Unified · Split
| @@ -486,7 +486,7 @@ class RestFormat(OutputFormat): · 485 unmodified lines | ||
| 486 | 486 | |
| 487 | 487 | self.lineprefix = " " |
| 488 | 488 | |
| 489 | − self.data += f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}{full_proto}\n\n" | |
| 489 | + self.data += f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}``{full_proto}``\n\n" | |
| 490 | 490 | |
| 491 | 491 | self.print_lineno(ln) |
| 492 | 492 | self.output_highlight(args.get('purpose', '')) |
| @@ -801,13 +801,12 @@ class ManFormat(OutputFormat): · 308 unmodified lines | ||
| 801 | 801 | |
| 802 | 802 | def out_var(self, fname, name, args): |
| 803 | 803 | out_name = self.arg_name(args, name) |
| 804 | − prototype = args.other_stuff["var_type"] | |
| 805 | 804 | full_proto = args.other_stuff["full_proto"] |
| 806 | 805 | |
| 807 | 806 | self.data += f'.TH "{self.modulename}" 9 "{out_name}" "{self.man_date}" "API Manual" LINUX' + "\n" |
| 808 | 807 | |
| 809 | 808 | self.data += ".SH NAME\n" |
| 810 | − self.data += f"{prototype} \\- {args['purpose']}\n" | |
| 809 | + self.data += f"{name} \\- {args['purpose']}\n" | |
| 811 | 810 | |
| 812 | 811 | self.data += ".SH SYNOPSIS\n" |
| 813 | 812 | self.data += f"{full_proto}\n" |
| @@ -949,12 +949,27 @@ class KernelDoc: · 948 unmodified lines | ||
| 949 | 949 | # Store the full prototype before modifying it |
| 950 | 950 | # |
| 951 | 951 | full_proto = proto |
| 952 | + declaration_name = None | |
| 953 | + | |
| 954 | + # | |
| 955 | + # Handle macro definitions | |
| 956 | + # | |
| 957 | + macro_prefixes = [ | |
| 958 | + KernRe(r"DEFINE_[\w_]+\s*\(([\w_]+)\)"), | |
| 959 | + ] | |
| 960 | + | |
| 961 | + for r in macro_prefixes: | |
| 962 | + match = r.search(proto) | |
| 963 | + if match: | |
| 964 | + declaration_name = match.group(1) | |
| 965 | + break | |
| 952 | 966 | |
| 953 | 967 | # |
| 954 | 968 | # Drop comments and macros to have a pure C prototype |
| 955 | 969 | # |
| 956 | − for search, sub in sub_prefixes: | |
| 957 | − proto = search.sub(sub, proto) | |
| 970 | + if not declaration_name: | |
| 971 | + for r, sub in sub_prefixes: | |
| 972 | + proto = r.sub(sub, proto) | |
| 958 | 973 | |
| 959 | 974 | proto = proto.rstrip() |
| 960 | 975 | |
| @@ -968,14 +983,16 @@ class KernelDoc: · 7 unmodified lines | ||
| 968 | 983 | return |
| 969 | 984 | |
| 970 | 985 | var_type = r.group(0) |
| 971 | − declaration_name = r.group(1) | |
| 986 | + | |
| 987 | + if not declaration_name: | |
| 988 | + declaration_name = r.group(1) | |
| 989 | + | |
| 972 | 990 | default_val = r.group(2) |
| 973 | 991 | if default_val: |
| 974 | 992 | default_val = default_val.lstrip("=").strip() |
| 975 | 993 | |
| 976 | 994 | self.output_declaration("var", declaration_name, |
| 977 | 995 | full_proto=full_proto, |
| 978 | − var_type=var_type, | |
| 979 | 996 | default_val=default_val, |
| 980 | 997 | purpose=self.entry.declaration_purpose) |
| 981 | 998 | |