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.

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>

+20 -23
+20 -23
scripts/lib/kdoc/kdoc_parser.py
··· 926 926 Stores a function of function macro inside self.entries array. 927 927 """ 928 928 929 - func_macro = False 929 + found = func_macro = False 930 930 return_type = '' 931 931 decl_type = 'function' 932 932 # 933 933 # Apply the initial transformations. 934 934 # 935 935 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 + # 938 939 new_proto = KernRe(r"^#\s*define\s+").sub("", prototype) 939 940 if new_proto != prototype: 940 - is_define_proto = True 941 941 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 944 954 945 955 # Yes, this truly is vile. We are looking for: 946 956 # 1. Return type (may be nothing if we're looking at a macro) ··· 978 968 # parenthesis. 979 969 # 980 970 proto_args = r'\(([^\(]*|.*)\)' 981 - 982 - found = False 983 - 984 - if is_define_proto: 985 - r = KernRe(r'^(' + name + r')\s+') 986 - 987 - if r.search(prototype): 988 - return_type = '' 989 - declaration_name = r.group(1) 990 - func_macro = True 991 - 992 - found = True 993 - 971 + # 972 + # (Except for the simple macro case) attempt to split up the prototype 973 + # in the various ways we understand. 974 + # 994 975 if not found: 995 976 patterns = [ 996 977 rf'^()({name})\s*{proto_args}', ··· 991 990 992 991 for p in patterns: 993 992 r = KernRe(p) 994 - 995 993 if r.match(prototype): 996 - 997 994 return_type = r.group(1) 998 995 declaration_name = r.group(2) 999 996 args = r.group(3) 1000 - 1001 997 self.create_parameter_list(ln, decl_type, args, ',', 1002 998 declaration_name) 1003 - 1004 999 found = True 1005 1000 break 1006 1001 if not found: