Skip to content

Commit d007ca6

Browse files
committed
perlapi: Add 'apidoc_flag' capability
This is meant to easily document the flags a function accepts or returns. Currently this only is used for generating X<> entries for the flags, but it allows replacing (in the next commit) the previous, clumsier, method used that does the same thing. And it allows for future enhancements, including generating tests by Devel::PPPort and automatic text added by autodoc.
1 parent 5d2f09f commit d007ca6

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

autodoc.pl

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
# apidoc_item
8585
my $item_flags_re = qr/[dD fF mM nN oO pT uU Wx;]/xx;
8686

87+
# Only certain flags are acceptable for apidoc_flag
88+
my $flag_flags_re = qr/[ A C dD eE h m n p u X ] /xx;
89+
8790
# Certain functions have plain and no_context versions, and meet the criteria
8891
# stated here. Each of their pods has been modified to have a marker line
8992
# which this program replaces by this wording. This way we can tweak the
@@ -102,7 +105,8 @@
102105
APIDOC_DEFN => 1,
103106
PLAIN_APIDOC => 2,
104107
APIDOC_ITEM => 3,
105-
APIDOC_SECTION => 4,
108+
APIDOC_FLAG => 4,
109+
APIDOC_SECTION => 5,
106110

107111
# This is the line type used for elements parsed in config.h.
108112
# Since that file is parsed after everything else, everything is
@@ -112,7 +116,7 @@
112116
# doesn't have to get involved. There are just a few of these,
113117
# with little likelihood of changes needed. They were manually
114118
# added to handy.h via 51b56f5c7c7.
115-
CONDITIONAL_APIDOC => 5,
119+
CONDITIONAL_APIDOC => 6,
116120
};
117121

118122
my $config_h = 'config.h';
@@ -789,7 +793,9 @@ ($file, $line_num, $input, $is_file_C)
789793
? APIDOC_DEFN
790794
: ($type_name eq 'section')
791795
? APIDOC_SECTION
792-
: ILLEGAL_APIDOC;
796+
: ($type_name eq 'flag')
797+
? APIDOC_FLAG
798+
: ILLEGAL_APIDOC;
793799

794800
my $mostly_proper_form =
795801
( $type != ILLEGAL_APIDOC
@@ -1007,8 +1013,8 @@ ($fh, $file)
10071013

10081014
push @items, $leader_ref;
10091015

1010-
# Now look for any 'apidoc_item' lines. These are in a block
1011-
# consisting solely of them, or all-blank lines
1016+
# Now look for any 'apidoc_(flag|item)' lines. These are in a
1017+
# block consisting solely of them, or all-blank lines
10121018
while (1) {
10131019
(my $item_line_type, $arg) = $get_next_line->();
10141020
last unless defined $item_line_type;
@@ -1019,7 +1025,40 @@ ($fh, $file)
10191025
next;
10201026
}
10211027

1022-
last unless $item_line_type == APIDOC_ITEM;
1028+
# Currently not much is done with these
1029+
if ($item_line_type == APIDOC_FLAG) {
1030+
my @components = split /\|+/, $arg;
1031+
my ($name, $flags);
1032+
if (@components == 1) {
1033+
$name = $components[0];
1034+
}
1035+
elsif ( @components == 2
1036+
|| (@components == 3 && $components[2] !~ /\S/))
1037+
{
1038+
$flags = $components[0];
1039+
if (my $illegal = $flags =~ s/$flag_flags_re//gr) {
1040+
die "[$illegal] illegal in apidoc_item "
1041+
. where_from_string($file, $line_num)
1042+
. " :\n$arg";
1043+
}
1044+
1045+
# Only mention the flags that go to the parent's pod
1046+
next if destination_pod($flags) ne $destpod;
1047+
1048+
$name = $components[1];
1049+
}
1050+
else {
1051+
die "Unexpected '| in ", $arg;
1052+
}
1053+
1054+
1055+
# We just make an X<> entry for it.
1056+
$docs{$destpod}{$section}{X_tags}{$arg} = $file;
1057+
next;
1058+
}
1059+
else {
1060+
last unless $item_line_type == APIDOC_ITEM;
1061+
}
10231062

10241063
# Reset $text; those blank lines it contains merely are
10251064
# separating 'apidoc_item' lines

embed.fnc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
: Scattered around the perl source are lines of the form:
278278
:
279279
: =for apidoc name ...
280+
: =for apidoc_flag name ...
280281
: =for apidoc_item name ...
281282
: =for apidoc_defn name ...
282283
:
@@ -313,6 +314,23 @@
313314
: listed as 'name' on each is part of the group whose head entry is the one
314315
: specified by 'name' on the apidoc line.
315316
:
317+
: Many functions and macros take a flags parameter in which 1 bits in various
318+
: positions are OR'ed together. Each position has a name. You should give
319+
: the names of each bit that the function understands by using
320+
:
321+
: =for apidoc_flag-name
322+
:
323+
: These are to be placed, intermixed in any order, with any 'apidoc_item'
324+
: statements just after the plain head '=for apidoc' line. If the function is
325+
: public, but some of the flags are not, you can say, for example,
326+
:
327+
: =for apidoc_flag C|PERL_SCAN_SILENT_NON_PORTABLE
328+
:
329+
: where the 'C' could be any of the visibility flags listed at the top of this
330+
: file. (Note that the term 'flag' is overloaded here. The function has a
331+
: flags parameter, and the entry describing it here has a flags field to aid in
332+
: that description.)
333+
:
316334
: After the block of apidoc-like statements, is the text that is the
317335
: documentation, ending with the next =cut or '=for apidoc foo' lines.
318336
:
@@ -359,6 +377,8 @@
359377
:
360378
: =for apidoc flags|return_type|name|arg1|arg2|...|argN
361379
: =for apidoc_item flags|return_type|name|arg1|arg2|...|argN
380+
: =for apidoc_flag name
381+
: =for apidoc_flag flags|name
362382
: =for apidoc_defn flags|return_type|name|arg1|arg2|...|argN
363383
:
364384
: The 'name' in any such line must not be the same as any in this file (i.e.,

0 commit comments

Comments
 (0)