line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CodeGen::Cpppp::Output; |
2
|
|
|
|
|
|
|
$INC{'CodeGen/Cpppp/Output.pm'}= 1; |
3
|
7
|
|
|
7
|
|
92
|
use v5.20; |
|
7
|
|
|
|
|
25
|
|
4
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
177
|
|
5
|
7
|
|
|
7
|
|
36
|
use Carp; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
364
|
|
6
|
7
|
|
|
7
|
|
72
|
use Scalar::Util 'looks_like_number'; |
|
7
|
|
|
|
|
43
|
|
|
7
|
|
|
|
|
340
|
|
7
|
7
|
|
|
7
|
|
51
|
use List::Util 'max'; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
549
|
|
8
|
7
|
|
|
7
|
|
46
|
use experimental 'signatures'; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
37
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %standard_sections= ( |
12
|
|
|
|
|
|
|
public => 100, |
13
|
|
|
|
|
|
|
protected => 200, |
14
|
|
|
|
|
|
|
private => 10000, |
15
|
|
|
|
|
|
|
); |
16
|
23
|
|
|
23
|
1
|
45
|
sub new($class, @args) { |
|
23
|
|
|
|
|
37
|
|
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
31
|
|
17
|
|
|
|
|
|
|
bless { |
18
|
|
|
|
|
|
|
section_priority => { %standard_sections }, |
19
|
|
|
|
|
|
|
out => {}, |
20
|
23
|
50
|
33
|
|
|
301
|
@args == 1 && ref $args[0]? %{$args[0]} |
|
0
|
50
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
: !(@args & 1)? @args |
22
|
|
|
|
|
|
|
: croak "Expected hashref or even-length list" |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
16
|
|
|
16
|
1
|
23
|
sub section_list($self) { |
|
16
|
|
|
|
|
22
|
|
|
16
|
|
|
|
|
22
|
|
28
|
16
|
|
|
|
|
33
|
my $pri= $self->section_priority; |
29
|
16
|
|
|
|
|
70
|
sort { $pri->{$a} <=> $pri->{$b} } keys %$pri; |
|
42
|
|
|
|
|
112
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
9
|
|
|
9
|
0
|
15
|
sub has_section($self, $name) { |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
10
|
|
33
|
9
|
|
|
|
|
22
|
defined $self->section_priority->{$name}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
29
|
|
|
29
|
1
|
39
|
sub section_priority($self) { |
|
29
|
|
|
|
|
47
|
|
|
29
|
|
|
|
|
41
|
|
37
|
|
|
|
|
|
|
$self->{section_priority} |
38
|
29
|
|
|
|
|
71
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
1
|
0
|
sub declare_sections($self, @list) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
41
|
0
|
|
|
|
|
0
|
my $pri= $self->section_priority; |
42
|
0
|
|
|
|
|
0
|
my $max_before_private= max grep $_ < $pri->{private}, values %$pri; |
43
|
0
|
|
|
|
|
0
|
my $next= $max_before_private + 1; |
44
|
0
|
|
|
|
|
0
|
while (@list) { |
45
|
0
|
|
|
|
|
0
|
my $name= shift @list; |
46
|
0
|
0
|
|
|
|
0
|
looks_like_number($name) and croak "Expected non-numeric name at '$name'"; |
47
|
0
|
0
|
|
|
|
0
|
if (looks_like_number($list[0])) { |
|
|
0
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$pri->{$name}= shift @list; |
49
|
|
|
|
|
|
|
} elsif (!defined $pri->{$name}) { |
50
|
0
|
0
|
|
|
|
0
|
$name =~ /\.\.|,/ and croak "Section names may not contain '..' or ','"; |
51
|
0
|
|
|
|
|
0
|
$pri->{$name}= $next++; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
0
|
$self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
30
|
|
|
30
|
1
|
47
|
sub append($self, $section, @code) { |
|
30
|
|
|
|
|
42
|
|
|
30
|
|
|
|
|
44
|
|
|
30
|
|
|
|
|
61
|
|
|
30
|
|
|
|
|
42
|
|
59
|
30
|
50
|
|
|
|
96
|
defined $self->{section_priority}{$section} or croak "Unknown section $section"; |
60
|
30
|
|
|
|
|
42
|
push @{$self->{out}{$section}}, @code; |
|
30
|
|
|
|
|
117
|
|
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
0
|
1
|
0
|
sub prepend($self, $section, @code) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
63
|
0
|
0
|
|
|
|
0
|
defined $self->{section_priority}{$section} or croak "Unknown section $section"; |
64
|
0
|
|
|
|
|
0
|
unshift @{$self->{out}{$section}}, @code; |
|
0
|
|
|
|
|
0
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
4
|
|
|
4
|
1
|
8
|
sub expand_section_selector($self, @list) { |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
8
|
|
69
|
4
|
50
|
|
|
|
22
|
@list= map +(ref $_ eq 'ARRAY'? @$_ : $_), @list; |
70
|
4
|
|
|
|
|
18
|
@list= map split(',', $_), @list; |
71
|
4
|
|
|
|
|
12
|
my $sec_pri= $self->section_priority; |
72
|
4
|
|
|
|
|
7
|
my %seen; |
73
|
4
|
|
|
|
|
21
|
for (@list) { |
74
|
4
|
50
|
|
|
|
15
|
if (/([^.]+)\.\.([^.]+)/) { |
75
|
0
|
|
0
|
|
|
0
|
my $low= $sec_pri->{$1} // croak "Unknown section $1"; |
76
|
0
|
|
0
|
|
|
0
|
my $high= $sec_pri->{$2} // croak "Unknown section $2"; |
77
|
0
|
|
|
|
|
0
|
for (keys %$sec_pri) { |
78
|
0
|
0
|
0
|
|
|
0
|
$seen{$_}++ if $sec_pri->{$_} >= $low && $sec_pri->{$_} <= $high; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} else { |
81
|
4
|
|
33
|
|
|
33
|
$sec_pri->{$_} // croak "Unknown section $_"; |
82
|
4
|
|
|
|
|
14
|
$seen{$_}++; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
4
|
|
|
|
|
21
|
sort { $sec_pri->{$a} <=> $sec_pri->{$b} } keys %seen; |
|
0
|
|
|
|
|
0
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
20
|
|
|
20
|
1
|
7549
|
sub get($self, @sections) { |
|
20
|
|
|
|
|
68
|
|
|
20
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
30
|
|
90
|
20
|
100
|
|
|
|
76
|
my @sec= @sections? $self->expand_section_selector(@sections) : $self->section_list; |
91
|
20
|
|
100
|
|
|
50
|
join '', map @{$self->{out}{$_} // []}, @sec; |
|
52
|
|
|
|
|
280
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
sub consume($self, @sections) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
my @sec= @sections? $self->expand_section_selector(@sections) : $self->section_list; |
96
|
0
|
|
0
|
|
|
|
my $out= join '', map @{delete $self->{out}{$_} // []}, @sec; |
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
@{$self->{out}{$_}}= () for @sec; |
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$out |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |