File Coverage

blib/lib/B/Generate.pm
Criterion Covered Total %
statement 24 68 35.2
branch 3 28 10.7
condition 1 24 4.1
subroutine 7 11 63.6
pod n/a
total 35 131 26.7


line stmt bran cond sub pod time code
1             package B::Generate;
2              
3             require 5.005_62;
4 7     7   295497 use strict;
  7         44  
  7         166  
5 7     7   29 use warnings;
  7         9  
  7         158  
6 7     7   28 use B ();
  7         9  
  7         184  
7              
8             require DynaLoader;
9 7     7   30 use vars qw( @ISA $VERSION );
  7         10  
  7         1290  
10             @ISA = qw(DynaLoader);
11             $VERSION = '1.56';
12              
13             {
14             # 'no warnings' does not work.
15             local $SIG{__WARN__} = sub {
16             return if $_[0] =~ /Subroutine B(?:::\w+)+ redefined/;
17             warn $_[0];
18             };
19             bootstrap B::Generate $VERSION;
20             }
21              
22             package
23             B::OP; # do not index
24 7     7   52 use constant OP_LIST => B::opnumber("list");
  7         19  
  7         996  
25 7     7   39 use B qw(OPf_PARENS OPf_KIDS);
  7         9  
  7         4540  
26              
27             # for convenience
28 0     0   0 sub B::NULL::type { 0 };
29              
30             # This is where we implement op.c in Perl. Sssh.
31             # XXX coverage: 0
32             sub linklist {
33 0     0   0 my $o = shift;
34 0 0 0     0 if ( $o->can("first") and $o->first and ${ $o->first } ) {
  0   0     0  
35 0         0 $o->next( $o->first->linklist );
36 0         0 for ( my $kid = $o->first; $$kid; $kid = $kid->sibling ) {
37 0 0       0 if ( ${ $kid->sibling } ) {
  0         0  
38 0         0 $kid->next( $kid->sibling->linklist );
39             }
40             else {
41 0         0 $kid->next($o);
42             }
43             }
44             }
45             else {
46 0         0 $o->next($o);
47             }
48 0         0 $o->clean;
49 0         0 return $o->next;
50             }
51              
52             # coverage: scope.t
53             sub append_elem {
54 0     0   0 my ( $class, $type, $first, $last ) = @_;
55 0 0 0     0 return $last unless $first and $$first;
56 0 0 0     0 return $first unless $last and $$last;
57              
58 0 0 0     0 if ( $first->type() != $type
      0        
59             or ( $type == OP_LIST and ( $first->flags & OPf_PARENS ) ) )
60             {
61 0         0 return B::LISTOP->new( $type, 0, $first, $last );
62             }
63              
64 0 0       0 if ( $first->flags() & OPf_KIDS ) {
65              
66 0         0 $first->last->sibling($last);
67             }
68             else {
69 0         0 $first->flags( $first->flags | OPf_KIDS );
70 0         0 $first->first($last);
71             }
72 0         0 $first->last($last);
73 0         0 return $first;
74             }
75              
76             # coverage: scope.t
77             sub prepend_elem {
78 0     0   0 my ( $class, $type, $first, $last ) = @_;
79 0 0       0 if ( $last->type() != $type ) {
80 0         0 return B::LISTOP->new( $type, 0, $first, $last );
81             }
82              
83 0 0       0 if ( $type == OP_LIST ) {
84 0         0 $first->sibling( $last->first->sibling );
85 0         0 $last->first->sibling($first);
86 0 0       0 $last->flags( $last->flags & ~OPf_PARENS )
87             unless ( $first->flags & OPf_PARENS );
88             }
89             else {
90 0 0       0 unless ( $last->flags & OPf_KIDS ) {
91 0         0 $last->last($first);
92 0         0 $last->flags( $last->flags | OPf_KIDS );
93             }
94 0         0 $first->sibling( $last->first );
95 0         0 $last->first($first);
96             }
97 0         0 $last->flags( $last->flags | OPf_KIDS );
98 0         0 return $last; # I cannot believe this works.
99             }
100              
101             # coverage: scope.t
102             sub scope {
103 1     1   866 my $o = shift;
104 1 50 33     7 return unless $o and $$o;
105 1 50       5 if ( $o->flags & OPf_PARENS ) {
106 0         0 $o = B::OP->prepend_elem( B::opnumber("lineseq"),
107             B::OP->new( "enter", 0 ), $o );
108 0         0 $o->type( B::opnumber("leave") );
109             }
110             else {
111 1 50       5 if ( $o->type == B::opnumber("lineseq") ) {
112 0         0 my $kid;
113 0         0 $o->type( B::opnumber("scope") );
114 0         0 $kid = $o->first;
115 0 0 0     0 die "This probably shouldn't happen (\$kid->null)\n"
116             if ( $kid->type == B::opnumber("nextstate")
117             or $kid->type == B::opnumber("dbstate") );
118             }
119             else {
120 1         11 $o = B::LISTOP->new( "scope", 0, $o, undef );
121             }
122             }
123 1         2 return ($o);
124             }
125              
126             1;
127             __END__