Skip to content

Commit a0db205

Browse files
author
Jonathan Corbet
committed
docs: kdoc: Regularize the use of the declaration name
Each declaration type passes through the name in a unique field of the "args" blob - even though we have always just passed the name separately. Get rid of all the weird names and just use the common version. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent de6f7ac commit a0db205

2 files changed

Lines changed: 15 additions & 30 deletions

File tree

scripts/lib/kdoc/kdoc_output.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ def out_function(self, fname, name, args):
367367

368368
func_macro = args.get('func_macro', False)
369369
if func_macro:
370-
signature = args['function']
370+
signature = name
371371
else:
372372
if args.get('functiontype'):
373373
signature = args['functiontype'] + " "
374-
signature += args['function'] + " ("
374+
signature += name + " ("
375375

376376
ln = args.get('declaration_start_line', 0)
377377
count = 0
@@ -391,7 +391,7 @@ def out_function(self, fname, name, args):
391391

392392
self.print_lineno(ln)
393393
if args.get('typedef') or not args.get('functiontype'):
394-
self.data += f".. c:macro:: {args['function']}\n\n"
394+
self.data += f".. c:macro:: {name}\n\n"
395395

396396
if args.get('typedef'):
397397
self.data += " **Typedef**: "
@@ -445,7 +445,6 @@ def out_function(self, fname, name, args):
445445
def out_enum(self, fname, name, args):
446446

447447
oldprefix = self.lineprefix
448-
name = args.get('enum', '')
449448
ln = args.get('declaration_start_line', 0)
450449

451450
self.data += f"\n\n.. c:enum:: {name}\n\n"
@@ -475,7 +474,6 @@ def out_enum(self, fname, name, args):
475474
def out_typedef(self, fname, name, args):
476475

477476
oldprefix = self.lineprefix
478-
name = args.get('typedef', '')
479477
ln = args.get('declaration_start_line', 0)
480478

481479
self.data += f"\n\n.. c:type:: {name}\n\n"
@@ -492,7 +490,6 @@ def out_typedef(self, fname, name, args):
492490

493491
def out_struct(self, fname, name, args):
494492

495-
name = args.get('struct', "")
496493
purpose = args.get('purpose', "")
497494
declaration = args.get('definition', "")
498495
dtype = args.get('type', "struct")
@@ -632,16 +629,16 @@ def out_doc(self, fname, name, args):
632629
def out_function(self, fname, name, args):
633630
"""output function in man"""
634631

635-
self.data += f'.TH "{args["function"]}" 9 "{args["function"]}" "{self.man_date}" "Kernel Hacker\'s Manual" LINUX' + "\n"
632+
self.data += f'.TH "{name}" 9 "{name}" "{self.man_date}" "Kernel Hacker\'s Manual" LINUX' + "\n"
636633

637634
self.data += ".SH NAME\n"
638-
self.data += f"{args['function']} \\- {args['purpose']}\n"
635+
self.data += f"{name} \\- {args['purpose']}\n"
639636

640637
self.data += ".SH SYNOPSIS\n"
641638
if args.get('functiontype', ''):
642-
self.data += f'.B "{args["functiontype"]}" {args["function"]}' + "\n"
639+
self.data += f'.B "{args["functiontype"]}" {name}' + "\n"
643640
else:
644-
self.data += f'.B "{args["function"]}' + "\n"
641+
self.data += f'.B "{name}' + "\n"
645642

646643
count = 0
647644
parenth = "("
@@ -676,16 +673,13 @@ def out_function(self, fname, name, args):
676673
self.output_highlight(text)
677674

678675
def out_enum(self, fname, name, args):
679-
680-
name = args.get('enum', '')
681-
682-
self.data += f'.TH "{self.modulename}" 9 "enum {args["enum"]}" "{self.man_date}" "API Manual" LINUX' + "\n"
676+
self.data += f'.TH "{self.modulename}" 9 "enum {name}" "{self.man_date}" "API Manual" LINUX' + "\n"
683677

684678
self.data += ".SH NAME\n"
685-
self.data += f"enum {args['enum']} \\- {args['purpose']}\n"
679+
self.data += f"enum {name} \\- {args['purpose']}\n"
686680

687681
self.data += ".SH SYNOPSIS\n"
688-
self.data += f"enum {args['enum']}" + " {\n"
682+
self.data += f"enum {name}" + " {\n"
689683

690684
count = 0
691685
for parameter in args.parameterlist:
@@ -710,36 +704,33 @@ def out_enum(self, fname, name, args):
710704

711705
def out_typedef(self, fname, name, args):
712706
module = self.modulename
713-
typedef = args.get('typedef')
714707
purpose = args.get('purpose')
715708

716-
self.data += f'.TH "{module}" 9 "{typedef}" "{self.man_date}" "API Manual" LINUX' + "\n"
709+
self.data += f'.TH "{module}" 9 "{name}" "{self.man_date}" "API Manual" LINUX' + "\n"
717710

718711
self.data += ".SH NAME\n"
719-
self.data += f"typedef {typedef} \\- {purpose}\n"
712+
self.data += f"typedef {name} \\- {purpose}\n"
720713

721714
for section, text in args.sections.items():
722715
self.data += f'.SH "{section}"' + "\n"
723716
self.output_highlight(text)
724717

725718
def out_struct(self, fname, name, args):
726719
module = self.modulename
727-
struct_type = args.get('type')
728-
struct_name = args.get('struct')
729720
purpose = args.get('purpose')
730721
definition = args.get('definition')
731722

732-
self.data += f'.TH "{module}" 9 "{struct_type} {struct_name}" "{self.man_date}" "API Manual" LINUX' + "\n"
723+
self.data += f'.TH "{module}" 9 "{args.type} {name}" "{self.man_date}" "API Manual" LINUX' + "\n"
733724

734725
self.data += ".SH NAME\n"
735-
self.data += f"{struct_type} {struct_name} \\- {purpose}\n"
726+
self.data += f"{args.type} {name} \\- {purpose}\n"
736727

737728
# Replace tabs with two spaces and handle newlines
738729
declaration = definition.replace("\t", " ")
739730
declaration = KernRe(r"\n").sub('"\n.br\n.BI "', declaration)
740731

741732
self.data += ".SH SYNOPSIS\n"
742-
self.data += f"{struct_type} {struct_name} " + "{" + "\n.br\n"
733+
self.data += f"{args.type} {name} " + "{" + "\n.br\n"
743734
self.data += f'.BI "{declaration}\n' + "};\n.br\n\n"
744735

745736
self.data += ".SH Members\n"

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ def dump_struct(self, ln, proto):
790790
level += 1
791791

792792
self.output_declaration(decl_type, declaration_name,
793-
struct=declaration_name,
794793
definition=declaration,
795794
purpose=self.entry.declaration_purpose)
796795

@@ -870,7 +869,6 @@ def dump_enum(self, ln, proto):
870869
f"Excess enum value '%{k}' description in '{declaration_name}'")
871870

872871
self.output_declaration('enum', declaration_name,
873-
enum=declaration_name,
874872
purpose=self.entry.declaration_purpose)
875873

876874
def dump_declaration(self, ln, prototype):
@@ -1031,14 +1029,12 @@ def dump_function(self, ln, prototype):
10311029

10321030
if 'typedef' in return_type:
10331031
self.output_declaration(decl_type, declaration_name,
1034-
function=declaration_name,
10351032
typedef=True,
10361033
functiontype=return_type,
10371034
purpose=self.entry.declaration_purpose,
10381035
func_macro=func_macro)
10391036
else:
10401037
self.output_declaration(decl_type, declaration_name,
1041-
function=declaration_name,
10421038
typedef=False,
10431039
functiontype=return_type,
10441040
purpose=self.entry.declaration_purpose,
@@ -1077,7 +1073,6 @@ def dump_typedef(self, ln, proto):
10771073
self.create_parameter_list(ln, decl_type, args, ',', declaration_name)
10781074

10791075
self.output_declaration(decl_type, declaration_name,
1080-
function=declaration_name,
10811076
typedef=True,
10821077
functiontype=return_type,
10831078
purpose=self.entry.declaration_purpose)
@@ -1099,7 +1094,6 @@ def dump_typedef(self, ln, proto):
10991094
return
11001095

11011096
self.output_declaration('typedef', declaration_name,
1102-
typedef=declaration_name,
11031097
purpose=self.entry.declaration_purpose)
11041098
return
11051099

0 commit comments

Comments
 (0)