Skip to content

Commit 370f430

Browse files
author
Jonathan Corbet
committed
docs: kdoc: consolidate some of the macro-processing logic
The logic to handle macros is split in dump_function(); bring it all together into a single place and add a comment saying what's going on. Remove the unneeded is_define_proto variable, and tighten up the code a bit. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent ff1f2af commit 370f430

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -926,21 +926,31 @@ def dump_function(self, ln, prototype):
926926
Stores a function of function macro inside self.entries array.
927927
"""
928928

929-
func_macro = False
929+
found = func_macro = False
930930
return_type = ''
931931
decl_type = 'function'
932932
#
933933
# Apply the initial transformations.
934934
#
935935
prototype = apply_transforms(function_xforms, prototype)
936-
937-
# Macros are a special case, as they change the prototype format
936+
#
937+
# If we have a macro, remove the "#define" at the front.
938+
#
938939
new_proto = KernRe(r"^#\s*define\s+").sub("", prototype)
939940
if new_proto != prototype:
940-
is_define_proto = True
941941
prototype = new_proto
942-
else:
943-
is_define_proto = False
942+
#
943+
# Dispense with the simple "#define A B" case here; the key
944+
# is the space after the name of the symbol being defined.
945+
# NOTE that the seemingly misnamed "func_macro" indicates a
946+
# macro *without* arguments.
947+
#
948+
r = KernRe(r'^(\w+)\s+')
949+
if r.search(prototype):
950+
return_type = ''
951+
declaration_name = r.group(1)
952+
func_macro = True
953+
found = True
944954

945955
# Yes, this truly is vile. We are looking for:
946956
# 1. Return type (may be nothing if we're looking at a macro)
@@ -968,19 +978,10 @@ def dump_function(self, ln, prototype):
968978
# parenthesis.
969979
#
970980
proto_args = r'\(([^\(]*|.*)\)'
971-
972-
found = False
973-
974-
if is_define_proto:
975-
r = KernRe(r'^(' + name + r')\s+')
976-
977-
if r.search(prototype):
978-
return_type = ''
979-
declaration_name = r.group(1)
980-
func_macro = True
981-
982-
found = True
983-
981+
#
982+
# (Except for the simple macro case) attempt to split up the prototype
983+
# in the various ways we understand.
984+
#
984985
if not found:
985986
patterns = [
986987
rf'^()({name})\s*{proto_args}',
@@ -990,16 +991,12 @@ def dump_function(self, ln, prototype):
990991

991992
for p in patterns:
992993
r = KernRe(p)
993-
994994
if r.match(prototype):
995-
996995
return_type = r.group(1)
997996
declaration_name = r.group(2)
998997
args = r.group(3)
999-
1000998
self.create_parameter_list(ln, decl_type, args, ',',
1001999
declaration_name)
1002-
10031000
found = True
10041001
break
10051002
if not found:

0 commit comments

Comments
 (0)