line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# The Perl::Tidy::IndentationItem class supplies items which contain |
4
|
|
|
|
|
|
|
# how much whitespace should be used at the start of a line |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
##################################################################### |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Perl::Tidy::IndentationItem; |
9
|
38
|
|
|
38
|
|
288
|
use strict; |
|
38
|
|
|
|
|
112
|
|
|
38
|
|
|
|
|
1158
|
|
10
|
38
|
|
|
38
|
|
230
|
use warnings; |
|
38
|
|
|
|
|
115
|
|
|
38
|
|
|
|
|
4289
|
|
11
|
|
|
|
|
|
|
our $VERSION = '20230701'; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
0
|
BEGIN { |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Array index names |
16
|
|
|
|
|
|
|
# Do not combine with other BEGIN blocks (c101). |
17
|
38
|
|
|
38
|
|
56149
|
my $i = 0; |
18
|
|
|
|
|
|
|
use constant { |
19
|
38
|
|
|
|
|
6834
|
_spaces_ => $i++, |
20
|
|
|
|
|
|
|
_level_ => $i++, |
21
|
|
|
|
|
|
|
_ci_level_ => $i++, |
22
|
|
|
|
|
|
|
_available_spaces_ => $i++, |
23
|
|
|
|
|
|
|
_closed_ => $i++, |
24
|
|
|
|
|
|
|
_comma_count_ => $i++, |
25
|
|
|
|
|
|
|
_lp_item_index_ => $i++, |
26
|
|
|
|
|
|
|
_have_child_ => $i++, |
27
|
|
|
|
|
|
|
_recoverable_spaces_ => $i++, |
28
|
|
|
|
|
|
|
_align_seqno_ => $i++, |
29
|
|
|
|
|
|
|
_marked_ => $i++, |
30
|
|
|
|
|
|
|
_stack_depth_ => $i++, |
31
|
|
|
|
|
|
|
_K_begin_line_ => $i++, |
32
|
|
|
|
|
|
|
_arrow_count_ => $i++, |
33
|
|
|
|
|
|
|
_standard_spaces_ => $i++, |
34
|
|
|
|
|
|
|
_K_extra_space_ => $i++, |
35
|
38
|
|
|
38
|
|
316
|
}; |
|
38
|
|
|
|
|
168
|
|
36
|
|
|
|
|
|
|
} ## end BEGIN |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub AUTOLOAD { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Catch any undefined sub calls so that we are sure to get |
41
|
|
|
|
|
|
|
# some diagnostic information. This sub should never be called |
42
|
|
|
|
|
|
|
# except for a programming error. |
43
|
0
|
|
|
0
|
|
0
|
our $AUTOLOAD; |
44
|
0
|
0
|
|
|
|
0
|
return if ( $AUTOLOAD =~ /\bDESTROY$/ ); |
45
|
0
|
|
|
|
|
0
|
my ( $pkg, $fname, $lno ) = caller(); |
46
|
0
|
|
|
|
|
0
|
my $my_package = __PACKAGE__; |
47
|
0
|
|
|
|
|
0
|
print STDERR <<EOM; |
48
|
|
|
|
|
|
|
====================================================================== |
49
|
|
|
|
|
|
|
Error detected in package '$my_package', version $VERSION |
50
|
|
|
|
|
|
|
Received unexpected AUTOLOAD call for sub '$AUTOLOAD' |
51
|
|
|
|
|
|
|
Called from package: '$pkg' |
52
|
|
|
|
|
|
|
Called from File '$fname' at line '$lno' |
53
|
|
|
|
|
|
|
This error is probably due to a recent programming change |
54
|
|
|
|
|
|
|
====================================================================== |
55
|
|
|
|
|
|
|
EOM |
56
|
0
|
|
|
|
|
0
|
exit 1; |
57
|
|
|
|
|
|
|
} ## end sub AUTOLOAD |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
0
|
|
|
sub DESTROY { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# required to avoid call to AUTOLOAD in some versions of perl |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Create an 'indentation_item' which describes one level of leading |
67
|
|
|
|
|
|
|
# whitespace when the '-lp' indentation is used. |
68
|
608
|
|
|
608
|
0
|
4015
|
my ( $class, %input_hash ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# DEFINITIONS: |
71
|
|
|
|
|
|
|
# spaces => # total leading white spaces |
72
|
|
|
|
|
|
|
# level => # the indentation 'level' |
73
|
|
|
|
|
|
|
# ci_level => # the 'continuation level' |
74
|
|
|
|
|
|
|
# available_spaces => # how many left spaces available |
75
|
|
|
|
|
|
|
# # for this level |
76
|
|
|
|
|
|
|
# closed => # index where we saw closing '}' |
77
|
|
|
|
|
|
|
# comma_count => # how many commas at this level? |
78
|
|
|
|
|
|
|
# lp_item_index => # index in output batch list |
79
|
|
|
|
|
|
|
# have_child => # any dependents? |
80
|
|
|
|
|
|
|
# recoverable_spaces => # how many spaces to the right |
81
|
|
|
|
|
|
|
# # we would like to move to get |
82
|
|
|
|
|
|
|
# # alignment (negative if left) |
83
|
|
|
|
|
|
|
# align_seqno => # if we are aligning with an opening structure, |
84
|
|
|
|
|
|
|
# # this is its seqno |
85
|
|
|
|
|
|
|
# marked => # if visited by corrector logic |
86
|
|
|
|
|
|
|
# stack_depth => # indentation nesting depth |
87
|
|
|
|
|
|
|
# K_begin_line => # first token index K of this level |
88
|
|
|
|
|
|
|
# arrow_count => # how many =>'s |
89
|
|
|
|
|
|
|
|
90
|
608
|
|
|
|
|
1349
|
my $self = []; |
91
|
608
|
|
|
|
|
1325
|
$self->[_spaces_] = $input_hash{spaces}; |
92
|
608
|
|
|
|
|
1082
|
$self->[_level_] = $input_hash{level}; |
93
|
608
|
|
|
|
|
973
|
$self->[_ci_level_] = $input_hash{ci_level}; |
94
|
608
|
|
|
|
|
1038
|
$self->[_available_spaces_] = $input_hash{available_spaces}; |
95
|
608
|
|
|
|
|
1145
|
$self->[_closed_] = -1; |
96
|
608
|
|
|
|
|
1192
|
$self->[_comma_count_] = 0; |
97
|
608
|
|
|
|
|
1267
|
$self->[_lp_item_index_] = $input_hash{lp_item_index}; |
98
|
608
|
|
|
|
|
990
|
$self->[_have_child_] = 0; |
99
|
608
|
|
|
|
|
1151
|
$self->[_recoverable_spaces_] = 0; |
100
|
608
|
|
|
|
|
1070
|
$self->[_align_seqno_] = $input_hash{align_seqno}; |
101
|
608
|
|
|
|
|
1170
|
$self->[_marked_] = 0; |
102
|
608
|
|
|
|
|
1003
|
$self->[_stack_depth_] = $input_hash{stack_depth}; |
103
|
608
|
|
|
|
|
1304
|
$self->[_K_begin_line_] = $input_hash{K_begin_line}; |
104
|
608
|
|
|
|
|
894
|
$self->[_arrow_count_] = 0; |
105
|
608
|
|
|
|
|
966
|
$self->[_standard_spaces_] = $input_hash{standard_spaces}; |
106
|
608
|
|
|
|
|
1370
|
$self->[_K_extra_space_] = $input_hash{K_extra_space}; |
107
|
|
|
|
|
|
|
|
108
|
608
|
|
|
|
|
1098
|
bless $self, $class; |
109
|
608
|
|
|
|
|
2190
|
return $self; |
110
|
|
|
|
|
|
|
} ## end sub new |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub permanently_decrease_available_spaces { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# make a permanent reduction in the available indentation spaces |
115
|
|
|
|
|
|
|
# at one indentation item. NOTE: if there are child nodes, their |
116
|
|
|
|
|
|
|
# total SPACES must be reduced by the caller. |
117
|
|
|
|
|
|
|
|
118
|
285
|
|
|
285
|
0
|
506
|
my ( $item, $spaces_needed ) = @_; |
119
|
285
|
|
|
|
|
516
|
my $available_spaces = $item->get_available_spaces(); |
120
|
285
|
100
|
|
|
|
580
|
my $deleted_spaces = |
121
|
|
|
|
|
|
|
( $available_spaces > $spaces_needed ) |
122
|
|
|
|
|
|
|
? $spaces_needed |
123
|
|
|
|
|
|
|
: $available_spaces; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Fixed for c085; a zero value must remain unchanged unless the closed |
126
|
|
|
|
|
|
|
# flag has been set. |
127
|
285
|
|
|
|
|
547
|
my $closed = $item->get_closed(); |
128
|
285
|
100
|
100
|
|
|
1122
|
$item->decrease_available_spaces($deleted_spaces) |
129
|
|
|
|
|
|
|
unless ( $available_spaces == 0 && $closed < 0 ); |
130
|
285
|
|
|
|
|
691
|
$item->decrease_SPACES($deleted_spaces); |
131
|
285
|
|
|
|
|
692
|
$item->set_recoverable_spaces(0); |
132
|
|
|
|
|
|
|
|
133
|
285
|
|
|
|
|
734
|
return $deleted_spaces; |
134
|
|
|
|
|
|
|
} ## end sub permanently_decrease_available_spaces |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub tentatively_decrease_available_spaces { |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# We are asked to tentatively delete $spaces_needed of indentation |
139
|
|
|
|
|
|
|
# for an indentation item. We may want to undo this later. NOTE: if |
140
|
|
|
|
|
|
|
# there are child nodes, their total SPACES must be reduced by the |
141
|
|
|
|
|
|
|
# caller. |
142
|
71
|
|
|
71
|
0
|
201
|
my ( $item, $spaces_needed ) = @_; |
143
|
71
|
|
|
|
|
171
|
my $available_spaces = $item->get_available_spaces(); |
144
|
71
|
100
|
|
|
|
198
|
my $deleted_spaces = |
145
|
|
|
|
|
|
|
( $available_spaces > $spaces_needed ) |
146
|
|
|
|
|
|
|
? $spaces_needed |
147
|
|
|
|
|
|
|
: $available_spaces; |
148
|
71
|
|
|
|
|
230
|
$item->decrease_available_spaces($deleted_spaces); |
149
|
71
|
|
|
|
|
205
|
$item->decrease_SPACES($deleted_spaces); |
150
|
71
|
|
|
|
|
229
|
$item->increase_recoverable_spaces($deleted_spaces); |
151
|
71
|
|
|
|
|
149
|
return $deleted_spaces; |
152
|
|
|
|
|
|
|
} ## end sub tentatively_decrease_available_spaces |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub get_stack_depth { |
155
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[_stack_depth_]; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub get_spaces { |
159
|
6462
|
|
|
6462
|
0
|
13492
|
return $_[0]->[_spaces_]; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub get_standard_spaces { |
163
|
25
|
|
|
25
|
0
|
54
|
return $_[0]->[_standard_spaces_]; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub get_marked { |
167
|
3065
|
|
|
3065
|
0
|
7344
|
return $_[0]->[_marked_]; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub set_marked { |
171
|
608
|
|
|
608
|
0
|
1113
|
my ( $self, $value ) = @_; |
172
|
608
|
50
|
|
|
|
1142
|
if ( defined($value) ) { |
173
|
608
|
|
|
|
|
915
|
$self->[_marked_] = $value; |
174
|
|
|
|
|
|
|
} |
175
|
608
|
|
|
|
|
1023
|
return $self->[_marked_]; |
176
|
|
|
|
|
|
|
} ## end sub set_marked |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub get_available_spaces { |
179
|
1018
|
|
|
1018
|
0
|
1934
|
return $_[0]->[_available_spaces_]; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub decrease_SPACES { |
183
|
885
|
|
|
885
|
0
|
1375
|
my ( $self, $value ) = @_; |
184
|
885
|
50
|
|
|
|
1529
|
if ( defined($value) ) { |
185
|
885
|
|
|
|
|
1273
|
$self->[_spaces_] -= $value; |
186
|
|
|
|
|
|
|
} |
187
|
885
|
|
|
|
|
1537
|
return $self->[_spaces_]; |
188
|
|
|
|
|
|
|
} ## end sub decrease_SPACES |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub decrease_available_spaces { |
191
|
356
|
|
|
356
|
0
|
634
|
my ( $self, $value ) = @_; |
192
|
|
|
|
|
|
|
|
193
|
356
|
50
|
|
|
|
703
|
if ( defined($value) ) { |
194
|
356
|
|
|
|
|
581
|
$self->[_available_spaces_] -= $value; |
195
|
|
|
|
|
|
|
} |
196
|
356
|
|
|
|
|
563
|
return $self->[_available_spaces_]; |
197
|
|
|
|
|
|
|
} ## end sub decrease_available_spaces |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub get_align_seqno { |
200
|
608
|
|
|
608
|
0
|
1556
|
return $_[0]->[_align_seqno_]; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub get_recoverable_spaces { |
204
|
300
|
|
|
300
|
0
|
1097
|
return $_[0]->[_recoverable_spaces_]; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub set_recoverable_spaces { |
208
|
445
|
|
|
445
|
0
|
811
|
my ( $self, $value ) = @_; |
209
|
445
|
50
|
|
|
|
889
|
if ( defined($value) ) { |
210
|
445
|
|
|
|
|
814
|
$self->[_recoverable_spaces_] = $value; |
211
|
|
|
|
|
|
|
} |
212
|
445
|
|
|
|
|
764
|
return $self->[_recoverable_spaces_]; |
213
|
|
|
|
|
|
|
} ## end sub set_recoverable_spaces |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub increase_recoverable_spaces { |
216
|
71
|
|
|
71
|
0
|
151
|
my ( $self, $value ) = @_; |
217
|
71
|
50
|
|
|
|
196
|
if ( defined($value) ) { |
218
|
71
|
|
|
|
|
144
|
$self->[_recoverable_spaces_] += $value; |
219
|
|
|
|
|
|
|
} |
220
|
71
|
|
|
|
|
123
|
return $self->[_recoverable_spaces_]; |
221
|
|
|
|
|
|
|
} ## end sub increase_recoverable_spaces |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub get_ci_level { |
224
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[_ci_level_]; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub get_level { |
228
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[_level_]; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub get_spaces_level_ci { |
232
|
1306
|
|
|
1306
|
0
|
2364
|
my $self = shift; |
233
|
1306
|
|
|
|
|
5087
|
return [ $self->[_spaces_], $self->[_level_], $self->[_ci_level_] ]; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub get_lp_item_index { |
237
|
62
|
|
|
62
|
0
|
148
|
return $_[0]->[_lp_item_index_]; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub get_K_begin_line { |
241
|
717
|
|
|
717
|
0
|
1616
|
return $_[0]->[_K_begin_line_]; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub get_K_extra_space { |
245
|
28
|
|
|
28
|
0
|
87
|
return $_[0]->[_K_extra_space_]; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub set_have_child { |
249
|
498
|
|
|
498
|
0
|
929
|
my ( $self, $value ) = @_; |
250
|
498
|
50
|
|
|
|
1102
|
if ( defined($value) ) { |
251
|
498
|
|
|
|
|
848
|
$self->[_have_child_] = $value; |
252
|
|
|
|
|
|
|
} |
253
|
498
|
|
|
|
|
955
|
return $self->[_have_child_]; |
254
|
|
|
|
|
|
|
} ## end sub set_have_child |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub get_have_child { |
257
|
69
|
|
|
69
|
0
|
184
|
return $_[0]->[_have_child_]; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub set_arrow_count { |
261
|
608
|
|
|
608
|
0
|
1061
|
my ( $self, $value ) = @_; |
262
|
608
|
50
|
|
|
|
1262
|
if ( defined($value) ) { |
263
|
608
|
|
|
|
|
1016
|
$self->[_arrow_count_] = $value; |
264
|
|
|
|
|
|
|
} |
265
|
608
|
|
|
|
|
1099
|
return $self->[_arrow_count_]; |
266
|
|
|
|
|
|
|
} ## end sub set_arrow_count |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub get_arrow_count { |
269
|
68
|
|
|
68
|
0
|
171
|
return $_[0]->[_arrow_count_]; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub set_comma_count { |
273
|
608
|
|
|
608
|
0
|
1031
|
my ( $self, $value ) = @_; |
274
|
608
|
50
|
|
|
|
1265
|
if ( defined($value) ) { |
275
|
608
|
|
|
|
|
982
|
$self->[_comma_count_] = $value; |
276
|
|
|
|
|
|
|
} |
277
|
608
|
|
|
|
|
1114
|
return $self->[_comma_count_]; |
278
|
|
|
|
|
|
|
} ## end sub set_comma_count |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub get_comma_count { |
281
|
68
|
|
|
68
|
0
|
154
|
return $_[0]->[_comma_count_]; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub set_closed { |
285
|
608
|
|
|
608
|
0
|
1115
|
my ( $self, $value ) = @_; |
286
|
608
|
50
|
|
|
|
1272
|
if ( defined($value) ) { |
287
|
608
|
|
|
|
|
1049
|
$self->[_closed_] = $value; |
288
|
|
|
|
|
|
|
} |
289
|
608
|
|
|
|
|
1195
|
return $self->[_closed_]; |
290
|
|
|
|
|
|
|
} ## end sub set_closed |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
sub get_closed { |
293
|
1142
|
|
|
1142
|
0
|
2520
|
return $_[0]->[_closed_]; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
1; |