Kamil Rytarowski | cb77f0d | 2017-05-07 23:25:26 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Jonathan Corbet | 3847637 | 2018-02-20 12:24:23 -0700 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Kamil Rytarowski | cb77f0d | 2017-05-07 23:25:26 +0200 | [diff] [blame] | 4 | use warnings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | use strict; |
| 6 | |
| 7 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## |
| 8 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## |
| 9 | ## Copyright (C) 2001 Simon Huggins ## |
Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 10 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 11 | ## Copyright (C) 2012 Dan Luedtke ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | ## ## |
| 13 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## |
| 14 | ## Copyright (c) 2000 MontaVista Software, Inc. ## |
Tomasz Warniełło | 2b306ec | 2022-02-18 19:16:28 +0100 | [diff] [blame] | 15 | # |
| 16 | # Copyright (C) 2022 Tomasz Warniełło (POD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Tomasz Warniełło | 43caf1a | 2022-02-18 19:16:19 +0100 | [diff] [blame] | 18 | use Pod::Usage qw/pod2usage/; |
| 19 | |
Tomasz Warniełło | a5cdaea | 2022-02-18 19:16:18 +0100 | [diff] [blame] | 20 | =head1 NAME |
| 21 | |
| 22 | kernel-doc - Print formatted kernel documentation to stdout |
| 23 | |
| 24 | =head1 SYNOPSIS |
| 25 | |
| 26 | kernel-doc [-h] [-v] [-Werror] |
| 27 | [ -man | |
| 28 | -rst [-sphinx-version VERSION] [-enable-lineno] | |
| 29 | -none |
| 30 | ] |
| 31 | [ |
| 32 | -export | |
| 33 | -internal | |
| 34 | [-function NAME] ... | |
| 35 | [-nosymbol NAME] ... |
| 36 | ] |
| 37 | [-no-doc-sections] |
| 38 | [-export-file FILE] ... |
| 39 | FILE ... |
| 40 | |
| 41 | Run `kernel-doc -h` for details. |
| 42 | |
Tomasz Warniełło | f158392 | 2022-02-18 19:16:20 +0100 | [diff] [blame] | 43 | =head1 DESCRIPTION |
| 44 | |
| 45 | Read C language source or header FILEs, extract embedded documentation comments, |
| 46 | and print formatted documentation to standard output. |
| 47 | |
| 48 | The documentation comments are identified by the "/**" opening comment mark. |
| 49 | |
| 50 | See Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. |
| 51 | |
Tomasz Warniełło | a5cdaea | 2022-02-18 19:16:18 +0100 | [diff] [blame] | 52 | =cut |
| 53 | |
Tomasz Warniełło | 2875f78 | 2022-02-18 19:16:21 +0100 | [diff] [blame] | 54 | # more perldoc at the end of the file |
| 55 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 56 | ## init lots of data |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | my $errors = 0; |
| 59 | my $warnings = 0; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 60 | my $anon_struct_union = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | # match expressions used to find embedded type information |
Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 63 | my $type_constant = '\b``([^\`]+)``\b'; |
| 64 | my $type_constant2 = '\%([-_\w]+)'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | my $type_func = '(\w+)\(\)'; |
Mike Rapoport | bfd228c | 2018-11-07 18:47:13 +0200 | [diff] [blame] | 66 | my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; |
Mauro Carvalho Chehab | ee2aa75 | 2020-04-14 18:48:28 +0200 | [diff] [blame] | 67 | my $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; |
Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 68 | my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params |
Mauro Carvalho Chehab | 346282d | 2020-04-14 18:48:27 +0200 | [diff] [blame] | 69 | my $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | my $type_env = '(\$\w+)'; |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 71 | my $type_enum = '\&(enum\s*([_\w]+))'; |
| 72 | my $type_struct = '\&(struct\s*([_\w]+))'; |
| 73 | my $type_typedef = '\&(typedef\s*([_\w]+))'; |
| 74 | my $type_union = '\&(union\s*([_\w]+))'; |
Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 75 | my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 76 | my $type_fallback = '\&([_\w]+)'; |
Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 77 | my $type_member_func = $type_member . '\(\)'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | # Output conversion substitutions. |
| 80 | # One for each output format |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | # these are pretty rough |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 83 | my @highlights_man = ( |
| 84 | [$type_constant, "\$1"], |
Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 85 | [$type_constant2, "\$1"], |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 86 | [$type_func, "\\\\fB\$1\\\\fP"], |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 87 | [$type_enum, "\\\\fI\$1\\\\fP"], |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 88 | [$type_struct, "\\\\fI\$1\\\\fP"], |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 89 | [$type_typedef, "\\\\fI\$1\\\\fP"], |
| 90 | [$type_union, "\\\\fI\$1\\\\fP"], |
Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 91 | [$type_param, "\\\\fI\$1\\\\fP"], |
Mauro Carvalho Chehab | ee2aa75 | 2020-04-14 18:48:28 +0200 | [diff] [blame] | 92 | [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 93 | [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], |
| 94 | [$type_fallback, "\\\\fI\$1\\\\fP"] |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 95 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | my $blankline_man = ""; |
| 97 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 98 | # rst-mode |
| 99 | my @highlights_rst = ( |
| 100 | [$type_constant, "``\$1``"], |
Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 101 | [$type_constant2, "``\$1``"], |
Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 102 | # Note: need to escape () to avoid func matching later |
Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 103 | [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], |
| 104 | [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], |
Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 105 | [$type_fp_param, "**\$1\\\\(\\\\)**"], |
Mauro Carvalho Chehab | 346282d | 2020-04-14 18:48:27 +0200 | [diff] [blame] | 106 | [$type_fp_param2, "**\$1\\\\(\\\\)**"], |
Jonathan Corbet | 344fdb2 | 2019-06-21 17:34:30 -0600 | [diff] [blame] | 107 | [$type_func, "\$1()"], |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 108 | [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], |
| 109 | [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], |
| 110 | [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], |
| 111 | [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], |
Jani Nikula | a7291e7 | 2016-05-26 13:57:06 +0300 | [diff] [blame] | 112 | # in rst this can refer to any type |
Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 113 | [$type_fallback, "\\:c\\:type\\:`\$1`"], |
Mauro Carvalho Chehab | ee2aa75 | 2020-04-14 18:48:28 +0200 | [diff] [blame] | 114 | [$type_param_ref, "**\$1\$2**"] |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 115 | ); |
| 116 | my $blankline_rst = "\n"; |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | # read arguments |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 119 | if ($#ARGV == -1) { |
Tomasz Warniełło | 43caf1a | 2022-02-18 19:16:19 +0100 | [diff] [blame] | 120 | pod2usage( |
| 121 | -message => "No arguments!\n", |
| 122 | -exitval => 1, |
| 123 | -verbose => 99, |
| 124 | -sections => 'SYNOPSIS', |
| 125 | -output => \*STDERR, |
| 126 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 129 | my $kernelversion; |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 130 | my ($sphinx_major, $sphinx_minor, $sphinx_patch); |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 131 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 132 | my $dohighlight = ""; |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | my $verbose = 0; |
Pierre-Louis Bossart | 2c12c81 | 2020-07-28 11:20:40 -0500 | [diff] [blame] | 135 | my $Werror = 0; |
Mauro Carvalho Chehab | bdfe2be | 2017-12-18 10:30:11 -0200 | [diff] [blame] | 136 | my $output_mode = "rst"; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 137 | my $output_preformatted = 0; |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 138 | my $no_doc_sections = 0; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 139 | my $enable_lineno = 0; |
Mauro Carvalho Chehab | bdfe2be | 2017-12-18 10:30:11 -0200 | [diff] [blame] | 140 | my @highlights = @highlights_rst; |
| 141 | my $blankline = $blankline_rst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | my $modulename = "Kernel API"; |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 143 | |
| 144 | use constant { |
| 145 | OUTPUT_ALL => 0, # output all symbols and doc sections |
| 146 | OUTPUT_INCLUDE => 1, # output only specified symbols |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 147 | OUTPUT_EXPORTED => 2, # output exported symbols |
| 148 | OUTPUT_INTERNAL => 3, # output non-exported symbols |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 149 | }; |
| 150 | my $output_selection = OUTPUT_ALL; |
Jonathan Corbet | b0d60bf | 2019-05-24 14:52:01 -0600 | [diff] [blame] | 151 | my $show_not_found = 0; # No longer used |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 152 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 153 | my @export_file_list; |
| 154 | |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 155 | my @build_time; |
| 156 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && |
| 157 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { |
| 158 | @build_time = gmtime($seconds); |
| 159 | } else { |
| 160 | @build_time = localtime; |
| 161 | } |
| 162 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 163 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', |
| 164 | 'July', 'August', 'September', 'October', |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 165 | 'November', 'December')[$build_time[4]] . |
| 166 | " " . ($build_time[5]+1900); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 168 | # Essentially these are globals. |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 169 | # They probably want to be tidied up, made more localised or something. |
| 170 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | # could cause "use of undefined value" or other bugs. |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 172 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 173 | my %nosymbol_table = (); |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 174 | my $declaration_start_line; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 175 | my ($type, $declaration_name, $return_type); |
Ilya Dryomov | 1c32fd0 | 2010-02-26 13:06:03 -0800 | [diff] [blame] | 176 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Randy Dunlap | bd0e88e | 2008-03-13 12:32:43 -0700 | [diff] [blame] | 178 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
| 179 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; |
| 180 | } |
| 181 | |
Pierre-Louis Bossart | 2c12c81 | 2020-07-28 11:20:40 -0500 | [diff] [blame] | 182 | if (defined($ENV{'KCFLAGS'})) { |
| 183 | my $kcflags = "$ENV{'KCFLAGS'}"; |
| 184 | |
| 185 | if ($kcflags =~ /Werror/) { |
| 186 | $Werror = 1; |
| 187 | } |
| 188 | } |
| 189 | |
Laurent Pinchart | bed4ed3 | 2021-07-31 01:54:01 +0300 | [diff] [blame] | 190 | if (defined($ENV{'KDOC_WERROR'})) { |
| 191 | $Werror = "$ENV{'KDOC_WERROR'}"; |
| 192 | } |
| 193 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 194 | # Generated docbook code is inserted in a template at a point where |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: |
Alexander A. Klimov | 93431e0 | 2020-05-26 08:05:44 +0200 | [diff] [blame] | 196 | # https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | # We keep track of number of generated entries and generate a dummy |
| 198 | # if needs be to ensure the expanded template can be postprocessed |
| 199 | # into html. |
| 200 | my $section_counter = 0; |
| 201 | |
| 202 | my $lineprefix=""; |
| 203 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 204 | # Parser states |
| 205 | use constant { |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 206 | STATE_NORMAL => 0, # normal code |
| 207 | STATE_NAME => 1, # looking for function name |
| 208 | STATE_BODY_MAYBE => 2, # body - or maybe more description |
| 209 | STATE_BODY => 3, # the body of the comment |
| 210 | STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line |
| 211 | STATE_PROTO => 5, # scanning prototype |
| 212 | STATE_DOCBLOCK => 6, # documentation block |
| 213 | STATE_INLINE => 7, # gathering doc outside main block |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 214 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | my $state; |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 216 | my $in_doc_sect; |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 217 | my $leading_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 219 | # Inline documentation state |
| 220 | use constant { |
| 221 | STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) |
| 222 | STATE_INLINE_NAME => 1, # looking for member name (@foo:) |
| 223 | STATE_INLINE_TEXT => 2, # looking for member documentation |
| 224 | STATE_INLINE_END => 3, # done |
| 225 | STATE_INLINE_ERROR => 4, # error - Comment without header was found. |
| 226 | # Spit a warning as it's not |
| 227 | # proper kernel-doc and ignore the rest. |
| 228 | }; |
| 229 | my $inline_doc_state; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #declaration types: can be |
| 232 | # 'function', 'struct', 'union', 'enum', 'typedef' |
| 233 | my $decl_type; |
| 234 | |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 235 | # Name of the kernel-doc identifier for non-DOC markups |
| 236 | my $identifier; |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. |
| 239 | my $doc_end = '\*/'; |
| 240 | my $doc_com = '\s*\*\s*'; |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 241 | my $doc_com_body = '\s*\* ?'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 242 | my $doc_decl = $doc_com . '(\w+)'; |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 243 | # @params and a strictly limited set of supported section names |
Jonathan Corbet | 212209cf | 2021-03-26 13:16:35 -0600 | [diff] [blame] | 244 | # Specifically: |
| 245 | # Match @word: |
| 246 | # @...: |
| 247 | # @{section-name}: |
| 248 | # while trying to not match literal block starts like "example::" |
| 249 | # |
Mike Rapoport | 76dd3e7 | 2018-11-07 18:47:12 +0200 | [diff] [blame] | 250 | my $doc_sect = $doc_com . |
Jonathan Corbet | 212209cf | 2021-03-26 13:16:35 -0600 | [diff] [blame] | 251 | '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 252 | my $doc_content = $doc_com_body . '(.*)'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 253 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 254 | my $doc_inline_start = '^\s*/\*\*\s*$'; |
Mauro Carvalho Chehab | fe7bc49 | 2018-02-16 11:48:18 -0200 | [diff] [blame] | 255 | my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 256 | my $doc_inline_end = '^\s*\*/\s*$'; |
Jani Nikula | 0c9aa20 | 2016-11-16 17:26:16 +0200 | [diff] [blame] | 257 | my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; |
Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 258 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 259 | my $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; |
| 260 | my $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | my %parameterdescs; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 263 | my %parameterdesc_start_lines; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | my @parameterlist; |
| 265 | my %sections; |
| 266 | my @sectionlist; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 267 | my %section_start_lines; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 268 | my $sectcheck; |
| 269 | my $struct_actual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | my $contents = ""; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 272 | my $new_start_line = 0; |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 273 | |
| 274 | # the canonical section names. see also $doc_sect above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | my $section_default = "Description"; # default section |
| 276 | my $section_intro = "Introduction"; |
| 277 | my $section = $section_default; |
| 278 | my $section_context = "Context"; |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 279 | my $section_return = "Return"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | my $undescribed = "-- undescribed --"; |
| 282 | |
| 283 | reset_state(); |
| 284 | |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 285 | while ($ARGV[0] =~ m/^--?(.*)/) { |
| 286 | my $cmd = $1; |
| 287 | shift @ARGV; |
| 288 | if ($cmd eq "man") { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | $output_mode = "man"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 290 | @highlights = @highlights_man; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | $blankline = $blankline_man; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 292 | } elsif ($cmd eq "rst") { |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 293 | $output_mode = "rst"; |
| 294 | @highlights = @highlights_rst; |
| 295 | $blankline = $blankline_rst; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 296 | } elsif ($cmd eq "none") { |
Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 297 | $output_mode = "none"; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 298 | } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | $modulename = shift @ARGV; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 300 | } elsif ($cmd eq "function") { # to only output specific functions |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 301 | $output_selection = OUTPUT_INCLUDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | $function = shift @ARGV; |
| 303 | $function_table{$function} = 1; |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 304 | } elsif ($cmd eq "nosymbol") { # Exclude specific symbols |
| 305 | my $symbol = shift @ARGV; |
| 306 | $nosymbol_table{$symbol} = 1; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 307 | } elsif ($cmd eq "export") { # only exported symbols |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 308 | $output_selection = OUTPUT_EXPORTED; |
Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 309 | %function_table = (); |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 310 | } elsif ($cmd eq "internal") { # only non-exported symbols |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 311 | $output_selection = OUTPUT_INTERNAL; |
Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 312 | %function_table = (); |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 313 | } elsif ($cmd eq "export-file") { |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 314 | my $file = shift @ARGV; |
| 315 | push(@export_file_list, $file); |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 316 | } elsif ($cmd eq "v") { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | $verbose = 1; |
Pierre-Louis Bossart | 2c12c81 | 2020-07-28 11:20:40 -0500 | [diff] [blame] | 318 | } elsif ($cmd eq "Werror") { |
| 319 | $Werror = 1; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 320 | } elsif (($cmd eq "h") || ($cmd eq "help")) { |
Tomasz Warniełło | 252b47d | 2022-02-18 19:16:26 +0100 | [diff] [blame] | 321 | pod2usage(-exitval => 0, -verbose => 2); |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 322 | } elsif ($cmd eq 'no-doc-sections') { |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 323 | $no_doc_sections = 1; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 324 | } elsif ($cmd eq 'enable-lineno') { |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 325 | $enable_lineno = 1; |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 326 | } elsif ($cmd eq 'show-not-found') { |
Jonathan Corbet | b0d60bf | 2019-05-24 14:52:01 -0600 | [diff] [blame] | 327 | $show_not_found = 1; # A no-op but don't fail |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 328 | } elsif ($cmd eq "sphinx-version") { |
| 329 | my $ver_string = shift @ARGV; |
| 330 | if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { |
| 331 | $sphinx_major = $1; |
| 332 | if (defined($2)) { |
| 333 | $sphinx_minor = substr($2,1); |
| 334 | } else { |
| 335 | $sphinx_minor = 0; |
| 336 | } |
| 337 | if (defined($3)) { |
| 338 | $sphinx_patch = substr($3,1) |
| 339 | } else { |
| 340 | $sphinx_patch = 0; |
| 341 | } |
| 342 | } else { |
| 343 | die "Sphinx version should either major.minor or major.minor.patch format\n"; |
| 344 | } |
Mauro Carvalho Chehab | b031ac4 | 2017-12-18 10:30:10 -0200 | [diff] [blame] | 345 | } else { |
Akira Yokosawa | e334f87 | 2022-02-24 22:02:46 +0900 | [diff] [blame] | 346 | # Unknown argument |
| 347 | pod2usage( |
| 348 | -message => "Argument unknown!\n", |
| 349 | -exitval => 1, |
| 350 | -verbose => 99, |
| 351 | -sections => 'SYNOPSIS', |
| 352 | -output => \*STDERR, |
| 353 | ); |
| 354 | } |
| 355 | if ($#ARGV < 0){ |
| 356 | pod2usage( |
| 357 | -message => "FILE argument missing\n", |
| 358 | -exitval => 1, |
| 359 | -verbose => 99, |
| 360 | -sections => 'SYNOPSIS', |
| 361 | -output => \*STDERR, |
| 362 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 366 | # continue execution near EOF; |
| 367 | |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 368 | # The C domain dialect changed on Sphinx 3. So, we need to check the |
| 369 | # version in order to produce the right tags. |
| 370 | sub findprog($) |
| 371 | { |
| 372 | foreach(split(/:/, $ENV{PATH})) { |
| 373 | return "$_/$_[0]" if(-x "$_/$_[0]"); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | sub get_sphinx_version() |
| 378 | { |
| 379 | my $ver; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 380 | |
| 381 | my $cmd = "sphinx-build"; |
| 382 | if (!findprog($cmd)) { |
| 383 | my $cmd = "sphinx-build3"; |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 384 | if (!findprog($cmd)) { |
| 385 | $sphinx_major = 1; |
| 386 | $sphinx_minor = 2; |
| 387 | $sphinx_patch = 0; |
| 388 | printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", |
| 389 | $sphinx_major, $sphinx_minor, $sphinx_patch; |
| 390 | return; |
| 391 | } |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | open IN, "$cmd --version 2>&1 |"; |
| 395 | while (<IN>) { |
| 396 | if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 397 | $sphinx_major = $1; |
| 398 | $sphinx_minor = $2; |
| 399 | $sphinx_patch = $3; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 400 | last; |
| 401 | } |
| 402 | # Sphinx 1.2.x uses a different format |
| 403 | if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 404 | $sphinx_major = $1; |
| 405 | $sphinx_minor = $2; |
| 406 | $sphinx_patch = $3; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 407 | last; |
| 408 | } |
| 409 | } |
| 410 | close IN; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 411 | } |
| 412 | |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 413 | # get kernel version from env |
| 414 | sub get_kernel_version() { |
Johannes Berg | 1b9bc22 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 415 | my $version = 'unknown kernel version'; |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 416 | |
| 417 | if (defined($ENV{'KERNELVERSION'})) { |
| 418 | $version = $ENV{'KERNELVERSION'}; |
| 419 | } |
| 420 | return $version; |
| 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 423 | # |
| 424 | sub print_lineno { |
| 425 | my $lineno = shift; |
| 426 | if ($enable_lineno && defined($lineno)) { |
Mauro Carvalho Chehab | b79dfef | 2022-03-26 11:27:24 +0100 | [diff] [blame] | 427 | print ".. LINENO " . $lineno . "\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 428 | } |
| 429 | } |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 430 | |
| 431 | sub emit_warning { |
| 432 | my $location = shift; |
| 433 | my $msg = shift; |
| 434 | print STDERR "$location: warning: $msg"; |
| 435 | ++$warnings; |
| 436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | ## |
| 438 | # dumps section contents to arrays/hashes intended for that purpose. |
| 439 | # |
| 440 | sub dump_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 441 | my $file = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | my $name = shift; |
| 443 | my $contents = join "\n", @_; |
| 444 | |
Jani Nikula | 13901ef | 2016-05-26 08:57:29 +0300 | [diff] [blame] | 445 | if ($name =~ m/$type_param/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | $name = $1; |
| 447 | $parameterdescs{$name} = $contents; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 448 | $sectcheck = $sectcheck . $name . " "; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 449 | $parameterdesc_start_lines{$name} = $new_start_line; |
| 450 | $new_start_line = 0; |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 451 | } elsif ($name eq "@\.\.\.") { |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 452 | $name = "..."; |
| 453 | $parameterdescs{$name} = $contents; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 454 | $sectcheck = $sectcheck . $name . " "; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 455 | $parameterdesc_start_lines{$name} = $new_start_line; |
| 456 | $new_start_line = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } else { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 458 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
Jani Nikula | 95b6be9 | 2016-06-10 11:14:05 +0300 | [diff] [blame] | 459 | # Only warn on user specified duplicate section names. |
| 460 | if ($name ne $section_default) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 461 | emit_warning("${file}:$.", "duplicate section name '$name'\n"); |
Jani Nikula | 95b6be9 | 2016-06-10 11:14:05 +0300 | [diff] [blame] | 462 | } |
Jani Nikula | 3221776 | 2016-05-29 09:40:44 +0300 | [diff] [blame] | 463 | $sections{$name} .= $contents; |
| 464 | } else { |
| 465 | $sections{$name} = $contents; |
| 466 | push @sectionlist, $name; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 467 | $section_start_lines{$name} = $new_start_line; |
| 468 | $new_start_line = 0; |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | ## |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 474 | # dump DOC: section after checking that it should go out |
| 475 | # |
| 476 | sub dump_doc_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 477 | my $file = shift; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 478 | my $name = shift; |
| 479 | my $contents = join "\n", @_; |
| 480 | |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 481 | if ($no_doc_sections) { |
| 482 | return; |
| 483 | } |
| 484 | |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 485 | return if (defined($nosymbol_table{$name})); |
| 486 | |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 487 | if (($output_selection == OUTPUT_ALL) || |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 488 | (($output_selection == OUTPUT_INCLUDE) && |
| 489 | defined($function_table{$name}))) |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 490 | { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 491 | dump_section($file, $name, $contents); |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 492 | output_blockhead({'sectionlist' => \@sectionlist, |
| 493 | 'sections' => \%sections, |
| 494 | 'module' => $modulename, |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 495 | 'content-only' => ($output_selection != OUTPUT_ALL), }); |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
| 499 | ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | # output function |
| 501 | # |
| 502 | # parameterdescs, a hash. |
| 503 | # function => "function name" |
| 504 | # parameterlist => @list of parameters |
| 505 | # parameterdescs => %parameter descriptions |
| 506 | # sectionlist => @list of sections |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 507 | # sections => %section descriptions |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 508 | # |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | sub output_highlight { |
| 511 | my $contents = join "\n",@_; |
| 512 | my $line; |
| 513 | |
| 514 | # DEBUG |
| 515 | # if (!defined $contents) { |
| 516 | # use Carp; |
| 517 | # confess "output_highlight got called with no args?\n"; |
| 518 | # } |
| 519 | |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 520 | # print STDERR "contents b4:$contents\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | eval $dohighlight; |
| 522 | die $@ if $@; |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 523 | # print STDERR "contents af:$contents\n"; |
| 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | foreach $line (split "\n", $contents) { |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 526 | if (! $output_preformatted) { |
| 527 | $line =~ s/^\s*//; |
| 528 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 529 | if ($line eq ""){ |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 530 | if (! $output_preformatted) { |
Jonathan Corbet | 0bba924 | 2018-02-05 12:40:15 -0700 | [diff] [blame] | 531 | print $lineprefix, $blankline; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } else { |
Randy Dunlap | cdccb31 | 2007-07-19 01:48:25 -0700 | [diff] [blame] | 534 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
| 535 | print "\\&$line"; |
| 536 | } else { |
| 537 | print $lineprefix, $line; |
| 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | print "\n"; |
| 541 | } |
| 542 | } |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | ## |
| 545 | # output function in man |
| 546 | sub output_function_man(%) { |
| 547 | my %args = %{$_[0]}; |
| 548 | my ($parameter, $section); |
| 549 | my $count; |
| 550 | |
| 551 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; |
| 552 | |
| 553 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 554 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 557 | if ($args{'functiontype'} ne "") { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 558 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 559 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 560 | print ".B \"" . $args{'function'} . "\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | $count = 0; |
| 563 | my $parenth = "("; |
| 564 | my $post = ","; |
| 565 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 566 | if ($count == $#{$args{'parameterlist'}}) { |
| 567 | $post = ");"; |
| 568 | } |
| 569 | $type = $args{'parametertypes'}{$parameter}; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 570 | if ($type =~ m/$function_pointer/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | # pointer-to-function |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 572 | print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } else { |
| 574 | $type =~ s/([^\*])$/$1 /; |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 575 | print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | $count++; |
| 578 | $parenth = ""; |
| 579 | } |
| 580 | |
| 581 | print ".SH ARGUMENTS\n"; |
| 582 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 583 | my $parameter_name = $parameter; |
| 584 | $parameter_name =~ s/\[.*//; |
| 585 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 586 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 588 | } |
| 589 | foreach $section (@{$args{'sectionlist'}}) { |
| 590 | print ".SH \"", uc $section, "\"\n"; |
| 591 | output_highlight($args{'sections'}{$section}); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | ## |
| 596 | # output enum in man |
| 597 | sub output_enum_man(%) { |
| 598 | my %args = %{$_[0]}; |
| 599 | my ($parameter, $section); |
| 600 | my $count; |
| 601 | |
| 602 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 603 | |
| 604 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 605 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 608 | print "enum " . $args{'enum'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | $count = 0; |
| 610 | foreach my $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 611 | print ".br\n.BI \" $parameter\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | if ($count == $#{$args{'parameterlist'}}) { |
| 613 | print "\n};\n"; |
| 614 | last; |
| 615 | } |
| 616 | else { |
| 617 | print ", \n.br\n"; |
| 618 | } |
| 619 | $count++; |
| 620 | } |
| 621 | |
| 622 | print ".SH Constants\n"; |
| 623 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 624 | my $parameter_name = $parameter; |
| 625 | $parameter_name =~ s/\[.*//; |
| 626 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 627 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 629 | } |
| 630 | foreach $section (@{$args{'sectionlist'}}) { |
| 631 | print ".SH \"$section\"\n"; |
| 632 | output_highlight($args{'sections'}{$section}); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | ## |
| 637 | # output struct in man |
| 638 | sub output_struct_man(%) { |
| 639 | my %args = %{$_[0]}; |
| 640 | my ($parameter, $section); |
| 641 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 642 | print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 645 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 647 | my $declaration = $args{'definition'}; |
| 648 | $declaration =~ s/\t/ /g; |
| 649 | $declaration =~ s/\n/"\n.br\n.BI \"/g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 651 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 652 | print ".BI \"$declaration\n};\n.br\n\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Randy Dunlap | c51d3dac | 2006-06-25 05:49:14 -0700 | [diff] [blame] | 654 | print ".SH Members\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 656 | ($parameter =~ /^#/) && next; |
| 657 | |
| 658 | my $parameter_name = $parameter; |
| 659 | $parameter_name =~ s/\[.*//; |
| 660 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 661 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 662 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 664 | } |
| 665 | foreach $section (@{$args{'sectionlist'}}) { |
| 666 | print ".SH \"$section\"\n"; |
| 667 | output_highlight($args{'sections'}{$section}); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | ## |
| 672 | # output typedef in man |
| 673 | sub output_typedef_man(%) { |
| 674 | my %args = %{$_[0]}; |
| 675 | my ($parameter, $section); |
| 676 | |
| 677 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 678 | |
| 679 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 680 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | foreach $section (@{$args{'sectionlist'}}) { |
| 683 | print ".SH \"$section\"\n"; |
| 684 | output_highlight($args{'sections'}{$section}); |
| 685 | } |
| 686 | } |
| 687 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 688 | sub output_blockhead_man(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | my %args = %{$_[0]}; |
| 690 | my ($parameter, $section); |
| 691 | my $count; |
| 692 | |
| 693 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 694 | |
| 695 | foreach $section (@{$args{'sectionlist'}}) { |
| 696 | print ".SH \"$section\"\n"; |
| 697 | output_highlight($args{'sections'}{$section}); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | ## |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 702 | # output in restructured text |
| 703 | # |
| 704 | |
| 705 | # |
| 706 | # This could use some work; it's used to output the DOC: sections, and |
| 707 | # starts by putting out the name of the doc section itself, but that tends |
| 708 | # to duplicate a header already in the template file. |
| 709 | # |
| 710 | sub output_blockhead_rst(%) { |
| 711 | my %args = %{$_[0]}; |
| 712 | my ($parameter, $section); |
| 713 | |
| 714 | foreach $section (@{$args{'sectionlist'}}) { |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 715 | next if (defined($nosymbol_table{$section})); |
| 716 | |
Jani Nikula | 9e72184 | 2016-05-29 22:27:35 +0300 | [diff] [blame] | 717 | if ($output_selection != OUTPUT_INCLUDE) { |
Michal Wajdeczko | 06a755d | 2021-01-18 12:08:13 +0100 | [diff] [blame] | 718 | print ".. _$section:\n\n"; |
Jani Nikula | 9e72184 | 2016-05-29 22:27:35 +0300 | [diff] [blame] | 719 | print "**$section**\n\n"; |
| 720 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 721 | print_lineno($section_start_lines{$section}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 722 | output_highlight_rst($args{'sections'}{$section}); |
| 723 | print "\n"; |
| 724 | } |
| 725 | } |
| 726 | |
Jonathan Corbet | af25029 | 2018-02-06 15:58:45 -0700 | [diff] [blame] | 727 | # |
| 728 | # Apply the RST highlights to a sub-block of text. |
Mike Rapoport | 76dd3e7 | 2018-11-07 18:47:12 +0200 | [diff] [blame] | 729 | # |
Jonathan Corbet | af25029 | 2018-02-06 15:58:45 -0700 | [diff] [blame] | 730 | sub highlight_block($) { |
| 731 | # The dohighlight kludge requires the text be called $contents |
| 732 | my $contents = shift; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 733 | eval $dohighlight; |
| 734 | die $@ if $@; |
Jonathan Corbet | af25029 | 2018-02-06 15:58:45 -0700 | [diff] [blame] | 735 | return $contents; |
| 736 | } |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 737 | |
Jonathan Corbet | af25029 | 2018-02-06 15:58:45 -0700 | [diff] [blame] | 738 | # |
| 739 | # Regexes used only here. |
| 740 | # |
| 741 | my $sphinx_literal = '^[^.].*::$'; |
| 742 | my $sphinx_cblock = '^\.\.\ +code-block::'; |
| 743 | |
| 744 | sub output_highlight_rst { |
| 745 | my $input = join "\n",@_; |
| 746 | my $output = ""; |
| 747 | my $line; |
| 748 | my $in_literal = 0; |
| 749 | my $litprefix; |
| 750 | my $block = ""; |
| 751 | |
| 752 | foreach $line (split "\n",$input) { |
| 753 | # |
| 754 | # If we're in a literal block, see if we should drop out |
| 755 | # of it. Otherwise pass the line straight through unmunged. |
| 756 | # |
| 757 | if ($in_literal) { |
| 758 | if (! ($line =~ /^\s*$/)) { |
| 759 | # |
| 760 | # If this is the first non-blank line in a literal |
| 761 | # block we need to figure out what the proper indent is. |
| 762 | # |
| 763 | if ($litprefix eq "") { |
| 764 | $line =~ /^(\s*)/; |
| 765 | $litprefix = '^' . $1; |
| 766 | $output .= $line . "\n"; |
| 767 | } elsif (! ($line =~ /$litprefix/)) { |
| 768 | $in_literal = 0; |
| 769 | } else { |
| 770 | $output .= $line . "\n"; |
| 771 | } |
| 772 | } else { |
| 773 | $output .= $line . "\n"; |
| 774 | } |
| 775 | } |
| 776 | # |
| 777 | # Not in a literal block (or just dropped out) |
| 778 | # |
| 779 | if (! $in_literal) { |
| 780 | $block .= $line . "\n"; |
| 781 | if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { |
| 782 | $in_literal = 1; |
| 783 | $litprefix = ""; |
| 784 | $output .= highlight_block($block); |
| 785 | $block = "" |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | if ($block) { |
| 791 | $output .= highlight_block($block); |
| 792 | } |
| 793 | foreach $line (split "\n", $output) { |
Jani Nikula | 830066a | 2016-05-26 22:04:33 +0300 | [diff] [blame] | 794 | print $lineprefix . $line . "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | sub output_function_rst(%) { |
| 799 | my %args = %{$_[0]}; |
| 800 | my ($parameter, $section); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 801 | my $oldprefix = $lineprefix; |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 802 | my $start = ""; |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 803 | my $is_macro = 0; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 804 | |
Mauro Carvalho Chehab | e3ad05f | 2020-09-25 10:05:40 +0200 | [diff] [blame] | 805 | if ($sphinx_major < 3) { |
| 806 | if ($args{'typedef'}) { |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 807 | print ".. c:type:: ". $args{'function'} . "\n\n"; |
Mauro Carvalho Chehab | e3ad05f | 2020-09-25 10:05:40 +0200 | [diff] [blame] | 808 | print_lineno($declaration_start_line); |
| 809 | print " **Typedef**: "; |
| 810 | $lineprefix = ""; |
| 811 | output_highlight_rst($args{'purpose'}); |
| 812 | $start = "\n\n**Syntax**\n\n ``"; |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 813 | $is_macro = 1; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 814 | } else { |
Mauro Carvalho Chehab | e3ad05f | 2020-09-25 10:05:40 +0200 | [diff] [blame] | 815 | print ".. c:function:: "; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 816 | } |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 817 | } else { |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 818 | if ($args{'typedef'} || $args{'functiontype'} eq "") { |
| 819 | $is_macro = 1; |
| 820 | print ".. c:macro:: ". $args{'function'} . "\n\n"; |
| 821 | } else { |
| 822 | print ".. c:function:: "; |
| 823 | } |
Mauro Carvalho Chehab | e3ad05f | 2020-09-25 10:05:40 +0200 | [diff] [blame] | 824 | |
| 825 | if ($args{'typedef'}) { |
| 826 | print_lineno($declaration_start_line); |
| 827 | print " **Typedef**: "; |
| 828 | $lineprefix = ""; |
| 829 | output_highlight_rst($args{'purpose'}); |
| 830 | $start = "\n\n**Syntax**\n\n ``"; |
| 831 | } else { |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 832 | print "``" if ($is_macro); |
Mauro Carvalho Chehab | e3ad05f | 2020-09-25 10:05:40 +0200 | [diff] [blame] | 833 | } |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 834 | } |
| 835 | if ($args{'functiontype'} ne "") { |
| 836 | $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; |
| 837 | } else { |
| 838 | $start .= $args{'function'} . " ("; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 839 | } |
| 840 | print $start; |
| 841 | |
| 842 | my $count = 0; |
| 843 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 844 | if ($count ne 0) { |
| 845 | print ", "; |
| 846 | } |
| 847 | $count++; |
| 848 | $type = $args{'parametertypes'}{$parameter}; |
Mauro Carvalho Chehab | a88b167 | 2016-07-22 11:46:36 -0300 | [diff] [blame] | 849 | |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 850 | if ($type =~ m/$function_pointer/) { |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 851 | # pointer-to-function |
Peter Maydell | e8f4ba8 | 2020-04-14 15:37:43 +0100 | [diff] [blame] | 852 | print $1 . $parameter . ") (" . $2 . ")"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 853 | } else { |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 854 | print $type; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 855 | } |
| 856 | } |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 857 | if ($is_macro) { |
| 858 | print ")``\n\n"; |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 859 | } else { |
Mauro Carvalho Chehab | 6e9e415 | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 860 | print ")\n\n"; |
| 861 | } |
| 862 | if (!$args{'typedef'}) { |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 863 | print_lineno($declaration_start_line); |
| 864 | $lineprefix = " "; |
| 865 | output_highlight_rst($args{'purpose'}); |
| 866 | print "\n"; |
| 867 | } |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 868 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 869 | print "**Parameters**\n\n"; |
| 870 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 871 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 872 | my $parameter_name = $parameter; |
Gabriel Krisman Bertazi | ada5f44 | 2017-01-09 18:11:57 -0200 | [diff] [blame] | 873 | $parameter_name =~ s/\[.*//; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 874 | $type = $args{'parametertypes'}{$parameter}; |
| 875 | |
| 876 | if ($type ne "") { |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 877 | print "``$type``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 878 | } else { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 879 | print "``$parameter``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 880 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 881 | |
| 882 | print_lineno($parameterdesc_start_lines{$parameter_name}); |
| 883 | |
Jani Nikula | 5e64fa9 | 2016-05-19 20:32:48 +0300 | [diff] [blame] | 884 | if (defined($args{'parameterdescs'}{$parameter_name}) && |
| 885 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 886 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 887 | } else { |
Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 888 | print " *undescribed*\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 889 | } |
| 890 | print "\n"; |
| 891 | } |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 892 | |
| 893 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 894 | output_section_rst(@_); |
| 895 | } |
| 896 | |
| 897 | sub output_section_rst(%) { |
| 898 | my %args = %{$_[0]}; |
| 899 | my $section; |
| 900 | my $oldprefix = $lineprefix; |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 901 | $lineprefix = ""; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 902 | |
| 903 | foreach $section (@{$args{'sectionlist'}}) { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 904 | print "**$section**\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 905 | print_lineno($section_start_lines{$section}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 906 | output_highlight_rst($args{'sections'}{$section}); |
| 907 | print "\n"; |
| 908 | } |
| 909 | print "\n"; |
| 910 | $lineprefix = $oldprefix; |
| 911 | } |
| 912 | |
| 913 | sub output_enum_rst(%) { |
| 914 | my %args = %{$_[0]}; |
| 915 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 916 | my $oldprefix = $lineprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 917 | my $count; |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 918 | |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 919 | if ($sphinx_major < 3) { |
| 920 | my $name = "enum " . $args{'enum'}; |
| 921 | print "\n\n.. c:type:: " . $name . "\n\n"; |
| 922 | } else { |
| 923 | my $name = $args{'enum'}; |
| 924 | print "\n\n.. c:enum:: " . $name . "\n\n"; |
| 925 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 926 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 927 | $lineprefix = " "; |
| 928 | output_highlight_rst($args{'purpose'}); |
| 929 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 930 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 931 | print "**Constants**\n\n"; |
| 932 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 933 | foreach $parameter (@{$args{'parameterlist'}}) { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 934 | print "``$parameter``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 935 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { |
| 936 | output_highlight_rst($args{'parameterdescs'}{$parameter}); |
| 937 | } else { |
Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 938 | print " *undescribed*\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 939 | } |
| 940 | print "\n"; |
| 941 | } |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 942 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 943 | $lineprefix = $oldprefix; |
| 944 | output_section_rst(@_); |
| 945 | } |
| 946 | |
| 947 | sub output_typedef_rst(%) { |
| 948 | my %args = %{$_[0]}; |
| 949 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 950 | my $oldprefix = $lineprefix; |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 951 | my $name; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 952 | |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 953 | if ($sphinx_major < 3) { |
| 954 | $name = "typedef " . $args{'typedef'}; |
| 955 | } else { |
| 956 | $name = $args{'typedef'}; |
| 957 | } |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 958 | print "\n\n.. c:type:: " . $name . "\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 959 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 960 | $lineprefix = " "; |
| 961 | output_highlight_rst($args{'purpose'}); |
| 962 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 963 | |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 964 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 965 | output_section_rst(@_); |
| 966 | } |
| 967 | |
| 968 | sub output_struct_rst(%) { |
| 969 | my %args = %{$_[0]}; |
| 970 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 971 | my $oldprefix = $lineprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 972 | |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 973 | if ($sphinx_major < 3) { |
| 974 | my $name = $args{'type'} . " " . $args{'struct'}; |
| 975 | print "\n\n.. c:type:: " . $name . "\n\n"; |
| 976 | } else { |
| 977 | my $name = $args{'struct'}; |
Mauro Carvalho Chehab | 72b97d0 | 2020-10-27 10:51:05 +0100 | [diff] [blame] | 978 | if ($args{'type'} eq 'union') { |
| 979 | print "\n\n.. c:union:: " . $name . "\n\n"; |
| 980 | } else { |
| 981 | print "\n\n.. c:struct:: " . $name . "\n\n"; |
| 982 | } |
Mauro Carvalho Chehab | efa44475 | 2020-09-24 15:30:37 +0200 | [diff] [blame] | 983 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 984 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 985 | $lineprefix = " "; |
| 986 | output_highlight_rst($args{'purpose'}); |
| 987 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 988 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 989 | print "**Definition**\n\n"; |
| 990 | print "::\n\n"; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 991 | my $declaration = $args{'definition'}; |
| 992 | $declaration =~ s/\t/ /g; |
| 993 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 994 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 995 | print "**Members**\n\n"; |
| 996 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 997 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 998 | ($parameter =~ /^#/) && next; |
| 999 | |
| 1000 | my $parameter_name = $parameter; |
| 1001 | $parameter_name =~ s/\[.*//; |
| 1002 | |
| 1003 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 1004 | $type = $args{'parametertypes'}{$parameter}; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1005 | print_lineno($parameterdesc_start_lines{$parameter_name}); |
Mauro Carvalho Chehab | 6d232c8 | 2016-08-22 22:02:57 -0300 | [diff] [blame] | 1006 | print "``" . $parameter . "``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1007 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1008 | print "\n"; |
| 1009 | } |
| 1010 | print "\n"; |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1011 | |
| 1012 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1013 | output_section_rst(@_); |
| 1014 | } |
| 1015 | |
Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 1016 | ## none mode output functions |
| 1017 | |
| 1018 | sub output_function_none(%) { |
| 1019 | } |
| 1020 | |
| 1021 | sub output_enum_none(%) { |
| 1022 | } |
| 1023 | |
| 1024 | sub output_typedef_none(%) { |
| 1025 | } |
| 1026 | |
| 1027 | sub output_struct_none(%) { |
| 1028 | } |
| 1029 | |
| 1030 | sub output_blockhead_none(%) { |
| 1031 | } |
| 1032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1034 | # generic output function for all types (function, struct/union, typedef, enum); |
| 1035 | # calls the generated, variable output_ function name based on |
| 1036 | # functype and output_mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | sub output_declaration { |
| 1038 | no strict 'refs'; |
| 1039 | my $name = shift; |
| 1040 | my $functype = shift; |
| 1041 | my $func = "output_${functype}_$output_mode"; |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 1042 | |
| 1043 | return if (defined($nosymbol_table{$name})); |
| 1044 | |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 1045 | if (($output_selection == OUTPUT_ALL) || |
| 1046 | (($output_selection == OUTPUT_INCLUDE || |
| 1047 | $output_selection == OUTPUT_EXPORTED) && |
| 1048 | defined($function_table{$name})) || |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 1049 | ($output_selection == OUTPUT_INTERNAL && |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 1050 | !($functype eq "function" && defined($function_table{$name})))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1052 | &$func(@_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | $section_counter++; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1058 | # generic output function - calls the right one based on current output mode. |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1059 | sub output_blockhead { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | no strict 'refs'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1061 | my $func = "output_blockhead_" . $output_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | &$func(@_); |
| 1063 | $section_counter++; |
| 1064 | } |
| 1065 | |
| 1066 | ## |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1067 | # takes a declaration (struct, union, enum, typedef) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | # invokes the right handler. NOT called for functions. |
| 1069 | sub dump_declaration($$) { |
| 1070 | no strict 'refs'; |
| 1071 | my ($prototype, $file) = @_; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1072 | my $func = "dump_" . $decl_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | &$func(@_); |
| 1074 | } |
| 1075 | |
| 1076 | sub dump_union($$) { |
| 1077 | dump_struct(@_); |
| 1078 | } |
| 1079 | |
| 1080 | sub dump_struct($$) { |
| 1081 | my $x = shift; |
| 1082 | my $file = shift; |
Aditya Srivastava | a746fe3 | 2021-02-25 20:20:33 +0530 | [diff] [blame] | 1083 | my $decl_type; |
| 1084 | my $members; |
| 1085 | my $type = qr{struct|union}; |
| 1086 | # For capturing struct/union definition body, i.e. "{members*}qualifiers*" |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1087 | my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; |
| 1088 | my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; |
| 1089 | my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Aditya Srivastava | a746fe3 | 2021-02-25 20:20:33 +0530 | [diff] [blame] | 1091 | if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { |
| 1092 | $decl_type = $1; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1093 | $declaration_name = $2; |
Aditya Srivastava | a746fe3 | 2021-02-25 20:20:33 +0530 | [diff] [blame] | 1094 | $members = $3; |
| 1095 | } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { |
| 1096 | $decl_type = $1; |
| 1097 | $declaration_name = $3; |
| 1098 | $members = $2; |
| 1099 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
Aditya Srivastava | a746fe3 | 2021-02-25 20:20:33 +0530 | [diff] [blame] | 1101 | if ($members) { |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1102 | if ($identifier ne $declaration_name) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1103 | emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1104 | return; |
| 1105 | } |
| 1106 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1107 | # ignore members marked private: |
Mauro Carvalho Chehab | 0d8c39e | 2015-10-05 09:03:48 -0300 | [diff] [blame] | 1108 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; |
| 1109 | $members =~ s/\/\*\s*private:.*//gosi; |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1110 | # strip comments: |
| 1111 | $members =~ s/\/\*.*?\*\///gos; |
Randy Dunlap | ef5da59 | 2010-03-23 13:35:14 -0700 | [diff] [blame] | 1112 | # strip attributes |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1113 | $members =~ s/\s*$attribute/ /gi; |
André Almeida | 2b5f78e | 2019-09-17 16:41:45 -0300 | [diff] [blame] | 1114 | $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; |
| 1115 | $members =~ s/\s*__packed\s*/ /gos; |
| 1116 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; |
André Almeida | f861537 | 2019-09-17 16:41:46 -0300 | [diff] [blame] | 1117 | $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; |
Jonathan Cameron | a070991 | 2020-09-10 19:54:15 +0100 | [diff] [blame] | 1118 | $members =~ s/\s*____cacheline_aligned/ /gos; |
Kees Cook | 50d7bd3 | 2021-05-17 20:01:15 -0700 | [diff] [blame] | 1119 | # unwrap struct_group(): |
| 1120 | # - first eat non-declaration parameters and rewrite for final match |
| 1121 | # - then remove macro, outer parens, and trailing semicolon |
| 1122 | $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; |
| 1123 | $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; |
| 1124 | $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; |
| 1125 | $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; |
Mauro Carvalho Chehab | 3556108 | 2020-06-23 09:09:00 +0200 | [diff] [blame] | 1126 | |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1127 | my $args = qr{([^,)]+)}; |
Conchúr Navid | b22b5a9 | 2015-11-08 10:52:00 +0100 | [diff] [blame] | 1128 | # replace DECLARE_BITMAP |
Mauro Carvalho Chehab | 3556108 | 2020-06-23 09:09:00 +0200 | [diff] [blame] | 1129 | $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; |
Randy Dunlap | 603bdf5 | 2021-10-29 19:11:21 -0700 | [diff] [blame] | 1130 | $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1131 | $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; |
Jakub Kicinski | 1cb566b | 2017-06-30 19:09:59 -0700 | [diff] [blame] | 1132 | # replace DECLARE_HASHTABLE |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1133 | $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; |
Mauro Carvalho Chehab | 45005b2 | 2017-12-08 09:05:12 -0500 | [diff] [blame] | 1134 | # replace DECLARE_KFIFO |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1135 | $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; |
Mauro Carvalho Chehab | 45005b2 | 2017-12-08 09:05:12 -0500 | [diff] [blame] | 1136 | # replace DECLARE_KFIFO_PTR |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1137 | $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; |
Kees Cook | 3080ea5 | 2021-08-09 11:21:23 -0700 | [diff] [blame] | 1138 | # replace DECLARE_FLEX_ARRAY |
| 1139 | $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1140 | my $declaration = $members; |
| 1141 | |
| 1142 | # Split nested struct/union elements as newer ones |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1143 | while ($members =~ m/$struct_members/) { |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1144 | my $newmember; |
| 1145 | my $maintype = $1; |
| 1146 | my $ids = $4; |
| 1147 | my $content = $3; |
| 1148 | foreach my $id(split /,/, $ids) { |
| 1149 | $newmember .= "$maintype $id; "; |
| 1150 | |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1151 | $id =~ s/[:\[].*//; |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1152 | $id =~ s/^\s*\**(\S+)\s*/$1/; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1153 | foreach my $arg (split /;/, $content) { |
| 1154 | next if ($arg =~ m/^\s*$/); |
Mauro Carvalho Chehab | 7c0d7e8 | 2017-12-18 10:30:16 -0200 | [diff] [blame] | 1155 | if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { |
| 1156 | # pointer-to-function |
| 1157 | my $type = $1; |
| 1158 | my $name = $2; |
| 1159 | my $extra = $3; |
| 1160 | next if (!$name); |
| 1161 | if ($id =~ m/^\s*$/) { |
| 1162 | # anonymous struct/union |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1163 | $newmember .= "$type$name$extra; "; |
Mauro Carvalho Chehab | 7c0d7e8 | 2017-12-18 10:30:16 -0200 | [diff] [blame] | 1164 | } else { |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1165 | $newmember .= "$type$id.$name$extra; "; |
Mauro Carvalho Chehab | 7c0d7e8 | 2017-12-18 10:30:16 -0200 | [diff] [blame] | 1166 | } |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1167 | } else { |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1168 | my $type; |
| 1169 | my $names; |
| 1170 | $arg =~ s/^\s+//; |
| 1171 | $arg =~ s/\s+$//; |
| 1172 | # Handle bitmaps |
| 1173 | $arg =~ s/:\s*\d+\s*//g; |
| 1174 | # Handle arrays |
Mauro Carvalho Chehab | d404d57 | 2018-03-29 10:58:59 -0400 | [diff] [blame] | 1175 | $arg =~ s/\[.*\]//g; |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1176 | # The type may have multiple words, |
| 1177 | # and multiple IDs can be defined, like: |
| 1178 | # const struct foo, *bar, foobar |
| 1179 | # So, we remove spaces when parsing the |
| 1180 | # names, in order to match just names |
| 1181 | # and commas for the names |
| 1182 | $arg =~ s/\s*,\s*/,/g; |
| 1183 | if ($arg =~ m/(.*)\s+([\S+,]+)/) { |
| 1184 | $type = $1; |
| 1185 | $names = $2; |
Mauro Carvalho Chehab | 7c0d7e8 | 2017-12-18 10:30:16 -0200 | [diff] [blame] | 1186 | } else { |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1187 | $newmember .= "$arg; "; |
| 1188 | next; |
| 1189 | } |
| 1190 | foreach my $name (split /,/, $names) { |
| 1191 | $name =~ s/^\s*\**(\S+)\s*/$1/; |
| 1192 | next if (($name =~ m/^\s*$/)); |
| 1193 | if ($id =~ m/^\s*$/) { |
| 1194 | # anonymous struct/union |
| 1195 | $newmember .= "$type $name; "; |
| 1196 | } else { |
| 1197 | $newmember .= "$type $id.$name; "; |
| 1198 | } |
Mauro Carvalho Chehab | 7c0d7e8 | 2017-12-18 10:30:16 -0200 | [diff] [blame] | 1199 | } |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1200 | } |
| 1201 | } |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1202 | } |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1203 | $members =~ s/$struct_members/$newmember/; |
Mauro Carvalho Chehab | 84ce5b9 | 2017-12-18 10:30:17 -0200 | [diff] [blame] | 1204 | } |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1205 | |
| 1206 | # Ignore other nested elements, like enums |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1207 | $members =~ s/(\{[^\{\}]*\})//g; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1208 | |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1209 | create_parameterlist($members, ';', $file, $declaration_name); |
Mauro Carvalho Chehab | 1081de2 | 2017-12-18 10:30:14 -0200 | [diff] [blame] | 1210 | check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1212 | # Adjust declaration for better display |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1213 | $declaration =~ s/([\{;])/$1\n/g; |
| 1214 | $declaration =~ s/\}\s+;/};/g; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1215 | # Better handle inlined enums |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1216 | do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1217 | |
| 1218 | my @def_args = split /\n/, $declaration; |
| 1219 | my $level = 1; |
| 1220 | $declaration = ""; |
| 1221 | foreach my $clause (@def_args) { |
| 1222 | $clause =~ s/^\s+//; |
| 1223 | $clause =~ s/\s+$//; |
| 1224 | $clause =~ s/\s+/ /; |
| 1225 | next if (!$clause); |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1226 | $level-- if ($clause =~ m/(\})/ && $level > 1); |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1227 | if (!($clause =~ m/^\s*#/)) { |
| 1228 | $declaration .= "\t" x $level; |
| 1229 | } |
| 1230 | $declaration .= "\t" . $clause . "\n"; |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1231 | $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | output_declaration($declaration_name, |
| 1234 | 'struct', |
| 1235 | {'struct' => $declaration_name, |
| 1236 | 'module' => $modulename, |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 1237 | 'definition' => $declaration, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | 'parameterlist' => \@parameterlist, |
| 1239 | 'parameterdescs' => \%parameterdescs, |
| 1240 | 'parametertypes' => \%parametertypes, |
| 1241 | 'sectionlist' => \@sectionlist, |
| 1242 | 'sections' => \%sections, |
| 1243 | 'purpose' => $declaration_purpose, |
| 1244 | 'type' => $decl_type |
| 1245 | }); |
| 1246 | } |
| 1247 | else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1248 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | ++$errors; |
| 1250 | } |
| 1251 | } |
| 1252 | |
Mauro Carvalho Chehab | 85afe60 | 2017-12-30 22:32:55 -0200 | [diff] [blame] | 1253 | |
| 1254 | sub show_warnings($$) { |
| 1255 | my $functype = shift; |
| 1256 | my $name = shift; |
| 1257 | |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 1258 | return 0 if (defined($nosymbol_table{$name})); |
| 1259 | |
Mauro Carvalho Chehab | 85afe60 | 2017-12-30 22:32:55 -0200 | [diff] [blame] | 1260 | return 1 if ($output_selection == OUTPUT_ALL); |
| 1261 | |
| 1262 | if ($output_selection == OUTPUT_EXPORTED) { |
| 1263 | if (defined($function_table{$name})) { |
| 1264 | return 1; |
| 1265 | } else { |
| 1266 | return 0; |
| 1267 | } |
| 1268 | } |
| 1269 | if ($output_selection == OUTPUT_INTERNAL) { |
| 1270 | if (!($functype eq "function" && defined($function_table{$name}))) { |
| 1271 | return 1; |
| 1272 | } else { |
| 1273 | return 0; |
| 1274 | } |
| 1275 | } |
| 1276 | if ($output_selection == OUTPUT_INCLUDE) { |
| 1277 | if (defined($function_table{$name})) { |
| 1278 | return 1; |
| 1279 | } else { |
| 1280 | return 0; |
| 1281 | } |
| 1282 | } |
Mauro Carvalho Chehab | 85afe60 | 2017-12-30 22:32:55 -0200 | [diff] [blame] | 1283 | die("Please add the new output type at show_warnings()"); |
| 1284 | } |
| 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | sub dump_enum($$) { |
| 1287 | my $x = shift; |
| 1288 | my $file = shift; |
Mauro Carvalho Chehab | d38c8cf | 2020-10-01 08:23:52 +0200 | [diff] [blame] | 1289 | my $members; |
| 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1292 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Conchúr Navid | 4468e21 | 2015-11-08 10:48:05 +0100 | [diff] [blame] | 1293 | # strip #define macros inside enums |
| 1294 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; |
Randy Dunlap | b6d676d | 2010-08-10 18:02:50 -0700 | [diff] [blame] | 1295 | |
Mauro Carvalho Chehab | d38c8cf | 2020-10-01 08:23:52 +0200 | [diff] [blame] | 1296 | if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { |
| 1297 | $declaration_name = $2; |
| 1298 | $members = $1; |
| 1299 | } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1300 | $declaration_name = $1; |
Mauro Carvalho Chehab | d38c8cf | 2020-10-01 08:23:52 +0200 | [diff] [blame] | 1301 | $members = $2; |
| 1302 | } |
| 1303 | |
Andy Shevchenko | ae5b17e | 2020-11-02 19:06:37 +0200 | [diff] [blame] | 1304 | if ($members) { |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1305 | if ($identifier ne $declaration_name) { |
Mauro Carvalho Chehab | 0b54c2e | 2021-03-03 09:42:14 +0100 | [diff] [blame] | 1306 | if ($identifier eq "") { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1307 | emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n"); |
Mauro Carvalho Chehab | 0b54c2e | 2021-03-03 09:42:14 +0100 | [diff] [blame] | 1308 | } else { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1309 | emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"); |
Mauro Carvalho Chehab | 0b54c2e | 2021-03-03 09:42:14 +0100 | [diff] [blame] | 1310 | } |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1311 | return; |
| 1312 | } |
Mauro Carvalho Chehab | 0b54c2e | 2021-03-03 09:42:14 +0100 | [diff] [blame] | 1313 | $declaration_name = "(anonymous)" if ($declaration_name eq ""); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1314 | |
Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1315 | my %_members; |
| 1316 | |
Markus Heiser | 463a0fd | 2017-06-16 21:27:48 +0200 | [diff] [blame] | 1317 | $members =~ s/\s+$//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
| 1319 | foreach my $arg (split ',', $members) { |
| 1320 | $arg =~ s/^\s*(\w+).*/$1/; |
| 1321 | push @parameterlist, $arg; |
| 1322 | if (!$parameterdescs{$arg}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1323 | $parameterdescs{$arg} = $undescribed; |
Mauro Carvalho Chehab | 85afe60 | 2017-12-30 22:32:55 -0200 | [diff] [blame] | 1324 | if (show_warnings("enum", $declaration_name)) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1325 | emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n"); |
Mauro Carvalho Chehab | 2defb27 | 2017-12-18 10:30:18 -0200 | [diff] [blame] | 1326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1328 | $_members{$arg} = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1330 | |
Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1331 | while (my ($k, $v) = each %parameterdescs) { |
| 1332 | if (!exists($_members{$k})) { |
Mauro Carvalho Chehab | 85afe60 | 2017-12-30 22:32:55 -0200 | [diff] [blame] | 1333 | if (show_warnings("enum", $declaration_name)) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1334 | emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n"); |
Mauro Carvalho Chehab | 2defb27 | 2017-12-18 10:30:18 -0200 | [diff] [blame] | 1335 | } |
Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | output_declaration($declaration_name, |
| 1340 | 'enum', |
| 1341 | {'enum' => $declaration_name, |
| 1342 | 'module' => $modulename, |
| 1343 | 'parameterlist' => \@parameterlist, |
| 1344 | 'parameterdescs' => \%parameterdescs, |
| 1345 | 'sectionlist' => \@sectionlist, |
| 1346 | 'sections' => \%sections, |
| 1347 | 'purpose' => $declaration_purpose |
| 1348 | }); |
Mauro Carvalho Chehab | d38c8cf | 2020-10-01 08:23:52 +0200 | [diff] [blame] | 1349 | } else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1350 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | ++$errors; |
| 1352 | } |
| 1353 | } |
| 1354 | |
Mauro Carvalho Chehab | 7d2c6b1 | 2020-12-02 09:17:32 +0100 | [diff] [blame] | 1355 | my $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; |
Mauro Carvalho Chehab | 7efc6c4 | 2020-10-27 11:20:37 +0100 | [diff] [blame] | 1356 | my $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; |
| 1357 | my $typedef_args = qr { \s*\((.*)\); }x; |
| 1358 | |
| 1359 | my $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; |
| 1360 | my $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; |
| 1361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | sub dump_typedef($$) { |
| 1363 | my $x = shift; |
| 1364 | my $file = shift; |
| 1365 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1366 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1367 | |
Mauro Carvalho Chehab | 7efc6c4 | 2020-10-27 11:20:37 +0100 | [diff] [blame] | 1368 | # Parse function typedef prototypes |
| 1369 | if ($x =~ $typedef1 || $x =~ $typedef2) { |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1370 | $return_type = $1; |
| 1371 | $declaration_name = $2; |
| 1372 | my $args = $3; |
Mauro Carvalho Chehab | 6b80975 | 2020-10-27 11:20:36 +0100 | [diff] [blame] | 1373 | $return_type =~ s/^\s+//; |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1374 | |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1375 | if ($identifier ne $declaration_name) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1376 | emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1377 | return; |
| 1378 | } |
| 1379 | |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1380 | create_parameterlist($args, ',', $file, $declaration_name); |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1381 | |
| 1382 | output_declaration($declaration_name, |
| 1383 | 'function', |
| 1384 | {'function' => $declaration_name, |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1385 | 'typedef' => 1, |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1386 | 'module' => $modulename, |
| 1387 | 'functiontype' => $return_type, |
| 1388 | 'parameterlist' => \@parameterlist, |
| 1389 | 'parameterdescs' => \%parameterdescs, |
| 1390 | 'parametertypes' => \%parametertypes, |
| 1391 | 'sectionlist' => \@sectionlist, |
| 1392 | 'sections' => \%sections, |
| 1393 | 'purpose' => $declaration_purpose |
| 1394 | }); |
| 1395 | return; |
| 1396 | } |
| 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1399 | $x =~ s/\(*.\)\s*;$/;/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | $x =~ s/\[*.\]\s*;$/;/; |
| 1401 | } |
| 1402 | |
| 1403 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1404 | $declaration_name = $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1406 | if ($identifier ne $declaration_name) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1407 | emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1408 | return; |
| 1409 | } |
| 1410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | output_declaration($declaration_name, |
| 1412 | 'typedef', |
| 1413 | {'typedef' => $declaration_name, |
| 1414 | 'module' => $modulename, |
| 1415 | 'sectionlist' => \@sectionlist, |
| 1416 | 'sections' => \%sections, |
| 1417 | 'purpose' => $declaration_purpose |
| 1418 | }); |
| 1419 | } |
| 1420 | else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1421 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | ++$errors; |
| 1423 | } |
| 1424 | } |
| 1425 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1426 | sub save_struct_actual($) { |
| 1427 | my $actual = shift; |
| 1428 | |
| 1429 | # strip all spaces from the actual param so that it looks like one string item |
| 1430 | $actual =~ s/\s*//g; |
| 1431 | $struct_actual = $struct_actual . $actual . " "; |
| 1432 | } |
| 1433 | |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1434 | sub create_parameterlist($$$$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | my $args = shift; |
| 1436 | my $splitter = shift; |
| 1437 | my $file = shift; |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1438 | my $declaration_name = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | my $type; |
| 1440 | my $param; |
| 1441 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1442 | # temporarily replace commas inside function pointer definition |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1443 | my $arg_expr = qr{\([^\),]+}; |
| 1444 | while ($args =~ /$arg_expr,/) { |
| 1445 | $args =~ s/($arg_expr),/$1#/g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | foreach my $arg (split($splitter, $args)) { |
| 1449 | # strip comments |
| 1450 | $arg =~ s/\/\*.*\*\///; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1451 | # strip leading/trailing spaces |
| 1452 | $arg =~ s/^\s*//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | $arg =~ s/\s*$//; |
| 1454 | $arg =~ s/\s+/ /; |
| 1455 | |
| 1456 | if ($arg =~ /^#/) { |
| 1457 | # Treat preprocessor directive as a typeless variable just to fill |
| 1458 | # corresponding data structures "correctly". Catch it later in |
| 1459 | # output_* subs. |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1460 | push_parameter($arg, "", "", $file); |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1461 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | # pointer-to-function |
| 1463 | $arg =~ tr/#/,/; |
Aditya Srivastava | 336ced2 | 2021-02-17 20:26:25 +0530 | [diff] [blame] | 1464 | $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | $param = $1; |
| 1466 | $type = $arg; |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1467 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1468 | save_struct_actual($param); |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1469 | push_parameter($param, $type, $arg, $file, $declaration_name); |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1470 | } elsif ($arg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | $arg =~ s/\s*:\s*/:/g; |
| 1472 | $arg =~ s/\s*\[/\[/g; |
| 1473 | |
| 1474 | my @args = split('\s*,\s*', $arg); |
| 1475 | if ($args[0] =~ m/\*/) { |
| 1476 | $args[0] =~ s/(\*+)\s*/ $1/; |
| 1477 | } |
Borislav Petkov | 884f281 | 2007-05-08 00:29:05 -0700 | [diff] [blame] | 1478 | |
| 1479 | my @first_arg; |
| 1480 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { |
| 1481 | shift @args; |
| 1482 | push(@first_arg, split('\s+', $1)); |
| 1483 | push(@first_arg, $2); |
| 1484 | } else { |
| 1485 | @first_arg = split('\s+', shift @args); |
| 1486 | } |
| 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | unshift(@args, pop @first_arg); |
| 1489 | $type = join " ", @first_arg; |
| 1490 | |
| 1491 | foreach $param (@args) { |
| 1492 | if ($param =~ m/^(\*+)\s*(.*)/) { |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1493 | save_struct_actual($2); |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1494 | |
| 1495 | push_parameter($2, "$type $1", $arg, $file, $declaration_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | elsif ($param =~ m/(.*?):(\d+)/) { |
Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 1498 | if ($type ne "") { # skip unnamed bit-fields |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1499 | save_struct_actual($1); |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1500 | push_parameter($1, "$type:$2", $arg, $file, $declaration_name) |
Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 1501 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | else { |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1504 | save_struct_actual($param); |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1505 | push_parameter($param, $type, $arg, $file, $declaration_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1512 | sub push_parameter($$$$$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | my $param = shift; |
| 1514 | my $type = shift; |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1515 | my $org_arg = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | my $file = shift; |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1517 | my $declaration_name = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1519 | if (($anon_struct_union == 1) && ($type eq "") && |
| 1520 | ($param eq "}")) { |
| 1521 | return; # ignore the ending }; from anon. struct/union |
| 1522 | } |
| 1523 | |
| 1524 | $anon_struct_union = 0; |
Mauro Carvalho Chehab | f9b5c53 | 2017-03-30 17:11:29 -0300 | [diff] [blame] | 1525 | $param =~ s/[\[\)].*//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1527 | if ($type eq "" && $param =~ /\.\.\.$/) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | { |
Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame] | 1529 | if (!$param =~ /\w\.\.\.$/) { |
| 1530 | # handles unnamed variable parameters |
| 1531 | $param = "..."; |
| 1532 | } |
Jonathan Neuschäfer | 43756e3 | 2019-11-07 14:41:33 +0100 | [diff] [blame] | 1533 | elsif ($param =~ /\w\.\.\.$/) { |
| 1534 | # for named variable parameters of the form `x...`, remove the dots |
| 1535 | $param =~ s/\.\.\.$//; |
| 1536 | } |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 1537 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
| 1538 | $parameterdescs{$param} = "variable arguments"; |
| 1539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | } |
| 1541 | elsif ($type eq "" && ($param eq "" or $param eq "void")) |
| 1542 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | $param="void"; |
| 1544 | $parameterdescs{void} = "no arguments"; |
| 1545 | } |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1546 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
| 1547 | # handle unnamed (anonymous) union or struct: |
| 1548 | { |
| 1549 | $type = $param; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1550 | $param = "{unnamed_" . $param . "}"; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1551 | $parameterdescs{$param} = "anonymous\n"; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1552 | $anon_struct_union = 1; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1553 | } |
| 1554 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1555 | # warn if parameter has no description |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1556 | # (but ignore ones starting with # as these are not parameters |
| 1557 | # but inline preprocessor statements); |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1558 | # Note: It will also ignore void params and unnamed structs/unions |
Mauro Carvalho Chehab | f9b5c53 | 2017-03-30 17:11:29 -0300 | [diff] [blame] | 1559 | if (!defined $parameterdescs{$param} && $param !~ /^#/) { |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1560 | $parameterdescs{$param} = $undescribed; |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1561 | |
Jonathan Corbet | be5cd20c | 2019-01-11 12:31:39 -0700 | [diff] [blame] | 1562 | if (show_warnings($type, $declaration_name) && $param !~ /\./) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1563 | emit_warning("${file}:$.", "Function parameter or member '$param' not described in '$declaration_name'\n"); |
Mauro Carvalho Chehab | 2defb27 | 2017-12-18 10:30:18 -0200 | [diff] [blame] | 1564 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1567 | # strip spaces from $param so that it is one continuous string |
Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 1568 | # on @parameterlist; |
| 1569 | # this fixes a problem where check_sections() cannot find |
| 1570 | # a parameter like "addr[6 + 2]" because it actually appears |
| 1571 | # as "addr[6", "+", "2]" on the parameter list; |
| 1572 | # but it's better to maintain the param string unchanged for output, |
| 1573 | # so just weaken the string compare in check_sections() to ignore |
| 1574 | # "[blah" in a parameter string; |
| 1575 | ###$param =~ s/\s*//g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | push @parameterlist, $param; |
Mauro Carvalho Chehab | ed8348e | 2020-09-30 12:24:43 +0200 | [diff] [blame] | 1577 | $org_arg =~ s/\s\s+/ /g; |
| 1578 | $parametertypes{$param} = $org_arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Mauro Carvalho Chehab | 1081de2 | 2017-12-18 10:30:14 -0200 | [diff] [blame] | 1581 | sub check_sections($$$$$) { |
| 1582 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1583 | my @sects = split ' ', $sectcheck; |
| 1584 | my @prms = split ' ', $prmscheck; |
| 1585 | my $err; |
| 1586 | my ($px, $sx); |
| 1587 | my $prm_clean; # strip trailing "[array size]" and/or beginning "*" |
| 1588 | |
| 1589 | foreach $sx (0 .. $#sects) { |
| 1590 | $err = 1; |
| 1591 | foreach $px (0 .. $#prms) { |
| 1592 | $prm_clean = $prms[$px]; |
| 1593 | $prm_clean =~ s/\[.*\]//; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1594 | $prm_clean =~ s/$attribute//i; |
Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 1595 | # ignore array size in a parameter string; |
| 1596 | # however, the original param string may contain |
| 1597 | # spaces, e.g.: addr[6 + 2] |
| 1598 | # and this appears in @prms as "addr[6" since the |
| 1599 | # parameter list is split at spaces; |
| 1600 | # hence just ignore "[..." for the sections check; |
| 1601 | $prm_clean =~ s/\[.*//; |
| 1602 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1603 | ##$prm_clean =~ s/^\**//; |
| 1604 | if ($prm_clean eq $sects[$sx]) { |
| 1605 | $err = 0; |
| 1606 | last; |
| 1607 | } |
| 1608 | } |
| 1609 | if ($err) { |
| 1610 | if ($decl_type eq "function") { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1611 | emit_warning("${file}:$.", |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1612 | "Excess function parameter " . |
| 1613 | "'$sects[$sx]' " . |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1614 | "description in '$decl_name'\n"); |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | ## |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1621 | # Checks the section describing the return value of a function. |
| 1622 | sub check_return_section { |
| 1623 | my $file = shift; |
| 1624 | my $declaration_name = shift; |
| 1625 | my $return_type = shift; |
| 1626 | |
| 1627 | # Ignore an empty return type (It's a macro) |
| 1628 | # Ignore functions with a "void" return type. (But don't ignore "void *") |
| 1629 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { |
| 1630 | return; |
| 1631 | } |
| 1632 | |
| 1633 | if (!defined($sections{$section_return}) || |
| 1634 | $sections{$section_return} eq "") { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1635 | emit_warning("${file}:$.", |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1636 | "No description found for return value of " . |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1637 | "'$declaration_name'\n"); |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | # takes a function prototype and the name of the current file being |
| 1643 | # processed and spits out all the details stored in the global |
| 1644 | # arrays/hashes. |
| 1645 | sub dump_function($$) { |
| 1646 | my $prototype = shift; |
| 1647 | my $file = shift; |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1648 | my $noret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
Mauro Carvalho Chehab | 5ef09c9 | 2020-10-09 10:15:25 +0200 | [diff] [blame] | 1650 | print_lineno($new_start_line); |
Mauro Carvalho Chehab | 5eb6b4b | 2020-09-09 16:10:33 +0200 | [diff] [blame] | 1651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | $prototype =~ s/^static +//; |
| 1653 | $prototype =~ s/^extern +//; |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 1654 | $prototype =~ s/^asmlinkage +//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | $prototype =~ s/^inline +//; |
| 1656 | $prototype =~ s/^__inline__ +//; |
Randy Dunlap | 32e7940 | 2006-10-11 01:22:10 -0700 | [diff] [blame] | 1657 | $prototype =~ s/^__inline +//; |
| 1658 | $prototype =~ s/^__always_inline +//; |
| 1659 | $prototype =~ s/^noinline +//; |
Randy Dunlap | 74fc5c6 | 2008-06-19 16:03:29 -0700 | [diff] [blame] | 1660 | $prototype =~ s/__init +//; |
Randy Dunlap | 2007220 | 2010-03-23 13:35:24 -0700 | [diff] [blame] | 1661 | $prototype =~ s/__init_or_module +//; |
Matthew Wilcox | 80342d4 | 2021-04-27 12:48:28 +0100 | [diff] [blame] | 1662 | $prototype =~ s/__deprecated +//; |
Aditya Srivastava | 084aa00 | 2021-03-06 17:05:10 +0530 | [diff] [blame] | 1663 | $prototype =~ s/__flatten +//; |
Randy Dunlap | 270a009 | 2014-08-24 18:17:17 -0700 | [diff] [blame] | 1664 | $prototype =~ s/__meminit +//; |
Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 1665 | $prototype =~ s/__must_check +//; |
Randy Dunlap | 0df7c0e | 2012-08-16 16:23:20 -0700 | [diff] [blame] | 1666 | $prototype =~ s/__weak +//; |
Matthew Wilcox | 0891f95 | 2018-03-15 05:06:23 -0700 | [diff] [blame] | 1667 | $prototype =~ s/__sched +//; |
Randy Dunlap | 95e760c | 2019-08-05 09:29:50 -0700 | [diff] [blame] | 1668 | $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; |
Kees Cook | a40a8a1 | 2021-10-11 11:06:50 -0700 | [diff] [blame] | 1669 | $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1670 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added |
Aditya Srivastava | 084aa00 | 2021-03-06 17:05:10 +0530 | [diff] [blame] | 1671 | $prototype =~ s/__attribute_const__ +//; |
Paolo Bonzini | b1aaa54 | 2017-01-02 16:22:24 +0100 | [diff] [blame] | 1672 | $prototype =~ s/__attribute__\s*\(\( |
| 1673 | (?: |
| 1674 | [\w\s]++ # attribute name |
| 1675 | (?:\([^)]*+\))? # attribute arguments |
| 1676 | \s*+,? # optional comma at the end |
| 1677 | )+ |
| 1678 | \)\)\s+//x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
| 1680 | # Yes, this truly is vile. We are looking for: |
| 1681 | # 1. Return type (may be nothing if we're looking at a macro) |
| 1682 | # 2. Function name |
| 1683 | # 3. Function parameters. |
| 1684 | # |
| 1685 | # All the while we have to watch out for function pointer parameters |
| 1686 | # (which IIRC is what the two sections are for), C types (these |
| 1687 | # regexps don't even start to express all the possibilities), and |
| 1688 | # so on. |
| 1689 | # |
| 1690 | # If you mess with these regexps, it's a good idea to check that |
| 1691 | # the following functions' documentation still comes out right: |
| 1692 | # - parport_register_device (function pointer parameters) |
| 1693 | # - atomic_set (macro) |
Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 1694 | # - pci_match_device, __copy_to_user (long return type) |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1695 | my $name = qr{[a-zA-Z0-9_~:]+}; |
| 1696 | my $prototype_end1 = qr{[^\(]*}; |
| 1697 | my $prototype_end2 = qr{[^\{]*}; |
| 1698 | my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; |
| 1699 | my $type1 = qr{[\w\s]+}; |
| 1700 | my $type2 = qr{$type1\*+}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1702 | if ($define && $prototype =~ m/^()($name)\s+/) { |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1703 | # This is an object-like macro, it has no return type and no parameter |
| 1704 | # list. |
| 1705 | # Function-like macros are not allowed to have spaces between |
| 1706 | # declaration_name and opening parenthesis (notice the \s+). |
| 1707 | $return_type = $1; |
| 1708 | $declaration_name = $2; |
| 1709 | $noret = 1; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1710 | } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || |
| 1711 | $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || |
| 1712 | $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | $return_type = $1; |
| 1714 | $declaration_name = $2; |
| 1715 | my $args = $3; |
| 1716 | |
Mauro Carvalho Chehab | 151c468 | 2017-12-18 10:30:15 -0200 | [diff] [blame] | 1717 | create_parameterlist($args, ',', $file, $declaration_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } else { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1719 | emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | return; |
| 1721 | } |
| 1722 | |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1723 | if ($identifier ne $declaration_name) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1724 | emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1725 | return; |
| 1726 | } |
| 1727 | |
Mauro Carvalho Chehab | 47bcacf | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 1728 | my $prms = join " ", @parameterlist; |
| 1729 | check_sections($file, $declaration_name, "function", $sectcheck, $prms); |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1730 | |
Mauro Carvalho Chehab | 47bcacf | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 1731 | # This check emits a lot of warnings at the moment, because many |
| 1732 | # functions don't have a 'Return' doc section. So until the number |
| 1733 | # of warnings goes sufficiently down, the check is only performed in |
| 1734 | # verbose mode. |
| 1735 | # TODO: always perform the check. |
| 1736 | if ($verbose && !$noret) { |
| 1737 | check_return_section($file, $declaration_name, $return_type); |
| 1738 | } |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1739 | |
Mauro Carvalho Chehab | 47bcacf | 2020-09-30 09:47:01 +0200 | [diff] [blame] | 1740 | # The function parser can be called with a typedef parameter. |
| 1741 | # Handle it. |
| 1742 | if ($return_type =~ /typedef/) { |
| 1743 | output_declaration($declaration_name, |
| 1744 | 'function', |
| 1745 | {'function' => $declaration_name, |
| 1746 | 'typedef' => 1, |
| 1747 | 'module' => $modulename, |
| 1748 | 'functiontype' => $return_type, |
| 1749 | 'parameterlist' => \@parameterlist, |
| 1750 | 'parameterdescs' => \%parameterdescs, |
| 1751 | 'parametertypes' => \%parametertypes, |
| 1752 | 'sectionlist' => \@sectionlist, |
| 1753 | 'sections' => \%sections, |
| 1754 | 'purpose' => $declaration_purpose |
| 1755 | }); |
| 1756 | } else { |
| 1757 | output_declaration($declaration_name, |
| 1758 | 'function', |
| 1759 | {'function' => $declaration_name, |
| 1760 | 'module' => $modulename, |
| 1761 | 'functiontype' => $return_type, |
| 1762 | 'parameterlist' => \@parameterlist, |
| 1763 | 'parameterdescs' => \%parameterdescs, |
| 1764 | 'parametertypes' => \%parametertypes, |
| 1765 | 'sectionlist' => \@sectionlist, |
| 1766 | 'sections' => \%sections, |
| 1767 | 'purpose' => $declaration_purpose |
| 1768 | }); |
| 1769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | sub reset_state { |
| 1773 | $function = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | %parameterdescs = (); |
| 1775 | %parametertypes = (); |
| 1776 | @parameterlist = (); |
| 1777 | %sections = (); |
| 1778 | @sectionlist = (); |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1779 | $sectcheck = ""; |
| 1780 | $struct_actual = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | $prototype = ""; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1782 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1783 | $state = STATE_NORMAL; |
| 1784 | $inline_doc_state = STATE_INLINE_NA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1787 | sub tracepoint_munge($) { |
| 1788 | my $file = shift; |
| 1789 | my $tracepointname = 0; |
| 1790 | my $tracepointargs = 0; |
| 1791 | |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1792 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1793 | $tracepointname = $1; |
| 1794 | } |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1795 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
| 1796 | $tracepointname = $1; |
| 1797 | } |
| 1798 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { |
| 1799 | $tracepointname = $2; |
| 1800 | } |
| 1801 | $tracepointname =~ s/^\s+//; #strip leading whitespace |
| 1802 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1803 | $tracepointargs = $1; |
| 1804 | } |
| 1805 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 1806 | emit_warning("${file}:$.", "Unrecognized tracepoint format: \n". |
| 1807 | "$prototype\n"); |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1808 | } else { |
| 1809 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1810 | $identifier = "trace_$identifier"; |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1814 | sub syscall_munge() { |
| 1815 | my $void = 0; |
| 1816 | |
Mauro Carvalho Chehab | 7c9aa01 | 2017-12-18 10:30:12 -0200 | [diff] [blame] | 1817 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1818 | ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { |
| 1819 | if ($prototype =~ m/SYSCALL_DEFINE0/) { |
| 1820 | $void = 1; |
| 1821 | ## $prototype = "long sys_$1(void)"; |
| 1822 | } |
| 1823 | |
| 1824 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name |
| 1825 | if ($prototype =~ m/long (sys_.*?),/) { |
| 1826 | $prototype =~ s/,/\(/; |
| 1827 | } elsif ($void) { |
| 1828 | $prototype =~ s/\)/\(void\)/; |
| 1829 | } |
| 1830 | |
| 1831 | # now delete all of the odd-number commas in $prototype |
| 1832 | # so that arg types & arg names don't have a comma between them |
| 1833 | my $count = 0; |
| 1834 | my $len = length($prototype); |
| 1835 | if ($void) { |
| 1836 | $len = 0; # skip the for-loop |
| 1837 | } |
| 1838 | for (my $ix = 0; $ix < $len; $ix++) { |
| 1839 | if (substr($prototype, $ix, 1) eq ',') { |
| 1840 | $count++; |
| 1841 | if ($count % 2 == 1) { |
| 1842 | substr($prototype, $ix, 1) = ' '; |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1848 | sub process_proto_function($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | my $x = shift; |
| 1850 | my $file = shift; |
| 1851 | |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1852 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 1853 | |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1854 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | # do nothing |
| 1856 | } |
| 1857 | elsif ($x =~ /([^\{]*)/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1858 | $prototype .= $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | } |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1860 | |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1861 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1862 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 1864 | $prototype =~ s@^\s+@@gos; # strip leading spaces |
Mauro Carvalho Chehab | 7ae281b | 2020-06-23 09:09:02 +0200 | [diff] [blame] | 1865 | |
| 1866 | # Handle prototypes for function pointers like: |
| 1867 | # int (*pcs_config)(struct foo) |
| 1868 | $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; |
| 1869 | |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1870 | if ($prototype =~ /SYSCALL_DEFINE/) { |
| 1871 | syscall_munge(); |
| 1872 | } |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1873 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
| 1874 | $prototype =~ /DEFINE_SINGLE_EVENT/) |
| 1875 | { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1876 | tracepoint_munge($file); |
| 1877 | } |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1878 | dump_function($prototype, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | reset_state(); |
| 1880 | } |
| 1881 | } |
| 1882 | |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1883 | sub process_proto_type($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | my $x = shift; |
| 1885 | my $file = shift; |
| 1886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 1888 | $x =~ s@^\s+@@gos; # strip leading spaces |
| 1889 | $x =~ s@\s+$@@gos; # strip trailing spaces |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1890 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 1891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | if ($x =~ /^#/) { |
| 1893 | # To distinguish preprocessor directive from regular declaration later. |
| 1894 | $x .= ";"; |
| 1895 | } |
| 1896 | |
| 1897 | while (1) { |
Ben Hutchings | 673bb2d | 2018-08-05 17:41:09 +0100 | [diff] [blame] | 1898 | if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { |
Markus Heiser | 463a0fd | 2017-06-16 21:27:48 +0200 | [diff] [blame] | 1899 | if( length $prototype ) { |
| 1900 | $prototype .= " " |
| 1901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | $prototype .= $1 . $2; |
| 1903 | ($2 eq '{') && $brcount++; |
| 1904 | ($2 eq '}') && $brcount--; |
| 1905 | if (($2 eq ';') && ($brcount == 0)) { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1906 | dump_declaration($prototype, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | reset_state(); |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1908 | last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | } |
| 1910 | $x = $3; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1911 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | $prototype .= $x; |
| 1913 | last; |
| 1914 | } |
| 1915 | } |
| 1916 | } |
| 1917 | |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1918 | |
Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 1919 | sub map_filename($) { |
| 1920 | my $file; |
| 1921 | my ($orig_file) = @_; |
| 1922 | |
| 1923 | if (defined($ENV{'SRCTREE'})) { |
| 1924 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; |
| 1925 | } else { |
| 1926 | $file = $orig_file; |
| 1927 | } |
| 1928 | |
| 1929 | if (defined($source_map{$file})) { |
| 1930 | $file = $source_map{$file}; |
| 1931 | } |
| 1932 | |
| 1933 | return $file; |
| 1934 | } |
| 1935 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 1936 | sub process_export_file($) { |
| 1937 | my ($orig_file) = @_; |
| 1938 | my $file = map_filename($orig_file); |
| 1939 | |
| 1940 | if (!open(IN,"<$file")) { |
| 1941 | print STDERR "Error: Cannot open file $file\n"; |
| 1942 | ++$errors; |
| 1943 | return; |
| 1944 | } |
| 1945 | |
| 1946 | while (<IN>) { |
| 1947 | if (/$export_symbol/) { |
Mauro Carvalho Chehab | eab795d | 2020-09-29 14:23:39 +0200 | [diff] [blame] | 1948 | next if (defined($nosymbol_table{$2})); |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 1949 | $function_table{$2} = 1; |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | close(IN); |
| 1954 | } |
| 1955 | |
Jonathan Corbet | 07048d1 | 2018-02-05 14:15:19 -0700 | [diff] [blame] | 1956 | # |
| 1957 | # Parsers for the various processing states. |
| 1958 | # |
| 1959 | # STATE_NORMAL: looking for the /** to begin everything. |
| 1960 | # |
| 1961 | sub process_normal() { |
| 1962 | if (/$doc_start/o) { |
| 1963 | $state = STATE_NAME; # next line is always the function name |
| 1964 | $in_doc_sect = 0; |
| 1965 | $declaration_start_line = $. + 1; |
| 1966 | } |
| 1967 | } |
| 1968 | |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1969 | # |
| 1970 | # STATE_NAME: Looking for the "name - description" line |
| 1971 | # |
| 1972 | sub process_name($$) { |
| 1973 | my $file = shift; |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1974 | my $descr; |
Jonathan Corbet | 07048d1 | 2018-02-05 14:15:19 -0700 | [diff] [blame] | 1975 | |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1976 | if (/$doc_block/o) { |
| 1977 | $state = STATE_DOCBLOCK; |
| 1978 | $contents = ""; |
Mauro Carvalho Chehab | 5ef09c9 | 2020-10-09 10:15:25 +0200 | [diff] [blame] | 1979 | $new_start_line = $.; |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1980 | |
| 1981 | if ( $1 eq "" ) { |
| 1982 | $section = $section_intro; |
| 1983 | } else { |
| 1984 | $section = $1; |
| 1985 | } |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1986 | } elsif (/$doc_decl/o) { |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1987 | $identifier = $1; |
Aditya Srivastava | 3e58e83 | 2021-03-29 14:59:45 +0530 | [diff] [blame] | 1988 | my $is_kernel_comment = 0; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1989 | my $decl_start = qr{$doc_com}; |
Aditya Srivastava | f9bbc12 | 2021-04-15 00:55:29 +0530 | [diff] [blame] | 1990 | # test for pointer declaration type, foo * bar() - desc |
| 1991 | my $fn_type = qr{\w+\s*\*\s*}; |
| 1992 | my $parenthesis = qr{\(\w*\)}; |
| 1993 | my $decl_end = qr{[-:].*}; |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 1994 | if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 1995 | $identifier = $1; |
| 1996 | } |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 1997 | if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { |
| 1998 | $decl_type = $1; |
| 1999 | $identifier = $2; |
Aditya Srivastava | 3e58e83 | 2021-03-29 14:59:45 +0530 | [diff] [blame] | 2000 | $is_kernel_comment = 1; |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 2001 | } |
Aditya Srivastava | f9bbc12 | 2021-04-15 00:55:29 +0530 | [diff] [blame] | 2002 | # Look for foo() or static void foo() - description; or misspelt |
| 2003 | # identifier |
Aditya Srivastava | e86bdb2 | 2021-05-14 20:12:44 +0530 | [diff] [blame] | 2004 | elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || |
| 2005 | /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { |
Aditya Srivastava | f9bbc12 | 2021-04-15 00:55:29 +0530 | [diff] [blame] | 2006 | $identifier = $1; |
| 2007 | $decl_type = 'function'; |
| 2008 | $identifier =~ s/^define\s+//; |
| 2009 | $is_kernel_comment = 1; |
| 2010 | } |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 2011 | $identifier =~ s/\s+$//; |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2012 | |
| 2013 | $state = STATE_BODY; |
| 2014 | # if there's no @param blocks need to set up default section |
| 2015 | # here |
| 2016 | $contents = ""; |
| 2017 | $section = $section_default; |
| 2018 | $new_start_line = $. + 1; |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 2019 | if (/[-:](.*)/) { |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2020 | # strip leading/trailing/multiple spaces |
| 2021 | $descr= $1; |
| 2022 | $descr =~ s/^\s*//; |
| 2023 | $descr =~ s/\s*$//; |
| 2024 | $descr =~ s/\s+/ /g; |
| 2025 | $declaration_purpose = $descr; |
| 2026 | $state = STATE_BODY_MAYBE; |
| 2027 | } else { |
| 2028 | $declaration_purpose = ""; |
| 2029 | } |
| 2030 | |
Aditya Srivastava | 3e58e83 | 2021-03-29 14:59:45 +0530 | [diff] [blame] | 2031 | if (!$is_kernel_comment) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2032 | emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_"); |
Aditya Srivastava | 3e58e83 | 2021-03-29 14:59:45 +0530 | [diff] [blame] | 2033 | $state = STATE_NORMAL; |
| 2034 | } |
| 2035 | |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2036 | if (($declaration_purpose eq "") && $verbose) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2037 | emit_warning("${file}:$.", "missing initial short description on line:\n$_"); |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Mauro Carvalho Chehab | 0b54c2e | 2021-03-03 09:42:14 +0100 | [diff] [blame] | 2040 | if ($identifier eq "" && $decl_type ne "enum") { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2041 | emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_"); |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 2042 | $state = STATE_NORMAL; |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | if ($verbose) { |
Mauro Carvalho Chehab | 52042e2 | 2021-01-14 09:04:47 +0100 | [diff] [blame] | 2046 | print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2047 | } |
| 2048 | } else { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2049 | emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n"); |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2050 | $state = STATE_NORMAL; |
| 2051 | } |
| 2052 | } |
Jonathan Corbet | 07048d1 | 2018-02-05 14:15:19 -0700 | [diff] [blame] | 2053 | |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2054 | |
| 2055 | # |
| 2056 | # STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. |
| 2057 | # |
| 2058 | sub process_body($$) { |
| 2059 | my $file = shift; |
| 2060 | |
Jonathan Neuschäfer | 43756e3 | 2019-11-07 14:41:33 +0100 | [diff] [blame] | 2061 | # Until all named variable macro parameters are |
| 2062 | # documented using the bare name (`x`) rather than with |
| 2063 | # dots (`x...`), strip the dots: |
| 2064 | if ($section =~ /\w\.\.\.$/) { |
| 2065 | $section =~ s/\.\.\.$//; |
| 2066 | |
| 2067 | if ($verbose) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2068 | emit_warning("${file}:$.", "Variable macro arguments should be documented without dots\n"); |
Jonathan Neuschäfer | 43756e3 | 2019-11-07 14:41:33 +0100 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2072 | if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { |
| 2073 | dump_section($file, $section, $contents); |
| 2074 | $section = $section_default; |
Mauro Carvalho Chehab | 5ef09c9 | 2020-10-09 10:15:25 +0200 | [diff] [blame] | 2075 | $new_start_line = $.; |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2076 | $contents = ""; |
| 2077 | } |
| 2078 | |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2079 | if (/$doc_sect/i) { # case insensitive for supported section names |
| 2080 | $newsection = $1; |
| 2081 | $newcontents = $2; |
| 2082 | |
| 2083 | # map the supported section names to the canonical names |
| 2084 | if ($newsection =~ m/^description$/i) { |
| 2085 | $newsection = $section_default; |
| 2086 | } elsif ($newsection =~ m/^context$/i) { |
| 2087 | $newsection = $section_context; |
| 2088 | } elsif ($newsection =~ m/^returns?$/i) { |
| 2089 | $newsection = $section_return; |
| 2090 | } elsif ($newsection =~ m/^\@return$/) { |
| 2091 | # special: @return is a section, not a param description |
| 2092 | $newsection = $section_return; |
| 2093 | } |
| 2094 | |
| 2095 | if (($contents ne "") && ($contents ne "\n")) { |
| 2096 | if (!$in_doc_sect && $verbose) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2097 | emit_warning("${file}:$.", "contents before sections\n"); |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2098 | } |
| 2099 | dump_section($file, $section, $contents); |
| 2100 | $section = $section_default; |
| 2101 | } |
| 2102 | |
| 2103 | $in_doc_sect = 1; |
| 2104 | $state = STATE_BODY; |
| 2105 | $contents = $newcontents; |
| 2106 | $new_start_line = $.; |
| 2107 | while (substr($contents, 0, 1) eq " ") { |
| 2108 | $contents = substr($contents, 1); |
| 2109 | } |
| 2110 | if ($contents ne "") { |
| 2111 | $contents .= "\n"; |
| 2112 | } |
| 2113 | $section = $newsection; |
| 2114 | $leading_space = undef; |
| 2115 | } elsif (/$doc_end/) { |
| 2116 | if (($contents ne "") && ($contents ne "\n")) { |
| 2117 | dump_section($file, $section, $contents); |
| 2118 | $section = $section_default; |
| 2119 | $contents = ""; |
| 2120 | } |
| 2121 | # look for doc_com + <text> + doc_end: |
| 2122 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2123 | emit_warning("${file}:$.", "suspicious ending line: $_"); |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | $prototype = ""; |
| 2127 | $state = STATE_PROTO; |
| 2128 | $brcount = 0; |
Mauro Carvalho Chehab | 5ef09c9 | 2020-10-09 10:15:25 +0200 | [diff] [blame] | 2129 | $new_start_line = $. + 1; |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2130 | } elsif (/$doc_content/) { |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2131 | if ($1 eq "") { |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2132 | if ($section eq $section_context) { |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2133 | dump_section($file, $section, $contents); |
| 2134 | $section = $section_default; |
| 2135 | $contents = ""; |
| 2136 | $new_start_line = $.; |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2137 | $state = STATE_BODY; |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2138 | } else { |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2139 | if ($section ne $section_default) { |
| 2140 | $state = STATE_BODY_WITH_BLANK_LINE; |
| 2141 | } else { |
| 2142 | $state = STATE_BODY; |
| 2143 | } |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2144 | $contents .= "\n"; |
| 2145 | } |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2146 | } elsif ($state == STATE_BODY_MAYBE) { |
| 2147 | # Continued declaration purpose |
| 2148 | chomp($declaration_purpose); |
| 2149 | $declaration_purpose .= " " . $1; |
| 2150 | $declaration_purpose =~ s/\s+/ /g; |
| 2151 | } else { |
| 2152 | my $cont = $1; |
| 2153 | if ($section =~ m/^@/ || $section eq $section_context) { |
| 2154 | if (!defined $leading_space) { |
| 2155 | if ($cont =~ m/^(\s+)/) { |
| 2156 | $leading_space = $1; |
| 2157 | } else { |
| 2158 | $leading_space = ""; |
| 2159 | } |
| 2160 | } |
| 2161 | $cont =~ s/^$leading_space//; |
| 2162 | } |
| 2163 | $contents .= $cont . "\n"; |
| 2164 | } |
| 2165 | } else { |
| 2166 | # i dont know - bad line? ignore. |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2167 | emit_warning("${file}:$.", "bad line: $_"); |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | |
Jonathan Corbet | cc79481 | 2018-02-05 15:46:30 -0700 | [diff] [blame] | 2172 | # |
| 2173 | # STATE_PROTO: reading a function/whatever prototype. |
| 2174 | # |
| 2175 | sub process_proto($$) { |
| 2176 | my $file = shift; |
| 2177 | |
| 2178 | if (/$doc_inline_oneline/) { |
| 2179 | $section = $1; |
| 2180 | $contents = $2; |
| 2181 | if ($contents ne "") { |
| 2182 | $contents .= "\n"; |
| 2183 | dump_section($file, $section, $contents); |
| 2184 | $section = $section_default; |
| 2185 | $contents = ""; |
| 2186 | } |
| 2187 | } elsif (/$doc_inline_start/) { |
| 2188 | $state = STATE_INLINE; |
| 2189 | $inline_doc_state = STATE_INLINE_NAME; |
| 2190 | } elsif ($decl_type eq 'function') { |
| 2191 | process_proto_function($_, $file); |
| 2192 | } else { |
| 2193 | process_proto_type($_, $file); |
| 2194 | } |
| 2195 | } |
| 2196 | |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2197 | # |
| 2198 | # STATE_DOCBLOCK: within a DOC: block. |
| 2199 | # |
| 2200 | sub process_docblock($$) { |
| 2201 | my $file = shift; |
| 2202 | |
| 2203 | if (/$doc_end/) { |
| 2204 | dump_doc_section($file, $section, $contents); |
| 2205 | $section = $section_default; |
| 2206 | $contents = ""; |
| 2207 | $function = ""; |
| 2208 | %parameterdescs = (); |
| 2209 | %parametertypes = (); |
| 2210 | @parameterlist = (); |
| 2211 | %sections = (); |
| 2212 | @sectionlist = (); |
| 2213 | $prototype = ""; |
| 2214 | $state = STATE_NORMAL; |
| 2215 | } elsif (/$doc_content/) { |
| 2216 | if ( $1 eq "" ) { |
| 2217 | $contents .= $blankline; |
| 2218 | } else { |
| 2219 | $contents .= $1 . "\n"; |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | # |
| 2225 | # STATE_INLINE: docbook comments within a prototype. |
| 2226 | # |
| 2227 | sub process_inline($$) { |
| 2228 | my $file = shift; |
| 2229 | |
| 2230 | # First line (state 1) needs to be a @parameter |
| 2231 | if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { |
| 2232 | $section = $1; |
| 2233 | $contents = $2; |
| 2234 | $new_start_line = $.; |
| 2235 | if ($contents ne "") { |
| 2236 | while (substr($contents, 0, 1) eq " ") { |
| 2237 | $contents = substr($contents, 1); |
| 2238 | } |
| 2239 | $contents .= "\n"; |
| 2240 | } |
| 2241 | $inline_doc_state = STATE_INLINE_TEXT; |
| 2242 | # Documentation block end */ |
| 2243 | } elsif (/$doc_inline_end/) { |
| 2244 | if (($contents ne "") && ($contents ne "\n")) { |
| 2245 | dump_section($file, $section, $contents); |
| 2246 | $section = $section_default; |
| 2247 | $contents = ""; |
| 2248 | } |
| 2249 | $state = STATE_PROTO; |
| 2250 | $inline_doc_state = STATE_INLINE_NA; |
| 2251 | # Regular text |
| 2252 | } elsif (/$doc_content/) { |
| 2253 | if ($inline_doc_state == STATE_INLINE_TEXT) { |
| 2254 | $contents .= $1 . "\n"; |
| 2255 | # nuke leading blank lines |
| 2256 | if ($contents =~ /^\s*$/) { |
| 2257 | $contents = ""; |
| 2258 | } |
| 2259 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { |
| 2260 | $inline_doc_state = STATE_INLINE_ERROR; |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2261 | emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_"); |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | |
Jonathan Corbet | cc79481 | 2018-02-05 15:46:30 -0700 | [diff] [blame] | 2266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | sub process_file($) { |
Randy Dunlap | 2283a11 | 2005-07-07 15:39:26 -0700 | [diff] [blame] | 2268 | my $file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | my $initial_section_counter = $section_counter; |
Ben Hutchings | 68f8666 | 2015-09-01 23:48:49 +0100 | [diff] [blame] | 2270 | my ($orig_file) = @_; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 2272 | $file = map_filename($orig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | |
Mauro Carvalho Chehab | dbe8ba0 | 2020-09-28 12:52:34 +0200 | [diff] [blame] | 2274 | if (!open(IN_FILE,"<$file")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | print STDERR "Error: Cannot open file $file\n"; |
| 2276 | ++$errors; |
| 2277 | return; |
| 2278 | } |
| 2279 | |
Ilya Dryomov | a9e7314 | 2010-02-26 13:05:47 -0800 | [diff] [blame] | 2280 | $. = 1; |
| 2281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | $section_counter = 0; |
Mauro Carvalho Chehab | dbe8ba0 | 2020-09-28 12:52:34 +0200 | [diff] [blame] | 2283 | while (<IN_FILE>) { |
Daniel Santos | 6547842 | 2012-10-04 17:15:05 -0700 | [diff] [blame] | 2284 | while (s/\\\s*$//) { |
Mauro Carvalho Chehab | dbe8ba0 | 2020-09-28 12:52:34 +0200 | [diff] [blame] | 2285 | $_ .= <IN_FILE>; |
Daniel Santos | 6547842 | 2012-10-04 17:15:05 -0700 | [diff] [blame] | 2286 | } |
Mauro Carvalho Chehab | 7c9aa01 | 2017-12-18 10:30:12 -0200 | [diff] [blame] | 2287 | # Replace tabs by spaces |
| 2288 | while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2289 | # Hand this line to the appropriate state handler |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2290 | if ($state == STATE_NORMAL) { |
Jonathan Corbet | 07048d1 | 2018-02-05 14:15:19 -0700 | [diff] [blame] | 2291 | process_normal(); |
Jonathan Corbet | 3cac2bc | 2018-02-05 14:36:33 -0700 | [diff] [blame] | 2292 | } elsif ($state == STATE_NAME) { |
| 2293 | process_name($file, $_); |
Mauro Carvalho Chehab | 0d55d48 | 2020-04-14 18:48:29 +0200 | [diff] [blame] | 2294 | } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || |
| 2295 | $state == STATE_BODY_WITH_BLANK_LINE) { |
Jonathan Corbet | d742f24 | 2018-02-05 15:36:05 -0700 | [diff] [blame] | 2296 | process_body($file, $_); |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2297 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2298 | process_inline($file, $_); |
Jonathan Corbet | cc79481 | 2018-02-05 15:46:30 -0700 | [diff] [blame] | 2299 | } elsif ($state == STATE_PROTO) { |
| 2300 | process_proto($file, $_); |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2301 | } elsif ($state == STATE_DOCBLOCK) { |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2302 | process_docblock($file, $_); |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | } |
Jonathan Corbet | c17add5 | 2018-02-05 16:11:47 -0700 | [diff] [blame] | 2305 | |
| 2306 | # Make sure we got something interesting. |
Jonathan Corbet | b0d60bf | 2019-05-24 14:52:01 -0600 | [diff] [blame] | 2307 | if ($initial_section_counter == $section_counter && $ |
| 2308 | output_mode ne "none") { |
| 2309 | if ($output_selection == OUTPUT_INCLUDE) { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2310 | emit_warning("${file}:1", "'$_' not found\n") |
Jonathan Corbet | b0d60bf | 2019-05-24 14:52:01 -0600 | [diff] [blame] | 2311 | for keys %function_table; |
Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 2312 | } |
Jonathan Corbet | b0d60bf | 2019-05-24 14:52:01 -0600 | [diff] [blame] | 2313 | else { |
Niklas Söderlund | df4bf98 | 2022-06-13 11:05:10 +0200 | [diff] [blame] | 2314 | emit_warning("${file}:1", "no structured comments found\n"); |
Johannes Berg | e946c43a | 2013-11-12 15:11:12 -0800 | [diff] [blame] | 2315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
Mauro Carvalho Chehab | dbe8ba0 | 2020-09-28 12:52:34 +0200 | [diff] [blame] | 2317 | close IN_FILE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | } |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2319 | |
| 2320 | |
Mauro Carvalho Chehab | 93351d4 | 2020-10-04 09:44:28 +0200 | [diff] [blame] | 2321 | if ($output_mode eq "rst") { |
| 2322 | get_sphinx_version() if (!$sphinx_major); |
| 2323 | } |
| 2324 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2325 | $kernelversion = get_kernel_version(); |
| 2326 | |
| 2327 | # generate a sequence of code that will splice in highlighting information |
| 2328 | # using the s// operator. |
Mauro Carvalho Chehab | 1ef0623 | 2015-11-17 13:29:49 -0200 | [diff] [blame] | 2329 | for (my $k = 0; $k < @highlights; $k++) { |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 2330 | my $pattern = $highlights[$k][0]; |
| 2331 | my $result = $highlights[$k][1]; |
| 2332 | # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; |
| 2333 | $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | # Read the file that maps relative names to absolute names for |
| 2337 | # separate source and object directories and for shadow trees. |
| 2338 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { |
| 2339 | my ($relname, $absname); |
| 2340 | while(<SOURCE_MAP>) { |
| 2341 | chop(); |
| 2342 | ($relname, $absname) = (split())[0..1]; |
| 2343 | $relname =~ s:^/+::; |
| 2344 | $source_map{$relname} = $absname; |
| 2345 | } |
| 2346 | close(SOURCE_MAP); |
| 2347 | } |
| 2348 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 2349 | if ($output_selection == OUTPUT_EXPORTED || |
| 2350 | $output_selection == OUTPUT_INTERNAL) { |
Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 2351 | |
| 2352 | push(@export_file_list, @ARGV); |
| 2353 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 2354 | foreach (@export_file_list) { |
| 2355 | chomp; |
| 2356 | process_export_file($_); |
| 2357 | } |
| 2358 | } |
| 2359 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2360 | foreach (@ARGV) { |
| 2361 | chomp; |
| 2362 | process_file($_); |
| 2363 | } |
| 2364 | if ($verbose && $errors) { |
| 2365 | print STDERR "$errors errors\n"; |
| 2366 | } |
| 2367 | if ($verbose && $warnings) { |
| 2368 | print STDERR "$warnings warnings\n"; |
| 2369 | } |
| 2370 | |
Pierre-Louis Bossart | 2c12c81 | 2020-07-28 11:20:40 -0500 | [diff] [blame] | 2371 | if ($Werror && $warnings) { |
| 2372 | print STDERR "$warnings warnings as Errors\n"; |
| 2373 | exit($warnings); |
| 2374 | } else { |
| 2375 | exit($output_mode eq "none" ? 0 : $errors) |
| 2376 | } |
Tomasz Warniełło | 2875f78 | 2022-02-18 19:16:21 +0100 | [diff] [blame] | 2377 | |
| 2378 | __END__ |
| 2379 | |
| 2380 | =head1 OPTIONS |
| 2381 | |
| 2382 | =head2 Output format selection (mutually exclusive): |
| 2383 | |
| 2384 | =over 8 |
| 2385 | |
| 2386 | =item -man |
| 2387 | |
| 2388 | Output troff manual page format. |
| 2389 | |
| 2390 | =item -rst |
| 2391 | |
| 2392 | Output reStructuredText format. This is the default. |
| 2393 | |
| 2394 | =item -none |
| 2395 | |
| 2396 | Do not output documentation, only warnings. |
| 2397 | |
| 2398 | =back |
| 2399 | |
Tomasz Warniełło | dd803b0 | 2022-02-18 19:16:22 +0100 | [diff] [blame] | 2400 | =head2 Output format modifiers |
| 2401 | |
| 2402 | =head3 reStructuredText only |
| 2403 | |
| 2404 | =over 8 |
| 2405 | |
| 2406 | =item -sphinx-version VERSION |
| 2407 | |
| 2408 | Use the ReST C domain dialect compatible with a specific Sphinx Version. |
| 2409 | |
| 2410 | If not specified, kernel-doc will auto-detect using the sphinx-build version |
| 2411 | found on PATH. |
| 2412 | |
| 2413 | =back |
| 2414 | |
Tomasz Warniełło | 9c77f10 | 2022-02-18 19:16:23 +0100 | [diff] [blame] | 2415 | =head2 Output selection (mutually exclusive): |
| 2416 | |
| 2417 | =over 8 |
| 2418 | |
| 2419 | =item -export |
| 2420 | |
| 2421 | Only output documentation for the symbols that have been exported using |
| 2422 | EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() in any input FILE or -export-file FILE. |
| 2423 | |
| 2424 | =item -internal |
| 2425 | |
| 2426 | Only output documentation for the symbols that have NOT been exported using |
| 2427 | EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() in any input FILE or -export-file FILE. |
| 2428 | |
| 2429 | =item -function NAME |
| 2430 | |
| 2431 | Only output documentation for the given function or DOC: section title. |
| 2432 | All other functions and DOC: sections are ignored. |
| 2433 | |
| 2434 | May be specified multiple times. |
| 2435 | |
| 2436 | =item -nosymbol NAME |
| 2437 | |
| 2438 | Exclude the specified symbol from the output documentation. |
| 2439 | |
| 2440 | May be specified multiple times. |
| 2441 | |
| 2442 | =back |
| 2443 | |
Tomasz Warniełło | c15de5a | 2022-02-18 19:16:24 +0100 | [diff] [blame] | 2444 | =head2 Output selection modifiers: |
| 2445 | |
| 2446 | =over 8 |
| 2447 | |
| 2448 | =item -no-doc-sections |
| 2449 | |
| 2450 | Do not output DOC: sections. |
| 2451 | |
| 2452 | =item -export-file FILE |
| 2453 | |
| 2454 | Specify an additional FILE in which to look for EXPORT_SYMBOL() and |
| 2455 | EXPORT_SYMBOL_GPL(). |
| 2456 | |
| 2457 | To be used with -export or -internal. |
| 2458 | |
| 2459 | May be specified multiple times. |
| 2460 | |
| 2461 | =back |
| 2462 | |
| 2463 | =head3 reStructuredText only |
| 2464 | |
| 2465 | =over 8 |
| 2466 | |
| 2467 | =item -enable-lineno |
| 2468 | |
Mauro Carvalho Chehab | b79dfef | 2022-03-26 11:27:24 +0100 | [diff] [blame] | 2469 | Enable output of .. LINENO lines. |
Tomasz Warniełło | c15de5a | 2022-02-18 19:16:24 +0100 | [diff] [blame] | 2470 | |
| 2471 | =back |
| 2472 | |
Tomasz Warniełło | 834cf6b | 2022-02-18 19:16:25 +0100 | [diff] [blame] | 2473 | =head2 Other parameters: |
| 2474 | |
| 2475 | =over 8 |
| 2476 | |
| 2477 | =item -h, -help |
| 2478 | |
| 2479 | Print this help. |
| 2480 | |
| 2481 | =item -v |
| 2482 | |
| 2483 | Verbose output, more warnings and other information. |
| 2484 | |
| 2485 | =item -Werror |
| 2486 | |
| 2487 | Treat warnings as errors. |
| 2488 | |
| 2489 | =back |
| 2490 | |
Tomasz Warniełło | 2875f78 | 2022-02-18 19:16:21 +0100 | [diff] [blame] | 2491 | =cut |