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
486486
487487 self.lineprefix = " "
488488
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"
490490
491491 self.print_lineno(ln)
492492 self.output_highlight(args.get('purpose', ''))
@@ -801,13 +801,12 @@ class ManFormat(OutputFormat): · 308 unmodified lines
801801
802802 def out_var(self, fname, name, args):
803803 out_name = self.arg_name(args, name)
804− prototype = args.other_stuff["var_type"]
805804 full_proto = args.other_stuff["full_proto"]
806805
807806 self.data += f'.TH "{self.modulename}" 9 "{out_name}" "{self.man_date}" "API Manual" LINUX' + "\n"
808807
809808 self.data += ".SH NAME\n"
810− self.data += f"{prototype} \\- {args['purpose']}\n"
809+ self.data += f"{name} \\- {args['purpose']}\n"
811810
812811 self.data += ".SH SYNOPSIS\n"
813812 self.data += f"{full_proto}\n"
tools/lib/python/kdoc/kdoc_parser.py+21−4
@@ -949,12 +949,27 @@ class KernelDoc: · 948 unmodified lines
949949 # Store the full prototype before modifying it
950950 #
951951 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
952966
953967 #
954968 # Drop comments and macros to have a pure C prototype
955969 #
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)
958973
959974 proto = proto.rstrip()
960975
@@ -968,14 +983,16 @@ class KernelDoc: · 7 unmodified lines
968983 return
969984
970985 var_type = r.group(0)
971− declaration_name = r.group(1)
986+
987+ if not declaration_name:
988+ declaration_name = r.group(1)
989+
972990 default_val = r.group(2)
973991 if default_val:
974992 default_val = default_val.lstrip("=").strip()
975993
976994 self.output_declaration("var", declaration_name,
977995 full_proto=full_proto,
978− var_type=var_type,
979996 default_val=default_val,
980997 purpose=self.entry.declaration_purpose)
981998