Skip to content

Commit 4c232a8

Browse files
author
Jonathan Corbet
committed
docs: kdoc: move the function transform patterns out of dump_function()
Move these definitions to file level, where they are executed once, and don't clutter the function itself. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent f853e83 commit 4c232a8

1 file changed

Lines changed: 35 additions & 43 deletions

File tree

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,37 @@
161161
(re.compile(r'\bSTRUCT_GROUP\('), r'\1'),
162162
]
163163

164+
#
165+
# Transforms for function prototypes
166+
#
167+
function_xforms = [
168+
(r"^static +", "", 0),
169+
(r"^extern +", "", 0),
170+
(r"^asmlinkage +", "", 0),
171+
(r"^inline +", "", 0),
172+
(r"^__inline__ +", "", 0),
173+
(r"^__inline +", "", 0),
174+
(r"^__always_inline +", "", 0),
175+
(r"^noinline +", "", 0),
176+
(r"^__FORTIFY_INLINE +", "", 0),
177+
(r"__init +", "", 0),
178+
(r"__init_or_module +", "", 0),
179+
(r"__deprecated +", "", 0),
180+
(r"__flatten +", "", 0),
181+
(r"__meminit +", "", 0),
182+
(r"__must_check +", "", 0),
183+
(r"__weak +", "", 0),
184+
(r"__sched +", "", 0),
185+
(r"_noprof", "", 0),
186+
(r"__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +", "", 0),
187+
(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +", "", 0),
188+
(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +", "", 0),
189+
(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)", r"\1, \2", 0),
190+
(r"__attribute_const__ +", "", 0),
191+
(r"__attribute__\s*\(\((?:[\w\s]+(?:\([^)]*\))?\s*,?)+\)\)\s+", "", 0),
192+
]
193+
194+
164195

165196
#
166197
# A little helper to get rid of excess white space
@@ -894,49 +925,10 @@ def dump_function(self, ln, prototype):
894925
return_type = ''
895926
decl_type = 'function'
896927

897-
# Prefixes that would be removed
898-
sub_prefixes = [
899-
(r"^static +", "", 0),
900-
(r"^extern +", "", 0),
901-
(r"^asmlinkage +", "", 0),
902-
(r"^inline +", "", 0),
903-
(r"^__inline__ +", "", 0),
904-
(r"^__inline +", "", 0),
905-
(r"^__always_inline +", "", 0),
906-
(r"^noinline +", "", 0),
907-
(r"^__FORTIFY_INLINE +", "", 0),
908-
(r"__init +", "", 0),
909-
(r"__init_or_module +", "", 0),
910-
(r"__deprecated +", "", 0),
911-
(r"__flatten +", "", 0),
912-
(r"__meminit +", "", 0),
913-
(r"__must_check +", "", 0),
914-
(r"__weak +", "", 0),
915-
(r"__sched +", "", 0),
916-
(r"_noprof", "", 0),
917-
(r"__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +", "", 0),
918-
(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +", "", 0),
919-
(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +", "", 0),
920-
(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)", r"\1, \2", 0),
921-
(r"__attribute_const__ +", "", 0),
922-
923-
# It seems that Python support for re.X is broken:
924-
# At least for me (Python 3.13), this didn't work
925-
# (r"""
926-
# __attribute__\s*\(\(
927-
# (?:
928-
# [\w\s]+ # attribute name
929-
# (?:\([^)]*\))? # attribute arguments
930-
# \s*,? # optional comma at the end
931-
# )+
932-
# \)\)\s+
933-
# """, "", re.X),
934-
935-
# So, remove whitespaces and comments from it
936-
(r"__attribute__\s*\(\((?:[\w\s]+(?:\([^)]*\))?\s*,?)+\)\)\s+", "", 0),
937-
]
938-
939-
for search, sub, flags in sub_prefixes:
928+
#
929+
# Apply the initial transformations.
930+
#
931+
for search, sub, flags in function_xforms:
940932
prototype = KernRe(search, flags).sub(sub, prototype)
941933

942934
# Macros are a special case, as they change the prototype format

0 commit comments

Comments
 (0)