line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# The Perl::Tidy::Debugger class shows line tokenization |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
##################################################################### |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Perl::Tidy::Debugger; |
8
|
38
|
|
|
38
|
|
262
|
use strict; |
|
38
|
|
|
|
|
75
|
|
|
38
|
|
|
|
|
1133
|
|
9
|
38
|
|
|
38
|
|
186
|
use warnings; |
|
38
|
|
|
|
|
92
|
|
|
38
|
|
|
|
|
1056
|
|
10
|
38
|
|
|
38
|
|
197
|
use English qw( -no_match_vars ); |
|
38
|
|
|
|
|
72
|
|
|
38
|
|
|
|
|
182
|
|
11
|
|
|
|
|
|
|
our $VERSION = '20230701'; |
12
|
|
|
|
|
|
|
|
13
|
38
|
|
|
38
|
|
14232
|
use constant EMPTY_STRING => q{}; |
|
38
|
|
|
|
|
83
|
|
|
38
|
|
|
|
|
4524
|
|
14
|
38
|
|
|
38
|
|
262
|
use constant SPACE => q{ }; |
|
38
|
|
|
|
|
86
|
|
|
38
|
|
|
|
|
26027
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
0
|
9
|
my ( $class, $filename, $is_encoded_data ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
20
|
return bless { |
21
|
|
|
|
|
|
|
_debug_file => $filename, |
22
|
|
|
|
|
|
|
_debug_file_opened => 0, |
23
|
|
|
|
|
|
|
_fh => undef, |
24
|
|
|
|
|
|
|
_is_encoded_data => $is_encoded_data, |
25
|
|
|
|
|
|
|
}, $class; |
26
|
|
|
|
|
|
|
} ## end sub new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub really_open_debug_file { |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
0
|
13
|
my $self = shift; |
31
|
2
|
|
|
|
|
14
|
my $debug_file = $self->{_debug_file}; |
32
|
2
|
|
|
|
|
10
|
my $is_encoded_data = $self->{_is_encoded_data}; |
33
|
2
|
|
|
|
|
15
|
my ( $fh, $filename ) = |
34
|
|
|
|
|
|
|
Perl::Tidy::streamhandle( $debug_file, 'w', $is_encoded_data ); |
35
|
2
|
50
|
|
|
|
25
|
if ( !$fh ) { |
36
|
0
|
|
|
|
|
0
|
Perl::Tidy::Warn("can't open $debug_file: $ERRNO\n"); |
37
|
|
|
|
|
|
|
} |
38
|
2
|
|
|
|
|
17
|
$self->{_debug_file_opened} = 1; |
39
|
2
|
|
|
|
|
6
|
$self->{_fh} = $fh; |
40
|
2
|
|
|
|
|
13
|
$fh->print( |
41
|
|
|
|
|
|
|
"Use -dump-token-types (-dtt) to get a list of token type codes\n"); |
42
|
2
|
|
|
|
|
4
|
return; |
43
|
|
|
|
|
|
|
} ## end sub really_open_debug_file |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub close_debug_file { |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
48
|
2
|
50
|
|
|
|
8
|
if ( $self->{_debug_file_opened} ) { |
49
|
2
|
50
|
|
|
|
4
|
if ( !eval { $self->{_fh}->close(); 1 } ) { |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ok, maybe no close function |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
5
|
return; |
55
|
|
|
|
|
|
|
} ## end sub close_debug_file |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub write_debug_entry { |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# This is a debug dump routine which may be modified as necessary |
60
|
|
|
|
|
|
|
# to dump tokens on a line-by-line basis. The output will be written |
61
|
|
|
|
|
|
|
# to the .DEBUG file when the -D flag is entered. |
62
|
7
|
|
|
7
|
0
|
20
|
my ( $self, $line_of_tokens ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
7
|
|
|
|
|
12
|
my $input_line = $line_of_tokens->{_line_text}; |
65
|
|
|
|
|
|
|
|
66
|
7
|
|
|
|
|
12
|
my $rtoken_type = $line_of_tokens->{_rtoken_type}; |
67
|
7
|
|
|
|
|
12
|
my $rtokens = $line_of_tokens->{_rtokens}; |
68
|
7
|
|
|
|
|
20
|
my $rlevels = $line_of_tokens->{_rlevels}; |
69
|
|
|
|
|
|
|
|
70
|
7
|
|
|
|
|
14
|
my $input_line_number = $line_of_tokens->{_line_number}; |
71
|
7
|
|
|
|
|
14
|
my $line_type = $line_of_tokens->{_line_type}; |
72
|
|
|
|
|
|
|
|
73
|
7
|
|
|
|
|
10
|
my ( $j, $num ); |
74
|
|
|
|
|
|
|
|
75
|
7
|
|
|
|
|
17
|
my $token_str = "$input_line_number: "; |
76
|
7
|
|
|
|
|
14
|
my $reconstructed_original = "$input_line_number: "; |
77
|
|
|
|
|
|
|
|
78
|
7
|
|
|
|
|
15
|
my $pattern = EMPTY_STRING; |
79
|
7
|
|
|
|
|
20
|
my @next_char = ( '"', '"' ); |
80
|
7
|
|
|
|
|
11
|
my $i_next = 0; |
81
|
7
|
100
|
|
|
|
21
|
unless ( $self->{_debug_file_opened} ) { $self->really_open_debug_file() } |
|
2
|
|
|
|
|
16
|
|
82
|
7
|
|
|
|
|
286
|
my $fh = $self->{_fh}; |
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
14
|
foreach my $j ( 0 .. @{$rtoken_type} - 1 ) { |
|
7
|
|
|
|
|
41
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# testing patterns |
87
|
20
|
100
|
|
|
|
41
|
if ( $rtoken_type->[$j] eq 'k' ) { |
88
|
2
|
|
|
|
|
7
|
$pattern .= $rtokens->[$j]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
18
|
|
|
|
|
28
|
$pattern .= $rtoken_type->[$j]; |
92
|
|
|
|
|
|
|
} |
93
|
20
|
|
|
|
|
31
|
$reconstructed_original .= $rtokens->[$j]; |
94
|
20
|
|
|
|
|
25
|
$num = length( $rtokens->[$j] ); |
95
|
20
|
|
|
|
|
31
|
my $type_str = $rtoken_type->[$j]; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# be sure there are no blank tokens (shouldn't happen) |
98
|
|
|
|
|
|
|
# This can only happen if a programming error has been made |
99
|
|
|
|
|
|
|
# because all valid tokens are non-blank |
100
|
20
|
50
|
|
|
|
39
|
if ( $type_str eq SPACE ) { |
101
|
0
|
|
|
|
|
0
|
$fh->print("BLANK TOKEN on the next line\n"); |
102
|
0
|
|
|
|
|
0
|
$type_str = $next_char[$i_next]; |
103
|
0
|
|
|
|
|
0
|
$i_next = 1 - $i_next; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
20
|
100
|
|
|
|
35
|
if ( length($type_str) == 1 ) { |
107
|
19
|
|
|
|
|
32
|
$type_str = $type_str x $num; |
108
|
|
|
|
|
|
|
} |
109
|
20
|
|
|
|
|
35
|
$token_str .= $type_str; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Write what you want here ... |
113
|
|
|
|
|
|
|
# $fh->print "$input_line\n"; |
114
|
|
|
|
|
|
|
# $fh->print "$pattern\n"; |
115
|
7
|
|
|
|
|
37
|
$fh->print("$reconstructed_original\n"); |
116
|
7
|
|
|
|
|
34
|
$fh->print("$token_str\n"); |
117
|
|
|
|
|
|
|
|
118
|
7
|
|
|
|
|
24
|
return; |
119
|
|
|
|
|
|
|
} ## end sub write_debug_entry |
120
|
|
|
|
|
|
|
1; |