line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use 5.010; |
3
|
22
|
|
|
22
|
|
9348
|
use strict; |
|
22
|
|
|
|
|
74
|
|
4
|
22
|
|
|
22
|
|
97
|
use warnings; |
|
22
|
|
|
|
|
34
|
|
|
22
|
|
|
|
|
388
|
|
5
|
22
|
|
|
22
|
|
90
|
#use Log::Any '$log'; |
|
22
|
|
|
|
|
32
|
|
|
22
|
|
|
|
|
607
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Mo qw(build default); |
8
|
22
|
|
|
22
|
|
103
|
|
|
22
|
|
|
|
|
36
|
|
|
22
|
|
|
|
|
109
|
|
9
|
|
|
|
|
|
|
extends 'Data::Sah::Compiler::TH'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
12
|
|
|
|
|
|
|
our $DATE = '2022-08-20'; # DATE |
13
|
|
|
|
|
|
|
our $DIST = 'Data-Sah'; # DIST |
14
|
|
|
|
|
|
|
our $VERSION = '0.912'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# handled in compiler's before_all_clauses() |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
90
|
0
|
|
# handled in compiler's after_all_clauses() |
20
|
|
|
|
54
|
0
|
|
|
21
|
|
|
|
498
|
0
|
|
|
22
|
|
|
|
54
|
0
|
|
my ($self, $cd) = @_; |
23
|
|
|
|
6
|
0
|
|
$self->compiler->_ignore_clause_and_attrs($cd); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
27
|
|
|
|
0
|
0
|
|
$self->compiler->_ignore_clause_and_attrs($cd); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
27
|
|
|
27
|
0
|
69
|
my ($self, $cd) = @_; |
31
|
27
|
|
|
|
|
83
|
$self->compiler->_ignore_clause_and_attrs($cd); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
35
|
27
|
|
|
27
|
0
|
67
|
$self->compiler->_ignore_clause($cd); |
36
|
27
|
|
|
|
|
85
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
39
|
|
|
|
|
|
|
$self->compiler->_ignore_clause($cd); |
40
|
27
|
|
|
27
|
0
|
60
|
} |
41
|
27
|
|
|
|
|
76
|
|
42
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
43
|
|
|
|
|
|
|
$self->compiler->_ignore_clause($cd); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
0
|
0
|
0
|
|
46
|
0
|
|
|
|
|
0
|
my ($self, $cd) = @_; |
47
|
|
|
|
|
|
|
$self->compiler->_ignore_clause($cd); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
27
|
|
|
27
|
0
|
59
|
my ($self, $cd) = @_; |
51
|
27
|
|
|
|
|
107
|
$self->compiler->_ignore_clause($cd); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
55
|
27
|
|
|
27
|
0
|
65
|
$self->compiler->_ignore_clause($cd); |
56
|
27
|
|
|
|
|
82
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# temporarily use temporary variable for referring to data (e.g. when converting |
59
|
|
|
|
|
|
|
# non-number to number for checking in clauses, or prefiltering) |
60
|
27
|
|
|
27
|
0
|
107
|
my ($self, $cd, $expr) = @_; |
61
|
27
|
|
|
|
|
76
|
my $c = $self->compiler; |
62
|
|
|
|
|
|
|
#$log->errorf("TMP: set_tmp_data_term"); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$expr //= $cd->{data_term}; |
65
|
0
|
|
|
0
|
0
|
0
|
|
66
|
0
|
|
|
|
|
0
|
my $tdn = $cd->{args}{tmp_data_name}; |
67
|
|
|
|
|
|
|
my $tdt = $cd->{args}{tmp_data_term}; |
68
|
|
|
|
|
|
|
my $t = $c->expr_array_subscript($tdt, $cd->{_subdata_level}); |
69
|
|
|
|
|
|
|
unless ($cd->{_save_data_term}) { |
70
|
0
|
|
|
0
|
0
|
0
|
$c->add_var($cd, $tdn, []); |
71
|
0
|
|
|
|
|
0
|
$cd->{_save_data_term} = $cd->{data_term}; |
72
|
|
|
|
|
|
|
$cd->{data_term} = $t; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
local $cd->{_debug_ccl_note} = 'set temporary data term'; |
75
|
|
|
|
|
|
|
$c->add_ccl($cd, "(".$c->expr_set($t, $expr). ", ".$c->true.")", |
76
|
|
|
|
|
|
|
{err_msg => ''}); |
77
|
530
|
|
|
530
|
0
|
964
|
} |
78
|
530
|
|
|
|
|
1010
|
|
79
|
|
|
|
|
|
|
my ($self, $cd) = @_; |
80
|
|
|
|
|
|
|
my $c = $self->compiler; |
81
|
530
|
|
66
|
|
|
1934
|
#$log->errorf("TMP: restore_data_term"); |
82
|
|
|
|
|
|
|
|
83
|
530
|
|
|
|
|
841
|
my $tdt = $cd->{args}{tmp_data_term}; |
84
|
530
|
|
|
|
|
771
|
if ($cd->{_save_data_term}) { |
85
|
530
|
|
|
|
|
1360
|
$cd->{data_term} = delete($cd->{_save_data_term}); |
86
|
530
|
50
|
|
|
|
1328
|
local $cd->{_debug_ccl_note} = 'restore original data term'; |
87
|
530
|
|
|
|
|
1503
|
$c->add_ccl($cd, "(".$c->expr_pop($tdt). ", ".$c->true.")", |
88
|
530
|
|
|
|
|
988
|
{err_msg => ''}); |
89
|
530
|
|
|
|
|
775
|
} |
90
|
|
|
|
|
|
|
} |
91
|
530
|
|
|
|
|
1272
|
|
92
|
530
|
|
|
|
|
1349
|
my ($self, $which, $cd) = @_; |
93
|
|
|
|
|
|
|
my $c = $self->compiler; |
94
|
|
|
|
|
|
|
my $cv = $cd->{cl_value}; |
95
|
|
|
|
|
|
|
my $dt = $cd->{data_term}; |
96
|
|
|
|
|
|
|
|
97
|
526
|
|
|
526
|
0
|
923
|
my $jccl; |
98
|
526
|
|
|
|
|
992
|
{ |
99
|
|
|
|
|
|
|
local $cd->{ccls} = []; |
100
|
|
|
|
|
|
|
for my $i (0..@$cv-1) { |
101
|
526
|
|
|
|
|
1756
|
local $cd->{spath} = [@{ $cd->{spath} }, $i]; |
102
|
526
|
50
|
|
|
|
1074
|
my $sch = $cv->[$i]; |
103
|
526
|
|
|
|
|
1011
|
my %iargs = %{$cd->{args}}; |
104
|
526
|
|
|
|
|
1089
|
$iargs{outer_cd} = $cd; |
105
|
526
|
|
|
|
|
1353
|
$iargs{schema} = $sch; |
106
|
|
|
|
|
|
|
$iargs{schema_is_normalized} = 0; |
107
|
|
|
|
|
|
|
$iargs{cache} = $cd->{args}{cache}; |
108
|
|
|
|
|
|
|
$iargs{indent_level}++; |
109
|
|
|
|
|
|
|
my $icd = $c->compile(%iargs); |
110
|
|
|
|
|
|
|
my @code = ( |
111
|
27
|
|
|
27
|
0
|
63
|
$icd->{result}, |
112
|
27
|
|
|
|
|
75
|
); |
113
|
27
|
|
|
|
|
114
|
$c->add_ccl($cd, join("", @code)); |
114
|
27
|
|
|
|
|
44
|
} |
115
|
|
|
|
|
|
|
if ($which eq 'all') { |
116
|
27
|
|
|
|
|
33
|
$jccl = $c->join_ccls( |
117
|
|
|
|
|
|
|
$cd, $cd->{ccls}, {err_msg=>''}); |
118
|
27
|
|
|
|
|
38
|
} else { |
|
27
|
|
|
|
|
58
|
|
119
|
27
|
|
|
|
|
70
|
$jccl = $c->join_ccls( |
120
|
54
|
|
|
|
|
69
|
$cd, $cd->{ccls}, {err_msg=>'', op=>'or'}); |
|
54
|
|
|
|
|
136
|
|
121
|
54
|
|
|
|
|
87
|
} |
122
|
54
|
|
|
|
|
62
|
} |
|
54
|
|
|
|
|
474
|
|
123
|
54
|
|
|
|
|
132
|
$c->add_ccl($cd, $jccl); |
124
|
54
|
|
|
|
|
103
|
} |
125
|
54
|
|
|
|
|
70
|
|
126
|
54
|
|
|
|
|
85
|
my ($self, $cd) = @_; |
127
|
54
|
|
|
|
|
66
|
my $c = $self->compiler; |
128
|
54
|
|
|
|
|
271
|
my $cv = $cd->{cl_value}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my ($cond, $then, $else) = @$cv; |
131
|
54
|
|
|
|
|
215
|
|
132
|
54
|
|
|
|
|
184
|
unless (!ref($cond) && ref($then) eq 'ARRAY' && !$else) { |
133
|
|
|
|
|
|
|
$c->_die($cd, "Sorry, for 'if' clause, I currently can only handle COND=str (expr), THEN=array (schema), and no ELSE"); |
134
|
27
|
100
|
|
|
|
63
|
} |
135
|
|
|
|
|
|
|
|
136
|
12
|
|
|
|
|
34
|
# COND |
137
|
|
|
|
|
|
|
my $comp_cond = $c->expr($cd, $cond); |
138
|
|
|
|
|
|
|
|
139
|
15
|
|
|
|
|
56
|
# THEN |
140
|
|
|
|
|
|
|
my $comp_then; |
141
|
|
|
|
|
|
|
{ |
142
|
27
|
|
|
|
|
100
|
local $cd->{ccls} = []; |
143
|
|
|
|
|
|
|
local $cd->{spath} = [@{ $cd->{spath} }, 'if']; |
144
|
|
|
|
|
|
|
my $sch = $then; |
145
|
|
|
|
|
|
|
my %iargs = %{$cd->{args}}; |
146
|
13
|
|
|
13
|
0
|
22
|
$iargs{outer_cd} = $cd; |
147
|
13
|
|
|
|
|
34
|
$iargs{schema} = $sch; |
148
|
13
|
|
|
|
|
48
|
$iargs{schema_is_normalized} = 0; |
149
|
|
|
|
|
|
|
$iargs{cache} = $cd->{args}{cache}; |
150
|
13
|
|
|
|
|
24
|
$iargs{indent_level}++; |
151
|
|
|
|
|
|
|
my $icd = $c->compile(%iargs); |
152
|
13
|
50
|
33
|
|
|
58
|
my @code = ( |
|
|
|
33
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
$icd->{result}, |
154
|
|
|
|
|
|
|
); |
155
|
|
|
|
|
|
|
$comp_then = join("", @code); |
156
|
|
|
|
|
|
|
} |
157
|
13
|
|
|
|
|
57
|
|
158
|
|
|
|
|
|
|
$c->add_ccl( |
159
|
|
|
|
|
|
|
$cd, |
160
|
13
|
|
|
|
|
154011
|
$c->expr_ternary($comp_cond, $comp_then, $c->true, {err_msg=>''}), |
161
|
|
|
|
|
|
|
); |
162
|
13
|
|
|
|
|
21
|
} |
|
13
|
|
|
|
|
30
|
|
163
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
29
|
|
164
|
13
|
|
|
|
|
20
|
1; |
165
|
13
|
|
|
|
|
18
|
# ABSTRACT: Base class for programming-language emiting compiler's type handlers |
|
13
|
|
|
|
|
138
|
|
166
|
13
|
|
|
|
|
33
|
|
167
|
13
|
|
|
|
|
18
|
|
168
|
13
|
|
|
|
|
22
|
=pod |
169
|
13
|
|
|
|
|
20
|
|
170
|
13
|
|
|
|
|
19
|
=encoding UTF-8 |
171
|
13
|
|
|
|
|
75
|
|
172
|
|
|
|
|
|
|
=head1 NAME |
173
|
|
|
|
|
|
|
|
174
|
13
|
|
|
|
|
54
|
Data::Sah::Compiler::Prog::TH - Base class for programming-language emiting compiler's type handlers |
175
|
13
|
|
|
|
|
169
|
|
176
|
|
|
|
|
|
|
=head1 VERSION |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This document describes version 0.912 of Data::Sah::Compiler::Prog::TH (from Perl distribution Data-Sah), released on 2022-08-20. |
179
|
13
|
|
|
|
|
38
|
|
180
|
|
|
|
|
|
|
=for Pod::Coverage ^(compiler|clause_.+|handle_.+|gen_.+|set_tmp_data_term|restore_data_term)$ |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 HOMEPAGE |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah>. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 SOURCE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Data-Sah>. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 CONTRIBUTING |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
To contribute, you can send patches by email/via RT, or send pull requests on |
198
|
|
|
|
|
|
|
GitHub. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Most of the time, you don't need to build the distribution yourself. You can |
201
|
|
|
|
|
|
|
simply modify the code, then test via: |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
% prove -l |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
If you want to build the distribution (e.g. to try to install it locally on your |
206
|
|
|
|
|
|
|
system), you can install L<Dist::Zilla>, |
207
|
|
|
|
|
|
|
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, |
208
|
|
|
|
|
|
|
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other |
209
|
|
|
|
|
|
|
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond |
210
|
|
|
|
|
|
|
that are considered a bug and can be reported to me. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
217
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 BUGS |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
224
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
225
|
|
|
|
|
|
|
feature. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |