diff options
author | Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> | 2015-08-04 08:04:08 -0400 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2015-08-06 15:05:35 -0400 |
commit | a4c6ebede2f99fc3aaa5a42228a16747d0aa2504 (patch) | |
tree | 14b2121cd22d9e58e10ec07c05d963740142aeb1 | |
parent | 64e32895f9d87aaa0842c07d0b17f4895955db20 (diff) |
scripts/kernel-doc Allow struct arguments documentation in struct body
Describing arguments at top of a struct definition works fine
for small/medium size structs, but it definitely doesn't work well
for struct with a huge list of elements.
Keeping the arguments list inside the struct body makes it easier
to maintain the documentation.
ie:
/**
* struct my_struct - short description
* @a: first member
* @b: second member
*
* Longer description
*/
struct my_struct {
int a;
int b;
/**
* @c: This is longer description of C
*
* You can use paragraphs to describe arguments
* using this method.
*/
int c;
};
This patch allows the use of this kind of syntax. Only one argument
per comment and user can use how many paragraphs he needs. It should
start with /**, which is already being used by kernel-doc. If those
comment doesn't follow those rules, it will be ignored.
Signed-off-by: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Stephan Mueller <smueller@chronox.de>
Cc: Michal Marek <mmarek@suse.cz>
Cc: linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: intel-gfx <intel-gfx@lists.freedesktop.org>
Cc: dri-devel <dri-devel@lists.freedesktop.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rwxr-xr-x | scripts/kernel-doc | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 0ac1a07874cc..3a4d895b9237 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
@@ -133,6 +133,30 @@ use strict; | |||
133 | # | 133 | # |
134 | # All descriptions can be multiline, except the short function description. | 134 | # All descriptions can be multiline, except the short function description. |
135 | # | 135 | # |
136 | # For really longs structs, you can also describe arguments inside the | ||
137 | # body of the struct. | ||
138 | # eg. | ||
139 | # /** | ||
140 | # * struct my_struct - short description | ||
141 | # * @a: first member | ||
142 | # * @b: second member | ||
143 | # * | ||
144 | # * Longer description | ||
145 | # */ | ||
146 | # struct my_struct { | ||
147 | # int a; | ||
148 | # int b; | ||
149 | # /** | ||
150 | # * @c: This is longer description of C | ||
151 | # * | ||
152 | # * You can use paragraphs to describe arguments | ||
153 | # * using this method. | ||
154 | # */ | ||
155 | # int c; | ||
156 | # }; | ||
157 | # | ||
158 | # This should be use only for struct/enum members. | ||
159 | # | ||
136 | # You can also add additional sections. When documenting kernel functions you | 160 | # You can also add additional sections. When documenting kernel functions you |
137 | # should document the "Context:" of the function, e.g. whether the functions | 161 | # should document the "Context:" of the function, e.g. whether the functions |
138 | # can be called form interrupts. Unlike other sections you can end it with an | 162 | # can be called form interrupts. Unlike other sections you can end it with an |
@@ -296,9 +320,19 @@ my $lineprefix=""; | |||
296 | # 2 - scanning field start. | 320 | # 2 - scanning field start. |
297 | # 3 - scanning prototype. | 321 | # 3 - scanning prototype. |
298 | # 4 - documentation block | 322 | # 4 - documentation block |
323 | # 5 - gathering documentation outside main block | ||
299 | my $state; | 324 | my $state; |
300 | my $in_doc_sect; | 325 | my $in_doc_sect; |
301 | 326 | ||
327 | # Split Doc State | ||
328 | # 0 - Invalid (Before start or after finish) | ||
329 | # 1 - Is started (the /** was found inside a struct) | ||
330 | # 2 - The @parameter header was found, start accepting multi paragraph text. | ||
331 | # 3 - Finished (the */ was found) | ||
332 | # 4 - Error - Comment without header was found. Spit a warning as it's not | ||
333 | # proper kernel-doc and ignore the rest. | ||
334 | my $split_doc_state; | ||
335 | |||
302 | #declaration types: can be | 336 | #declaration types: can be |
303 | # 'function', 'struct', 'union', 'enum', 'typedef' | 337 | # 'function', 'struct', 'union', 'enum', 'typedef' |
304 | my $decl_type; | 338 | my $decl_type; |
@@ -313,6 +347,9 @@ my $doc_decl = $doc_com . '(\w+)'; | |||
313 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; | 347 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; |
314 | my $doc_content = $doc_com_body . '(.*)'; | 348 | my $doc_content = $doc_com_body . '(.*)'; |
315 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; | 349 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
350 | my $doc_split_start = '^\s*/\*\*\s*$'; | ||
351 | my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | ||
352 | my $doc_split_end = '^\s*\*/\s*$'; | ||
316 | 353 | ||
317 | my %constants; | 354 | my %constants; |
318 | my %parameterdescs; | 355 | my %parameterdescs; |
@@ -2190,6 +2227,7 @@ sub reset_state { | |||
2190 | $prototype = ""; | 2227 | $prototype = ""; |
2191 | 2228 | ||
2192 | $state = 0; | 2229 | $state = 0; |
2230 | $split_doc_state = 0; | ||
2193 | } | 2231 | } |
2194 | 2232 | ||
2195 | sub tracepoint_munge($) { | 2233 | sub tracepoint_munge($) { |
@@ -2462,7 +2500,6 @@ sub process_file($) { | |||
2462 | } | 2500 | } |
2463 | $section = $newsection; | 2501 | $section = $newsection; |
2464 | } elsif (/$doc_end/) { | 2502 | } elsif (/$doc_end/) { |
2465 | |||
2466 | if (($contents ne "") && ($contents ne "\n")) { | 2503 | if (($contents ne "") && ($contents ne "\n")) { |
2467 | dump_section($file, $section, xml_escape($contents)); | 2504 | dump_section($file, $section, xml_escape($contents)); |
2468 | $section = $section_default; | 2505 | $section = $section_default; |
@@ -2503,8 +2540,44 @@ sub process_file($) { | |||
2503 | print STDERR "Warning(${file}:$.): bad line: $_"; | 2540 | print STDERR "Warning(${file}:$.): bad line: $_"; |
2504 | ++$warnings; | 2541 | ++$warnings; |
2505 | } | 2542 | } |
2543 | } elsif ($state == 5) { # scanning for split parameters | ||
2544 | # First line (state 1) needs to be a @parameter | ||
2545 | if ($split_doc_state == 1 && /$doc_split_sect/o) { | ||
2546 | $section = $1; | ||
2547 | $contents = $2; | ||
2548 | if ($contents ne "") { | ||
2549 | while ((substr($contents, 0, 1) eq " ") || | ||
2550 | substr($contents, 0, 1) eq "\t") { | ||
2551 | $contents = substr($contents, 1); | ||
2552 | } | ||
2553 | $contents .= "\n"; | ||
2554 | } | ||
2555 | $split_doc_state = 2; | ||
2556 | # Documentation block end */ | ||
2557 | } elsif (/$doc_split_end/) { | ||
2558 | if (($contents ne "") && ($contents ne "\n")) { | ||
2559 | dump_section($file, $section, xml_escape($contents)); | ||
2560 | $section = $section_default; | ||
2561 | $contents = ""; | ||
2562 | } | ||
2563 | $state = 3; | ||
2564 | $split_doc_state = 0; | ||
2565 | # Regular text | ||
2566 | } elsif (/$doc_content/) { | ||
2567 | if ($split_doc_state == 2) { | ||
2568 | $contents .= $1 . "\n"; | ||
2569 | } elsif ($split_doc_state == 1) { | ||
2570 | $split_doc_state = 4; | ||
2571 | print STDERR "Warning(${file}:$.): "; | ||
2572 | print STDERR "Incorrect use of kernel-doc format: $_"; | ||
2573 | ++$warnings; | ||
2574 | } | ||
2575 | } | ||
2506 | } elsif ($state == 3) { # scanning for function '{' (end of prototype) | 2576 | } elsif ($state == 3) { # scanning for function '{' (end of prototype) |
2507 | if ($decl_type eq 'function') { | 2577 | if (/$doc_split_start/) { |
2578 | $state = 5; | ||
2579 | $split_doc_state = 1; | ||
2580 | } elsif ($decl_type eq 'function') { | ||
2508 | process_state3_function($_, $file); | 2581 | process_state3_function($_, $file); |
2509 | } else { | 2582 | } else { |
2510 | process_state3_type($_, $file); | 2583 | process_state3_type($_, $file); |