Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

doc: kdoc: unify transform handling

Both functions and structs are passed through a set of regex-based
transforms, but the two were structured differently, despite being the same
thing. Create a utility function to apply transformations and use it in
both cases.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>

+34 -31
+34 -31
scripts/lib/kdoc/kdoc_parser.py
··· 78 78 # 79 79 struct_args_pattern = r'([^,)]+)' 80 80 81 - struct_prefixes = [ 81 + struct_xforms = [ 82 82 # Strip attributes 83 83 (KernRe(r"__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)", flags=re.I | re.S, cache=False), ' '), 84 84 (KernRe(r'\s*__aligned\s*\([^;]*\)', re.S), ' '), ··· 165 165 # Transforms for function prototypes 166 166 # 167 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), 168 + (KernRe(r"^static +"), ""), 169 + (KernRe(r"^extern +"), ""), 170 + (KernRe(r"^asmlinkage +"), ""), 171 + (KernRe(r"^inline +"), ""), 172 + (KernRe(r"^__inline__ +"), ""), 173 + (KernRe(r"^__inline +"), ""), 174 + (KernRe(r"^__always_inline +"), ""), 175 + (KernRe(r"^noinline +"), ""), 176 + (KernRe(r"^__FORTIFY_INLINE +"), ""), 177 + (KernRe(r"__init +"), ""), 178 + (KernRe(r"__init_or_module +"), ""), 179 + (KernRe(r"__deprecated +"), ""), 180 + (KernRe(r"__flatten +"), ""), 181 + (KernRe(r"__meminit +"), ""), 182 + (KernRe(r"__must_check +"), ""), 183 + (KernRe(r"__weak +"), ""), 184 + (KernRe(r"__sched +"), ""), 185 + (KernRe(r"_noprof"), ""), 186 + (KernRe(r"__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +"), ""), 187 + (KernRe(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +"), ""), 188 + (KernRe(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +"), ""), 189 + (KernRe(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)"), r"\1, \2"), 190 + (KernRe(r"__attribute_const__ +"), ""), 191 + (KernRe(r"__attribute__\s*\(\((?:[\w\s]+(?:\([^)]*\))?\s*,?)+\)\)\s+"), ""), 192 192 ] 193 193 194 - 194 + # 195 + # Apply a set of transforms to a block of text. 196 + # 197 + def apply_transforms(xforms, text): 198 + for search, subst in xforms: 199 + text = search.sub(subst, text) 200 + return text 195 201 196 202 # 197 203 # A little helper to get rid of excess white space ··· 813 807 # Go through the list of members applying all of our transformations. 814 808 # 815 809 members = trim_private_members(members) 816 - for search, sub in struct_prefixes: 817 - members = search.sub(sub, members) 810 + members = apply_transforms(struct_xforms, members) 818 811 819 812 nested = NestedMatch() 820 813 for search, sub in struct_nested_prefixes: ··· 929 924 func_macro = False 930 925 return_type = '' 931 926 decl_type = 'function' 932 - 933 927 # 934 928 # Apply the initial transformations. 935 929 # 936 - for search, sub, flags in function_xforms: 937 - prototype = KernRe(search, flags).sub(sub, prototype) 930 + prototype = apply_transforms(function_xforms, prototype) 938 931 939 932 # Macros are a special case, as they change the prototype format 940 933 new_proto = KernRe(r"^#\s*define\s+").sub("", prototype)