line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
3
|
|
|
3
|
|
11219
|
package YATT::Translator::Perl; use YATT::Inc; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
25
|
|
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
83
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings qw(FATAL all NONFATAL misc); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
149
|
|
5
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
259
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#======================================== |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %TYPE_MAP; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
17
|
use base qw(YATT::Registry); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1737
|
|
12
|
|
|
|
|
|
|
use YATT::Fields [cf_mode => 'render'] |
13
|
3
|
|
|
0
|
|
32
|
, [cf_product => sub {[]}] |
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
, qw(target_cache |
15
|
|
|
|
|
|
|
delayed_target |
16
|
|
|
|
|
|
|
generating_widget |
17
|
|
|
|
|
|
|
cf_pagevars |
18
|
3
|
|
|
3
|
|
16
|
cf_debug_translator); |
|
3
|
|
|
|
|
6
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
16
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
3
|
|
|
|
|
144
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = qw(qqvalue qparen); |
22
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
15
|
use YATT::Registry::NS; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
198
|
|
25
|
3
|
|
|
3
|
|
15
|
use YATT::Widget; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
144
|
|
26
|
3
|
|
|
3
|
|
16
|
use YATT::Util qw(checked_eval add_arg_order_in terse_dump coalesce); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
198
|
|
27
|
3
|
|
|
|
|
291
|
use YATT::LRXML::Node qw(node_path node_body node_name |
28
|
|
|
|
|
|
|
node_size node_flag |
29
|
|
|
|
|
|
|
node_children |
30
|
|
|
|
|
|
|
create_node |
31
|
|
|
|
|
|
|
stringify_node |
32
|
3
|
|
|
3
|
|
15
|
TEXT_TYPE ELEMENT_TYPE ENTITY_TYPE); |
|
3
|
|
|
|
|
5
|
|
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
3
|
|
1812
|
use YATT::LRXML::EntityPath; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
230
|
|
35
|
3
|
|
|
3
|
|
25
|
use YATT::Util::Taint; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
294
|
|
36
|
3
|
|
|
3
|
|
19
|
use YATT::Util::Symbol qw(declare_alias); |
|
3
|
|
|
|
|
43
|
|
|
3
|
|
|
|
|
7708
|
|
37
|
|
|
|
|
|
|
require YATT::ArgMacro; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#======================================== |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub qqvalue ($); |
42
|
|
|
|
|
|
|
sub qparen ($); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#======================================== |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub after_configure { |
47
|
14
|
|
|
14
|
0
|
30
|
my MY $trans = shift; |
48
|
14
|
|
|
|
|
85
|
$trans->SUPER::after_configure; |
49
|
14
|
|
50
|
|
|
134
|
$trans->{cf_type_map} ||= \%TYPE_MAP; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub emit { |
53
|
142
|
|
|
142
|
0
|
306
|
my MY $gen = shift; |
54
|
142
|
|
|
|
|
246
|
my $script = join "", @{$gen->{cf_product}}; |
|
142
|
|
|
|
|
521
|
|
55
|
142
|
|
|
|
|
332
|
$gen->{cf_product} = []; |
56
|
142
|
|
|
|
|
745
|
$script; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#======================================== |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub call_handler { |
62
|
31
|
|
|
31
|
0
|
91
|
(my MY $trans, my ($method, $widget_path)) = splice @_, 0, 3; |
63
|
31
|
50
|
|
|
|
171
|
my ($handler, $pkg) = $trans->get_handler_to |
64
|
|
|
|
|
|
|
($method, ref $widget_path ? @$widget_path : split /[:\.]/, $widget_path); |
65
|
11
|
|
|
|
|
59
|
&YATT::break_handler; |
66
|
11
|
|
|
|
|
5275
|
$handler->($pkg, @_); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parse_elempath { |
70
|
161
|
|
|
161
|
0
|
453
|
my ($pack, @elpath) = @_; |
71
|
161
|
100
|
|
|
|
590
|
if (@elpath == 1) { |
72
|
142
|
50
|
|
|
|
320
|
if (ref $elpath[0]) { |
73
|
0
|
|
|
|
|
0
|
@elpath = @{$elpath[0]}; |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
} else { |
75
|
142
|
|
|
|
|
417
|
@elpath = split '/', $elpath[0]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# root dir should be ignored. |
80
|
161
|
50
|
33
|
|
|
1592
|
shift @elpath if !defined $elpath[0] || $elpath[0] eq ''; |
81
|
|
|
|
|
|
|
|
82
|
161
|
|
|
|
|
643
|
@elpath; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_handler_to { |
86
|
161
|
|
|
161
|
0
|
465
|
(my MY $trans, my ($method)) = splice @_, 0, 2; |
87
|
161
|
|
|
|
|
575
|
my @elpath = $trans->parse_elempath(@_); |
88
|
|
|
|
|
|
|
|
89
|
161
|
|
|
|
|
252
|
my @result; |
90
|
161
|
50
|
|
|
|
452
|
if (wantarray) { |
91
|
161
|
|
|
|
|
528
|
@result = $trans->lookup_handler_to($method, @elpath); |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
0
|
$result[0] = $trans->lookup_handler_to($method, @elpath); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
141
|
50
|
|
|
|
408
|
unless (@result) { |
97
|
0
|
|
|
|
|
0
|
croak "Can't find widget: " . join(":", @elpath); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
141
|
50
|
|
|
|
1001
|
wantarray ? @result : $result[0]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub lookup_handler_to { |
104
|
161
|
|
|
161
|
0
|
433
|
(my MY $trans, my ($method, @elpath)) = @_; |
105
|
|
|
|
|
|
|
|
106
|
161
|
|
|
|
|
492
|
$trans->{cf_mode} = $method; # XXX: local |
107
|
161
|
|
|
|
|
266
|
@{$trans->{cf_product}} = (); |
|
161
|
|
|
|
|
483
|
|
108
|
|
|
|
|
|
|
|
109
|
161
|
50
|
|
|
|
767
|
my Widget $widget = $trans->get_widget(@elpath) |
110
|
|
|
|
|
|
|
or return; |
111
|
|
|
|
|
|
|
|
112
|
156
|
|
|
|
|
757
|
$trans->ensure_widget_is_generated($widget); |
113
|
142
|
100
|
|
|
|
515
|
if (my $script = $trans->emit) { |
114
|
117
|
50
|
|
|
|
323
|
print STDERR $script if $trans->{cf_debug_translator}; |
115
|
117
|
|
|
|
|
541
|
$trans->checked_eval |
116
|
|
|
|
|
|
|
(join(";" |
117
|
|
|
|
|
|
|
, 'use strict' |
118
|
|
|
|
|
|
|
, 'use warnings FATAL => qw(all)' |
119
|
|
|
|
|
|
|
# XXX: 何が redefine されるかは分からないから… |
120
|
|
|
|
|
|
|
, 'no warnings "redefine"' |
121
|
|
|
|
|
|
|
, untaint_any($script))); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
141
|
|
|
|
|
551
|
my ($pkg, $funcname) = $trans->get_funcname_to($method, $widget); |
125
|
141
|
|
|
|
|
1506
|
my $handler = $pkg->can($funcname); |
126
|
|
|
|
|
|
|
|
127
|
141
|
50
|
|
|
|
447
|
return $handler unless wantarray; |
128
|
141
|
|
|
|
|
386
|
($handler |
129
|
|
|
|
|
|
|
, scalar $trans->get_package_from_widget($widget) |
130
|
|
|
|
|
|
|
, $widget); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_funcname_to { |
134
|
436
|
|
|
436
|
0
|
1025
|
(my MY $trans, my ($mode), my Widget $widget) = @_; |
135
|
436
|
|
|
|
|
1159
|
my $pkg = $trans->get_package_from_widget($widget); |
136
|
436
|
|
|
|
|
1343
|
my $fname = "${mode}_$$widget{cf_name}"; |
137
|
436
|
100
|
|
|
|
1823
|
wantarray ? ($pkg, $fname) : join("::", $pkg, $fname); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_package_from_widget { |
141
|
593
|
|
|
593
|
0
|
934
|
(my MY $trans, my Widget $widget) = @_; |
142
|
|
|
|
|
|
|
my $primary = $trans->get_package |
143
|
593
|
|
|
|
|
2164
|
(my Template $tmpl = $trans->nsobj($widget->{cf_template_nsid})); |
144
|
|
|
|
|
|
|
|
145
|
593
|
100
|
|
|
|
2505
|
return $primary unless wantarray; |
146
|
16
|
|
|
|
|
59
|
($primary, $trans->get_rc_package_from_template($tmpl)); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub get_rc_package_from_template { |
150
|
153
|
|
|
153
|
0
|
245
|
(my MY $trans, my Template $tmpl) = @_; |
151
|
153
|
|
|
|
|
721
|
$trans->get_package($trans->nsobj($tmpl->{cf_parent_nsid})); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#---------------------------------------- |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub generate { |
157
|
0
|
|
|
0
|
0
|
0
|
my MY $gen = shift; |
158
|
0
|
|
|
|
|
0
|
foreach my $elempath (@_) { |
159
|
0
|
0
|
|
|
|
0
|
if (my $widget = $gen->get_widget(@$elempath)) { |
|
|
0
|
|
|
|
|
|
160
|
0
|
|
|
|
|
0
|
$gen->ensure_widget_is_generated($widget); |
161
|
|
|
|
|
|
|
} elsif (my $ns = $gen->get_ns($elempath)) { |
162
|
0
|
|
|
|
|
0
|
$gen->ensure_ns_is_generated($ns); |
163
|
|
|
|
|
|
|
} else { |
164
|
0
|
|
|
|
|
0
|
croak "Invalid widget path: " . join(":", @$elempath); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
0
|
$gen->emit; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub mark_delayed_target { |
171
|
0
|
|
|
0
|
0
|
0
|
(my MY $gen, my Widget $widget) = @_; |
172
|
0
|
|
|
|
|
0
|
$gen->{delayed_target}{$widget->{cf_template_nsid}}++; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub ensure_widget_is_generated { |
176
|
243
|
|
|
243
|
0
|
506
|
(my MY $gen, my Widget $widget) = @_; |
177
|
243
|
|
|
|
|
1049
|
$gen->ensure_template_is_generated($widget->{cf_template_nsid}); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub ensure_template_is_generated { |
181
|
|
|
|
|
|
|
# (my MY $gen, my $tmplid) = @_; |
182
|
|
|
|
|
|
|
# $tmplid = $tmplid->cget('nsid') if ref $tmplid; |
183
|
246
|
|
|
246
|
0
|
590
|
(my MY $gen, my $id_or_obj) = @_; |
184
|
246
|
|
|
|
|
394
|
(my $tmplid, my Template $tmpl) = do { |
185
|
246
|
50
|
|
|
|
653
|
if (ref $id_or_obj) { |
186
|
0
|
|
|
|
|
0
|
($id_or_obj->cget('nsid'), $id_or_obj) |
187
|
|
|
|
|
|
|
} else { |
188
|
246
|
|
|
|
|
900
|
($id_or_obj, $gen->nsobj($id_or_obj)); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
}; |
191
|
246
|
100
|
|
|
|
900
|
if (my $baseid = $tmpl->{cf_base_template}) { |
192
|
3
|
|
|
|
|
11
|
$gen->ensure_template_is_generated($baseid); |
193
|
|
|
|
|
|
|
} |
194
|
246
|
100
|
|
|
|
1026
|
unless ($gen->{target_cache}{$tmplid}++) { |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# eval は? |
197
|
141
|
|
|
|
|
208
|
push @{$$gen{cf_product}} |
|
141
|
|
|
|
|
624
|
|
198
|
|
|
|
|
|
|
, $gen->generate_template($gen->nsobj($tmplid)); |
199
|
|
|
|
|
|
|
} |
200
|
232
|
50
|
|
|
|
461
|
if (my @delayed = keys %{$gen->{delayed_target}}) { |
|
232
|
|
|
|
|
1233
|
|
201
|
0
|
|
|
|
|
0
|
foreach my $nsid (@delayed) { |
202
|
0
|
0
|
|
|
|
0
|
next if $gen->{target_cache}{$nsid}; |
203
|
0
|
|
|
|
|
0
|
delete $gen->{delayed_target}{$nsid}; |
204
|
0
|
|
|
|
|
0
|
$gen->ensure_template_is_generated($nsid); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub forget_template { |
210
|
146
|
|
|
146
|
0
|
335
|
(my MY $gen, my $tmplid) = @_; |
211
|
146
|
50
|
|
|
|
980
|
$tmplid = $tmplid->cget('nsid') if ref $tmplid; |
212
|
146
|
50
|
|
|
|
824
|
delete $gen->{target_cache}{$tmplid} ? 1 : 0; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my %calling_conv; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub generate_template { |
218
|
141
|
|
|
141
|
0
|
302
|
(my MY $gen, my Template $tmpl) = @_; |
219
|
|
|
|
|
|
|
print STDERR "Generate: $tmpl->{cf_loadkey}\n" |
220
|
141
|
50
|
|
|
|
538
|
if $gen->{cf_debug_translator}; |
221
|
141
|
|
|
|
|
539
|
my $metainfo = $tmpl->metainfo; |
222
|
|
|
|
|
|
|
my @use = map { |
223
|
141
|
50
|
|
|
|
370
|
unless (defined $_) { |
224
|
|
|
|
|
|
|
() |
225
|
141
|
|
|
|
|
447
|
} else { |
226
|
0
|
0
|
|
|
|
0
|
map {"use $_;"} ref $_ ? @$_ : $_ |
|
0
|
|
|
|
|
0
|
|
227
|
|
|
|
|
|
|
} |
228
|
141
|
|
|
|
|
383
|
} $gen->{cf_use}; |
229
|
141
|
|
|
|
|
279
|
my @file_scope = do { |
230
|
141
|
100
|
|
|
|
517
|
if ($gen->{cf_pagevars}) { |
231
|
1
|
|
|
|
|
8
|
$gen->checked_eval(qq{require $gen->{cf_pagevars}}); |
232
|
1
|
|
|
|
|
7
|
push @use, "use $gen->{cf_pagevars} (qw($tmpl->{cf_name}), 1);"; |
233
|
|
|
|
|
|
|
($gen->{cf_pagevars}->build_scope_for($gen, $tmpl->{cf_name}) |
234
|
1
|
|
|
|
|
10
|
, [\%calling_conv]); |
235
|
|
|
|
|
|
|
} else { |
236
|
140
|
|
|
|
|
693
|
\%calling_conv; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
}; |
239
|
141
|
|
|
|
|
316
|
my @script; |
240
|
141
|
|
|
|
|
281
|
foreach my $widget (@{$tmpl->widget_list}) { |
|
141
|
|
|
|
|
604
|
|
241
|
220
|
|
|
|
|
801
|
push @script, $gen->generate_widget($widget, $metainfo, \@file_scope); |
242
|
|
|
|
|
|
|
} |
243
|
127
|
|
|
|
|
568
|
join("", q{package } . $gen->get_package($tmpl) . ';' |
244
|
|
|
|
|
|
|
, join("",@use) |
245
|
|
|
|
|
|
|
, @script); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub generate_lineinfo { |
249
|
406
|
|
|
406
|
0
|
946
|
(my MY $gen, my Widget $widget, my ($start, $prefix)) = @_; |
250
|
406
|
100
|
|
|
|
2041
|
return if $gen->{cf_no_lineinfo}; |
251
|
|
|
|
|
|
|
sprintf qq{%s#line %d "%s"\n}, $prefix || '' |
252
|
50
|
|
100
|
|
|
433
|
, $start, $widget->{cf_filename}; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub generating_widget { |
256
|
0
|
|
|
0
|
0
|
0
|
my MY $gen = shift; |
257
|
0
|
|
|
|
|
0
|
$gen->{generating_widget}[0]; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub generate_widget { |
261
|
220
|
|
|
220
|
0
|
494
|
(my MY $gen, my Widget $widget, my ($metainfo, $file_scope)) = @_; |
262
|
220
|
|
|
|
|
649
|
local $gen->{generating_widget}[0] = $widget; |
263
|
|
|
|
|
|
|
my @body = $gen->generate_body |
264
|
|
|
|
|
|
|
([{}, $widget->widget_scope($file_scope)] |
265
|
|
|
|
|
|
|
, $widget->cursor(metainfo => $metainfo->clone |
266
|
|
|
|
|
|
|
(startline => $widget->{cf_body_start} |
267
|
220
|
|
|
|
|
1058
|
, caller_widget => $widget))); |
268
|
|
|
|
|
|
|
# body が空の場合もありうる。 |
269
|
206
|
100
|
|
|
|
2345
|
return unless @body; |
270
|
203
|
|
|
|
|
865
|
my ($pkg, $funcname) = $gen->get_funcname_to($gen->{cf_mode}, $widget); |
271
|
|
|
|
|
|
|
join("" |
272
|
|
|
|
|
|
|
, $gen->generate_lineinfo($widget, $widget->{cf_decl_start}, "\n") |
273
|
|
|
|
|
|
|
, $gen->generate_getargs($widget, $metainfo) |
274
|
|
|
|
|
|
|
, $gen->generate_lineinfo($widget, $widget->{cf_body_start}) |
275
|
203
|
|
|
|
|
814
|
, $gen->as_sub |
276
|
|
|
|
|
|
|
($funcname |
277
|
|
|
|
|
|
|
, $gen->genprolog($widget) |
278
|
|
|
|
|
|
|
, $gen->as_statement_list(@body)) |
279
|
|
|
|
|
|
|
, "\n"); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
sub generate_getargs { |
283
|
203
|
|
|
203
|
0
|
359
|
(my MY $gen, my Widget $widget, my ($metainfo)) = @_; |
284
|
203
|
|
|
|
|
915
|
$gen->as_sub("getargs_$$widget{cf_name}", sprintf q{ |
285
|
|
|
|
|
|
|
my ($call) = shift; |
286
|
|
|
|
|
|
|
$_[0] = shift @$call; shift; |
287
|
|
|
|
|
|
|
my $args = $_[0] = shift @$call; shift; |
288
|
|
|
|
|
|
|
if (ref $args eq 'ARRAY') { |
289
|
|
|
|
|
|
|
%s} else { |
290
|
|
|
|
|
|
|
%s |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
, $gen->gen_getargs_static($widget, $metainfo) |
294
|
|
|
|
|
|
|
, $gen->gen_getargs_dynamic($widget, $metainfo)); |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub genprolog { |
298
|
203
|
|
|
203
|
0
|
341
|
(my MY $gen, my Widget $widget) = @_; |
299
|
203
|
|
|
|
|
594
|
my @args = qw($this $args); |
300
|
203
|
100
|
66
|
|
|
681
|
if ($widget->{arg_order} && @{$widget->{arg_order}}) { |
|
161
|
|
|
|
|
814
|
|
301
|
161
|
|
|
|
|
287
|
foreach my $name (@{$widget->{arg_order}}) { |
|
161
|
|
|
|
|
425
|
|
302
|
391
|
|
|
|
|
1100
|
push @args, $widget->{arg_dict}{$name}->as_lvalue |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
sprintf q{getargs_%s(\@_, my (%s))} |
306
|
203
|
|
|
|
|
1355
|
, $$widget{cf_name}, join(", ", @args); |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub generate_body { |
310
|
285
|
|
|
285
|
0
|
588
|
(my MY $gen, my ($scope, $cursor)) = @_; |
311
|
285
|
|
|
|
|
875
|
my @code; |
312
|
285
|
|
|
|
|
917
|
for (; $cursor->readable; $cursor->next) { |
313
|
850
|
50
|
|
|
|
2549
|
if (my $sub = $gen->can("trans_" . (my $t = $cursor->node_type_name))) { |
314
|
850
|
|
|
|
|
2465
|
push @code, $sub->($gen, $scope, $cursor); |
315
|
|
|
|
|
|
|
} else { |
316
|
0
|
|
|
|
|
0
|
die $gen->node_error($cursor, "Can't handle node type: %s", $t); |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
} |
319
|
269
|
|
|
|
|
1262
|
@code; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub as_sub { |
323
|
444
|
|
|
444
|
0
|
1038
|
my ($gen, $func_name) = splice @_, 0, 2; |
324
|
444
|
|
|
|
|
1405
|
"sub $func_name ". $gen->as_block(@_); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub as_block { |
328
|
460
|
|
|
460
|
0
|
757
|
my ($gen) = shift; |
329
|
460
|
50
|
|
|
|
1154
|
return '{}' unless @_; |
330
|
460
|
|
|
|
|
832
|
my $last = pop; |
331
|
460
|
|
|
|
|
663
|
$last .= do { |
332
|
460
|
100
|
|
|
|
2848
|
if ($last =~ s/(\n+)$//) { |
333
|
326
|
|
|
|
|
1143
|
"}$1"; |
334
|
|
|
|
|
|
|
} else { |
335
|
134
|
|
|
|
|
270
|
'}'; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
}; |
338
|
460
|
|
|
|
|
3923
|
'{ '.join("; ", @_, $last); |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub as_join { |
342
|
14
|
|
|
14
|
0
|
27
|
my MY $gen = shift; |
343
|
14
|
|
|
|
|
27
|
my (@result); |
344
|
14
|
|
|
|
|
32
|
foreach my $trans (@_) { |
345
|
35
|
50
|
|
|
|
75
|
if (ref $trans) { |
346
|
0
|
|
|
|
|
0
|
push @result, qq(YATT::capture {$$trans}); |
347
|
|
|
|
|
|
|
} else { |
348
|
35
|
|
|
|
|
79
|
push @result, $trans; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
} |
351
|
14
|
|
|
|
|
134
|
sprintf q{join('', %s)}, join ", ", @result; |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
use YATT::Types |
355
|
3
|
|
|
3
|
|
22
|
[queued_joiner => [qw(queue printable last_ws)]]; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
32
|
|
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::joiner { |
358
|
|
|
|
|
|
|
# 行が変わらない限り、一つの print に入れる。 |
359
|
|
|
|
|
|
|
# 行が変われば、別の print にする。 |
360
|
|
|
|
|
|
|
# 印字可能要素が無いなら、空白をそのまま入れる。 |
361
|
279
|
|
|
279
|
0
|
641
|
(my queued_joiner $me, my ($head)) = splice @_, 0, 2; |
362
|
279
|
|
|
|
|
676
|
my ($line, $prenl, @result, $argc, $nlines) = ('', ''); |
363
|
279
|
|
|
|
|
628
|
foreach my $i (@_) { |
364
|
590
|
100
|
|
|
|
1906
|
unless ($i =~ /\S/) { |
365
|
44
|
50
|
|
|
|
219
|
push @result, $i |
366
|
|
|
|
|
|
|
and next; |
367
|
|
|
|
|
|
|
} |
368
|
546
|
100
|
|
|
|
1089
|
if ($line eq '') { |
369
|
|
|
|
|
|
|
# 先頭 |
370
|
306
|
100
|
|
|
|
1101
|
if ($i =~ s/^(\s+)//) { |
371
|
86
|
|
|
|
|
210
|
$prenl .= $1; |
372
|
|
|
|
|
|
|
} |
373
|
306
|
50
|
|
|
|
884
|
if ($i ne '') { |
374
|
306
|
|
|
|
|
804
|
$line .= $prenl . $head . $i; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
} else { |
377
|
|
|
|
|
|
|
# 残り |
378
|
240
|
|
|
|
|
521
|
$line .= ', ' . $i; |
379
|
|
|
|
|
|
|
} |
380
|
546
|
100
|
|
|
|
1630
|
if ($i =~ /\n/) { |
381
|
246
|
|
|
|
|
401
|
push @result, $line; |
382
|
246
|
|
|
|
|
438
|
$line = ''; |
383
|
246
|
|
|
|
|
595
|
$prenl = ''; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
279
|
100
|
|
|
|
676
|
push @result, $line if $line ne ''; |
387
|
279
|
|
|
|
|
806
|
@result; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::add { |
391
|
689
|
|
|
689
|
0
|
1208
|
(my queued_joiner $me, my $str) = @_; |
392
|
689
|
|
|
|
|
876
|
push @{$me->{queue}}, $str; |
|
689
|
|
|
|
|
1727
|
|
393
|
689
|
100
|
|
|
|
2245
|
if ($str =~ /\S/) { |
394
|
546
|
|
|
|
|
888
|
$me->{printable}++; |
395
|
546
|
|
|
|
|
1341
|
undef $me->{last_ws}; |
396
|
|
|
|
|
|
|
} else { |
397
|
143
|
|
|
|
|
470
|
$me->{last_ws} = 1; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::emit_to { |
402
|
406
|
|
|
406
|
0
|
662
|
(my queued_joiner $me, my ($result)) = @_; |
403
|
406
|
100
|
|
|
|
973
|
if ($me->{printable}) { |
404
|
279
|
100
|
|
|
|
483
|
my $ws; $ws = pop @{$me->{queue}} if $me->{last_ws}; |
|
279
|
|
|
|
|
754
|
|
|
20
|
|
|
|
|
64
|
|
405
|
279
|
50
|
|
|
|
346
|
push @$result, $me->joiner('print ', @{$me->{queue}}) if @{$me->{queue}}; |
|
279
|
|
|
|
|
929
|
|
|
279
|
|
|
|
|
1214
|
|
406
|
279
|
100
|
|
|
|
866
|
$result->[-1] .= $ws if $me->{last_ws}; |
407
|
|
|
|
|
|
|
} else { |
408
|
127
|
100
|
|
|
|
418
|
push @$result, @{$me->{queue}} if $me->{queue}; |
|
87
|
|
|
|
|
242
|
|
409
|
|
|
|
|
|
|
} |
410
|
406
|
|
|
|
|
579
|
undef @{$me->{queue}}; |
|
406
|
|
|
|
|
991
|
|
411
|
406
|
|
|
|
|
707
|
undef $me->{printable}; |
412
|
406
|
|
|
|
|
722
|
undef $me->{last_ws}; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub as_statement_list { |
416
|
256
|
|
|
256
|
0
|
430
|
my MY $gen = shift; |
417
|
256
|
|
|
|
|
1630
|
my queued_joiner $queue = queued_joiner->new; |
418
|
256
|
|
|
|
|
420
|
my (@result); |
419
|
256
|
|
|
|
|
570
|
foreach my $trans (@_) { |
420
|
839
|
100
|
|
|
|
1604
|
if (ref $trans) { |
421
|
150
|
|
|
|
|
476
|
$queue->emit_to(\@result); |
422
|
150
|
|
|
|
|
354
|
push @result, $$trans; |
423
|
|
|
|
|
|
|
} else { |
424
|
689
|
|
|
|
|
1520
|
$queue->add($trans); |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
} |
427
|
256
|
|
|
|
|
599
|
$queue->emit_to(\@result); |
428
|
256
|
50
|
|
|
|
1600
|
wantarray ? @result : join('', @result); |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
#---------------------------------------- |
432
|
|
|
|
|
|
|
# trans_zzz |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
sub trans_comment { |
435
|
0
|
|
|
0
|
0
|
0
|
(my MY $trans, my ($scope, $node)) = @_; |
436
|
0
|
|
|
|
|
0
|
\ ("\n" x $node->node_nlines); |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
sub trans_text { |
440
|
527
|
|
|
527
|
0
|
954
|
(my MY $trans, my ($scope, $node)) = @_; |
441
|
527
|
|
|
|
|
1523
|
my $body = $node->current; |
442
|
527
|
|
|
|
|
1116
|
my ($pre, $post) = ('', ''); |
443
|
527
|
|
|
|
|
1814
|
my $CRLF = qr{\r?\n}; |
444
|
527
|
100
|
|
|
|
1903
|
if ($node->node_is_beginning) { |
|
|
100
|
|
|
|
|
|
445
|
233
|
100
|
|
|
|
2463
|
$pre = $1 if $body =~ s/^($CRLF+)//; |
446
|
|
|
|
|
|
|
} elsif ($node->node_is_end) { |
447
|
211
|
100
|
100
|
|
|
698
|
if (not $node->has_parent |
448
|
|
|
|
|
|
|
and $node->metainfo->caller_widget->no_last_newline) { |
449
|
35
|
|
|
|
|
350
|
$body =~ s/($CRLF+)$//s; |
450
|
|
|
|
|
|
|
} else { |
451
|
176
|
100
|
|
|
|
1523
|
$post = $2 if $body =~ s/($CRLF)($CRLF+)$/$1/s; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
} |
454
|
527
|
|
|
|
|
1021
|
$pre.do { |
455
|
527
|
100
|
|
|
|
2456
|
if ($body eq '') { |
|
|
100
|
|
|
|
|
|
456
|
146
|
|
|
|
|
1060
|
'' |
457
|
|
|
|
|
|
|
} elsif ($body =~ /^$CRLF$/) { |
458
|
129
|
|
|
|
|
487
|
sprintf qq{"%s"\n}, qcrlf($body); |
459
|
|
|
|
|
|
|
} else { |
460
|
252
|
|
|
|
|
633
|
qparen($body); |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
}.$post; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
sub trans_pi { |
466
|
17
|
|
|
17
|
0
|
45
|
(my MY $trans, my ($scope, $node)) = @_; |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# XXX: 処理を許すかどうか、選べるようにすべき。あるいは、mapping が欲しい。 |
469
|
17
|
50
|
|
|
|
68
|
if ($node->node_nsname ne 'perl') { |
470
|
0
|
|
|
|
|
0
|
return ''; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
17
|
|
|
|
|
61
|
my $body = $trans->genexpr_node($scope, 0, $node->open); |
474
|
17
|
100
|
|
|
|
224
|
unless ($body =~ s/^(=+)//) { |
|
|
100
|
|
|
|
|
|
475
|
3
|
|
|
|
|
13
|
\ $body; |
476
|
|
|
|
|
|
|
} elsif (length($1) >= 3) { |
477
|
|
|
|
|
|
|
# print without escaping. |
478
|
6
|
|
|
|
|
41
|
\ qq{print $body}; |
479
|
|
|
|
|
|
|
} else { |
480
|
8
|
|
|
|
|
47
|
qq{YATT::escape(do {$body})} |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub genexpr_node { |
485
|
34
|
|
|
34
|
0
|
91
|
(my MY $trans, my ($scope, $early_escaped, $node)) = @_; |
486
|
34
|
100
|
|
|
|
146
|
join("", map { ref $_ ? $$_ : $trans->dots_for_arrows(my $cp = $_) } |
|
53
|
|
|
|
|
258
|
|
487
|
|
|
|
|
|
|
$trans->mark_vars($scope, $early_escaped, $node)); |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
#======================================== |
491
|
|
|
|
|
|
|
|
492
|
3
|
|
|
3
|
|
19
|
use YATT::Util::Enum -prefix => 'ENT_', qw(RAW ESCAPED PRINTED); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
30
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
sub trans_entity { |
495
|
158
|
|
|
158
|
0
|
376
|
(my MY $trans, my ($scope, $node)) = @_; |
496
|
158
|
|
|
|
|
645
|
$trans->generate_entref($scope, ENT_PRINTED, $node); |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub trans_html { |
500
|
11
|
|
|
11
|
0
|
31
|
(my MY $trans, my ($scope, $node)) = @_; |
501
|
11
|
|
|
|
|
46
|
my $tag = $node->node_name; |
502
|
11
|
|
|
|
|
22
|
my ($string, $tagc, $end) = do { |
503
|
11
|
100
|
|
|
|
42
|
if ($node->is_empty_element) { |
504
|
9
|
|
|
|
|
36
|
("<$tag", " />", ''); |
505
|
|
|
|
|
|
|
} else { |
506
|
2
|
|
|
|
|
10
|
("<$tag", ">", "$tag>"); |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
}; |
509
|
|
|
|
|
|
|
|
510
|
11
|
|
|
|
|
49
|
my $item = $node->open; |
511
|
11
|
|
|
|
|
28
|
my @script; |
512
|
11
|
|
|
|
|
39
|
for (; $item->readable; $item->next) { |
513
|
24
|
100
|
|
|
|
83
|
last unless $item->is_primary_attribute; |
514
|
22
|
|
|
|
|
79
|
my $name = $item->node_name; |
515
|
22
|
50
|
|
|
|
79
|
if (my $var = $trans->has_pass_through_var($scope, $item, $name)) { |
516
|
0
|
|
|
|
|
0
|
push @script, qparen($string), $var->as_escaped; |
517
|
0
|
|
|
|
|
0
|
$string = ''; |
518
|
0
|
|
|
|
|
0
|
next; |
519
|
|
|
|
|
|
|
} |
520
|
22
|
|
|
|
|
44
|
$string .= ' '; |
521
|
22
|
|
|
|
|
71
|
my ($open, $close) = $item->node_attribute_format; |
522
|
22
|
|
|
|
|
44
|
$string .= $open; |
523
|
|
|
|
|
|
|
# XXX: quote されてないとき、変数推測をしても良いかも。 |
524
|
22
|
|
|
|
|
73
|
for (my $frag = $item->open; $frag->readable; $frag->next) { |
525
|
27
|
|
|
|
|
96
|
my $type = $frag->node_type; |
526
|
27
|
100
|
|
|
|
91
|
if ($type == TEXT_TYPE) { |
|
|
50
|
|
|
|
|
|
527
|
12
|
|
|
|
|
35
|
$string .= $frag->current; |
528
|
|
|
|
|
|
|
} elsif ($type == ENTITY_TYPE) { |
529
|
|
|
|
|
|
|
# should be entity |
530
|
15
|
|
|
|
|
47
|
push @script, qparen($string) |
531
|
|
|
|
|
|
|
, $trans->generate_entref($scope, ENT_ESCAPED, $frag); |
532
|
15
|
|
|
|
|
70
|
$string = ''; |
533
|
|
|
|
|
|
|
} else { |
534
|
0
|
|
|
|
|
0
|
die $trans->node_error($frag, "Invalid node in html attribute"); |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
} |
537
|
22
|
|
|
|
|
137
|
$string .= $close; |
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
|
540
|
11
|
50
|
|
|
|
72
|
$string .= $tagc if $tagc ne ''; |
541
|
11
|
|
|
|
|
44
|
for (; $item->readable; $item->next) { |
542
|
4
|
100
|
|
|
|
14
|
if ($item->node_type == TEXT_TYPE) { |
543
|
2
|
|
|
|
|
7
|
$string .= $item->current; |
544
|
|
|
|
|
|
|
} else { |
545
|
2
|
|
|
|
|
17
|
push @script, qparen($string), $trans->generate_body($scope, $item); |
546
|
2
|
|
|
|
|
11
|
$string = ''; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
} |
549
|
11
|
100
|
|
|
|
34
|
$string .= $end if $end; |
550
|
11
|
50
|
|
|
|
49
|
push @script, qparen($string) if $string ne ''; |
551
|
11
|
|
|
|
|
105
|
@script; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
#======================================== |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
my %control = (if => undef, unless => undef); |
557
|
|
|
|
|
|
|
sub trans_element { |
558
|
137
|
|
|
137
|
0
|
309
|
(my MY $trans, my ($scope, $node)) = @_; |
559
|
137
|
|
|
|
|
715
|
my $tmpl = $trans->get_template_from_node($node); |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# ■ 最初に要素マクロ ← RC から検索。 |
562
|
137
|
100
|
|
|
|
622
|
if (my $macro = $trans->has_element_macro($tmpl, $node, $node->node_path)) { |
563
|
|
|
|
|
|
|
# XXX: ssri:foreach → yatt:foreach も。 |
564
|
23
|
|
|
|
|
99
|
return $macro->($trans, $scope, $node->open); |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# ■ 次に if/unless/else, |
568
|
114
|
100
|
|
|
|
568
|
if (my @arm = $trans->collect_arms($node, else => \%control)) { |
569
|
5
|
|
|
|
|
27
|
return $trans->gencall_conditional($scope, @arm); |
570
|
|
|
|
|
|
|
} |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# ■ 無条件呼び出し |
573
|
109
|
|
|
|
|
408
|
$trans->gencall_always($scope, $node); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
sub gencall_conditional { |
577
|
5
|
|
|
5
|
0
|
14
|
(my MY $trans, my ($scope, $ifunless, @elses)) = @_; |
578
|
5
|
|
|
|
|
13
|
my $pkg; |
579
|
5
|
|
|
|
|
10
|
my $script = do { |
580
|
5
|
|
|
|
|
12
|
my ($cond, $action) = @$ifunless; # (node, cursor) |
581
|
|
|
|
|
|
|
sprintf(q{%s (%s) {%s}} |
582
|
|
|
|
|
|
|
, $cond->node_name |
583
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0, $cond->open) |
584
|
5
|
|
|
|
|
21
|
, ${ $trans->gencall_always($scope, $action->make_wrapped) }); |
|
5
|
|
|
|
|
27
|
|
585
|
|
|
|
|
|
|
}; |
586
|
|
|
|
|
|
|
|
587
|
5
|
|
|
|
|
54
|
foreach my $arm (@elses) { |
588
|
5
|
|
|
|
|
26
|
my ($cond, $action) = @$arm; |
589
|
5
|
|
|
|
|
11
|
$script .= do { |
590
|
5
|
100
|
|
|
|
16
|
if ($cond) { |
591
|
2
|
|
|
|
|
10
|
sprintf q{ elsif (%s) } |
592
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0, $cond->open); |
593
|
|
|
|
|
|
|
} else { |
594
|
3
|
|
|
|
|
11
|
q{ else } |
595
|
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
|
}; |
597
|
|
|
|
|
|
|
$script .= sprintf q{{%s}} |
598
|
5
|
|
|
|
|
17
|
, ${ $trans->gencall_always($scope, $action->make_wrapped) }; |
|
5
|
|
|
|
|
23
|
|
599
|
|
|
|
|
|
|
} |
600
|
5
|
|
|
|
|
37
|
\ $script; |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub gencall_always { |
604
|
119
|
|
|
119
|
0
|
382
|
(my MY $trans, my ($scope, $node)) = @_; |
605
|
|
|
|
|
|
|
|
606
|
119
|
|
|
|
|
506
|
my $tmpl = $trans->get_template_from_node($node); |
607
|
119
|
50
|
|
|
|
513
|
my @elempath = $node->node_path or do { |
608
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "Empty element path"); |
609
|
|
|
|
|
|
|
}; |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
# ■ 局所引数… これも、型の固有処理に任せる. delegate もここで。 |
612
|
119
|
100
|
|
|
|
484
|
if (my $codevar = $trans->find_codearg($scope, @elempath)) { |
613
|
|
|
|
|
|
|
# ← 特に、親の call の body の中で、 で |
614
|
|
|
|
|
|
|
# 呼ばれるとき, だよね? |
615
|
30
|
|
|
|
|
111
|
return $codevar->gen_call($trans, $scope, $node); |
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
# ■ さもなければ、通常の Widget の呼び出し |
619
|
89
|
|
|
|
|
360
|
my Widget $widget = $trans->get_widget_from_template($tmpl, @elempath); |
620
|
89
|
100
|
|
|
|
319
|
unless ($widget) { |
621
|
2
|
|
|
|
|
11
|
die $trans->node_error($node, "No such widget"); |
622
|
|
|
|
|
|
|
} |
623
|
87
|
|
|
|
|
315
|
$trans->gencall($widget, $scope, $node->open); |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
sub has_unique_argmacro { |
627
|
87
|
|
|
87
|
0
|
176
|
(my MY $trans, my Widget $callee, my Widget $caller) = @_; |
628
|
87
|
100
|
|
|
|
386
|
return unless $callee->{argmacro_dict}; |
629
|
|
|
|
|
|
|
# 現状では、name の重複は無いはず。 |
630
|
19
|
|
|
|
|
45
|
my %suppress; $suppress{$_->call_spec} = 1 for @{$caller->{argmacro_order}}; |
|
19
|
|
|
|
|
38
|
|
|
19
|
|
|
|
|
98
|
|
631
|
19
|
100
|
|
|
|
46
|
my @order = grep {not $suppress{$_->call_spec}} @{$callee->{argmacro_order}} |
|
16
|
|
|
|
|
74
|
|
|
19
|
|
|
|
|
64
|
|
632
|
|
|
|
|
|
|
or return; |
633
|
11
|
|
|
|
|
25
|
my %dict; |
634
|
11
|
|
|
|
|
24
|
foreach my $arg (keys %{$callee->{argmacro_dict}}) { |
|
11
|
|
|
|
|
66
|
|
635
|
45
|
|
|
|
|
105
|
$dict{$arg} = $callee->{argmacro_dict}{$arg}; |
636
|
|
|
|
|
|
|
} |
637
|
11
|
|
|
|
|
67
|
(\%dict, \@order); |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub gencall { |
641
|
87
|
|
|
87
|
0
|
230
|
(my MY $trans, my Widget $widget, my ($scope, $node)) = @_; |
642
|
87
|
|
|
|
|
350
|
$trans->ensure_widget_is_generated($widget); |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
# 引数マクロの抜き出し |
645
|
87
|
100
|
|
|
|
341
|
if (my ($dict, $order) = $trans->has_unique_argmacro |
646
|
|
|
|
|
|
|
($widget, $node->metainfo->caller_widget)) { |
647
|
11
|
|
|
|
|
88
|
$node = YATT::ArgMacro->expand_all_macros |
648
|
|
|
|
|
|
|
($trans, $scope, $node, $widget, $dict, $order); |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
87
|
|
|
|
|
416
|
my $func = $trans->get_funcname_to($trans->{cf_mode}, $widget); |
652
|
|
|
|
|
|
|
# actual 一覧の作成 |
653
|
87
|
|
|
|
|
445
|
my ($post, @args) = $trans->genargs_static |
654
|
|
|
|
|
|
|
($scope, $node, $widget->arg_specs); |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
# XXX: calling convention 周り |
657
|
|
|
|
|
|
|
return \ sprintf(' %s($this, [%s])%s', $func |
658
|
83
|
100
|
|
|
|
341
|
, join(", ", map {defined $_ ? $_ : 'undef'} @args) |
|
127
|
|
|
|
|
1112
|
|
659
|
|
|
|
|
|
|
, $post); |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
sub has_single_bare_varexpr { |
663
|
6
|
|
|
6
|
0
|
12
|
(my MY $trans, my ($scope, $node)) = @_; |
664
|
6
|
|
|
|
|
25
|
my $clone = $node->clone($node->clone_path); |
665
|
6
|
|
|
|
|
25
|
my $parent = $clone->parent; |
666
|
6
|
100
|
66
|
|
|
26
|
return unless $parent->is_bare_attribute and $parent->node_size == 1; |
667
|
1
|
|
|
|
|
7
|
my (@expr) = ($trans->mark_vars($scope, ENT_RAW, $clone)); |
668
|
1
|
50
|
33
|
|
|
9
|
return unless @expr and ref $expr[0] eq 'SCALAR'; |
669
|
1
|
|
|
|
|
9
|
$expr[0]; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
sub has_pass_through_var { |
673
|
133
|
|
|
133
|
0
|
374
|
(my MY $trans, my ($scope, $args, $name)) = @_; |
674
|
133
|
100
|
|
|
|
572
|
return if $args->node_size >= 2; |
675
|
118
|
100
|
100
|
|
|
352
|
if ($args->node_size == 1 and ($args->node_flag || 0) == 0) { |
|
|
100
|
100
|
|
|
|
|
676
|
|
|
|
|
|
|
# bareword 渡し。 |
677
|
20
|
|
|
|
|
76
|
$trans->find_var($scope, $args->node_body); |
678
|
|
|
|
|
|
|
} elsif ($args->node_size == 0) { |
679
|
|
|
|
|
|
|
# value less 渡し |
680
|
43
|
|
|
|
|
104
|
$trans->find_var($scope, $name); |
681
|
|
|
|
|
|
|
} |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
sub genargs_static { |
685
|
117
|
|
|
117
|
0
|
310
|
(my MY $trans, my ($scope, $args, $arg_dict, $arg_order, $delegate_vars)) = @_; |
686
|
117
|
|
|
|
|
408
|
my ($body, @actual) = $args->variant_builder; |
687
|
117
|
|
|
|
|
571
|
my ($postnl, $startline) = ('', $args->linenum); |
688
|
117
|
|
|
|
|
490
|
for (my $nth = 0; $args->readable; $args->next) { |
689
|
177
|
100
|
|
|
|
521
|
unless ($args->is_attribute) { |
690
|
75
|
|
|
|
|
237
|
$body->add_node($args->current); |
691
|
75
|
|
|
|
|
243
|
next; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
|
694
|
102
|
|
|
|
|
401
|
my ($name, $typename) = $trans->arg_name_types($args); |
695
|
102
|
100
|
|
|
|
271
|
unless (defined $name) { |
696
|
2
|
50
|
|
|
|
10
|
$name = $arg_order->[$nth++] |
697
|
|
|
|
|
|
|
or die $trans->node_error($args, "Too many args"); |
698
|
|
|
|
|
|
|
} |
699
|
102
|
|
|
|
|
207
|
my $argdecl = $arg_dict->{$name}; |
700
|
102
|
50
|
|
|
|
272
|
unless ($argdecl) { |
701
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "Unknown arg '%s'", $name); |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
# XXX: $typename (attname:type の type) を活用していない。 |
704
|
|
|
|
|
|
|
# XXX: code 型引数を primary で渡したときにまで、 print が作られてる。 |
705
|
|
|
|
|
|
|
# $args->is_quoted_by_element で判別せよ。 |
706
|
102
|
|
|
|
|
134
|
$actual[$argdecl->argno] = do { |
707
|
102
|
100
|
|
|
|
391
|
if (my $var = $trans->has_pass_through_var($scope, $args, $name)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
708
|
|
|
|
|
|
|
# XXX: early_escaped が一致するか、検査せよ。 |
709
|
38
|
100
|
|
|
|
125
|
$argdecl->early_escaped ? $var->as_escaped : $var->as_lvalue; |
710
|
|
|
|
|
|
|
} elsif (defined $args->node_body) { |
711
|
60
|
|
|
|
|
226
|
$argdecl->gen_assignable_node($trans, $scope, $args); |
712
|
|
|
|
|
|
|
} elsif ($argdecl->isa($trans->t_scalar)) { |
713
|
3
|
|
|
|
|
11
|
$argdecl->quote_assignable(my $copy = 1); |
714
|
|
|
|
|
|
|
} else { |
715
|
1
|
|
|
|
|
6
|
die $trans->node_error($args, "valueless arg '%s'", $name); |
716
|
|
|
|
|
|
|
} |
717
|
|
|
|
|
|
|
}; |
718
|
|
|
|
|
|
|
} |
719
|
116
|
100
|
66
|
|
|
452
|
if ($body->array_size |
720
|
|
|
|
|
|
|
and my $bodydecl = $arg_dict->{body}) { |
721
|
|
|
|
|
|
|
# if $actual[$bodydecl->argno]; なら、エラーを報告すべきでは? |
722
|
|
|
|
|
|
|
# code か、html か。 |
723
|
35
|
|
|
|
|
144
|
$actual[$bodydecl->argno] |
724
|
|
|
|
|
|
|
= $bodydecl->gen_assignable_node($trans, $scope, $body, 1); |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
114
|
|
|
|
|
540
|
for (my $i = 0; $i < @$arg_order; $i++) { |
728
|
212
|
100
|
|
|
|
673
|
next if defined $actual[$i]; |
729
|
79
|
|
|
|
|
143
|
my $name = $arg_order->[$i]; |
730
|
79
|
100
|
|
|
|
375
|
if ($delegate_vars->{$name}) { |
|
|
100
|
|
|
|
|
|
731
|
|
|
|
|
|
|
# delegate 宣言では、型は同じになるはず。 |
732
|
|
|
|
|
|
|
# XXX: 引数rename |
733
|
17
|
|
|
|
|
50
|
$actual[$i] = $arg_dict->{$name}->as_lvalue; |
734
|
|
|
|
|
|
|
} elsif ($arg_dict->{$name}->is_required) { |
735
|
1
|
|
|
|
|
4
|
die $trans->node_error($args->parent |
736
|
|
|
|
|
|
|
, "Argument '%s' is missing", $name); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
|
740
|
113
|
100
|
|
|
|
511
|
if ($args->parent->is_empty_element) { |
741
|
80
|
|
|
|
|
244
|
my $diff = $args->parent->linenum(+1) |
742
|
|
|
|
|
|
|
- $startline - $args->count_lines_of(@actual); |
743
|
80
|
100
|
|
|
|
411
|
$postnl = "\n" x $diff if $diff; |
744
|
|
|
|
|
|
|
} else { |
745
|
|
|
|
|
|
|
# XXX: どうする? |
746
|
|
|
|
|
|
|
} |
747
|
113
|
|
|
|
|
944
|
($postnl, @actual); |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
sub collect_arms { |
751
|
114
|
|
|
114
|
0
|
303
|
my ($pack, $call, $key, $dict) = @_; |
752
|
114
|
|
|
|
|
473
|
my ($type, $name) = $call->node_headings; |
753
|
114
|
|
|
|
|
427
|
my $args = $call->open; |
754
|
114
|
|
|
|
|
539
|
my ($cond, $body) = $pack->consume_arm($args, $dict, $type, $name |
755
|
|
|
|
|
|
|
, primary_only => 1); |
756
|
114
|
100
|
|
|
|
1177
|
return unless $cond; |
757
|
5
|
|
|
|
|
18
|
my @case = [$cond, $body]; |
758
|
5
|
|
|
|
|
27
|
for (; $args->readable; $args->next) { |
759
|
9
|
100
|
66
|
|
|
31
|
if ($args->is_attribute && $args->node_name eq $key) { |
760
|
5
|
|
|
|
|
19
|
push @case, [$pack->consume_arm($args->open, $dict, $type, $name)]; |
761
|
|
|
|
|
|
|
} else { |
762
|
|
|
|
|
|
|
# XXX: 多分、$case[0] (== $body) |
763
|
4
|
|
|
|
|
45
|
$case[-1][-1]->add_node($args->current); |
764
|
|
|
|
|
|
|
} |
765
|
|
|
|
|
|
|
} |
766
|
5
|
|
|
|
|
39
|
@case; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
sub consume_arm { |
770
|
119
|
|
|
119
|
0
|
374
|
my ($trans, $node, $dict, $type, $name, @opts) = @_; |
771
|
119
|
|
|
|
|
531
|
my $arm = $node->variant_builder($type, $name); |
772
|
119
|
|
|
|
|
623
|
my @cond = $arm->filter_or_add_from($node, $dict, @opts); |
773
|
119
|
50
|
|
|
|
335
|
if (@cond >= 2) { |
774
|
|
|
|
|
|
|
die $trans->node_error |
775
|
|
|
|
|
|
|
($node, "Too many condtitions: %s" |
776
|
0
|
|
|
|
|
0
|
, join("", map {stringify_node($_)} @cond)); |
|
0
|
|
|
|
|
0
|
|
777
|
|
|
|
|
|
|
} |
778
|
|
|
|
|
|
|
# $cond[0] は undef かもしれない。 ex. <:else/> |
779
|
|
|
|
|
|
|
|
780
|
119
|
100
|
|
|
|
226
|
my $cond; $cond = $trans->fake_cursor_from($arm, $cond[0]) if defined $cond[0]; |
|
119
|
|
|
|
|
320
|
|
781
|
119
|
|
|
|
|
409
|
($cond, $arm); |
782
|
|
|
|
|
|
|
} |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
#---------------------------------------- |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
sub has_element_macro { |
787
|
137
|
|
|
137
|
0
|
470
|
(my MY $trans, my Template $tmpl, my ($node, @elempath)) = @_; |
788
|
|
|
|
|
|
|
# XXX: macro の一覧は、ちゃんと取り出せるか? |
789
|
|
|
|
|
|
|
|
790
|
137
|
50
|
|
|
|
453
|
if (@elempath > 2) { |
791
|
|
|
|
|
|
|
# Not implemented. |
792
|
0
|
|
|
|
|
0
|
return; |
793
|
|
|
|
|
|
|
} |
794
|
|
|
|
|
|
|
|
795
|
137
|
|
|
|
|
494
|
my $pkg = $trans->get_rc_package_from_template($tmpl); |
796
|
137
|
|
|
|
|
253
|
my $ns; |
797
|
137
|
|
|
|
|
325
|
foreach my $shift (0, 1) { |
798
|
251
|
100
|
|
|
|
901
|
$ns = $trans->strip_ns(\@elempath) if $shift; |
799
|
251
|
|
|
|
|
701
|
my $macro_name = join("_", macro => @elempath); |
800
|
251
|
100
|
66
|
|
|
4195
|
if (my $sub = $pkg->can($macro_name) || $trans->can($macro_name)) { |
801
|
23
|
|
|
|
|
130
|
return $sub; |
802
|
|
|
|
|
|
|
} |
803
|
|
|
|
|
|
|
} |
804
|
|
|
|
|
|
|
} |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
#======================================== |
807
|
|
|
|
|
|
|
# 宣言関連 |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
# XXX: use は perl 固有だから、ここに持たせるのは理にかなう。 |
810
|
|
|
|
0
|
0
|
|
sub declare_use { |
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
sub attr_declare_delegate { |
814
|
7
|
|
|
7
|
0
|
38
|
(my MY $trans, my ($widget, $args, $argname, $subtype, @param)) = @_; |
815
|
7
|
100
|
|
|
|
36
|
my @elempath = $subtype ? @$subtype : $argname; |
816
|
7
|
|
|
|
|
40
|
my Template $tmpl = $trans->get_template_from_node($args); |
817
|
7
|
|
|
|
|
44
|
my Widget $base = $trans->get_widget_from_template($tmpl, @elempath); |
818
|
7
|
50
|
|
|
|
28
|
unless ($base) { |
819
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "No such widget %s" |
820
|
|
|
|
|
|
|
, join(":", @elempath)); |
821
|
|
|
|
|
|
|
} |
822
|
7
|
50
|
|
|
|
35
|
if ($tmpl->{cf_nsid} != $base->template_nsid) { |
823
|
0
|
|
|
|
|
0
|
$trans->mark_delayed_target($base); |
824
|
|
|
|
|
|
|
} |
825
|
|
|
|
|
|
|
|
826
|
7
|
100
|
|
|
|
133
|
if ($base->{arg_dict}{$argname}) { |
827
|
1
|
|
|
|
|
7
|
die $trans->node_error($args, q{delegate '%1$s' hides argument '%1$s' of widget %2$s} |
828
|
|
|
|
|
|
|
, $argname, join(":", @elempath)); |
829
|
|
|
|
|
|
|
} |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
# pass thru する変数名の一覧。 |
832
|
|
|
|
|
|
|
# でも、未指定なものだけね。 |
833
|
|
|
|
|
|
|
# XXX: 引数rename |
834
|
6
|
|
|
|
|
13
|
my %vars; $vars{$_} = 1 for $widget->copy_specs_from($base); |
|
6
|
|
|
|
|
34
|
|
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
# |
837
|
|
|
|
|
|
|
# arg とは別の、コンパイル時のみの仮想的な変数として登録。 |
838
|
|
|
|
|
|
|
# |
839
|
6
|
50
|
|
|
|
27
|
if ($widget->has_virtual_var($argname)) { |
840
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "Duplicate delegate? %s", $argname); |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
$widget->add_virtual_var |
843
|
6
|
|
|
|
|
31
|
($argname, $trans->create_var(delegate => $args |
844
|
|
|
|
|
|
|
, base_path => \@elempath |
845
|
|
|
|
|
|
|
, base_widget => $base |
846
|
|
|
|
|
|
|
, delegate_vars => \%vars, @param)); |
847
|
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
sub after_define_args { |
850
|
173
|
|
|
173
|
0
|
306
|
(my MY $trans, my ($target)) = @_; |
851
|
173
|
100
|
|
|
|
565
|
unless ($target->has_arg('body')) { |
852
|
154
|
|
|
|
|
538
|
$target->add_arg(body => $trans->create_var('code')); |
853
|
|
|
|
|
|
|
} |
854
|
173
|
|
|
|
|
599
|
$trans; |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
sub decode_decl_entpath { |
858
|
16
|
|
|
16
|
0
|
39
|
(my MY $trans, my $node) = @_; |
859
|
16
|
|
|
|
|
59
|
my ($has_body, @entpath) |
860
|
|
|
|
|
|
|
= $trans->decode_entpath($node, my $entns = [$node->node_path]); |
861
|
|
|
|
|
|
|
|
862
|
16
|
100
|
|
|
|
63
|
unless ($has_body) { |
863
|
10
|
|
|
|
|
45
|
return $node->node_nsname('', '_'); |
864
|
|
|
|
|
|
|
} |
865
|
|
|
|
|
|
|
|
866
|
6
|
|
|
|
|
10
|
my (@macro_name, $rename_spec); |
867
|
6
|
|
|
|
|
17
|
while (@entpath) { |
868
|
6
|
|
|
|
|
12
|
my ($type, $name, @args) = @{shift @entpath}; |
|
6
|
|
|
|
|
18
|
|
869
|
6
|
50
|
|
|
|
27
|
if ($type eq 'var') { |
|
|
50
|
|
|
|
|
|
870
|
0
|
0
|
|
|
|
0
|
if (@args) { |
871
|
|
|
|
|
|
|
# foo{name,name,...} case. |
872
|
0
|
|
|
|
|
0
|
die $trans->node_nimpl($node); |
873
|
|
|
|
|
|
|
} else { |
874
|
0
|
|
|
|
|
0
|
push @macro_name, $name; |
875
|
|
|
|
|
|
|
} |
876
|
|
|
|
|
|
|
} elsif ($type eq 'call') { |
877
|
6
|
|
|
|
|
14
|
push @macro_name, $name; |
878
|
6
|
|
|
|
|
12
|
foreach my $arg (@args) { |
879
|
6
|
|
|
|
|
14
|
my ($type, $name, @args) = @$arg; |
880
|
6
|
50
|
|
|
|
24
|
if ($type ne 'text') { |
|
|
50
|
|
|
|
|
|
881
|
0
|
|
|
|
|
0
|
die $trans->node_nimpl($node); |
882
|
|
|
|
|
|
|
} elsif ($rename_spec) { |
883
|
0
|
|
|
|
|
0
|
die $trans->node_nimpl($node); # Error: ()() |
884
|
|
|
|
|
|
|
} else { |
885
|
6
|
|
|
|
|
44
|
$rename_spec = [split /=/, $name, 2]; |
886
|
|
|
|
|
|
|
} |
887
|
|
|
|
|
|
|
} |
888
|
|
|
|
|
|
|
} else { |
889
|
0
|
|
|
|
|
0
|
die $trans->nimpl($node); |
890
|
|
|
|
|
|
|
} |
891
|
|
|
|
|
|
|
} |
892
|
|
|
|
|
|
|
|
893
|
6
|
|
|
|
|
30
|
(join("_", @macro_name), $rename_spec); |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
# For ArgMacro |
897
|
|
|
|
|
|
|
sub add_decl_entity { |
898
|
51
|
|
|
51
|
0
|
115
|
(my MY $trans, my Widget $widget, my ($node)) = @_; |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
# Widget の configure を呼ぶだけ、のケース ← config(value) でどう? |
901
|
|
|
|
|
|
|
{ |
902
|
51
|
|
|
|
|
222
|
my $is_sysns = $trans->shift_ns_by(yatt => |
903
|
|
|
|
|
|
|
my $entns = [$node->node_path]); |
904
|
51
|
100
|
66
|
|
|
370
|
if ($is_sysns && @$entns == 1) { |
905
|
35
|
50
|
|
|
|
168
|
if ($widget->can_configure($entns->[0])) { |
906
|
35
|
|
|
|
|
145
|
$widget->configure($entns->[0], 1); |
907
|
35
|
|
|
|
|
165
|
return; |
908
|
|
|
|
|
|
|
} |
909
|
|
|
|
|
|
|
} |
910
|
|
|
|
|
|
|
} |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
{ |
913
|
51
|
|
|
|
|
80
|
my ($macro_name, @args) = $trans->decode_decl_entpath($node); |
|
16
|
|
|
|
|
53
|
|
|
16
|
|
|
|
|
60
|
|
914
|
|
|
|
|
|
|
|
915
|
16
|
|
|
|
|
72
|
foreach my $pkg ($trans->get_package_from_widget($widget)) { |
916
|
16
|
|
|
|
|
27
|
my $macro_class = do { |
917
|
16
|
50
|
|
|
|
254
|
my $sub = $pkg->can($macro_name) |
918
|
|
|
|
|
|
|
or next; |
919
|
16
|
|
|
|
|
52
|
$sub->(); |
920
|
|
|
|
|
|
|
}; |
921
|
16
|
50
|
|
|
|
178
|
unless ($macro_class->can('handle')) { |
922
|
0
|
|
|
|
|
0
|
die $trans->node_error |
923
|
|
|
|
|
|
|
($node, "ArgMacro doesn't implement ->handle method: %s" |
924
|
|
|
|
|
|
|
, $node->node_name); |
925
|
|
|
|
|
|
|
} |
926
|
16
|
|
|
|
|
98
|
return $macro_class->register_in($trans, $node, $widget, @args); |
927
|
|
|
|
|
|
|
} |
928
|
|
|
|
|
|
|
} |
929
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "No such ArgMacro: %s" |
930
|
|
|
|
|
|
|
, $node->node_nsname); |
931
|
|
|
|
|
|
|
} |
932
|
|
|
|
|
|
|
|
933
|
|
|
|
|
|
|
#======================================== |
934
|
|
|
|
|
|
|
# 変数関連 |
935
|
|
|
|
|
|
|
|
936
|
3
|
|
|
|
|
23
|
use YATT::Types [VarType => |
937
|
|
|
|
|
|
|
[qw(cf_varname ^cf_argno ^cf_subtype |
938
|
|
|
|
|
|
|
cf_default cf_default_mode |
939
|
|
|
|
|
|
|
cf_filename cf_linenum |
940
|
|
|
|
|
|
|
)]] |
941
|
3
|
|
|
3
|
|
20
|
, qw(:export_alias); |
|
3
|
|
|
|
|
6
|
|
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
sub find_var { |
944
|
414
|
|
|
414
|
0
|
1199
|
(my MY $trans, my ($scope, $varName)) = @_; |
945
|
414
|
|
|
|
|
1227
|
for (; $scope; $scope = $scope->[1]) { |
946
|
987
|
50
|
|
|
|
2020
|
croak "Undefined varName!" unless defined $varName; |
947
|
987
|
100
|
|
|
|
4100
|
if (defined (my $value = $scope->[0]{$varName})) { |
948
|
275
|
|
|
|
|
1025
|
return $value; |
949
|
|
|
|
|
|
|
} |
950
|
|
|
|
|
|
|
} |
951
|
139
|
|
|
|
|
724
|
return; |
952
|
|
|
|
|
|
|
} |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
sub find_codearg { |
955
|
145
|
|
|
145
|
0
|
464
|
(my MY $trans, my ($scope, @elempath)) = @_; |
956
|
145
|
50
|
|
|
|
447
|
return if @elempath >= 3; |
957
|
145
|
|
|
|
|
584
|
$trans->strip_ns(\@elempath); |
958
|
145
|
50
|
|
|
|
421
|
return unless @elempath == 1; |
959
|
145
|
100
|
|
|
|
524
|
my $var = $trans->find_var($scope, $elempath[0]) |
960
|
|
|
|
|
|
|
or return; |
961
|
40
|
100
|
66
|
|
|
354
|
return unless ref $var and $var->can('arg_specs'); |
962
|
38
|
|
|
|
|
140
|
$var; |
963
|
|
|
|
|
|
|
} |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
sub gen_getargs_static { |
966
|
203
|
|
|
203
|
0
|
367
|
(my MY $gen, my Widget $widget, my ($metainfo)) = @_; |
967
|
203
|
|
|
|
|
345
|
my (@args, %scope); |
968
|
203
|
100
|
|
|
|
610
|
foreach my $name ($widget->{arg_order} ? @{$widget->{arg_order}} : ()) { |
|
161
|
|
|
|
|
522
|
|
969
|
391
|
|
|
|
|
819
|
my VarType $var = $widget->{arg_dict}{$name}; |
970
|
391
|
|
|
|
|
793
|
$scope{$name} = $var; |
971
|
391
|
|
|
|
|
1083
|
my $decl = sprintf q{my %s = $_[%d]}, $var->as_lvalue, $$var{cf_argno}; |
972
|
391
|
|
|
|
|
2066
|
my $value = $var->gen_getarg |
973
|
|
|
|
|
|
|
($gen, [\%scope], $widget, $metainfo, qq{\$args->[$$var{cf_argno}]}); |
974
|
391
|
|
|
|
|
1679
|
push @args, "$decl = $value;\n"; |
975
|
|
|
|
|
|
|
} |
976
|
203
|
|
|
|
|
1150
|
join "", @args; |
977
|
|
|
|
|
|
|
} |
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
sub gen_getargs_dynamic { |
980
|
203
|
|
|
203
|
0
|
1252
|
''; |
981
|
|
|
|
|
|
|
} |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
sub gen_pass_through_arg_typed { |
984
|
0
|
|
|
0
|
0
|
0
|
(my MY $gen, my ($type, $scope, $baseNC, $targetNode)) = @_; |
985
|
0
|
0
|
|
|
|
0
|
my $node = $targetNode |
986
|
|
|
|
|
|
|
? $gen->fake_cursor_from($baseNC, $targetNode) |
987
|
|
|
|
|
|
|
: $baseNC; |
988
|
0
|
|
|
|
|
0
|
my $name = $node->node_name; |
989
|
0
|
0
|
|
|
|
0
|
if (my $var = $gen->has_pass_through_var($scope, $node, $name)) { |
990
|
0
|
|
|
|
|
0
|
$var->as_lvalue; |
991
|
|
|
|
|
|
|
} else { |
992
|
0
|
|
|
|
|
0
|
$gen->faked_gentype($type => $scope, $node) |
993
|
|
|
|
|
|
|
} |
994
|
|
|
|
|
|
|
} |
995
|
|
|
|
|
|
|
|
996
|
|
|
|
|
|
|
sub try_pass_through { |
997
|
0
|
|
|
0
|
0
|
0
|
(my MY $trans, my ($scope, $cursor, $rawNode, $defaultFlag)) = @_; |
998
|
0
|
0
|
0
|
|
|
0
|
if (node_size($rawNode) == 1 and node_flag($rawNode) == 0 |
|
|
0
|
0
|
|
|
|
|
999
|
|
|
|
|
|
|
and (my $nm = node_body($rawNode)) =~ /^\w+$/) { |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
# [name=bareword_ident] |
1002
|
|
|
|
|
|
|
# Must be an existing variable. |
1003
|
0
|
0
|
|
|
|
0
|
if (my $var = $trans->find_var($scope, $nm)) { |
1004
|
0
|
|
|
|
|
0
|
$var->as_lvalue; |
1005
|
|
|
|
|
|
|
} else { |
1006
|
0
|
|
|
|
|
0
|
die $trans->node_error($cursor, "No such variable '%s'", $nm); |
1007
|
|
|
|
|
|
|
} |
1008
|
|
|
|
|
|
|
} elsif (node_size($rawNode) == 0) { |
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
# [name] |
1011
|
|
|
|
|
|
|
# variable or flag. |
1012
|
0
|
0
|
|
|
|
0
|
if (my $var = $trans->find_var($scope, my $nm = node_name($rawNode))) { |
|
|
0
|
|
|
|
|
|
1013
|
0
|
|
|
|
|
0
|
$var->as_lvalue; |
1014
|
|
|
|
|
|
|
} elsif (defined $defaultFlag) { |
1015
|
0
|
|
|
|
|
0
|
$defaultFlag |
1016
|
|
|
|
|
|
|
} else { |
1017
|
0
|
|
|
|
|
0
|
die $trans->node_error($cursor, "No such variable '%s'", $nm); |
1018
|
|
|
|
|
|
|
} |
1019
|
|
|
|
|
|
|
} else { |
1020
|
0
|
|
|
|
|
0
|
undef; |
1021
|
|
|
|
|
|
|
} |
1022
|
|
|
|
|
|
|
} |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
sub mark_vars { |
1025
|
102
|
|
|
102
|
0
|
230
|
(my MY $trans, my ($scope, $early_escaped, $node)) = @_; |
1026
|
102
|
|
|
|
|
162
|
my @result; |
1027
|
102
|
|
|
|
|
345
|
for (; $node->readable; $node->next) { |
1028
|
149
|
100
|
|
|
|
463
|
if ($node->node_type == TEXT_TYPE) { |
|
|
50
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
# XXX: dots_for_arrows |
1030
|
109
|
|
|
|
|
300
|
push @result, $node->current; |
1031
|
|
|
|
|
|
|
} elsif ($node->node_type == ELEMENT_TYPE) { |
1032
|
0
|
|
|
|
|
0
|
push @result, \ $trans->generate_captured($scope, $node); |
1033
|
|
|
|
|
|
|
} else { |
1034
|
40
|
|
|
|
|
158
|
push @result, \ $trans->generate_entref($scope, $early_escaped, $node); |
1035
|
|
|
|
|
|
|
} |
1036
|
|
|
|
|
|
|
} |
1037
|
102
|
|
|
|
|
437
|
@result; |
1038
|
|
|
|
|
|
|
} |
1039
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
sub feed_array_if { |
1041
|
283
|
|
|
283
|
0
|
548
|
(my MY $trans, my ($name, $array)) = @_; |
1042
|
283
|
50
|
|
|
|
707
|
return unless @$array >= 1; |
1043
|
283
|
100
|
|
|
|
1479
|
return unless $array->[0][0] eq $name; |
1044
|
90
|
|
|
|
|
148
|
my $desc = shift @$array; |
1045
|
90
|
50
|
|
|
|
256
|
wantarray ? @{$desc}[1..$#$desc] : $desc; |
|
90
|
|
|
|
|
452
|
|
1046
|
|
|
|
|
|
|
} |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
# $node の情報を借りながら、@_ を generate. |
1049
|
|
|
|
|
|
|
sub gen_entref_list { |
1050
|
32
|
|
|
32
|
0
|
94
|
(my MY $trans, my ($scope, $node)) = splice @_, 0, 3; |
1051
|
32
|
|
|
|
|
57
|
my @result; |
1052
|
32
|
|
|
|
|
84
|
foreach my $item (@_) { |
1053
|
50
|
100
|
|
|
|
183
|
push @result, $trans->gen_entref_path |
1054
|
|
|
|
|
|
|
($scope, $node |
1055
|
|
|
|
|
|
|
, is_nested_entpath($item) ? @$item : $item); |
1056
|
|
|
|
|
|
|
} |
1057
|
32
|
|
|
|
|
175
|
@result; |
1058
|
|
|
|
|
|
|
} |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
sub gen_entref_path { |
1061
|
90
|
|
|
90
|
0
|
305
|
(my MY $trans, my ($scope, $node)) = splice @_, 0, 3; |
1062
|
90
|
|
|
|
|
181
|
my $var; |
1063
|
90
|
|
|
|
|
131
|
my @expr = do { |
1064
|
90
|
100
|
|
|
|
300
|
if (my ($name, @args) = $trans->feed_array_if(call => \@_)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1065
|
16
|
|
|
|
|
98
|
my $pkg = $trans->get_package_from_node($node); |
1066
|
16
|
|
|
|
|
40
|
my $dont_call; |
1067
|
16
|
|
|
|
|
28
|
my $call = do { |
1068
|
|
|
|
|
|
|
# XXX: codevar は、path の先頭だけ。 |
1069
|
|
|
|
|
|
|
# 引数にも現れるから、 |
1070
|
16
|
100
|
|
|
|
206
|
if ($pkg->can(my $en = "entity_$name")) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1071
|
8
|
|
|
|
|
48
|
sprintf('%s->%s', $pkg, $en); |
1072
|
|
|
|
|
|
|
} elsif ($var = $trans->find_codearg($scope, $name)) { |
1073
|
1
|
|
|
|
|
5
|
sprintf('%1$s && %1$s->', $var->as_lvalue); |
1074
|
|
|
|
|
|
|
} elsif ($var = $trans->find_var($scope, $name)) { |
1075
|
1
|
50
|
|
|
|
7
|
if (my $handler = $var->can("entmacro_")) { |
1076
|
1
|
|
|
|
|
2
|
$dont_call++; |
1077
|
1
|
|
|
|
|
5
|
$handler->($var, $trans, $scope, $node, \@_, [], @args); |
1078
|
|
|
|
|
|
|
} else { |
1079
|
|
|
|
|
|
|
# XXX: 本当は $pkg よりもファイル名を出すべき。 |
1080
|
0
|
|
|
|
|
0
|
die $trans->node_error |
1081
|
|
|
|
|
|
|
($node, "not implemented call '%s' for %s in %s" |
1082
|
|
|
|
|
|
|
, $name, $pkg, $node->node_body); |
1083
|
|
|
|
|
|
|
} |
1084
|
|
|
|
|
|
|
} elsif (my $handler = $trans->can("entmacro_$name")) { |
1085
|
|
|
|
|
|
|
# XXX: $pkg->can の方が、拡張向きで良いのだが… |
1086
|
|
|
|
|
|
|
# 予約語も持ちたい。 |
1087
|
6
|
|
|
|
|
12
|
$dont_call++; |
1088
|
6
|
|
|
|
|
31
|
$handler->($pkg, $trans, $scope, $node, \@_, [], @args); |
1089
|
|
|
|
|
|
|
} else { |
1090
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "not implemented call '%s' in %s" |
1091
|
|
|
|
|
|
|
, $name, $node->node_body); |
1092
|
|
|
|
|
|
|
} |
1093
|
|
|
|
|
|
|
}; |
1094
|
|
|
|
|
|
|
|
1095
|
16
|
100
|
66
|
|
|
142
|
($dont_call || ref $call) ? $call : sprintf q{(%s(%s))}, $call, join ", " |
1096
|
|
|
|
|
|
|
, $trans->gen_entref_list($scope, $node, @args); |
1097
|
|
|
|
|
|
|
} elsif (($name) = $trans->feed_array_if(var => \@_)) { |
1098
|
35
|
50
|
|
|
|
100
|
unless ($var = $trans->find_var($scope, $name)) { |
1099
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "No such variable '%s'", $name); |
1100
|
|
|
|
|
|
|
} else { |
1101
|
35
|
|
|
|
|
109
|
$var->as_lvalue; |
1102
|
|
|
|
|
|
|
} |
1103
|
|
|
|
|
|
|
} elsif (($name) = $trans->feed_array_if(expr => \@_)) { |
1104
|
11
|
|
|
|
|
36
|
$name; |
1105
|
|
|
|
|
|
|
} elsif (my @items = $trans->feed_array_if(array => \@_)) { |
1106
|
2
|
|
|
|
|
10
|
'['.join(", ", $trans->gen_entref_list($scope, $node, @items)).']'; |
1107
|
|
|
|
|
|
|
} elsif (my @pairs = $trans->feed_array_if(hash => \@_)) { |
1108
|
|
|
|
|
|
|
# XXX: '=>' is better. |
1109
|
0
|
|
|
|
|
0
|
'{'.join(", ", $trans->gen_entref_list($scope, $node, @pairs)).'}'; |
1110
|
|
|
|
|
|
|
} elsif (($name) = $trans->feed_array_if(text => \@_)) { |
1111
|
26
|
|
|
|
|
63
|
qqvalue($name); |
1112
|
|
|
|
|
|
|
} else { |
1113
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "NIMPL(%s)", terse_dump(@_)); |
1114
|
|
|
|
|
|
|
} |
1115
|
|
|
|
|
|
|
}; |
1116
|
|
|
|
|
|
|
|
1117
|
90
|
|
|
|
|
349
|
while (@_) { |
1118
|
33
|
|
|
|
|
53
|
my $item = shift; |
1119
|
33
|
|
|
|
|
63
|
push @expr, do { |
1120
|
33
|
|
|
|
|
81
|
my ($type, $name, @args) = @$item; |
1121
|
33
|
100
|
|
|
|
120
|
if ($type eq 'call') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
# 先頭の変数が確定している場合の、特殊処理。 |
1123
|
|
|
|
|
|
|
# XXX: 同じ名前のメソッドが呼べなくなる、というデメリットが有る。 |
1124
|
20
|
100
|
33
|
|
|
369
|
if ($var and not ref $name |
|
|
|
66
|
|
|
|
|
1125
|
|
|
|
|
|
|
and my $handler = $var->can("entmacro_$name")) { |
1126
|
|
|
|
|
|
|
# ここまでの式を reset する必要が有る時がある。 |
1127
|
19
|
|
|
|
|
75
|
$handler->($var, $trans, $scope, $node, \@_, \@expr, @args); |
1128
|
|
|
|
|
|
|
} else { |
1129
|
1
|
|
|
|
|
6
|
sprintf q{%s(%s)}, $name, join ", " |
1130
|
|
|
|
|
|
|
, $trans->gen_entref_list($scope, $node, @args); |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
} elsif ($type eq 'var') { |
1133
|
2
|
50
|
|
|
|
11
|
sprintf '{%s}', join ", ", ref $name |
1134
|
|
|
|
|
|
|
? $trans->gen_entref_list($scope, $node, $name, @args) |
1135
|
|
|
|
|
|
|
: qqvalue($name); |
1136
|
|
|
|
|
|
|
} elsif ($type eq 'aref') { |
1137
|
|
|
|
|
|
|
# list は本来冗長だが、nest の処理のため。 |
1138
|
11
|
50
|
|
|
|
50
|
sprintf '[%s]', join", ", ref $name |
1139
|
|
|
|
|
|
|
? $trans->gen_entref_list($scope, $node, $name, @args) |
1140
|
|
|
|
|
|
|
: $name; |
1141
|
|
|
|
|
|
|
} else { |
1142
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "NIMPL(type=$type)"); |
1143
|
|
|
|
|
|
|
} |
1144
|
|
|
|
|
|
|
}; |
1145
|
|
|
|
|
|
|
} |
1146
|
|
|
|
|
|
|
|
1147
|
90
|
100
|
|
|
|
385
|
@expr > 1 ? join("->", @expr) : $expr[0]; |
1148
|
|
|
|
|
|
|
} |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
sub find_if_codearg { |
1151
|
156
|
|
|
156
|
0
|
341
|
(my MY $trans, my ($scope, $node, $entpath)) = @_; |
1152
|
156
|
|
|
|
|
501
|
my @entns = $node->node_path; |
1153
|
156
|
100
|
|
|
|
570
|
return unless $trans->strip_ns(\@entns); |
1154
|
155
|
100
|
|
|
|
1021
|
return if @entns; |
1155
|
24
|
100
|
|
|
|
94
|
return unless @$entpath == 1; |
1156
|
18
|
50
|
|
|
|
60
|
return unless $entpath->[0][0] eq 'call'; |
1157
|
18
|
|
|
|
|
27
|
my ($op, $name, @args) = @{$entpath->[0]}; |
|
18
|
|
|
|
|
58
|
|
1158
|
18
|
100
|
|
|
|
58
|
my $codearg = $trans->find_codearg($scope, $name) |
1159
|
|
|
|
|
|
|
or return; |
1160
|
7
|
|
|
|
|
36
|
($codearg, @args); |
1161
|
|
|
|
|
|
|
} |
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
sub decode_entpath { |
1164
|
229
|
|
|
229
|
0
|
429
|
(my MY $trans, my ($node, $entns)) = @_; |
1165
|
229
|
|
|
|
|
480
|
my $has_entns = defined $entns; |
1166
|
229
|
100
|
|
|
|
569
|
unless ($has_entns) { |
1167
|
213
|
|
|
|
|
699
|
$trans->strip_ns($entns = [$node->node_path]); |
1168
|
|
|
|
|
|
|
} |
1169
|
229
|
|
|
|
|
916
|
my $body = $node->node_body; |
1170
|
229
|
100
|
100
|
|
|
921
|
substr($body, 0, 0) = ':' if defined $body and not defined $node->node_name; |
1171
|
229
|
|
|
|
|
634
|
my @entpath = $trans->parse_entpath(join('', map {':'.$_} @$entns) |
|
194
|
|
|
|
|
1115
|
|
1172
|
|
|
|
|
|
|
. coalesce($body, '') |
1173
|
|
|
|
|
|
|
, $trans, $node); |
1174
|
|
|
|
|
|
|
|
1175
|
227
|
100
|
|
|
|
684
|
my $has_body = $body ? 1 : 0; |
1176
|
|
|
|
|
|
|
|
1177
|
227
|
100
|
|
|
|
883
|
$has_entns ? ($has_body, @entpath) : ($entns, $has_body, @entpath); |
1178
|
|
|
|
|
|
|
} |
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
sub generate_entref { |
1181
|
213
|
|
|
213
|
0
|
536
|
(my MY $trans, my ($scope, $escaped, $node)) = @_; |
1182
|
|
|
|
|
|
|
|
1183
|
213
|
|
|
|
|
746
|
my ($entns, $has_body, @entpath) = $trans->decode_entpath($node); |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
# 特例。&yatt:codevar(); は、副作用で print. |
1186
|
211
|
100
|
100
|
|
|
1012
|
if ($escaped == ENT_PRINTED |
1187
|
|
|
|
|
|
|
and my ($codearg, @args) |
1188
|
|
|
|
|
|
|
= $trans->find_if_codearg($scope, $node, \@entpath)) { |
1189
|
|
|
|
|
|
|
return \ sprintf('%1$s && %1$s->(%2$s)', $codearg->as_lvalue |
1190
|
|
|
|
|
|
|
, join(", ", map { |
1191
|
7
|
|
|
|
|
22
|
$trans->gen_entref_path($scope, $node, $_) |
|
0
|
|
|
|
|
0
|
|
1192
|
|
|
|
|
|
|
} @args)); |
1193
|
|
|
|
|
|
|
# 引数。 |
1194
|
|
|
|
|
|
|
} |
1195
|
204
|
100
|
66
|
|
|
1029
|
if ($has_body || @$entns > 1) { |
1196
|
|
|
|
|
|
|
# path が有る。 |
1197
|
40
|
|
|
|
|
181
|
my $expr = $trans->gen_entref_path($scope, $node, @entpath); |
1198
|
|
|
|
|
|
|
# XXX: sub { print } なら \ $expr にすべきだが、 |
1199
|
|
|
|
|
|
|
# sub { value } などは、むしろ YATT::escape(do {$expr}) すべき。 |
1200
|
40
|
100
|
|
|
|
240
|
return $expr if ref $expr; |
1201
|
38
|
100
|
|
|
|
370
|
return $escaped ? qq(YATT::escape($expr)) : $expr; |
1202
|
|
|
|
|
|
|
} |
1203
|
|
|
|
|
|
|
|
1204
|
164
|
|
|
|
|
287
|
my $varName = shift @$entns; |
1205
|
164
|
100
|
|
|
|
534
|
unless (my $vardecl = $trans->find_var($scope, $varName)) { |
1206
|
7
|
|
|
|
|
42
|
die $trans->node_error($node, "No such variable '%s'", $varName); |
1207
|
|
|
|
|
|
|
} else { |
1208
|
157
|
100
|
|
|
|
606
|
$escaped ? $vardecl->as_escaped : $vardecl->as_lvalue; |
1209
|
|
|
|
|
|
|
} |
1210
|
|
|
|
|
|
|
} |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
#======================================== |
1213
|
|
|
|
|
|
|
# マクロなどで、cursor になっていない targetNode を入手した後で、 |
1214
|
|
|
|
|
|
|
# それを再び cursor にして、指定の型のソースを生成する仕組み。 |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
# デフォルト値を最初に指定。 |
1217
|
|
|
|
|
|
|
sub default_gentype { |
1218
|
0
|
|
|
0
|
0
|
0
|
(my MY $trans, my ($default, $type, $scope, $baseNC, $targetNode)) = @_; |
1219
|
0
|
0
|
|
|
|
0
|
if (ref $type) { |
1220
|
0
|
|
|
|
|
0
|
croak "Type mismatch: \$type should be string for default_gentype: $type"; |
1221
|
|
|
|
|
|
|
} |
1222
|
0
|
0
|
0
|
|
|
0
|
unless (defined $targetNode and node_body($targetNode)) { |
1223
|
0
|
|
|
|
|
0
|
return $default; |
1224
|
|
|
|
|
|
|
} |
1225
|
|
|
|
|
|
|
# my $name = node_name($targetNode); |
1226
|
|
|
|
|
|
|
# if (my $var |
1227
|
|
|
|
|
|
|
# = $trans->has_pass_through_var($scope, $targetNode, $name)) { |
1228
|
|
|
|
|
|
|
# $var->as_lvalue; |
1229
|
|
|
|
|
|
|
# } else { |
1230
|
0
|
|
|
|
|
0
|
$trans->faked_gentype($type, $scope, $baseNC, $targetNode); |
1231
|
|
|
|
|
|
|
# } |
1232
|
|
|
|
|
|
|
} |
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
sub faked_gentype { |
1235
|
2
|
|
|
2
|
0
|
7
|
(my MY $trans, my ($type, $scope, $baseNC, $targetNode)) = @_; |
1236
|
2
|
50
|
|
|
|
8
|
my $node = $targetNode ? $trans->fake_cursor_from($baseNC, $targetNode) |
1237
|
|
|
|
|
|
|
: $baseNC; |
1238
|
2
|
50
|
|
|
|
16
|
my $sub = $trans->can("t_$type") |
1239
|
|
|
|
|
|
|
or die $trans->node_error($node, "No such argtype: %s", $type); |
1240
|
2
|
|
|
|
|
17
|
$sub->()->gen_assignable_node($trans, $scope, $node); |
1241
|
|
|
|
|
|
|
} |
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
# expr 専用。デフォルト値も渡せる。 |
1244
|
|
|
|
|
|
|
sub faked_genexpr { |
1245
|
0
|
|
|
0
|
0
|
0
|
(my MY $trans, my ($scope, $baseNC, $targetNode, $default, $ent_flag)) = @_; |
1246
|
0
|
0
|
0
|
|
|
0
|
unless (defined $targetNode and node_body($targetNode)) { |
1247
|
0
|
|
|
|
|
0
|
return $default; |
1248
|
|
|
|
|
|
|
} |
1249
|
|
|
|
|
|
|
# open するのが、faked_gentype(scalar) とも違う所、のはず。 |
1250
|
0
|
|
|
|
|
0
|
my $nc = $trans->fake_cursor_from($baseNC, $targetNode)->open; |
1251
|
0
|
0
|
|
|
|
0
|
$trans->genexpr_node($scope, defined $ent_flag ? $ent_flag : ENT_RAW |
1252
|
|
|
|
|
|
|
, $nc); |
1253
|
|
|
|
|
|
|
} |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
#======================================== |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::gen_getarg { |
1258
|
391
|
|
|
391
|
0
|
907
|
(my VarType $var, my MY $gen |
1259
|
|
|
|
|
|
|
, my ($scope, $widget, $metainfo, $actual)) = @_; |
1260
|
|
|
|
|
|
|
return $actual unless defined $var->{cf_default} |
1261
|
391
|
100
|
100
|
|
|
2007
|
and defined (my $mode = $var->{cf_default_mode}); |
1262
|
|
|
|
|
|
|
|
1263
|
12
|
100
|
|
|
|
46
|
if ($mode eq "!") { |
1264
|
2
|
|
|
|
|
14
|
return qq{defined $actual ? $actual : } |
1265
|
|
|
|
|
|
|
. qq{die "Argument '$var->{cf_varname}' is undef!"} |
1266
|
|
|
|
|
|
|
} |
1267
|
|
|
|
|
|
|
|
1268
|
10
|
|
|
|
|
14
|
my ($cond) = do { |
1269
|
10
|
100
|
|
|
|
43
|
if ($mode eq "|") { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1270
|
2
|
|
|
|
|
5
|
qq{$actual} |
1271
|
|
|
|
|
|
|
} elsif ($mode eq "?") { |
1272
|
6
|
|
|
|
|
22
|
qq{defined $actual && $actual ne ""} |
1273
|
|
|
|
|
|
|
} elsif ($mode eq "/") { |
1274
|
2
|
|
|
|
|
6
|
qq{defined $actual} |
1275
|
|
|
|
|
|
|
} else { |
1276
|
0
|
|
|
|
|
0
|
die "Unknown defaulting mode: $mode" |
1277
|
|
|
|
|
|
|
} |
1278
|
|
|
|
|
|
|
}; |
1279
|
|
|
|
|
|
|
|
1280
|
|
|
|
|
|
|
my $default = $var->gen_assignable_node |
1281
|
|
|
|
|
|
|
($gen, $scope |
1282
|
|
|
|
|
|
|
, $gen->fake_cursor($widget, $metainfo |
1283
|
10
|
100
|
|
|
|
64
|
, map {ref $_ ? @$_ : $_} $var->{cf_default}) |
1284
|
10
|
|
|
|
|
27
|
, 1); |
1285
|
|
|
|
|
|
|
|
1286
|
10
|
|
|
|
|
84
|
qq{($cond ? $actual : $default)}; |
1287
|
|
|
|
|
|
|
} |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::gen_assignable_node { |
1290
|
67
|
|
|
67
|
0
|
159
|
(my VarType $var, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1291
|
|
|
|
|
|
|
# early escaped な変数への代入値は、代入前に escape される。 |
1292
|
67
|
|
|
|
|
215
|
my $escaped = $var->early_escaped; |
1293
|
67
|
100
|
|
|
|
305
|
$var->quote_assignable |
1294
|
|
|
|
|
|
|
($trans->mark_vars($scope, $escaped, $is_opened ? $node : $node->open)); |
1295
|
|
|
|
|
|
|
} |
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::is_required { |
1298
|
62
|
|
|
62
|
0
|
100
|
my VarType $var = shift; |
1299
|
62
|
100
|
|
|
|
413
|
defined $var->{cf_default_mode} && $var->{cf_default_mode} eq '!'; |
1300
|
|
|
|
|
|
|
} |
1301
|
|
|
|
|
|
|
|
1302
|
0
|
|
|
0
|
0
|
0
|
sub YATT::Translator::Perl::VarType::can_call { 0 } |
1303
|
103
|
|
|
103
|
0
|
394
|
sub YATT::Translator::Perl::VarType::early_escaped { 0 } |
1304
|
929
|
|
|
929
|
0
|
4795
|
sub YATT::Translator::Perl::VarType::lvalue_format {'$%s'} |
1305
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_lvalue { |
1306
|
956
|
|
|
956
|
0
|
1564
|
my VarType $var = shift; |
1307
|
956
|
|
|
|
|
2257
|
sprintf $var->lvalue_format, $var->{cf_varname}; |
1308
|
|
|
|
|
|
|
} |
1309
|
|
|
|
|
|
|
|
1310
|
107
|
|
|
107
|
0
|
923
|
sub YATT::Translator::Perl::VarType::escaped_format {'YATT::escape($%s)'} |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_escaped { |
1313
|
123
|
|
|
123
|
0
|
175
|
my VarType $var = shift; |
1314
|
123
|
|
|
|
|
328
|
sprintf $var->escaped_format, $var->{cf_varname}; |
1315
|
|
|
|
|
|
|
} |
1316
|
|
|
|
|
|
|
|
1317
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_typespec { |
1318
|
0
|
|
|
0
|
0
|
0
|
shift->type_name; |
1319
|
|
|
|
|
|
|
} |
1320
|
|
|
|
|
|
|
|
1321
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_argspec { |
1322
|
0
|
|
|
0
|
0
|
0
|
(my VarType $var) = @_; |
1323
|
0
|
|
|
|
|
0
|
my $spec = $var->as_typespec; |
1324
|
0
|
0
|
|
|
|
0
|
if (my $mode = $var->{cf_default_mode}) { |
1325
|
0
|
|
|
|
|
0
|
$spec .= $mode; |
1326
|
0
|
0
|
|
|
|
0
|
if (defined (my $default = $var->{cf_default})) { |
1327
|
|
|
|
|
|
|
$spec .= join "", map { |
1328
|
0
|
0
|
|
|
|
0
|
ref $_ ? map(ref $_ ? stringify_node($_) : $_, @$_) : $_ |
|
0
|
0
|
|
|
|
0
|
|
1329
|
|
|
|
|
|
|
} $default; |
1330
|
|
|
|
|
|
|
} |
1331
|
|
|
|
|
|
|
} |
1332
|
0
|
|
|
|
|
0
|
$spec; |
1333
|
|
|
|
|
|
|
} |
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
use YATT::ArgTypes |
1336
|
3
|
|
|
|
|
62
|
(-type_map => \%TYPE_MAP |
1337
|
|
|
|
|
|
|
, -base => VarType |
1338
|
|
|
|
|
|
|
, -type_fmt => join("::", MY, 't_%s') |
1339
|
|
|
|
|
|
|
, [text => -alias => ''] |
1340
|
|
|
|
|
|
|
, [html => \ lvalue_format => '$html_%s', \ early_escaped => 1] |
1341
|
|
|
|
|
|
|
, [scalar => -alias => ['value', 'flag']] |
1342
|
|
|
|
|
|
|
, ['list'] |
1343
|
|
|
|
|
|
|
, [attr => -base => 'text'] |
1344
|
|
|
|
|
|
|
, [code => -alias => 'expr', \ can_call => 1 |
1345
|
|
|
|
|
|
|
# 引数の型情報 |
1346
|
|
|
|
|
|
|
, -fields => [qw(arg_dict arg_order)]] |
1347
|
|
|
|
|
|
|
, [delegate => -fields => [qw(cf_base_path |
1348
|
|
|
|
|
|
|
cf_base_widget |
1349
|
|
|
|
|
|
|
cf_delegate_vars)]] |
1350
|
|
|
|
|
|
|
, qw(:type_name) |
1351
|
3
|
|
|
3
|
|
1383
|
); |
|
3
|
|
|
|
|
8
|
|
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
$calling_conv{this} = t_scalar->new(varname => 'this'); |
1354
|
|
|
|
|
|
|
$calling_conv{args} = t_scalar->new(varname => 'args'); |
1355
|
|
|
|
|
|
|
$calling_conv{_} = t_scalar->new(varname => '_'); |
1356
|
|
|
|
|
|
|
|
1357
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_text::quote_assignable { |
1358
|
45
|
|
|
45
|
|
79
|
shift; |
1359
|
45
|
|
|
|
|
79
|
my ($nvars); |
1360
|
|
|
|
|
|
|
my @items = map { |
1361
|
45
|
100
|
|
|
|
96
|
if (ref $_) { |
|
53
|
|
|
|
|
134
|
|
1362
|
7
|
|
|
|
|
16
|
$nvars++; |
1363
|
7
|
|
|
|
|
20
|
$$_ |
1364
|
|
|
|
|
|
|
} else { |
1365
|
|
|
|
|
|
|
# $var is prohibited. |
1366
|
46
|
|
|
|
|
140
|
qparen($_); |
1367
|
|
|
|
|
|
|
} |
1368
|
|
|
|
|
|
|
} @_; |
1369
|
45
|
100
|
100
|
|
|
262
|
if (@items == 1 && !$nvars) { |
1370
|
39
|
|
|
|
|
210
|
$items[0]; |
1371
|
|
|
|
|
|
|
} else { |
1372
|
6
|
|
|
|
|
42
|
MY->as_join(@items); |
1373
|
|
|
|
|
|
|
} |
1374
|
|
|
|
|
|
|
} |
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
# XXX: 本当に良いのか? |
1377
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_html::quote_assignable { |
1378
|
0
|
|
|
0
|
|
0
|
shift; |
1379
|
0
|
|
|
|
|
0
|
sprintf q{YATT::escape(%s)}, t_text->quote_assignable(@_); |
1380
|
|
|
|
|
|
|
} |
1381
|
|
|
|
|
|
|
|
1382
|
16
|
|
|
16
|
|
200
|
sub YATT::Translator::Perl::t_html::escaped_format {shift->lvalue_format} |
1383
|
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_html::gen_assignable_node { |
1385
|
6
|
|
|
6
|
|
15
|
(my VarType $var, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1386
|
|
|
|
|
|
|
# XXX: フラグがダサい。 |
1387
|
6
|
100
|
|
|
|
28
|
my $n = $is_opened ? $node : $node->open; |
1388
|
6
|
100
|
|
|
|
25
|
if (my $expr = $trans->has_single_bare_varexpr($scope, $n)) { |
1389
|
1
|
|
|
|
|
9
|
t_scalar->quote_assignable($expr); |
1390
|
|
|
|
|
|
|
} else { |
1391
|
5
|
|
|
|
|
18
|
$trans->as_join($trans->generate_body($scope, $n)); |
1392
|
|
|
|
|
|
|
} |
1393
|
|
|
|
|
|
|
} |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_attr::as_typespec { |
1396
|
0
|
|
|
0
|
|
0
|
my t_attr $var = shift; |
1397
|
0
|
|
0
|
|
|
0
|
join(":", $var->type_name, $var->{cf_subtype} || $var->{cf_varname}); |
1398
|
|
|
|
|
|
|
} |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
|
1401
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_attr::entmacro_ { |
1402
|
1
|
|
|
1
|
|
4
|
(my t_attr $var, my MY $trans |
1403
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1404
|
1
|
50
|
|
|
|
5
|
if (@$restExpr) { |
1405
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "attr() should be last call."); |
1406
|
|
|
|
|
|
|
} |
1407
|
1
|
50
|
|
|
|
5
|
if (ref $var->{cf_subtype}) { |
1408
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "nested subtype for attr"); |
1409
|
|
|
|
|
|
|
} |
1410
|
1
|
|
|
|
|
5
|
my @expr = $trans->gen_entref_list($scope, $node, @args); |
1411
|
|
|
|
|
|
|
sprintf(q{YATT::attr('%s', %s)} |
1412
|
|
|
|
|
|
|
, $var->{cf_subtype} || $var->{cf_varname} |
1413
|
1
|
|
33
|
|
|
8
|
, join(", ", $var->as_lvalue, @expr)); |
1414
|
|
|
|
|
|
|
} |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_attr::as_escaped { |
1417
|
4
|
|
|
4
|
|
8
|
my t_attr $var = shift; |
1418
|
4
|
50
|
|
|
|
16
|
if (ref $var->{cf_subtype}) { |
1419
|
0
|
|
|
|
|
0
|
die "nested subtype for attr: $var->{cf_varname}"; |
1420
|
|
|
|
|
|
|
} |
1421
|
4
|
|
|
|
|
24
|
my $realvar = sprintf $var->lvalue_format, $var->{cf_varname}; |
1422
|
|
|
|
|
|
|
sprintf(q{YATT::named_attr('%s', %s)} |
1423
|
|
|
|
|
|
|
, $var->{cf_subtype} || $var->{cf_varname} |
1424
|
4
|
|
33
|
|
|
36
|
, $realvar); |
1425
|
|
|
|
|
|
|
} |
1426
|
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_scalar::quote_assignable { |
1428
|
13
|
|
|
13
|
|
25
|
shift; |
1429
|
13
|
100
|
|
|
|
33
|
'scalar(do {'.join("", map { ref $_ ? $$_ : $_ } @_).'})'; |
|
21
|
|
|
|
|
140
|
|
1430
|
|
|
|
|
|
|
} |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::quote_assignable { |
1433
|
13
|
|
|
13
|
|
25
|
shift; |
1434
|
13
|
100
|
|
|
|
37
|
'['.join("", map { ref $_ ? $$_ : $_ } @_).']'; |
|
25
|
|
|
|
|
147
|
|
1435
|
|
|
|
|
|
|
} |
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_expand { |
1438
|
17
|
|
|
17
|
|
63
|
(my t_list $var, my MY $trans |
1439
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1440
|
17
|
|
|
|
|
56
|
my $was = join "->", splice @$queue, 0; |
1441
|
17
|
|
|
|
|
107
|
sprintf q{map($_ ? @$_ : (), %s)}, $was; |
1442
|
|
|
|
|
|
|
} |
1443
|
|
|
|
|
|
|
|
1444
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_size { |
1445
|
2
|
|
|
2
|
|
5
|
(my t_list $var, my MY $trans |
1446
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1447
|
2
|
|
|
|
|
7
|
my $was = join "->", splice @$queue, 0; |
1448
|
2
|
|
|
|
|
13
|
sprintf q{scalar(map(defined $_ ? @$_ : (), %s))}, $was; |
1449
|
|
|
|
|
|
|
} |
1450
|
|
|
|
|
|
|
|
1451
|
|
|
|
|
|
|
# XXX: head($n), tail($n) |
1452
|
|
|
|
|
|
|
|
1453
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_head { |
1454
|
0
|
|
|
0
|
|
0
|
(my t_list $var, my MY $trans |
1455
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1456
|
0
|
|
|
|
|
0
|
my $was = join "->", splice @$queue, 0; |
1457
|
0
|
|
|
|
|
0
|
sprintf q{map($_ ? $$_[0] : (), %s)}, $was; |
1458
|
|
|
|
|
|
|
} |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_tail { |
1461
|
0
|
|
|
0
|
|
0
|
(my t_list $var, my MY $trans |
1462
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1463
|
0
|
|
|
|
|
0
|
my $was = join "->", splice @$queue, 0; |
1464
|
0
|
|
|
|
|
0
|
sprintf q{map($_ ? @{$_}[1..$#$_] : (), %s)}, $was; |
1465
|
|
|
|
|
|
|
} |
1466
|
|
|
|
|
|
|
|
1467
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_call { |
1468
|
25
|
|
|
25
|
|
57
|
(my t_code $argdecl, my MY $trans, my ($scope, $node)) = @_; |
1469
|
25
|
|
|
|
|
95
|
my ($post, @args) = $trans->genargs_static |
1470
|
|
|
|
|
|
|
($scope, $node->open, $argdecl->arg_specs); |
1471
|
|
|
|
|
|
|
# XXX: こっちを () しなくて済むのはなぜ? => の call だから? |
1472
|
25
|
|
|
|
|
175
|
return \ sprintf '%1$s && %1$s->(%2$s)%3$s', $argdecl->as_lvalue |
1473
|
|
|
|
|
|
|
, join(", ", @args), $post; |
1474
|
|
|
|
|
|
|
} |
1475
|
|
|
|
|
|
|
|
1476
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::arg_specs { |
1477
|
31
|
|
|
31
|
|
59
|
my t_code $argdecl = shift; |
1478
|
31
|
|
100
|
|
|
305
|
($argdecl->{arg_dict} ||= {}, $argdecl->{arg_order} ||= []); |
|
|
|
100
|
|
|
|
|
1479
|
|
|
|
|
|
|
} |
1480
|
|
|
|
|
|
|
|
1481
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_args { |
1482
|
39
|
|
|
39
|
|
71
|
(my t_code $argdecl) = @_; |
1483
|
|
|
|
|
|
|
return unless $argdecl->{arg_order} |
1484
|
39
|
100
|
100
|
|
|
278
|
&& (my @args = @{$argdecl->{arg_order}}); |
|
16
|
|
|
|
|
125
|
|
1485
|
|
|
|
|
|
|
\ sprintf('my (%s) = @_', join(", ", map { |
1486
|
9
|
|
|
|
|
28
|
$argdecl->{arg_dict}{$_}->as_lvalue; |
|
10
|
|
|
|
|
47
|
|
1487
|
|
|
|
|
|
|
} @args)); |
1488
|
|
|
|
|
|
|
} |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_body { |
1491
|
40
|
|
|
40
|
|
154
|
(my t_code $argdecl, my MY $trans, my ($scope, $is_expr, $node)) = @_; |
1492
|
40
|
50
|
|
|
|
141
|
return unless $node->array_size; |
1493
|
40
|
100
|
|
|
|
132
|
if ($is_expr) { |
1494
|
1
|
|
|
|
|
8
|
$trans->genexpr_node($scope, ENT_RAW, $node); |
1495
|
|
|
|
|
|
|
} else { |
1496
|
|
|
|
|
|
|
$trans->as_statement_list |
1497
|
|
|
|
|
|
|
($argdecl->gen_args |
1498
|
39
|
|
|
|
|
120
|
, $trans->generate_body([{}, [$argdecl->{arg_dict}, $scope]], $node)); |
1499
|
|
|
|
|
|
|
} |
1500
|
|
|
|
|
|
|
} |
1501
|
|
|
|
|
|
|
|
1502
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_assignable_node { |
1503
|
40
|
|
|
40
|
|
97
|
(my t_code $argdecl, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1504
|
40
|
|
100
|
|
|
173
|
my $is_expr = !$is_opened && !$node->is_quoted_by_element; |
1505
|
40
|
100
|
|
|
|
193
|
$trans->as_sub('', $argdecl->gen_body($trans, $scope, $is_expr |
1506
|
|
|
|
|
|
|
, $is_opened ? $node : $node->open)); |
1507
|
|
|
|
|
|
|
} |
1508
|
|
|
|
|
|
|
|
1509
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::has_arg { |
1510
|
12
|
|
|
12
|
|
26
|
(my t_code $argdecl, my ($name)) = @_; |
1511
|
12
|
|
|
|
|
80
|
defined $argdecl->{arg_dict}{$name}; |
1512
|
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::add_arg { |
1515
|
13
|
|
|
13
|
|
40
|
(my t_code $codevar, my ($name, $arg)) = @_; |
1516
|
13
|
|
|
|
|
80
|
add_arg_order_in($codevar->{arg_dict}, $codevar->{arg_order}, $name, $arg); |
1517
|
13
|
|
|
|
|
65
|
$codevar; |
1518
|
|
|
|
|
|
|
} |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::clone { |
1521
|
6
|
|
|
6
|
|
13
|
(my t_code $orig) = @_; |
1522
|
6
|
|
|
|
|
32
|
my t_code $new = $orig->SUPER::clone; |
1523
|
6
|
|
|
|
|
37
|
my ($dict, $order) = $orig->arg_specs; |
1524
|
6
|
|
|
|
|
20
|
foreach my $name (@$order) { |
1525
|
1
|
|
|
|
|
6
|
$new->add_arg($name, $dict->{$name}->clone); |
1526
|
|
|
|
|
|
|
} |
1527
|
|
|
|
|
|
|
$new |
1528
|
6
|
|
|
|
|
27
|
} |
1529
|
|
|
|
|
|
|
|
1530
|
|
|
|
|
|
|
# code 型の変数宣言の生成 |
1531
|
|
|
|
|
|
|
sub create_var_code { |
1532
|
172
|
|
|
172
|
0
|
441
|
(my MY $trans, my ($node, @param)) = @_; |
1533
|
172
|
|
|
|
|
1457
|
my t_code $codevar = $trans->t_code->new(@param); |
1534
|
172
|
100
|
|
|
|
502
|
$trans->define_args($codevar, $node->open) if $node; |
1535
|
172
|
|
|
|
|
881
|
$codevar; |
1536
|
|
|
|
|
|
|
} |
1537
|
|
|
|
|
|
|
|
1538
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_delegate::gen_call { |
1539
|
5
|
|
|
5
|
|
14
|
(my t_delegate $argdecl, my MY $trans, my ($scope, $node)) = @_; |
1540
|
|
|
|
|
|
|
my $func = $trans->get_funcname_to($trans->{cf_mode} |
1541
|
5
|
|
|
|
|
24
|
, $argdecl->{cf_base_widget}); |
1542
|
|
|
|
|
|
|
# XXX: テストを書け。body が code か html か、だ。 |
1543
|
|
|
|
|
|
|
# my $body_dict = $argdecl->{cf_base_widget}->get_arg_spec(body => undef); |
1544
|
5
|
|
|
|
|
13
|
my $body_spec = $argdecl->{cf_base_widget}->{arg_dict}->{body}; |
1545
|
5
|
|
|
|
|
11
|
my $body_scope = do { |
1546
|
5
|
50
|
|
|
|
26
|
if ($body_spec->type_name eq 'code') { |
1547
|
5
|
|
|
|
|
16
|
[$body_spec->{arg_dict}, $scope] |
1548
|
|
|
|
|
|
|
} else { |
1549
|
0
|
|
|
|
|
0
|
$scope |
1550
|
|
|
|
|
|
|
} |
1551
|
|
|
|
|
|
|
}; |
1552
|
5
|
|
|
|
|
26
|
my ($post, @args) = $trans->genargs_static |
1553
|
|
|
|
|
|
|
([{}, $body_scope] |
1554
|
|
|
|
|
|
|
, $node->open, $argdecl->arg_specs); |
1555
|
|
|
|
|
|
|
return \ sprintf(' %s($this, [%s])%s', $func |
1556
|
5
|
50
|
|
|
|
29
|
, join(", ", map {defined $_ ? $_ : 'undef'} @args) |
|
18
|
|
|
|
|
99
|
|
1557
|
|
|
|
|
|
|
, $post); |
1558
|
|
|
|
|
|
|
} |
1559
|
|
|
|
|
|
|
|
1560
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_delegate::arg_specs { |
1561
|
5
|
|
|
5
|
|
12
|
my t_delegate $argdecl = shift; |
1562
|
|
|
|
|
|
|
($argdecl->{cf_base_widget}->arg_specs |
1563
|
5
|
|
|
|
|
38
|
, $argdecl->{cf_delegate_vars}); |
1564
|
|
|
|
|
|
|
} |
1565
|
|
|
|
|
|
|
|
1566
|
|
|
|
|
|
|
#======================================== |
1567
|
|
|
|
|
|
|
|
1568
|
|
|
|
|
|
|
sub make_arg_spec { |
1569
|
7
|
|
|
7
|
0
|
16
|
my ($dict, $order) = splice @_, 0, 2; |
1570
|
7
|
|
|
|
|
16
|
foreach my $name (@_) { |
1571
|
19
|
|
|
|
|
40
|
$dict->{$name} = @$order; |
1572
|
19
|
|
|
|
|
40
|
push @$order, $name; |
1573
|
|
|
|
|
|
|
} |
1574
|
|
|
|
|
|
|
} |
1575
|
|
|
|
|
|
|
|
1576
|
|
|
|
|
|
|
sub arg_name_types { |
1577
|
109
|
|
|
109
|
0
|
214
|
(my MY $trans, my ($args)) = @_; |
1578
|
109
|
|
|
|
|
341
|
my (@path) = $args->node_path; |
1579
|
109
|
100
|
66
|
|
|
336
|
if ($args->is_attribute and $args->is_quoted_by_element) { |
1580
|
8
|
|
|
|
|
15
|
shift @path; |
1581
|
|
|
|
|
|
|
} |
1582
|
109
|
|
|
|
|
269
|
my ($name) = shift @path; |
1583
|
109
|
50
|
|
|
|
451
|
@path >= 2 ? ($name, \@path) : ($name, $path[0]); |
1584
|
|
|
|
|
|
|
} |
1585
|
|
|
|
|
|
|
|
1586
|
|
|
|
|
|
|
# macro の、 my:type=var など専用。 |
1587
|
|
|
|
|
|
|
sub feed_arg_spec { |
1588
|
14
|
|
|
14
|
0
|
42
|
(my MY $trans, my ($args, $arg_dict, $arg_order)) = splice @_, 0, 4; |
1589
|
14
|
|
|
|
|
21
|
my $found; |
1590
|
14
|
|
|
|
|
70
|
for (my $nth = 0; $args->readable; $args->next) { |
1591
|
31
|
100
|
|
|
|
107
|
last unless $args->is_primary_attribute; |
1592
|
17
|
|
|
|
|
66
|
my ($name, @ext) = $args->node_path; |
1593
|
17
|
100
|
|
|
|
55
|
unless (defined $name) { |
1594
|
4
|
50
|
|
|
|
22
|
$name = $arg_order->[$nth++] |
1595
|
|
|
|
|
|
|
or die $trans->node_error($args, "Too many args"); |
1596
|
|
|
|
|
|
|
} |
1597
|
17
|
50
|
|
|
|
67
|
defined (my $argno = $arg_dict->{$name}) |
1598
|
|
|
|
|
|
|
or die $trans->node_error($args, "Unknown arg '%s'", $name); |
1599
|
|
|
|
|
|
|
|
1600
|
17
|
|
|
|
|
60
|
$_[$argno] = $args->current; |
1601
|
17
|
|
|
|
|
66
|
$found++; |
1602
|
|
|
|
|
|
|
} |
1603
|
14
|
|
|
|
|
57
|
$found; |
1604
|
|
|
|
|
|
|
} |
1605
|
|
|
|
|
|
|
|
1606
|
|
|
|
|
|
|
{ |
1607
|
|
|
|
|
|
|
# list=list/value, my=text, ith=text |
1608
|
|
|
|
|
|
|
make_arg_spec(\ my %arg_dict, \ my @arg_order |
1609
|
|
|
|
|
|
|
, qw(list my ith)); |
1610
|
|
|
|
|
|
|
|
1611
|
|
|
|
|
|
|
declare_alias macro_yatt_foreach => \¯o_foreach; |
1612
|
|
|
|
|
|
|
sub macro_foreach { |
1613
|
6
|
|
|
6
|
0
|
22
|
(my MY $trans, my ($scope, $args, $fragment)) = @_; |
1614
|
|
|
|
|
|
|
|
1615
|
6
|
50
|
|
|
|
36
|
$trans->feed_arg_spec($args, \%arg_dict, \@arg_order |
1616
|
|
|
|
|
|
|
, my ($list, $my, $ith)) |
1617
|
|
|
|
|
|
|
or die $trans->node_error($args, "Not enough arguments"); |
1618
|
|
|
|
|
|
|
|
1619
|
6
|
50
|
|
|
|
25
|
unless (defined $list) { |
1620
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "no list= is given"); |
1621
|
|
|
|
|
|
|
} |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
# $ith をまだ使っていない。 |
1624
|
6
|
|
|
|
|
13
|
my %local; |
1625
|
6
|
|
|
|
|
13
|
my $loopvar = do { |
1626
|
6
|
100
|
|
|
|
19
|
if ($my) { |
1627
|
5
|
|
|
|
|
22
|
my ($x, @type) = node_path($my); |
1628
|
5
|
|
|
|
|
21
|
my $varname = node_body($my); |
1629
|
5
|
|
50
|
|
|
43
|
$local{$varname} = $trans->create_var |
1630
|
|
|
|
|
|
|
($type[0] || '', undef, varname => $varname); |
1631
|
5
|
|
|
|
|
17
|
'my $' . $varname; |
1632
|
|
|
|
|
|
|
} else { |
1633
|
|
|
|
|
|
|
# _ は? entity 自体に処理させるか… |
1634
|
1
|
|
|
|
|
4
|
'' |
1635
|
|
|
|
|
|
|
} |
1636
|
|
|
|
|
|
|
}; |
1637
|
|
|
|
|
|
|
|
1638
|
6
|
|
|
|
|
17
|
my $fmt = q{foreach %1$s (%2$s) %3$s}; |
1639
|
6
|
|
|
|
|
10
|
my $listexpr = do { |
1640
|
6
|
|
|
|
|
12
|
if (0) { |
1641
|
|
|
|
|
|
|
print STDERR "# foreach list: " |
1642
|
|
|
|
|
|
|
, YATT::LRXML::Node::stringify_node($list), "\n"; |
1643
|
|
|
|
|
|
|
} |
1644
|
|
|
|
|
|
|
# XXX: 何故使い分けが必要になってしまうのか? |
1645
|
|
|
|
|
|
|
# my $fc = $args->adopter_for($list); |
1646
|
|
|
|
|
|
|
# my $fc = $trans->fake_cursor_from($args, $list); |
1647
|
6
|
100
|
|
|
|
30
|
if (my $var = $trans->has_pass_through_var |
1648
|
|
|
|
|
|
|
($scope, my $fc = $trans->fake_cursor_from($args, $list), 'list')) { |
1649
|
3
|
100
|
|
|
|
20
|
unless ($var->type_name eq 'list') { |
1650
|
1
|
|
|
|
|
6
|
my $path = $args->parent->node_path; |
1651
|
1
|
|
|
|
|
11
|
die $trans->node_error($fc, "$path - should be list type") |
1652
|
|
|
|
|
|
|
} |
1653
|
2
|
|
|
|
|
9
|
'@'.$var->as_lvalue; |
1654
|
|
|
|
|
|
|
} else { |
1655
|
3
|
|
|
|
|
16
|
$trans->genexpr_node($scope, 0, $args->adopter_for($list)); |
1656
|
|
|
|
|
|
|
} |
1657
|
|
|
|
|
|
|
}; |
1658
|
5
|
|
|
|
|
53
|
my @statements = $trans->as_statement_list |
1659
|
|
|
|
|
|
|
($trans->generate_body([\%local, $scope], $args)); |
1660
|
|
|
|
|
|
|
|
1661
|
5
|
50
|
|
|
|
23
|
if ($fragment) { |
1662
|
0
|
|
|
|
|
0
|
($fmt, $loopvar, $listexpr, \@statements); |
1663
|
|
|
|
|
|
|
} else { |
1664
|
5
|
|
|
|
|
23
|
\ sprintf $fmt, $loopvar, $listexpr, $trans->as_block(@statements); |
1665
|
|
|
|
|
|
|
} |
1666
|
|
|
|
|
|
|
} |
1667
|
|
|
|
|
|
|
} |
1668
|
|
|
|
|
|
|
|
1669
|
|
|
|
|
|
|
{ |
1670
|
|
|
|
|
|
|
# if |
1671
|
|
|
|
|
|
|
make_arg_spec(\ my %arg_dict, \ my @arg_order |
1672
|
|
|
|
|
|
|
, qw(if unless)); |
1673
|
|
|
|
|
|
|
sub gen_macro_if_arm { |
1674
|
8
|
|
|
8
|
0
|
27
|
(my MY $trans, my ($scope, $primary, $pkg, $if, $unless, $body)) = @_; |
1675
|
8
|
|
|
|
|
18
|
my $header = do { |
1676
|
8
|
100
|
|
|
|
25
|
if ($primary) { |
1677
|
5
|
|
|
|
|
12
|
my ($kw, $cond) = do { |
1678
|
5
|
50
|
|
|
|
14
|
if ($if) { (if => $if) } |
|
5
|
0
|
|
|
|
19
|
|
1679
|
0
|
|
|
|
|
0
|
elsif ($unless) { (unless => $unless) } |
1680
|
0
|
|
|
|
|
0
|
else { die "??" } |
1681
|
|
|
|
|
|
|
}; |
1682
|
5
|
|
|
|
|
31
|
sprintf q{%s (%s) }, $kw |
1683
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0 |
1684
|
|
|
|
|
|
|
, $trans->fake_cursor_from($body, $cond, 1)); |
1685
|
|
|
|
|
|
|
} else { |
1686
|
3
|
|
|
|
|
7
|
my ($cond, $true) = do { |
1687
|
3
|
100
|
|
|
|
15
|
if ($if) { ($if, 1) } |
|
1
|
50
|
|
|
|
5
|
|
1688
|
0
|
|
|
|
|
0
|
elsif ($unless) { ($unless, 0) } |
1689
|
|
|
|
|
|
|
else {} |
1690
|
|
|
|
|
|
|
}; |
1691
|
3
|
100
|
|
|
|
13
|
unless (defined $cond) { |
1692
|
2
|
|
|
|
|
7
|
q{else } |
1693
|
|
|
|
|
|
|
} else { |
1694
|
1
|
|
|
|
|
8
|
my $expr = $trans->genexpr_node |
1695
|
|
|
|
|
|
|
($scope, 0 |
1696
|
|
|
|
|
|
|
, $trans->fake_cursor_from($body, $cond, 1)); |
1697
|
1
|
50
|
|
|
|
13
|
sprintf q{elsif (%s) }, $true ? $expr : qq{not($expr)}; |
1698
|
|
|
|
|
|
|
} |
1699
|
|
|
|
|
|
|
} |
1700
|
|
|
|
|
|
|
}; |
1701
|
8
|
|
|
|
|
51
|
$header . $trans->as_block |
1702
|
|
|
|
|
|
|
($trans->as_statement_list |
1703
|
|
|
|
|
|
|
($trans->generate_body($scope, $body))); |
1704
|
|
|
|
|
|
|
} |
1705
|
|
|
|
|
|
|
|
1706
|
|
|
|
|
|
|
declare_alias macro_yatt_if => \¯o_if; |
1707
|
|
|
|
|
|
|
sub macro_if { |
1708
|
5
|
|
|
5
|
0
|
15
|
(my MY $trans, my ($scope, $args)) = @_; |
1709
|
|
|
|
|
|
|
|
1710
|
5
|
|
|
|
|
13
|
my @case = do { |
1711
|
5
|
50
|
|
|
|
29
|
$trans->feed_arg_spec($args, \%arg_dict, \@arg_order |
1712
|
|
|
|
|
|
|
, my ($if, $unless)) |
1713
|
|
|
|
|
|
|
or die $trans->node_error($args, "Not enough arguments"); |
1714
|
5
|
|
|
|
|
27
|
([$if, $unless, $args->variant_builder]); |
1715
|
|
|
|
|
|
|
}; |
1716
|
5
|
|
|
|
|
22
|
for (; $args->readable; $args->next) { |
1717
|
12
|
100
|
66
|
|
|
45
|
if ($args->is_attribute && $args->node_name eq 'else') { |
1718
|
3
|
|
|
|
|
13
|
my $kid = $args->open; |
1719
|
3
|
|
|
|
|
16
|
$trans->feed_arg_spec($kid, \%arg_dict, \@arg_order |
1720
|
|
|
|
|
|
|
, my ($if, $unless)); |
1721
|
3
|
|
|
|
|
19
|
push @case, [$if, $unless, $kid]; |
1722
|
|
|
|
|
|
|
} else { |
1723
|
|
|
|
|
|
|
# XXX: 多分、$case[0] |
1724
|
9
|
|
|
|
|
41
|
$case[-1][-1]->add_node($args->current); |
1725
|
|
|
|
|
|
|
} |
1726
|
|
|
|
|
|
|
} |
1727
|
|
|
|
|
|
|
|
1728
|
5
|
|
|
|
|
31
|
my $pkg = $trans->get_package_from_node($args); |
1729
|
5
|
|
|
|
|
16
|
my @script = $trans->gen_macro_if_arm($scope, 1, $pkg, @{shift @case}); |
|
5
|
|
|
|
|
23
|
|
1730
|
5
|
|
|
|
|
47
|
while (my $arm = shift @case) { |
1731
|
3
|
|
|
|
|
12
|
push @script, $trans->gen_macro_if_arm($scope, 0, $pkg, @$arm); |
1732
|
|
|
|
|
|
|
} |
1733
|
5
|
|
|
|
|
47
|
\ join " ", @script; |
1734
|
|
|
|
|
|
|
} |
1735
|
|
|
|
|
|
|
} |
1736
|
|
|
|
|
|
|
|
1737
|
|
|
|
|
|
|
{ |
1738
|
|
|
|
|
|
|
declare_alias macro_yatt_block => \¯o_block; |
1739
|
|
|
|
|
|
|
sub macro_block { |
1740
|
3
|
|
|
3
|
0
|
7
|
(my MY $trans, my ($scope, $args)) = @_; |
1741
|
3
|
|
|
|
|
14
|
\ $trans->as_block |
1742
|
|
|
|
|
|
|
($trans->as_statement_list |
1743
|
|
|
|
|
|
|
($trans->generate_body([{}, $scope], $args))); |
1744
|
|
|
|
|
|
|
} |
1745
|
|
|
|
|
|
|
|
1746
|
|
|
|
|
|
|
declare_alias macro_yatt_my => \¯o_my; |
1747
|
|
|
|
|
|
|
sub macro_my { |
1748
|
6
|
|
|
6
|
0
|
21
|
(my MY $trans, my ($scope, $args)) = @_; |
1749
|
6
|
|
|
|
|
34
|
my @assign; |
1750
|
6
|
|
|
|
|
22
|
my $filename = $args->metainfo->filename; |
1751
|
6
|
|
|
|
|
26
|
for (; $args->readable; $args->next) { |
1752
|
8
|
100
|
|
|
|
39
|
last unless $args->is_primary_attribute; |
1753
|
7
|
|
|
|
|
38
|
my ($name, $typename) = $trans->arg_name_types($args); |
1754
|
7
|
100
|
66
|
|
|
45
|
$typename ||= $args->next_is_body ? 'html' : 'text'; |
1755
|
7
|
50
|
|
|
|
28
|
if (my VarType $old = $scope->[0]{$name}) { |
1756
|
|
|
|
|
|
|
die $trans->node_error |
1757
|
|
|
|
|
|
|
($args, "Variable '%s' redefined (previously at file %s line %s)" |
1758
|
|
|
|
|
|
|
, $name, $old->{cf_filename} || '(unknown)' |
1759
|
0
|
|
0
|
|
|
0
|
, $old->{cf_linenum} || '(unknown)'); |
|
|
|
0
|
|
|
|
|
1760
|
|
|
|
|
|
|
} |
1761
|
7
|
|
|
|
|
38
|
my $var = $scope->[0]{$name} |
1762
|
|
|
|
|
|
|
= $trans->create_var($typename, $args |
1763
|
|
|
|
|
|
|
, varname => $name |
1764
|
|
|
|
|
|
|
, filename => $filename |
1765
|
|
|
|
|
|
|
, linenum => $args->linenum); |
1766
|
|
|
|
|
|
|
|
1767
|
7
|
100
|
|
|
|
33
|
push @assign, [$var, $args->node_size |
1768
|
|
|
|
|
|
|
? $var->gen_assignable_node($trans, $scope, $args) |
1769
|
|
|
|
|
|
|
: ()]; |
1770
|
|
|
|
|
|
|
} |
1771
|
|
|
|
|
|
|
|
1772
|
6
|
100
|
|
|
|
21
|
if ($args->readable) { |
1773
|
1
|
|
|
|
|
4
|
my $var = $assign[-1][0]; |
1774
|
1
|
|
33
|
|
|
9
|
$assign[-1][1] ||= $var->gen_assignable_node($trans, $scope, $args, 1); |
1775
|
|
|
|
|
|
|
} |
1776
|
|
|
|
|
|
|
|
1777
|
6
|
|
|
|
|
12
|
my @script; |
1778
|
6
|
|
|
|
|
50
|
foreach my $desc (@assign) { |
1779
|
7
|
|
|
|
|
18
|
my ($var, $value) = @$desc; |
1780
|
7
|
|
|
|
|
24
|
my $script = sprintf q{my %s}, $var->as_lvalue; |
1781
|
7
|
100
|
|
|
|
31
|
$script .= q{ = } . $value if defined $value; |
1782
|
7
|
|
|
|
|
21
|
push @script, \ $script; |
1783
|
|
|
|
|
|
|
} |
1784
|
6
|
|
|
|
|
40
|
@script; |
1785
|
|
|
|
|
|
|
} |
1786
|
|
|
|
|
|
|
} |
1787
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
{ |
1789
|
|
|
|
|
|
|
declare_alias macro_yatt_format => \¯o_format; |
1790
|
|
|
|
|
|
|
sub macro_format { |
1791
|
3
|
|
|
3
|
0
|
8
|
(my MY $trans, my ($scope, $args)) = @_; |
1792
|
|
|
|
|
|
|
|
1793
|
3
|
50
|
33
|
|
|
15
|
unless ($args->readable && $args->is_primary_attribute) { |
1794
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "format parameter is missing"); |
1795
|
|
|
|
|
|
|
} |
1796
|
|
|
|
|
|
|
|
1797
|
3
|
|
|
|
|
14
|
my $name = $args->node_name; |
1798
|
|
|
|
|
|
|
|
1799
|
3
|
|
|
|
|
7
|
my $format = do { |
1800
|
3
|
100
|
|
|
|
15
|
if (my $var = $trans->has_pass_through_var($scope, $args, $name)) { |
1801
|
1
|
|
|
|
|
5
|
$var->as_lvalue; |
1802
|
|
|
|
|
|
|
} else { |
1803
|
2
|
|
|
|
|
17
|
$trans->faked_gentype(text => $scope, $args); |
1804
|
|
|
|
|
|
|
} |
1805
|
|
|
|
|
|
|
}; |
1806
|
|
|
|
|
|
|
|
1807
|
3
|
|
|
|
|
21
|
$args->next; |
1808
|
|
|
|
|
|
|
|
1809
|
3
|
|
|
|
|
14
|
sprintf(q|sprintf(%s, %s)| |
1810
|
|
|
|
|
|
|
, $format |
1811
|
|
|
|
|
|
|
, $trans->as_join($trans->generate_body([{}, $scope], $args))); |
1812
|
|
|
|
|
|
|
} |
1813
|
|
|
|
|
|
|
} |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
sub macro_dbfetch { |
1816
|
0
|
|
|
0
|
0
|
0
|
require YATT::Translator::Perl::macro_dbfetch; |
1817
|
0
|
|
|
|
|
0
|
shift->YATT::Translator::Perl::macro_dbfetch::macro(@_); |
1818
|
|
|
|
|
|
|
} |
1819
|
|
|
|
|
|
|
|
1820
|
|
|
|
|
|
|
sub feed_arg_or_make_hash_of { |
1821
|
0
|
|
|
0
|
0
|
0
|
(my $trans |
1822
|
|
|
|
|
|
|
, my ($type, $scope, $args, $arg_dict, $arg_order)) = splice @_, 0, 6; |
1823
|
0
|
|
|
|
|
0
|
my (@primary, @secondary); |
1824
|
0
|
|
|
|
|
0
|
for (my $nth = 0; $args->readable; $args->next) { |
1825
|
0
|
0
|
|
|
|
0
|
last unless $args->is_primary_attribute; |
1826
|
0
|
|
|
|
|
0
|
my ($name, @ext) = $args->node_path; |
1827
|
0
|
0
|
|
|
|
0
|
unless (defined $name) { |
1828
|
0
|
0
|
|
|
|
0
|
$name = $arg_order->[$nth++] |
1829
|
|
|
|
|
|
|
or die $trans->node_error($args, "Too many args"); |
1830
|
|
|
|
|
|
|
} |
1831
|
0
|
0
|
|
|
|
0
|
if ($name =~ /^-(.*)/) { |
1832
|
|
|
|
|
|
|
# XXX: そもそも -name=[...] で構造化したかった |
1833
|
0
|
|
|
|
|
0
|
push @secondary, [$name, $trans->faked_gentype |
1834
|
|
|
|
|
|
|
($type => $scope, $args, $args->current)]; |
1835
|
0
|
|
|
|
|
0
|
next; |
1836
|
|
|
|
|
|
|
} |
1837
|
0
|
0
|
|
|
|
0
|
defined (my $argno = $arg_dict->{$name}) or do { |
1838
|
0
|
|
|
|
|
0
|
push @primary, [$name, $trans->faked_gentype |
1839
|
|
|
|
|
|
|
($type => $scope, $args, $args->current)]; |
1840
|
0
|
|
|
|
|
0
|
next; |
1841
|
|
|
|
|
|
|
}; |
1842
|
|
|
|
|
|
|
|
1843
|
0
|
|
|
|
|
0
|
$_[$argno] = $args->current; |
1844
|
|
|
|
|
|
|
} |
1845
|
0
|
0
|
|
|
|
0
|
grep {@$_ ? $_ : ()} (\@primary, \@secondary); |
|
0
|
|
|
|
|
0
|
|
1846
|
|
|
|
|
|
|
} |
1847
|
|
|
|
|
|
|
|
1848
|
|
|
|
|
|
|
#======================================== |
1849
|
|
|
|
|
|
|
sub entmacro_if { |
1850
|
4
|
|
|
4
|
0
|
15
|
my ($this, $trans |
1851
|
|
|
|
|
|
|
, $scope, $node, $restExpr, $queue, @args) = @_; |
1852
|
|
|
|
|
|
|
# XXX: $cond を文字列にするのは不便。 |
1853
|
4
|
|
|
|
|
21
|
my ($cond, $then, $else) |
1854
|
|
|
|
|
|
|
= $trans->gen_entref_list($scope, $node, @args); |
1855
|
|
|
|
|
|
|
# XXX: 三項演算だと、狂いが出そうな。 |
1856
|
|
|
|
|
|
|
sprintf q{((%s) ? %s : %s)} |
1857
|
4
|
50
|
50
|
|
|
19
|
, map {ref $_ ? $$_ : $_} $cond, $then, $else || q{''}; |
|
12
|
|
|
|
|
52
|
|
1858
|
|
|
|
|
|
|
}; |
1859
|
|
|
|
|
|
|
|
1860
|
|
|
|
|
|
|
sub entmacro_render { |
1861
|
2
|
|
|
2
|
0
|
6
|
my ($this, $trans |
1862
|
|
|
|
|
|
|
, $scope, $node, $restExpr, $queue, @args) = @_; |
1863
|
2
|
|
|
|
|
10
|
my ($type, @expr) |
1864
|
|
|
|
|
|
|
= $trans->gen_entref_list($scope, $node, @args); |
1865
|
2
|
|
|
|
|
15
|
\ sprintf q{__PACKAGE__->can('render_'.%s)->($this, [%s])} |
1866
|
|
|
|
|
|
|
, $type, join(", ", @expr); |
1867
|
|
|
|
|
|
|
}; |
1868
|
|
|
|
|
|
|
#======================================== |
1869
|
|
|
|
|
|
|
|
1870
|
|
|
|
|
|
|
sub paren_escape ($) { |
1871
|
352
|
50
|
|
352
|
0
|
888
|
unless (defined $_[0]) { |
1872
|
0
|
|
|
|
|
0
|
confess "Undefined text"; |
1873
|
|
|
|
|
|
|
} |
1874
|
352
|
|
|
|
|
809
|
$_[0] =~ s{([\(\)\\])}{\\$1}g; |
1875
|
352
|
|
|
|
|
2463
|
$_[0] |
1876
|
|
|
|
|
|
|
} |
1877
|
|
|
|
|
|
|
|
1878
|
|
|
|
|
|
|
sub qparen ($) { |
1879
|
352
|
|
|
352
|
0
|
839
|
'q('.paren_escape($_[0]).')' |
1880
|
|
|
|
|
|
|
} |
1881
|
|
|
|
|
|
|
|
1882
|
|
|
|
|
|
|
sub qqvalue ($) { |
1883
|
26
|
|
|
26
|
0
|
71
|
'q'.qparen($_[0]); |
1884
|
|
|
|
|
|
|
} |
1885
|
|
|
|
|
|
|
|
1886
|
|
|
|
|
|
|
{ |
1887
|
|
|
|
|
|
|
my %map = ("\r", "r", "\n", "n"); |
1888
|
|
|
|
|
|
|
sub qcrlf ($) { |
1889
|
129
|
|
|
129
|
0
|
245
|
my ($crlf) = @_; |
1890
|
129
|
|
|
|
|
967
|
$crlf =~ s{([\r\n])}{\\$map{$1}}g; |
1891
|
129
|
|
|
|
|
1129
|
$crlf; |
1892
|
|
|
|
|
|
|
} |
1893
|
|
|
|
|
|
|
} |
1894
|
|
|
|
|
|
|
|
1895
|
|
|
|
|
|
|
sub dots_for_arrows { |
1896
|
31
|
|
|
31
|
0
|
43
|
shift; |
1897
|
31
|
50
|
|
|
|
94
|
return unless defined $_[0]; |
1898
|
31
|
|
|
|
|
76
|
$_[0] =~ s{\b\.(?=\w+\()}{->}g; |
1899
|
31
|
|
|
|
|
146
|
$_[0]; |
1900
|
|
|
|
|
|
|
} |
1901
|
|
|
|
|
|
|
|
1902
|
|
|
|
|
|
|
1; |