line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mylisp::Lint; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22
|
use 5.012; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
no warnings "experimental"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT = |
9
|
|
|
|
|
|
|
qw(is_define new_lint update_pos report ns in_package in_ns out_block out_ns set_name_value get_name_value); |
10
|
1
|
|
|
1
|
|
5
|
use Spp::Builtin; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
165
|
|
11
|
1
|
|
|
1
|
|
5
|
use Spp::Tools; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
96
|
|
12
|
1
|
|
|
1
|
|
261
|
use Mylisp::Type; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
575
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub is_define { |
15
|
0
|
|
|
0
|
0
|
|
my ($t, $name) = @_; |
16
|
0
|
|
|
|
|
|
my $stack = $t->{'stack'}; |
17
|
0
|
|
|
|
|
|
for my $ns (@{$stack}) { |
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $stable = $t->{'st'}; |
19
|
0
|
0
|
|
|
|
|
if (exists $stable->{$ns}{$name}) { return 1 } |
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
|
return 0; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new_lint { |
25
|
0
|
|
|
0
|
0
|
|
my $code = shift; |
26
|
0
|
|
|
|
|
|
my $parser = get_type_parser(); |
27
|
0
|
|
|
|
|
|
my $patter = get_type_ast(); |
28
|
0
|
|
|
|
|
|
{ 'code' => $code, |
29
|
|
|
|
|
|
|
'offline' => 'offline', |
30
|
|
|
|
|
|
|
'stack' => [], |
31
|
|
|
|
|
|
|
'st' => {}, |
32
|
|
|
|
|
|
|
'return' => 'str', |
33
|
|
|
|
|
|
|
'parser' => $parser, |
34
|
|
|
|
|
|
|
'patter' => $patter |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub update_pos { |
39
|
0
|
|
|
0
|
0
|
|
my ($t, $atom) = @_; |
40
|
0
|
|
|
|
|
|
$t->{'offline'} = offline($atom); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub report { |
44
|
0
|
|
|
0
|
0
|
|
my ($t, $message) = @_; |
45
|
0
|
|
|
|
|
|
my $code = $t->{'code'}; |
46
|
0
|
|
|
|
|
|
my $offline = $t->{'offline'}; |
47
|
0
|
|
|
|
|
|
my ($off_str, $line_str) = flat($offline); |
48
|
0
|
|
|
|
|
|
my $off = to_int($off_str); |
49
|
0
|
|
|
|
|
|
my $line = to_int($line_str); |
50
|
0
|
|
|
|
|
|
my $str = to_end(substr($code, $off)); |
51
|
0
|
|
|
|
|
|
say "line: $line $message"; |
52
|
0
|
|
|
|
|
|
say " $str\n ^"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub ns { |
56
|
0
|
|
|
0
|
0
|
|
my $t = shift; |
57
|
0
|
|
|
|
|
|
my $stack = $t->{'stack'}; |
58
|
0
|
|
|
|
|
|
return $stack->[0]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub in_package { |
62
|
0
|
|
|
0
|
0
|
|
my ($t, $ns) = @_; |
63
|
0
|
|
|
|
|
|
in_ns($t, $ns); |
64
|
0
|
|
|
|
|
|
set_name_value($t, $ns, 'package'); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub in_ns { |
68
|
0
|
|
|
0
|
0
|
|
my ($t, $ns) = @_; |
69
|
0
|
|
|
|
|
|
$t->{'st'}{$ns} = {}; |
70
|
0
|
|
|
|
|
|
unshift @{ $t->{'stack'} }, $ns; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub out_block { |
74
|
0
|
|
|
0
|
0
|
|
my ($t, $ns) = @_; |
75
|
0
|
|
|
|
|
|
out_ns($t); |
76
|
0
|
|
|
|
|
|
my $table = $t->{'st'}; |
77
|
0
|
|
|
|
|
|
delete $table->{$ns}; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
0
|
0
|
|
sub out_ns { my $t = shift; shift @{ $t->{'stack'} }; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_name_value { |
82
|
0
|
|
|
0
|
0
|
|
my ($t, $name, $value) = @_; |
83
|
0
|
|
|
|
|
|
my $ns = ns($t); |
84
|
0
|
|
|
|
|
|
my $stable = $t->{'st'}; |
85
|
0
|
0
|
|
|
|
|
if (exists $stable->{$ns}{$name}) { |
86
|
0
|
|
|
|
|
|
report($t, "exists symbol define |$name|."); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
$t->{'st'}{$ns}{$name} = $value; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_name_value { |
92
|
0
|
|
|
0
|
0
|
|
my ($t, $name) = @_; |
93
|
0
|
|
|
|
|
|
my $stack = $t->{'stack'}; |
94
|
0
|
|
|
|
|
|
for my $ns (@{$stack}) { |
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $stable = $t->{'st'}; |
96
|
0
|
0
|
|
|
|
|
if (exists $stable->{$ns}{$name}) { |
97
|
0
|
|
|
|
|
|
return $t->{'st'}{$ns}{$name}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
report($t, "symbol <$name> not define!"); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
1; |