History

kernel-doc: add support to handle DEFINE_ variables

Improve the parser and output plugin to work with macros, adding support for the common pattern of using DEFINE_* to create variables.

Mauro Carvalho Chehab committed 11 months ago

Commit bdd1cf81 parent 1045ec32 files · +23 −7Browse files

Showing the changes to tools/lib/python (2 of 2 files). Show all

Unified · Split

2 files
  1. tools/lib/python/kdoc/kdoc_output.py +2 −3
  2. tools/lib/python/kdoc/kdoc_parser.py +21 −4
tools/lib/python/kdoc/kdoc_output.py+2−3
@@ -486,7 +486,7 @@ class RestFormat(OutputFormat): · 485 unmodified lines
486 486
487 self.lineprefix = " "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 self.print_lineno(ln)491 self.print_lineno(ln)
492 self.output_highlight(args.get('purpose', ''))492 self.output_highlight(args.get('purpose', ''))
@@ -801,13 +801,12 @@ class ManFormat(OutputFormat): · 308 unmodified lines
801 801
802 def out_var(self, fname, name, args):802 def out_var(self, fname, name, args):
803 out_name = self.arg_name(args, name)803 out_name = self.arg_name(args, name)
804 prototype = args.other_stuff["var_type"]
805 full_proto = args.other_stuff["full_proto"]804 full_proto = args.other_stuff["full_proto"]
806 805
807 self.data += f'.TH "{self.modulename}" 9 "{out_name}" "{self.man_date}" "API Manual" LINUX' + "\n"806 self.data += f'.TH "{self.modulename}" 9 "{out_name}" "{self.man_date}" "API Manual" LINUX' + "\n"
808 807
809 self.data += ".SH NAME\n"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 self.data += ".SH SYNOPSIS\n"811 self.data += ".SH SYNOPSIS\n"
813 self.data += f"{full_proto}\n"812 self.data += f"{full_proto}\n"
tools/lib/python/kdoc/kdoc_parser.py+21−4
@@ -949,12 +949,27 @@ class KernelDoc: · 948 unmodified lines
949 # Store the full prototype before modifying it949 # Store the full prototype before modifying it
950 #950 #
951 full_proto = proto951 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 # Drop comments and macros to have a pure C prototype968 # Drop comments and macros to have a pure C prototype
955 #969 #
956 for search, sub in sub_prefixes:970 if not declaration_name:
957 proto = search.sub(sub, proto)971 for r, sub in sub_prefixes:
972 proto = r.sub(sub, proto)
958 973
959 proto = proto.rstrip()974 proto = proto.rstrip()
960 975
@@ -968,14 +983,16 @@ class KernelDoc: · 7 unmodified lines
968 return983 return
969 984
970 var_type = r.group(0)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 default_val = r.group(2)990 default_val = r.group(2)
973 if default_val:991 if default_val:
974 default_val = default_val.lstrip("=").strip()992 default_val = default_val.lstrip("=").strip()
975 993
976 self.output_declaration("var", declaration_name,994 self.output_declaration("var", declaration_name,
977 full_proto=full_proto,995 full_proto=full_proto,
978 var_type=var_type,
979 default_val=default_val,996 default_val=default_val,
980 purpose=self.entry.declaration_purpose)997 purpose=self.entry.declaration_purpose)
981 998