| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##################################################################### |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# the Perl::Tidy::FileWriter class writes the output file |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
##################################################################### |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Perl::Tidy::FileWriter; |
|
8
|
39
|
|
|
39
|
|
275
|
use strict; |
|
|
39
|
|
|
|
|
84
|
|
|
|
39
|
|
|
|
|
1199
|
|
|
9
|
39
|
|
|
39
|
|
203
|
use warnings; |
|
|
39
|
|
|
|
|
93
|
|
|
|
39
|
|
|
|
|
3586
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '20230912'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
39
|
|
|
39
|
|
943
|
use constant DEVEL_MODE => 0; |
|
|
39
|
|
|
|
|
116
|
|
|
|
39
|
|
|
|
|
2382
|
|
|
13
|
39
|
|
|
39
|
|
239
|
use constant EMPTY_STRING => q{}; |
|
|
39
|
|
|
|
|
75
|
|
|
|
39
|
|
|
|
|
8255
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Catch any undefined sub calls so that we are sure to get |
|
18
|
|
|
|
|
|
|
# some diagnostic information. This sub should never be called |
|
19
|
|
|
|
|
|
|
# except for a programming error. |
|
20
|
0
|
|
|
0
|
|
0
|
our $AUTOLOAD; |
|
21
|
0
|
0
|
|
|
|
0
|
return if ( $AUTOLOAD =~ /\bDESTROY$/ ); |
|
22
|
0
|
|
|
|
|
0
|
my ( $pkg, $fname, $lno ) = caller(); |
|
23
|
0
|
|
|
|
|
0
|
my $my_package = __PACKAGE__; |
|
24
|
0
|
|
|
|
|
0
|
print {*STDERR} <<EOM; |
|
|
0
|
|
|
|
|
0
|
|
|
25
|
|
|
|
|
|
|
====================================================================== |
|
26
|
|
|
|
|
|
|
Error detected in package '$my_package', version $VERSION |
|
27
|
|
|
|
|
|
|
Received unexpected AUTOLOAD call for sub '$AUTOLOAD' |
|
28
|
|
|
|
|
|
|
Called from package: '$pkg' |
|
29
|
|
|
|
|
|
|
Called from File '$fname' at line '$lno' |
|
30
|
|
|
|
|
|
|
This error is probably due to a recent programming change |
|
31
|
|
|
|
|
|
|
====================================================================== |
|
32
|
|
|
|
|
|
|
EOM |
|
33
|
0
|
|
|
|
|
0
|
exit 1; |
|
34
|
|
|
|
|
|
|
} ## end sub AUTOLOAD |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
0
|
|
|
sub DESTROY { |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# required to avoid call to AUTOLOAD in some versions of perl |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $input_stream_name = EMPTY_STRING; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Maximum number of little messages; probably need not be changed. |
|
44
|
39
|
|
|
39
|
|
315
|
use constant MAX_NAG_MESSAGES => 6; |
|
|
39
|
|
|
|
|
81
|
|
|
|
39
|
|
|
|
|
5578
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
BEGIN { |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Array index names for variables. |
|
49
|
|
|
|
|
|
|
# Do not combine with other BEGIN blocks (c101). |
|
50
|
39
|
|
|
39
|
|
51922
|
my $i = 0; |
|
51
|
|
|
|
|
|
|
use constant { |
|
52
|
39
|
|
|
|
|
8743
|
_logger_object_ => $i++, |
|
53
|
|
|
|
|
|
|
_rOpts_ => $i++, |
|
54
|
|
|
|
|
|
|
_output_line_number_ => $i++, |
|
55
|
|
|
|
|
|
|
_consecutive_blank_lines_ => $i++, |
|
56
|
|
|
|
|
|
|
_consecutive_nonblank_lines_ => $i++, |
|
57
|
|
|
|
|
|
|
_consecutive_new_blank_lines_ => $i++, |
|
58
|
|
|
|
|
|
|
_first_line_length_error_ => $i++, |
|
59
|
|
|
|
|
|
|
_max_line_length_error_ => $i++, |
|
60
|
|
|
|
|
|
|
_last_line_length_error_ => $i++, |
|
61
|
|
|
|
|
|
|
_first_line_length_error_at_ => $i++, |
|
62
|
|
|
|
|
|
|
_max_line_length_error_at_ => $i++, |
|
63
|
|
|
|
|
|
|
_last_line_length_error_at_ => $i++, |
|
64
|
|
|
|
|
|
|
_line_length_error_count_ => $i++, |
|
65
|
|
|
|
|
|
|
_max_output_line_length_ => $i++, |
|
66
|
|
|
|
|
|
|
_max_output_line_length_at_ => $i++, |
|
67
|
|
|
|
|
|
|
_rK_checklist_ => $i++, |
|
68
|
|
|
|
|
|
|
_K_arrival_order_matches_ => $i++, |
|
69
|
|
|
|
|
|
|
_K_sequence_error_msg_ => $i++, |
|
70
|
|
|
|
|
|
|
_K_last_arrival_ => $i++, |
|
71
|
|
|
|
|
|
|
_save_logfile_ => $i++, |
|
72
|
|
|
|
|
|
|
_routput_string_ => $i++, |
|
73
|
39
|
|
|
39
|
|
310
|
}; |
|
|
39
|
|
|
|
|
190
|
|
|
74
|
|
|
|
|
|
|
} ## end BEGIN |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub Die { |
|
77
|
0
|
|
|
0
|
0
|
0
|
my ($msg) = @_; |
|
78
|
0
|
|
|
|
|
0
|
Perl::Tidy::Die($msg); |
|
79
|
0
|
|
|
|
|
0
|
return; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub Fault { |
|
83
|
0
|
|
|
0
|
0
|
0
|
my ($msg) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# This routine is called for errors that really should not occur |
|
86
|
|
|
|
|
|
|
# except if there has been a bug introduced by a recent program change. |
|
87
|
|
|
|
|
|
|
# Please add comments at calls to Fault to explain why the call |
|
88
|
|
|
|
|
|
|
# should not occur, and where to look to fix it. |
|
89
|
0
|
|
|
|
|
0
|
my ( $package0, $filename0, $line0, $subroutine0 ) = caller(0); |
|
90
|
0
|
|
|
|
|
0
|
my ( $package1, $filename1, $line1, $subroutine1 ) = caller(1); |
|
91
|
0
|
|
|
|
|
0
|
my ( $package2, $filename2, $line2, $subroutine2 ) = caller(2); |
|
92
|
0
|
|
|
|
|
0
|
my $pkg = __PACKAGE__; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
Die(<<EOM); |
|
95
|
|
|
|
|
|
|
============================================================================== |
|
96
|
|
|
|
|
|
|
While operating on input stream with name: '$input_stream_name' |
|
97
|
|
|
|
|
|
|
A fault was detected at line $line0 of sub '$subroutine1' |
|
98
|
|
|
|
|
|
|
in file '$filename1' |
|
99
|
|
|
|
|
|
|
which was called from line $line1 of sub '$subroutine2' |
|
100
|
|
|
|
|
|
|
Message: '$msg' |
|
101
|
|
|
|
|
|
|
This is probably an error introduced by a recent programming change. |
|
102
|
|
|
|
|
|
|
$pkg reports VERSION='$VERSION'. |
|
103
|
|
|
|
|
|
|
============================================================================== |
|
104
|
|
|
|
|
|
|
EOM |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# This return is to keep Perl-Critic from complaining. |
|
107
|
0
|
|
|
|
|
0
|
return; |
|
108
|
|
|
|
|
|
|
} ## end sub Fault |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub warning { |
|
111
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $msg ) = @_; |
|
112
|
0
|
|
|
|
|
0
|
my $logger_object = $self->[_logger_object_]; |
|
113
|
0
|
0
|
|
|
|
0
|
if ($logger_object) { $logger_object->warning($msg); } |
|
|
0
|
|
|
|
|
0
|
|
|
114
|
0
|
|
|
|
|
0
|
return; |
|
115
|
|
|
|
|
|
|
} ## end sub warning |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub write_logfile_entry { |
|
118
|
1122
|
|
|
1122
|
0
|
2800
|
my ( $self, $msg ) = @_; |
|
119
|
1122
|
|
|
|
|
2368
|
my $logger_object = $self->[_logger_object_]; |
|
120
|
1122
|
100
|
|
|
|
2772
|
if ($logger_object) { |
|
121
|
1118
|
|
|
|
|
2842
|
$logger_object->write_logfile_entry($msg); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
1122
|
|
|
|
|
2771
|
return; |
|
124
|
|
|
|
|
|
|
} ## end sub write_logfile_entry |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub new { |
|
127
|
561
|
|
|
561
|
0
|
2262
|
my ( $class, $line_sink_object, $rOpts, $logger_object ) = @_; |
|
128
|
|
|
|
|
|
|
|
|
129
|
561
|
|
|
|
|
1504
|
my $self = []; |
|
130
|
561
|
|
|
|
|
1787
|
$self->[_logger_object_] = $logger_object; |
|
131
|
561
|
|
|
|
|
1582
|
$self->[_rOpts_] = $rOpts; |
|
132
|
561
|
|
|
|
|
1478
|
$self->[_output_line_number_] = 1; |
|
133
|
561
|
|
|
|
|
1438
|
$self->[_consecutive_blank_lines_] = 0; |
|
134
|
561
|
|
|
|
|
1630
|
$self->[_consecutive_nonblank_lines_] = 0; |
|
135
|
561
|
|
|
|
|
1628
|
$self->[_consecutive_new_blank_lines_] = 0; |
|
136
|
561
|
|
|
|
|
1407
|
$self->[_first_line_length_error_] = 0; |
|
137
|
561
|
|
|
|
|
1381
|
$self->[_max_line_length_error_] = 0; |
|
138
|
561
|
|
|
|
|
1507
|
$self->[_last_line_length_error_] = 0; |
|
139
|
561
|
|
|
|
|
1338
|
$self->[_first_line_length_error_at_] = 0; |
|
140
|
561
|
|
|
|
|
1384
|
$self->[_max_line_length_error_at_] = 0; |
|
141
|
561
|
|
|
|
|
1344
|
$self->[_last_line_length_error_at_] = 0; |
|
142
|
561
|
|
|
|
|
1588
|
$self->[_line_length_error_count_] = 0; |
|
143
|
561
|
|
|
|
|
1392
|
$self->[_max_output_line_length_] = 0; |
|
144
|
561
|
|
|
|
|
1405
|
$self->[_max_output_line_length_at_] = 0; |
|
145
|
561
|
|
|
|
|
1670
|
$self->[_rK_checklist_] = []; |
|
146
|
561
|
|
|
|
|
1517
|
$self->[_K_arrival_order_matches_] = 0; |
|
147
|
561
|
|
|
|
|
1745
|
$self->[_K_sequence_error_msg_] = EMPTY_STRING; |
|
148
|
561
|
|
|
|
|
1649
|
$self->[_K_last_arrival_] = -1; |
|
149
|
561
|
|
|
|
|
1676
|
$self->[_save_logfile_] = defined($logger_object); |
|
150
|
561
|
|
|
|
|
1482
|
$self->[_routput_string_] = undef; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# '$line_sink_object' is a SCALAR ref which receives the lines. |
|
153
|
561
|
|
|
|
|
1785
|
my $ref = ref($line_sink_object); |
|
154
|
561
|
50
|
|
|
|
2859
|
if ( !$ref ) { |
|
|
|
50
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
Fault("FileWriter expects line_sink_object to be a ref\n"); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
elsif ( $ref eq 'SCALAR' ) { |
|
158
|
561
|
|
|
|
|
1553
|
$self->[_routput_string_] = $line_sink_object; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
else { |
|
161
|
0
|
|
|
|
|
0
|
my $str = $ref; |
|
162
|
0
|
0
|
|
|
|
0
|
if ( length($str) > 63 ) { $str = substr( $str, 0, 60 ) . '...' } |
|
|
0
|
|
|
|
|
0
|
|
|
163
|
0
|
|
|
|
|
0
|
Fault(<<EOM); |
|
164
|
|
|
|
|
|
|
FileWriter expects 'line_sink_object' to be ref to SCALAR but it is ref to: |
|
165
|
|
|
|
|
|
|
$str |
|
166
|
|
|
|
|
|
|
EOM |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# save input stream name for local error messages |
|
170
|
561
|
|
|
|
|
1471
|
$input_stream_name = EMPTY_STRING; |
|
171
|
561
|
100
|
|
|
|
1902
|
if ($logger_object) { |
|
172
|
559
|
|
|
|
|
2979
|
$input_stream_name = $logger_object->get_input_stream_name(); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
561
|
|
|
|
|
1701
|
bless $self, $class; |
|
176
|
561
|
|
|
|
|
1816
|
return $self; |
|
177
|
|
|
|
|
|
|
} ## end sub new |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub setup_convergence_test { |
|
180
|
558
|
|
|
558
|
0
|
2144
|
my ( $self, $rlist ) = @_; |
|
181
|
558
|
100
|
|
|
|
1171
|
if ( @{$rlist} ) { |
|
|
558
|
|
|
|
|
2100
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# We are going to destroy the list, so make a copy |
|
184
|
|
|
|
|
|
|
# and put in reverse order so we can pop values |
|
185
|
547
|
|
|
|
|
1176
|
my @list = @{$rlist}; |
|
|
547
|
|
|
|
|
2058
|
|
|
186
|
547
|
100
|
|
|
|
2095
|
if ( $list[0] < $list[-1] ) { |
|
187
|
471
|
|
|
|
|
1312
|
@list = reverse @list; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
547
|
|
|
|
|
1729
|
$self->[_rK_checklist_] = \@list; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
558
|
|
|
|
|
1416
|
$self->[_K_arrival_order_matches_] = 1; |
|
192
|
558
|
|
|
|
|
1320
|
$self->[_K_sequence_error_msg_] = EMPTY_STRING; |
|
193
|
558
|
|
|
|
|
1195
|
$self->[_K_last_arrival_] = -1; |
|
194
|
558
|
|
|
|
|
1643
|
return; |
|
195
|
|
|
|
|
|
|
} ## end sub setup_convergence_test |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub get_convergence_check { |
|
198
|
561
|
|
|
561
|
0
|
1663
|
my ($self) = @_; |
|
199
|
561
|
|
|
|
|
1468
|
my $rlist = $self->[_rK_checklist_]; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# converged if all K arrived and in correct order |
|
202
|
561
|
|
66
|
|
|
3610
|
return $self->[_K_arrival_order_matches_] && !@{$rlist}; |
|
203
|
|
|
|
|
|
|
} ## end sub get_convergence_check |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub get_output_line_number { |
|
206
|
493
|
|
|
493
|
0
|
1340
|
return $_[0]->[_output_line_number_]; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub decrement_output_line_number { |
|
210
|
561
|
|
|
561
|
0
|
1478
|
$_[0]->[_output_line_number_]--; |
|
211
|
561
|
|
|
|
|
1217
|
return; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub get_consecutive_nonblank_lines { |
|
215
|
1
|
|
|
1
|
0
|
5
|
return $_[0]->[_consecutive_nonblank_lines_]; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub get_consecutive_blank_lines { |
|
219
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[_consecutive_blank_lines_]; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub reset_consecutive_blank_lines { |
|
223
|
120
|
|
|
120
|
0
|
250
|
$_[0]->[_consecutive_blank_lines_] = 0; |
|
224
|
120
|
|
|
|
|
208
|
return; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# This sub call allows termination of logfile writing for efficiency when we |
|
228
|
|
|
|
|
|
|
# know that the logfile will not be saved. |
|
229
|
|
|
|
|
|
|
sub set_save_logfile { |
|
230
|
559
|
|
|
559
|
0
|
1854
|
my ( $self, $save_logfile ) = @_; |
|
231
|
559
|
|
|
|
|
1631
|
$self->[_save_logfile_] = $save_logfile; |
|
232
|
559
|
|
|
|
|
1518
|
return; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub want_blank_line { |
|
236
|
21
|
|
|
21
|
0
|
53
|
my $self = shift; |
|
237
|
21
|
100
|
|
|
|
91
|
if ( !$self->[_consecutive_blank_lines_] ) { |
|
238
|
13
|
|
|
|
|
59
|
$self->write_blank_code_line(); |
|
239
|
|
|
|
|
|
|
} |
|
240
|
21
|
|
|
|
|
49
|
return; |
|
241
|
|
|
|
|
|
|
} ## end sub want_blank_line |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub require_blank_code_lines { |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# write out the requested number of blanks regardless of the value of -mbl |
|
246
|
|
|
|
|
|
|
# unless -mbl=0. This allows extra blank lines to be written for subs and |
|
247
|
|
|
|
|
|
|
# packages even with the default -mbl=1 |
|
248
|
45
|
|
|
45
|
0
|
145
|
my ( $self, $count ) = @_; |
|
249
|
45
|
|
|
|
|
132
|
my $need = $count - $self->[_consecutive_blank_lines_]; |
|
250
|
45
|
|
|
|
|
91
|
my $rOpts = $self->[_rOpts_]; |
|
251
|
45
|
|
|
|
|
118
|
my $forced = $rOpts->{'maximum-consecutive-blank-lines'} > 0; |
|
252
|
45
|
|
|
|
|
153
|
foreach ( 0 .. $need - 1 ) { |
|
253
|
31
|
|
|
|
|
94
|
$self->write_blank_code_line($forced); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
45
|
|
|
|
|
124
|
return; |
|
256
|
|
|
|
|
|
|
} ## end sub require_blank_code_lines |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub write_blank_code_line { |
|
259
|
873
|
|
|
873
|
0
|
2153
|
my ( $self, $forced ) = @_; |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# Write a blank line of code, given: |
|
262
|
|
|
|
|
|
|
# $forced = optional flag which, if set, forces the blank line |
|
263
|
|
|
|
|
|
|
# to be written. This allows the -mbl flag to be temporarily |
|
264
|
|
|
|
|
|
|
# exceeded. |
|
265
|
|
|
|
|
|
|
|
|
266
|
873
|
|
|
|
|
1833
|
my $rOpts = $self->[_rOpts_]; |
|
267
|
|
|
|
|
|
|
return |
|
268
|
|
|
|
|
|
|
if (!$forced |
|
269
|
|
|
|
|
|
|
&& $self->[_consecutive_blank_lines_] >= |
|
270
|
873
|
100
|
100
|
|
|
4693
|
$rOpts->{'maximum-consecutive-blank-lines'} ); |
|
271
|
|
|
|
|
|
|
|
|
272
|
771
|
|
|
|
|
1551
|
$self->[_consecutive_nonblank_lines_] = 0; |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# Balance old blanks against new (forced) blanks instead of writing them. |
|
275
|
|
|
|
|
|
|
# This fixes case b1073. |
|
276
|
771
|
50
|
66
|
|
|
3179
|
if ( !$forced && $self->[_consecutive_new_blank_lines_] > 0 ) { |
|
277
|
0
|
|
|
|
|
0
|
$self->[_consecutive_new_blank_lines_]--; |
|
278
|
0
|
|
|
|
|
0
|
return; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
|
|
281
|
771
|
|
|
|
|
1244
|
${ $self->[_routput_string_] } .= "\n"; |
|
|
771
|
|
|
|
|
1951
|
|
|
282
|
|
|
|
|
|
|
|
|
283
|
771
|
|
|
|
|
1391
|
$self->[_output_line_number_]++; |
|
284
|
771
|
|
|
|
|
1278
|
$self->[_consecutive_blank_lines_]++; |
|
285
|
771
|
100
|
|
|
|
1848
|
$self->[_consecutive_new_blank_lines_]++ if ($forced); |
|
286
|
|
|
|
|
|
|
|
|
287
|
771
|
|
|
|
|
1651
|
return; |
|
288
|
|
|
|
|
|
|
} ## end sub write_blank_code_line |
|
289
|
|
|
|
|
|
|
|
|
290
|
39
|
|
|
39
|
|
334
|
use constant MAX_PRINTED_CHARS => 80; |
|
|
39
|
|
|
|
|
98
|
|
|
|
39
|
|
|
|
|
38490
|
|
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub write_code_line { |
|
293
|
7384
|
|
|
7384
|
0
|
15224
|
my ( $self, $str, $K ) = @_; |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# Write a line of code, given |
|
296
|
|
|
|
|
|
|
# $str = the line of code |
|
297
|
|
|
|
|
|
|
# $K = an optional check integer which, if if given, must |
|
298
|
|
|
|
|
|
|
# increase monotonically. This was added to catch cache |
|
299
|
|
|
|
|
|
|
# sequence errors in the vertical aligner. |
|
300
|
|
|
|
|
|
|
|
|
301
|
7384
|
|
|
|
|
13185
|
$self->[_consecutive_blank_lines_] = 0; |
|
302
|
7384
|
|
|
|
|
11355
|
$self->[_consecutive_new_blank_lines_] = 0; |
|
303
|
7384
|
|
|
|
|
11005
|
$self->[_consecutive_nonblank_lines_]++; |
|
304
|
7384
|
|
|
|
|
10860
|
$self->[_output_line_number_]++; |
|
305
|
|
|
|
|
|
|
|
|
306
|
7384
|
|
|
|
|
10512
|
${ $self->[_routput_string_] } .= $str; |
|
|
7384
|
|
|
|
|
21179
|
|
|
307
|
|
|
|
|
|
|
|
|
308
|
7384
|
100
|
|
|
|
17643
|
if ( $self->[_save_logfile_] ) { $self->check_line_lengths($str) } |
|
|
5
|
|
|
|
|
17
|
|
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
#---------------------------- |
|
311
|
|
|
|
|
|
|
# Convergence and error check |
|
312
|
|
|
|
|
|
|
#---------------------------- |
|
313
|
7384
|
100
|
|
|
|
15299
|
if ( defined($K) ) { |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# Convergence check: we are checking if all defined K values arrive in |
|
316
|
|
|
|
|
|
|
# the order which was defined by the caller. Quit checking if any |
|
317
|
|
|
|
|
|
|
# unexpected K value arrives. |
|
318
|
6581
|
100
|
|
|
|
13973
|
if ( $self->[_K_arrival_order_matches_] ) { |
|
319
|
3212
|
|
|
|
|
4986
|
my $Kt = pop @{ $self->[_rK_checklist_] }; |
|
|
3212
|
|
|
|
|
6749
|
|
|
320
|
3212
|
100
|
66
|
|
|
13252
|
if ( !defined($Kt) || $Kt != $K ) { |
|
321
|
265
|
|
|
|
|
936
|
$self->[_K_arrival_order_matches_] = 0; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
} |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
# Check for out-of-order arrivals of index K. The K values are the |
|
326
|
|
|
|
|
|
|
# token indexes of the last token of code lines, and they should come |
|
327
|
|
|
|
|
|
|
# out in increasing order. Otherwise something is seriously wrong. |
|
328
|
|
|
|
|
|
|
# Most likely a recent programming change to VerticalAligner.pm has |
|
329
|
|
|
|
|
|
|
# caused lines to go out in the wrong order. This could happen if |
|
330
|
|
|
|
|
|
|
# either the cache or buffer that it uses are emptied in the wrong |
|
331
|
|
|
|
|
|
|
# order. |
|
332
|
6581
|
50
|
33
|
|
|
16223
|
if ( $K < $self->[_K_last_arrival_] |
|
333
|
|
|
|
|
|
|
&& !$self->[_K_sequence_error_msg_] ) |
|
334
|
|
|
|
|
|
|
{ |
|
335
|
0
|
|
|
|
|
0
|
my $K_prev = $self->[_K_last_arrival_]; |
|
336
|
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
0
|
chomp $str; |
|
338
|
0
|
0
|
|
|
|
0
|
if ( length($str) > MAX_PRINTED_CHARS ) { |
|
339
|
0
|
|
|
|
|
0
|
$str = substr( $str, 0, MAX_PRINTED_CHARS ) . "..."; |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
0
|
my $msg = <<EOM; |
|
343
|
|
|
|
|
|
|
While operating on input stream with name: '$input_stream_name' |
|
344
|
|
|
|
|
|
|
Lines have arrived out of order in sub 'write_code_line' |
|
345
|
|
|
|
|
|
|
as detected by token index K=$K arriving after index K=$K_prev in the following line: |
|
346
|
|
|
|
|
|
|
$str |
|
347
|
|
|
|
|
|
|
This is probably due to a recent programming change and needs to be fixed. |
|
348
|
|
|
|
|
|
|
EOM |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
# Always die during development, this needs to be fixed |
|
351
|
0
|
|
|
|
|
0
|
if (DEVEL_MODE) { Fault($msg) } |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# Otherwise warn if string is not empty (added for b1378) |
|
354
|
0
|
0
|
|
|
|
0
|
$self->warning($msg) if ( length($str) ); |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
# Only issue this warning once |
|
357
|
0
|
|
|
|
|
0
|
$self->[_K_sequence_error_msg_] = $msg; |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
} |
|
360
|
6581
|
|
|
|
|
10422
|
$self->[_K_last_arrival_] = $K; |
|
361
|
|
|
|
|
|
|
} |
|
362
|
7384
|
|
|
|
|
16272
|
return; |
|
363
|
|
|
|
|
|
|
} ## end sub write_code_line |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub write_line { |
|
366
|
259
|
|
|
259
|
0
|
600
|
my ( $self, $str ) = @_; |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
# Write a line directly to the output, without any counting of blank or |
|
369
|
|
|
|
|
|
|
# non-blank lines. |
|
370
|
|
|
|
|
|
|
|
|
371
|
259
|
|
|
|
|
408
|
${ $self->[_routput_string_] } .= $str; |
|
|
259
|
|
|
|
|
721
|
|
|
372
|
|
|
|
|
|
|
|
|
373
|
259
|
50
|
|
|
|
693
|
if ( chomp $str ) { $self->[_output_line_number_]++; } |
|
|
259
|
|
|
|
|
473
|
|
|
374
|
259
|
50
|
|
|
|
563
|
if ( $self->[_save_logfile_] ) { $self->check_line_lengths($str) } |
|
|
0
|
|
|
|
|
0
|
|
|
375
|
|
|
|
|
|
|
|
|
376
|
259
|
|
|
|
|
514
|
return; |
|
377
|
|
|
|
|
|
|
} ## end sub write_line |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub check_line_lengths { |
|
380
|
5
|
|
|
5
|
0
|
10
|
my ( $self, $str ) = @_; |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
# collect info on line lengths for logfile |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# This calculation of excess line length ignores any internal tabs |
|
385
|
5
|
|
|
|
|
11
|
my $rOpts = $self->[_rOpts_]; |
|
386
|
5
|
|
|
|
|
10
|
chomp $str; |
|
387
|
5
|
|
|
|
|
7
|
my $len_str = length($str); |
|
388
|
5
|
|
|
|
|
19
|
my $exceed = $len_str - $rOpts->{'maximum-line-length'}; |
|
389
|
5
|
50
|
33
|
|
|
39
|
if ( $str && substr( $str, 0, 1 ) eq "\t" && $str =~ /^\t+/g ) { |
|
|
|
|
33
|
|
|
|
|
|
390
|
0
|
|
|
|
|
0
|
$exceed += pos($str) * $rOpts->{'indent-columns'}; |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# Note that we just incremented output line number to future value |
|
394
|
|
|
|
|
|
|
# so we must subtract 1 for current line number |
|
395
|
5
|
100
|
|
|
|
14
|
if ( $len_str > $self->[_max_output_line_length_] ) { |
|
396
|
3
|
|
|
|
|
6
|
$self->[_max_output_line_length_] = $len_str; |
|
397
|
3
|
|
|
|
|
8
|
$self->[_max_output_line_length_at_] = |
|
398
|
|
|
|
|
|
|
$self->[_output_line_number_] - 1; |
|
399
|
|
|
|
|
|
|
} |
|
400
|
|
|
|
|
|
|
|
|
401
|
5
|
50
|
|
|
|
90
|
if ( $exceed > 0 ) { |
|
402
|
0
|
|
|
|
|
0
|
my $output_line_number = $self->[_output_line_number_]; |
|
403
|
0
|
|
|
|
|
0
|
$self->[_last_line_length_error_] = $exceed; |
|
404
|
0
|
|
|
|
|
0
|
$self->[_last_line_length_error_at_] = $output_line_number - 1; |
|
405
|
0
|
0
|
|
|
|
0
|
if ( $self->[_line_length_error_count_] == 0 ) { |
|
406
|
0
|
|
|
|
|
0
|
$self->[_first_line_length_error_] = $exceed; |
|
407
|
0
|
|
|
|
|
0
|
$self->[_first_line_length_error_at_] = $output_line_number - 1; |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
|
|
410
|
0
|
0
|
|
|
|
0
|
if ( $self->[_last_line_length_error_] > |
|
411
|
|
|
|
|
|
|
$self->[_max_line_length_error_] ) |
|
412
|
|
|
|
|
|
|
{ |
|
413
|
0
|
|
|
|
|
0
|
$self->[_max_line_length_error_] = $exceed; |
|
414
|
0
|
|
|
|
|
0
|
$self->[_max_line_length_error_at_] = $output_line_number - 1; |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
0
|
0
|
|
|
|
0
|
if ( $self->[_line_length_error_count_] < MAX_NAG_MESSAGES ) { |
|
418
|
0
|
|
|
|
|
0
|
$self->write_logfile_entry( |
|
419
|
|
|
|
|
|
|
"Line length exceeded by $exceed characters\n"); |
|
420
|
|
|
|
|
|
|
} |
|
421
|
0
|
|
|
|
|
0
|
$self->[_line_length_error_count_]++; |
|
422
|
|
|
|
|
|
|
} |
|
423
|
5
|
|
|
|
|
15
|
return; |
|
424
|
|
|
|
|
|
|
} ## end sub check_line_lengths |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
sub report_line_length_errors { |
|
427
|
561
|
|
|
561
|
0
|
1392
|
my $self = shift; |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# Write summary info about line lengths to the log file |
|
430
|
|
|
|
|
|
|
|
|
431
|
561
|
|
|
|
|
1465
|
my $rOpts = $self->[_rOpts_]; |
|
432
|
561
|
|
|
|
|
1487
|
my $line_length_error_count = $self->[_line_length_error_count_]; |
|
433
|
561
|
50
|
|
|
|
1970
|
if ( $line_length_error_count == 0 ) { |
|
434
|
561
|
|
|
|
|
4121
|
$self->write_logfile_entry( |
|
435
|
|
|
|
|
|
|
"No lines exceeded $rOpts->{'maximum-line-length'} characters\n"); |
|
436
|
561
|
|
|
|
|
2062
|
my $max_output_line_length = $self->[_max_output_line_length_]; |
|
437
|
561
|
|
|
|
|
2076
|
my $max_output_line_length_at = $self->[_max_output_line_length_at_]; |
|
438
|
561
|
|
|
|
|
3751
|
$self->write_logfile_entry( |
|
439
|
|
|
|
|
|
|
" Maximum output line length was $max_output_line_length at line $max_output_line_length_at\n" |
|
440
|
|
|
|
|
|
|
); |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
else { |
|
444
|
|
|
|
|
|
|
|
|
445
|
0
|
0
|
|
|
|
0
|
my $word = ( $line_length_error_count > 1 ) ? "s" : EMPTY_STRING; |
|
446
|
0
|
|
|
|
|
0
|
$self->write_logfile_entry( |
|
447
|
|
|
|
|
|
|
"$line_length_error_count output line$word exceeded $rOpts->{'maximum-line-length'} characters:\n" |
|
448
|
|
|
|
|
|
|
); |
|
449
|
|
|
|
|
|
|
|
|
450
|
0
|
0
|
|
|
|
0
|
$word = ( $line_length_error_count > 1 ) ? "First" : EMPTY_STRING; |
|
451
|
0
|
|
|
|
|
0
|
my $first_line_length_error = $self->[_first_line_length_error_]; |
|
452
|
0
|
|
|
|
|
0
|
my $first_line_length_error_at = $self->[_first_line_length_error_at_]; |
|
453
|
0
|
|
|
|
|
0
|
$self->write_logfile_entry( |
|
454
|
|
|
|
|
|
|
" $word at line $first_line_length_error_at by $first_line_length_error characters\n" |
|
455
|
|
|
|
|
|
|
); |
|
456
|
|
|
|
|
|
|
|
|
457
|
0
|
0
|
|
|
|
0
|
if ( $line_length_error_count > 1 ) { |
|
458
|
0
|
|
|
|
|
0
|
my $max_line_length_error = $self->[_max_line_length_error_]; |
|
459
|
0
|
|
|
|
|
0
|
my $max_line_length_error_at = $self->[_max_line_length_error_at_]; |
|
460
|
0
|
|
|
|
|
0
|
my $last_line_length_error = $self->[_last_line_length_error_]; |
|
461
|
0
|
|
|
|
|
0
|
my $last_line_length_error_at = |
|
462
|
|
|
|
|
|
|
$self->[_last_line_length_error_at_]; |
|
463
|
0
|
|
|
|
|
0
|
$self->write_logfile_entry( |
|
464
|
|
|
|
|
|
|
" Maximum at line $max_line_length_error_at by $max_line_length_error characters\n" |
|
465
|
|
|
|
|
|
|
); |
|
466
|
0
|
|
|
|
|
0
|
$self->write_logfile_entry( |
|
467
|
|
|
|
|
|
|
" Last at line $last_line_length_error_at by $last_line_length_error characters\n" |
|
468
|
|
|
|
|
|
|
); |
|
469
|
|
|
|
|
|
|
} |
|
470
|
|
|
|
|
|
|
} |
|
471
|
561
|
|
|
|
|
2081
|
return; |
|
472
|
|
|
|
|
|
|
} ## end sub report_line_length_errors |
|
473
|
|
|
|
|
|
|
1; |