This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: INC handlers and shutdown-time warnings
[perl5.git] / ext / B / B.pm
CommitLineData
a798dbf2
MB
1# B.pm
2#
1a52ab62 3# Copyright (c) 1996, 1997, 1998 Malcolm Beattie
a798dbf2
MB
4#
5# You may distribute under the terms of either the GNU General Public
6# License or the Artistic License, as specified in the README file.
7#
8package B;
28b605d8 9
85594c31 10our $VERSION = '1.16';
28b605d8 11
9426adcd 12use XSLoader ();
a798dbf2 13require Exporter;
9426adcd 14@ISA = qw(Exporter);
b2590c4e 15
f72d64f0
DC
16# walkoptree_slow comes from B.pm (you are there),
17# walkoptree comes from B.xs
f6c2d85b
JH
18@EXPORT_OK = qw(minus_c ppname save_BEGINs
19 class peekop cast_I32 cstring cchar hash threadsv_names
b2590c4e 20 main_root main_start main_cv svref_2object opnumber
5ce57cc0 21 sub_generation amagic_generation perlstring
f6c2d85b
JH
22 walkoptree_slow walkoptree walkoptree_exec walksymtable
23 parents comppadlist sv_undef compile_stats timing_info
e412117e 24 begin_av init_av check_av end_av regex_padav dowarn defstash
baccf54f 25 curstash warnhook diehook inc_gv @optype @specialsv_name
651aa52e 26 );
e412117e 27push @EXPORT_OK, qw(unitcheck_av) if $] > 5.009;
b2590c4e 28
4c1f658f 29sub OPf_KIDS ();
a798dbf2
MB
30use strict;
31@B::SV::ISA = 'B::OBJECT';
32@B::NULL::ISA = 'B::SV';
33@B::PV::ISA = 'B::SV';
34@B::IV::ISA = 'B::SV';
4edc9001 35@B::NV::ISA = 'B::SV';
a798dbf2
MB
36@B::RV::ISA = 'B::SV';
37@B::PVIV::ISA = qw(B::PV B::IV);
4edc9001 38@B::PVNV::ISA = qw(B::PVIV B::NV);
a798dbf2 39@B::PVMG::ISA = 'B::PVNV';
a01b8a53 40# Change in the inheritance hierarchy post 5.9.0
f5ba1307 41@B::PVLV::ISA = $] > 5.009 ? 'B::GV' : 'B::PVMG';
a798dbf2
MB
42@B::BM::ISA = 'B::PVMG';
43@B::AV::ISA = 'B::PVMG';
44@B::GV::ISA = 'B::PVMG';
45@B::HV::ISA = 'B::PVMG';
46@B::CV::ISA = 'B::PVMG';
276493cb
SM
47@B::IO::ISA = 'B::PVMG';
48@B::FM::ISA = 'B::CV';
a798dbf2
MB
49
50@B::OP::ISA = 'B::OBJECT';
51@B::UNOP::ISA = 'B::OP';
52@B::BINOP::ISA = 'B::UNOP';
53@B::LOGOP::ISA = 'B::UNOP';
a798dbf2
MB
54@B::LISTOP::ISA = 'B::BINOP';
55@B::SVOP::ISA = 'B::OP';
7934575e 56@B::PADOP::ISA = 'B::OP';
a798dbf2 57@B::PVOP::ISA = 'B::OP';
a798dbf2
MB
58@B::LOOP::ISA = 'B::LISTOP';
59@B::PMOP::ISA = 'B::LISTOP';
60@B::COP::ISA = 'B::OP';
61
62@B::SPECIAL::ISA = 'B::OBJECT';
63
baccf54f
NC
64@B::optype = qw(OP UNOP BINOP LOGOP LISTOP PMOP SVOP PADOP PVOP LOOP COP);
65# bytecode.pl contained the following comment:
66# Nullsv *must* come first in the following so that the condition
67# ($$sv == 0) can continue to be used to test (sv == Nullsv).
68@B::specialsv_name = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no
69 (SV*)pWARN_ALL (SV*)pWARN_NONE (SV*)pWARN_STD);
70
a798dbf2
MB
71{
72 # Stop "-w" from complaining about the lack of a real B::OBJECT class
73 package B::OBJECT;
74}
75
002b978b
RH
76sub B::GV::SAFENAME {
77 my $name = (shift())->NAME;
d9963e60
RH
78
79 # The regex below corresponds to the isCONTROLVAR macro
80 # from toke.c
81
7a9b44b9
RH
82 $name =~ s/^([\cA-\cZ\c\\c[\c]\c?\c_\c^])/"^".
83 chr( utf8::unicode_to_native( 64 ^ ord($1) ))/e;
84
85 # When we say unicode_to_native we really mean ascii_to_native,
86 # which matters iff this is a non-ASCII platform (EBCDIC).
87
002b978b
RH
88 return $name;
89}
90
d9963e60
RH
91sub B::IV::int_value {
92 my ($self) = @_;
93 return (($self->FLAGS() & SVf_IVisUV()) ? $self->UVX : $self->IV);
94}
95
f3402b25
RH
96sub B::NULL::as_string() {""}
97sub B::IV::as_string() {goto &B::IV::int_value}
98sub B::PV::as_string() {goto &B::PV::PV}
99
a798dbf2
MB
100my $debug;
101my $op_count = 0;
102my @parents = ();
103
104sub debug {
105 my ($class, $value) = @_;
106 $debug = $value;
107 walkoptree_debug($value);
108}
109
a798dbf2
MB
110sub class {
111 my $obj = shift;
112 my $name = ref $obj;
113 $name =~ s/^.*:://;
114 return $name;
115}
116
117sub parents { \@parents }
118
119# For debugging
120sub peekop {
121 my $op = shift;
3f872cb9 122 return sprintf("%s (0x%x) %s", class($op), $$op, $op->name);
a798dbf2
MB
123}
124
b2590c4e 125sub walkoptree_slow {
a798dbf2
MB
126 my($op, $method, $level) = @_;
127 $op_count++; # just for statistics
128 $level ||= 0;
129 warn(sprintf("walkoptree: %d. %s\n", $level, peekop($op))) if $debug;
156f89f0 130 $op->$method($level) if $op->can($method);
a798dbf2
MB
131 if ($$op && ($op->flags & OPf_KIDS)) {
132 my $kid;
133 unshift(@parents, $op);
134 for ($kid = $op->first; $$kid; $kid = $kid->sibling) {
b2590c4e 135 walkoptree_slow($kid, $method, $level + 1);
a798dbf2
MB
136 }
137 shift @parents;
138 }
156f89f0
JJ
139 if (class($op) eq 'PMOP'
140 && ref($op->pmreplroot)
141 && ${$op->pmreplroot}
142 && $op->pmreplroot->isa( 'B::OP' ))
143 {
0091380b
RGS
144 unshift(@parents, $op);
145 walkoptree_slow($op->pmreplroot, $method, $level + 1);
146 shift @parents;
147 }
a798dbf2
MB
148}
149
150sub compile_stats {
151 return "Total number of OPs processed: $op_count\n";
152}
153
154sub timing_info {
155 my ($sec, $min, $hr) = localtime;
156 my ($user, $sys) = times;
157 sprintf("%02d:%02d:%02d user=$user sys=$sys",
158 $hr, $min, $sec, $user, $sys);
159}
160
161my %symtable;
2b8dc4d2
DM
162
163sub clearsym {
164 %symtable = ();
165}
166
a798dbf2
MB
167sub savesym {
168 my ($obj, $value) = @_;
169# warn(sprintf("savesym: sym_%x => %s\n", $$obj, $value)); # debug
170 $symtable{sprintf("sym_%x", $$obj)} = $value;
171}
172
173sub objsym {
174 my $obj = shift;
175 return $symtable{sprintf("sym_%x", $$obj)};
176}
177
178sub walkoptree_exec {
179 my ($op, $method, $level) = @_;
244826eb 180 $level ||= 0;
a798dbf2
MB
181 my ($sym, $ppname);
182 my $prefix = " " x $level;
183 for (; $$op; $op = $op->next) {
184 $sym = objsym($op);
185 if (defined($sym)) {
186 print $prefix, "goto $sym\n";
187 return;
188 }
189 savesym($op, sprintf("%s (0x%lx)", class($op), $$op));
190 $op->$method($level);
3f872cb9 191 $ppname = $op->name;
1a67a97c 192 if ($ppname =~
62e36f8a 193 /^(d?or(assign)?|and(assign)?|mapwhile|grepwhile|entertry|range|cond_expr)$/)
1a67a97c 194 {
a798dbf2
MB
195 print $prefix, uc($1), " => {\n";
196 walkoptree_exec($op->other, $method, $level + 1);
197 print $prefix, "}\n";
3f872cb9 198 } elsif ($ppname eq "match" || $ppname eq "subst") {
a798dbf2
MB
199 my $pmreplstart = $op->pmreplstart;
200 if ($$pmreplstart) {
201 print $prefix, "PMREPLSTART => {\n";
202 walkoptree_exec($pmreplstart, $method, $level + 1);
203 print $prefix, "}\n";
204 }
3f872cb9 205 } elsif ($ppname eq "substcont") {
a798dbf2
MB
206 print $prefix, "SUBSTCONT => {\n";
207 walkoptree_exec($op->other->pmreplstart, $method, $level + 1);
208 print $prefix, "}\n";
209 $op = $op->other;
3f872cb9 210 } elsif ($ppname eq "enterloop") {
a798dbf2
MB
211 print $prefix, "REDO => {\n";
212 walkoptree_exec($op->redoop, $method, $level + 1);
213 print $prefix, "}\n", $prefix, "NEXT => {\n";
214 walkoptree_exec($op->nextop, $method, $level + 1);
215 print $prefix, "}\n", $prefix, "LAST => {\n";
216 walkoptree_exec($op->lastop, $method, $level + 1);
217 print $prefix, "}\n";
3f872cb9 218 } elsif ($ppname eq "subst") {
a798dbf2
MB
219 my $replstart = $op->pmreplstart;
220 if ($$replstart) {
221 print $prefix, "SUBST => {\n";
222 walkoptree_exec($replstart, $method, $level + 1);
223 print $prefix, "}\n";
224 }
225 }
226 }
227}
228
229sub walksymtable {
230 my ($symref, $method, $recurse, $prefix) = @_;
231 my $sym;
0cc1d052 232 my $ref;
b6b0fb7b
MB
233 my $fullname;
234 no strict 'refs';
0cc1d052
NIS
235 $prefix = '' unless defined $prefix;
236 while (($sym, $ref) = each %$symref) {
b6b0fb7b 237 $fullname = "*main::".$prefix.$sym;
a798dbf2
MB
238 if ($sym =~ /::$/) {
239 $sym = $prefix . $sym;
b4e94495 240 if ($sym ne "main::" && $sym ne "<none>::" && &$recurse($sym)) {
b6b0fb7b 241 walksymtable(\%$fullname, $method, $recurse, $sym);
a798dbf2
MB
242 }
243 } else {
b6b0fb7b 244 svref_2object(\*$fullname)->$method();
a798dbf2
MB
245 }
246 }
247}
248
249{
250 package B::Section;
251 my $output_fh;
252 my %sections;
85cf7f2e 253
a798dbf2
MB
254 sub new {
255 my ($class, $section, $symtable, $default) = @_;
256 $output_fh ||= FileHandle->new_tmpfile;
257 my $obj = bless [-1, $section, $symtable, $default], $class;
258 $sections{$section} = $obj;
259 return $obj;
260 }
85cf7f2e 261
a798dbf2
MB
262 sub get {
263 my ($class, $section) = @_;
264 return $sections{$section};
265 }
266
267 sub add {
268 my $section = shift;
269 while (defined($_ = shift)) {
270 print $output_fh "$section->[1]\t$_\n";
271 $section->[0]++;
272 }
273 }
274
275 sub index {
276 my $section = shift;
277 return $section->[0];
278 }
279
280 sub name {
281 my $section = shift;
282 return $section->[1];
283 }
284
285 sub symtable {
286 my $section = shift;
287 return $section->[2];
288 }
85cf7f2e 289
a798dbf2
MB
290 sub default {
291 my $section = shift;
292 return $section->[3];
293 }
85cf7f2e 294
a798dbf2
MB
295 sub output {
296 my ($section, $fh, $format) = @_;
297 my $name = $section->name;
298 my $sym = $section->symtable || {};
299 my $default = $section->default;
300
301 seek($output_fh, 0, 0);
302 while (<$output_fh>) {
303 chomp;
304 s/^(.*?)\t//;
305 if ($1 eq $name) {
306 s{(s\\_[0-9a-f]+)} {
307 exists($sym->{$1}) ? $sym->{$1} : $default;
308 }ge;
309 printf $fh $format, $_;
310 }
311 }
312 }
313}
314
9426adcd 315XSLoader::load 'B';
a798dbf2
MB
316
3171;
7f20e9dd
GS
318
319__END__
320
321=head1 NAME
322
323B - The Perl Compiler
324
325=head1 SYNOPSIS
326
327 use B;
328
329=head1 DESCRIPTION
330
1a52ab62
MB
331The C<B> module supplies classes which allow a Perl program to delve
332into its own innards. It is the module used to implement the
333"backends" of the Perl compiler. Usage of the compiler does not
334require knowledge of this module: see the F<O> module for the
335user-visible part. The C<B> module is of use to those who want to
336write new compiler backends. This documentation assumes that the
337reader knows a fair amount about perl's internals including such
338things as SVs, OPs and the internal symbol table and syntax tree
339of a program.
340
85cf7f2e
MJD
341=head1 OVERVIEW
342
343The C<B> module contains a set of utility functions for querying the
344current state of the Perl interpreter; typically these functions
345return objects from the B::SV and B::OP classes, or their derived
346classes. These classes in turn define methods for querying the
347resulting objects about their own internal state.
348
349=head1 Utility Functions
350
351The C<B> module exports a variety of functions: some are simple
352utility functions, others provide a Perl program with a way to
353get an initial "handle" on an internal object.
354
355=head2 Functions Returning C<B::SV>, C<B::AV>, C<B::HV>, and C<B::CV> objects
356
3d036c2b 357For descriptions of the class hierarchy of these objects and the
85cf7f2e
MJD
358methods that can be called on them, see below, L<"OVERVIEW OF
359CLASSES"> and L<"SV-RELATED CLASSES">.
360
361=over 4
362
363=item sv_undef
364
365Returns the SV object corresponding to the C variable C<sv_undef>.
366
367=item sv_yes
368
369Returns the SV object corresponding to the C variable C<sv_yes>.
370
371=item sv_no
372
373Returns the SV object corresponding to the C variable C<sv_no>.
374
375=item svref_2object(SVREF)
376
377Takes a reference to any Perl value, and turns the referred-to value
378into an object in the appropriate B::OP-derived or B::SV-derived
379class. Apart from functions such as C<main_root>, this is the primary
380way to get an initial "handle" on an internal perl data structure
381which can then be followed with the other access methods.
382
f31c3107
SM
383The returned object will only be valid as long as the underlying OPs
384and SVs continue to exist. Do not attempt to use the object after the
385underlying structures are freed.
386
85cf7f2e
MJD
387=item amagic_generation
388
389Returns the SV object corresponding to the C variable C<amagic_generation>.
390
e13efe3c 391=item init_av
85cf7f2e
MJD
392
393Returns the AV object (i.e. in class B::AV) representing INIT blocks.
394
ece599bd
RGS
395=item check_av
396
397Returns the AV object (i.e. in class B::AV) representing CHECK blocks.
398
676456c2
AG
399=item unitcheck_av
400
401Returns the AV object (i.e. in class B::AV) representing UNITCHECK blocks.
402
85cf7f2e
MJD
403=item begin_av
404
405Returns the AV object (i.e. in class B::AV) representing BEGIN blocks.
406
407=item end_av
408
409Returns the AV object (i.e. in class B::AV) representing END blocks.
410
411=item comppadlist
412
413Returns the AV object (i.e. in class B::AV) of the global comppadlist.
414
415=item regex_padav
416
417Only when perl was compiled with ithreads.
418
e13efe3c 419=item main_cv
85cf7f2e
MJD
420
421Return the (faked) CV corresponding to the main part of the Perl
422program.
423
424=back
425
426=head2 Functions for Examining the Symbol Table
427
428=over 4
429
430=item walksymtable(SYMREF, METHOD, RECURSE, PREFIX)
431
432Walk the symbol table starting at SYMREF and call METHOD on each
433symbol (a B::GV object) visited. When the walk reaches package
434symbols (such as "Foo::") it invokes RECURSE, passing in the symbol
435name, and only recurses into the package if that sub returns true.
436
437PREFIX is the name of the SYMREF you're walking.
438
439For example:
440
441 # Walk CGI's symbol table calling print_subs on each symbol.
442 # Recurse only into CGI::Util::
443 walksymtable(\%CGI::, 'print_subs', sub { $_[0] eq 'CGI::Util::' },
444 'CGI::');
445
446print_subs() is a B::GV method you have declared. Also see L<"B::GV
447Methods">, below.
448
449=back
450
451=head2 Functions Returning C<B::OP> objects or for walking op trees
452
3d036c2b 453For descriptions of the class hierarchy of these objects and the
85cf7f2e
MJD
454methods that can be called on them, see below, L<"OVERVIEW OF
455CLASSES"> and L<"OP-RELATED CLASSES">.
456
457=over 4
458
459=item main_root
460
461Returns the root op (i.e. an object in the appropriate B::OP-derived
462class) of the main part of the Perl program.
463
464=item main_start
465
466Returns the starting op of the main part of the Perl program.
467
468=item walkoptree(OP, METHOD)
469
470Does a tree-walk of the syntax tree based at OP and calls METHOD on
471each op it visits. Each node is visited before its children. If
472C<walkoptree_debug> (see below) has been called to turn debugging on then
473the method C<walkoptree_debug> is called on each op before METHOD is
474called.
475
476=item walkoptree_debug(DEBUG)
477
478Returns the current debugging flag for C<walkoptree>. If the optional
479DEBUG argument is non-zero, it sets the debugging flag to that. See
480the description of C<walkoptree> above for what the debugging flag
481does.
482
483=back
484
485=head2 Miscellaneous Utility Functions
486
487=over 4
488
489=item ppname(OPNUM)
490
491Return the PP function name (e.g. "pp_add") of op number OPNUM.
492
493=item hash(STR)
494
495Returns a string in the form "0x..." representing the value of the
496internal hash function used by perl on string STR.
497
498=item cast_I32(I)
499
500Casts I to the internal I32 type used by that perl.
501
502=item minus_c
503
504Does the equivalent of the C<-c> command-line option. Obviously, this
505is only useful in a BEGIN block or else the flag is set too late.
506
507=item cstring(STR)
508
509Returns a double-quote-surrounded escaped version of STR which can
510be used as a string in C source code.
511
512=item perlstring(STR)
513
514Returns a double-quote-surrounded escaped version of STR which can
515be used as a string in Perl source code.
516
517=item class(OBJ)
518
519Returns the class of an object without the part of the classname
520preceding the first C<"::">. This is used to turn C<"B::UNOP"> into
521C<"UNOP"> for example.
522
523=item threadsv_names
524
525In a perl compiled for threads, this returns a list of the special
526per-thread threadsv variables.
527
528=back
529
baccf54f
NC
530=head2 Exported utility variabiles
531
532=over 4
533
534=item @optype
535
536 my $op_type = $optype[$op_type_num];
85cf7f2e 537
baccf54f
NC
538A simple mapping of the op type number to its type (like 'COP' or 'BINOP').
539
540=item @specialsv_name
541
542 my $sv_name = $specialsv_name[$sv_index];
543
544Certain SV types are considered 'special'. They're represented by
545B::SPECIAL and are referred to by a number from the specialsv_list.
546This array maps that number back to the name of the SV (like 'Nullsv'
547or '&PL_sv_undef').
548
549=back
85cf7f2e
MJD
550
551
1a52ab62
MB
552=head1 OVERVIEW OF CLASSES
553
554The C structures used by Perl's internals to hold SV and OP
555information (PVIV, AV, HV, ..., OP, SVOP, UNOP, ...) are modelled on a
556class hierarchy and the C<B> module gives access to them via a true
557object hierarchy. Structure fields which point to other objects
558(whether types of SV or types of OP) are represented by the C<B>
85cf7f2e
MJD
559module as Perl objects of the appropriate class.
560
561The bulk of the C<B> module is the methods for accessing fields of
562these structures.
563
564Note that all access is read-only. You cannot modify the internals by
f31c3107
SM
565using this module. Also, note that the B::OP and B::SV objects created
566by this module are only valid for as long as the underlying objects
567exist; their creation doesn't increase the reference counts of the
568underlying objects. Trying to access the fields of a freed object will
569give incomprehensible results, or worse.
1a52ab62
MB
570
571=head2 SV-RELATED CLASSES
572
573B::IV, B::NV, B::RV, B::PV, B::PVIV, B::PVNV, B::PVMG, B::BM, B::PVLV,
574B::AV, B::HV, B::CV, B::GV, B::FM, B::IO. These classes correspond in
575the obvious way to the underlying C structures of similar names. The
a01b8a53
YST
576inheritance hierarchy mimics the underlying C "inheritance". For 5.9.1
577and later this is:
85cf7f2e
MJD
578
579 B::SV
580 |
4edc9001
NC
581 +--------------+----------+------------+
582 | | | |
583 B::PV B::IV B::NV B::RV
b591c46e
NC
584 \ / /
585 \ / /
586 B::PVIV /
587 \ /
588 \ /
589 \ /
590 B::PVNV
591 |
592 |
593 B::PVMG
594 |
595 +-----+----+------+-----+-----+
596 | | | | | |
597 B::BM B::AV B::GV B::HV B::CV B::IO
598 | |
599 B::PVLV |
600 B::FM
85cf7f2e
MJD
601
602
a01b8a53
YST
603For 5.9.0 and earlier, PVLV is a direct subclass of PVMG, so the base
604of this diagram is
f5ba1307
NC
605
606 |
607 B::PVMG
608 |
609 +------+-----+----+------+-----+-----+
610 | | | | | | |
611 B::PVLV B::BM B::AV B::GV B::HV B::CV B::IO
612 |
613 |
614 B::FM
615
616
85cf7f2e 617Access methods correspond to the underlying C macros for field access,
1a52ab62
MB
618usually with the leading "class indication" prefix removed (Sv, Av,
619Hv, ...). The leading prefix is only left in cases where its removal
620would cause a clash in method name. For example, C<GvREFCNT> stays
621as-is since its abbreviation would clash with the "superclass" method
622C<REFCNT> (corresponding to the C function C<SvREFCNT>).
623
85cf7f2e 624=head2 B::SV Methods
1a52ab62
MB
625
626=over 4
627
628=item REFCNT
629
630=item FLAGS
631
429a5ce7
SM
632=item object_2svref
633
634Returns a reference to the regular scalar corresponding to this
635B::SV object. In other words, this method is the inverse operation
636to the svref_2object() subroutine. This scalar and other data it points
637at should be considered read-only: modifying them is neither safe nor
638guaranteed to have a sensible effect.
639
1a52ab62
MB
640=back
641
85cf7f2e 642=head2 B::IV Methods
1a52ab62
MB
643
644=over 4
645
646=item IV
647
d9963e60
RH
648Returns the value of the IV, I<interpreted as
649a signed integer>. This will be misleading
650if C<FLAGS & SVf_IVisUV>. Perhaps you want the
651C<int_value> method instead?
652
1a52ab62
MB
653=item IVX
654
d9963e60
RH
655=item UVX
656
657=item int_value
658
659This method returns the value of the IV as an integer.
660It differs from C<IV> in that it returns the correct
661value regardless of whether it's stored signed or
662unsigned.
663
1a52ab62
MB
664=item needs64bits
665
666=item packiv
667
668=back
669
85cf7f2e 670=head2 B::NV Methods
1a52ab62
MB
671
672=over 4
673
674=item NV
675
676=item NVX
677
678=back
679
85cf7f2e 680=head2 B::RV Methods
1a52ab62
MB
681
682=over 4
683
684=item RV
685
686=back
687
85cf7f2e 688=head2 B::PV Methods
1a52ab62
MB
689
690=over 4
691
692=item PV
693
76ef7183
JH
694This method is the one you usually want. It constructs a
695string using the length and offset information in the struct:
696for ordinary scalars it will return the string that you'd see
697from Perl, even if it contains null characters.
698
9d2bbe64
MB
699=item RV
700
701Same as B::RV::RV, except that it will die() if the PV isn't
702a reference.
703
0b40bd6d
RH
704=item PVX
705
76ef7183
JH
706This method is less often useful. It assumes that the string
707stored in the struct is null-terminated, and disregards the
708length information.
709
710It is the appropriate method to use if you need to get the name
711of a lexical variable from a padname array. Lexical variable names
712are always stored with a null terminator, and the length field
713(SvCUR) is overloaded for other purposes and can't be relied on here.
714
1a52ab62
MB
715=back
716
85cf7f2e 717=head2 B::PVMG Methods
1a52ab62
MB
718
719=over 4
720
721=item MAGIC
722
723=item SvSTASH
724
725=back
726
85cf7f2e 727=head2 B::MAGIC Methods
1a52ab62
MB
728
729=over 4
730
731=item MOREMAGIC
732
9d2bbe64
MB
733=item precomp
734
735Only valid on r-magic, returns the string that generated the regexp.
736
1a52ab62
MB
737=item PRIVATE
738
739=item TYPE
740
741=item FLAGS
742
743=item OBJ
744
9d2bbe64
MB
745Will die() if called on r-magic.
746
1a52ab62
MB
747=item PTR
748
9d2bbe64
MB
749=item REGEX
750
751Only valid on r-magic, returns the integer value of the REGEX stored
752in the MAGIC.
753
1a52ab62
MB
754=back
755
85cf7f2e 756=head2 B::PVLV Methods
1a52ab62
MB
757
758=over 4
759
760=item TARGOFF
761
762=item TARGLEN
763
764=item TYPE
765
766=item TARG
767
768=back
769
85cf7f2e 770=head2 B::BM Methods
1a52ab62
MB
771
772=over 4
773
774=item USEFUL
775
776=item PREVIOUS
777
778=item RARE
779
780=item TABLE
781
782=back
783
85cf7f2e 784=head2 B::GV Methods
1a52ab62
MB
785
786=over 4
787
87d7fd28
GS
788=item is_empty
789
790This method returns TRUE if the GP field of the GV is NULL.
791
1a52ab62
MB
792=item NAME
793
002b978b
RH
794=item SAFENAME
795
796This method returns the name of the glob, but if the first
797character of the name is a control character, then it converts
798it to ^X first, so that *^G would return "^G" rather than "\cG".
799
800It's useful if you want to print out the name of a variable.
801If you restrict yourself to globs which exist at compile-time
802then the result ought to be unambiguous, because code like
803C<${"^G"} = 1> is compiled as two ops - a constant string and
804a dereference (rv2gv) - so that the glob is created at runtime.
805
806If you're working with globs at runtime, and need to disambiguate
807*^G from *{"^G"}, then you should use the raw NAME method.
808
1a52ab62
MB
809=item STASH
810
811=item SV
812
813=item IO
814
815=item FORM
816
817=item AV
818
819=item HV
820
821=item EGV
822
823=item CV
824
825=item CVGEN
826
827=item LINE
828
b195d487
GS
829=item FILE
830
1a52ab62
MB
831=item FILEGV
832
833=item GvREFCNT
834
835=item FLAGS
836
837=back
838
85cf7f2e 839=head2 B::IO Methods
1a52ab62
MB
840
841=over 4
842
843=item LINES
844
845=item PAGE
846
847=item PAGE_LEN
848
849=item LINES_LEFT
850
851=item TOP_NAME
852
853=item TOP_GV
854
855=item FMT_NAME
856
857=item FMT_GV
858
859=item BOTTOM_NAME
860
861=item BOTTOM_GV
862
863=item SUBPROCESS
864
865=item IoTYPE
866
867=item IoFLAGS
868
9d2bbe64
MB
869=item IsSTD
870
871Takes one arguments ( 'stdin' | 'stdout' | 'stderr' ) and returns true
872if the IoIFP of the object is equal to the handle whose name was
873passed as argument ( i.e. $io->IsSTD('stderr') is true if
874IoIFP($io) == PerlIO_stdin() ).
875
1a52ab62
MB
876=back
877
85cf7f2e 878=head2 B::AV Methods
1a52ab62
MB
879
880=over 4
881
882=item FILL
883
884=item MAX
885
1a52ab62
MB
886=item ARRAY
887
429a5ce7
SM
888=item ARRAYelt
889
890Like C<ARRAY>, but takes an index as an argument to get only one element,
891rather than a list of all of them.
892
edcc7c74
NC
893=item OFF
894
895This method is deprecated if running under Perl 5.8, and is no longer present
896if running under Perl 5.9
897
898=item AvFLAGS
899
900This method returns the AV specific flags. In Perl 5.9 these are now stored
901in with the main SV flags, so this method is no longer present.
902
1a52ab62
MB
903=back
904
85cf7f2e 905=head2 B::CV Methods
1a52ab62
MB
906
907=over 4
908
909=item STASH
910
911=item START
912
913=item ROOT
914
915=item GV
916
57843af0
GS
917=item FILE
918
1a52ab62
MB
919=item DEPTH
920
921=item PADLIST
922
923=item OUTSIDE
924
a3985cdc
DM
925=item OUTSIDE_SEQ
926
1a52ab62
MB
927=item XSUB
928
929=item XSUBANY
930
9d2bbe64
MB
931For constant subroutines, returns the constant SV returned by the subroutine.
932
5cfd8ad4
VB
933=item CvFLAGS
934
de3f1649
JT
935=item const_sv
936
1a52ab62
MB
937=back
938
85cf7f2e 939=head2 B::HV Methods
1a52ab62
MB
940
941=over 4
942
943=item FILL
944
945=item MAX
946
947=item KEYS
948
949=item RITER
950
951=item NAME
952
1a52ab62
MB
953=item ARRAY
954
edcc7c74
NC
955=item PMROOT
956
957This method is not present if running under Perl 5.9, as the PMROOT
958information is no longer stored directly in the hash.
959
1a52ab62
MB
960=back
961
962=head2 OP-RELATED CLASSES
963
85cf7f2e 964C<B::OP>, C<B::UNOP>, C<B::BINOP>, C<B::LOGOP>, C<B::LISTOP>, C<B::PMOP>,
651aa52e 965C<B::SVOP>, C<B::PADOP>, C<B::PVOP>, C<B::LOOP>, C<B::COP>.
85cf7f2e
MJD
966
967These classes correspond in the obvious way to the underlying C
968structures of similar names. The inheritance hierarchy mimics the
969underlying C "inheritance":
970
971 B::OP
972 |
5ce57cc0
JJ
973 +---------------+--------+--------+-------+
974 | | | | |
975 B::UNOP B::SVOP B::PADOP B::COP B::PVOP
85cf7f2e
MJD
976 ,' `-.
977 / `--.
978 B::BINOP B::LOGOP
979 |
980 |
981 B::LISTOP
982 ,' `.
983 / \
984 B::LOOP B::PMOP
985
986Access methods correspond to the underlying C structre field names,
987with the leading "class indication" prefix (C<"op_">) removed.
988
989=head2 B::OP Methods
1a52ab62 990
a60ba18b
JC
991These methods get the values of similarly named fields within the OP
992data structure. See top of C<op.h> for more info.
993
1a52ab62
MB
994=over 4
995
996=item next
997
998=item sibling
999
3f872cb9
GS
1000=item name
1001
1002This returns the op name as a string (e.g. "add", "rv2av").
1003
1a52ab62
MB
1004=item ppaddr
1005
dc333d64
GS
1006This returns the function name as a string (e.g. "PL_ppaddr[OP_ADD]",
1007"PL_ppaddr[OP_RV2AV]").
1a52ab62
MB
1008
1009=item desc
1010
4369b173 1011This returns the op description from the global C PL_op_desc array
1a52ab62
MB
1012(e.g. "addition" "array deref").
1013
1014=item targ
1015
1016=item type
1017
a60ba18b
JC
1018=item opt
1019
1a52ab62
MB
1020=item flags
1021
1022=item private
1023
a60ba18b
JC
1024=item spare
1025
1a52ab62
MB
1026=back
1027
1028=head2 B::UNOP METHOD
1029
1030=over 4
1031
1032=item first
1033
1034=back
1035
1036=head2 B::BINOP METHOD
1037
1038=over 4
1039
1040=item last
1041
1042=back
1043
1044=head2 B::LOGOP METHOD
1045
1046=over 4
1047
1048=item other
1049
1050=back
1051
1a52ab62
MB
1052=head2 B::LISTOP METHOD
1053
1054=over 4
1055
1056=item children
1057
1058=back
1059
85cf7f2e 1060=head2 B::PMOP Methods
1a52ab62
MB
1061
1062=over 4
1063
1064=item pmreplroot
1065
1066=item pmreplstart
1067
1068=item pmnext
1069
1070=item pmregexp
1071
1072=item pmflags
1073
c737faaf 1074=item extflags
1a52ab62
MB
1075
1076=item precomp
1077
651aa52e 1078=item pmoffset
9d2bbe64
MB
1079
1080Only when perl was compiled with ithreads.
1081
1a52ab62
MB
1082=back
1083
1084=head2 B::SVOP METHOD
1085
1086=over 4
1087
1088=item sv
1089
065a1863
GS
1090=item gv
1091
1a52ab62
MB
1092=back
1093
7934575e 1094=head2 B::PADOP METHOD
1a52ab62
MB
1095
1096=over 4
1097
7934575e 1098=item padix
1a52ab62
MB
1099
1100=back
1101
1102=head2 B::PVOP METHOD
1103
1104=over 4
1105
1106=item pv
1107
1108=back
1109
85cf7f2e 1110=head2 B::LOOP Methods
1a52ab62
MB
1111
1112=over 4
1113
1114=item redoop
1115
1116=item nextop
1117
1118=item lastop
1119
1120=back
1121
85cf7f2e 1122=head2 B::COP Methods
1a52ab62
MB
1123
1124=over 4
1125
1126=item label
1127
1128=item stash
1129
6e6a1aef
RGS
1130=item stashpv
1131
57843af0 1132=item file
1a52ab62
MB
1133
1134=item cop_seq
1135
1136=item arybase
1137
1138=item line
1139
6e6a1aef
RGS
1140=item warnings
1141
1142=item io
1143
d5ec2987
NC
1144=item hints
1145
1a52ab62
MB
1146=back
1147
7f20e9dd
GS
1148
1149=head1 AUTHOR
1150
1151Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
1152
1153=cut