line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
3
|
|
|
3
|
|
9221
|
package YATT::Translator::Perl; use YATT::Inc; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
3
|
3
|
|
|
3
|
|
10
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
95
|
|
4
|
3
|
|
|
3
|
|
10
|
use warnings FATAL => qw(all); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
116
|
|
5
|
3
|
|
|
3
|
|
10
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
211
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#======================================== |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our %TYPE_MAP; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
11
|
use base qw(YATT::Registry); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
966
|
|
12
|
0
|
|
|
0
|
|
0
|
use YATT::Fields [cf_mode => 'render'] |
13
|
3
|
|
|
|
|
22
|
, [cf_product => sub {[]}] |
14
|
|
|
|
|
|
|
, qw(target_cache |
15
|
|
|
|
|
|
|
delayed_target |
16
|
|
|
|
|
|
|
generating_widget |
17
|
|
|
|
|
|
|
cf_pagevars |
18
|
3
|
|
|
3
|
|
11
|
cf_debug_translator); |
|
3
|
|
|
|
|
3
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
10
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
3
|
|
|
|
|
97
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = qw(qqvalue qparen); |
22
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
14
|
use YATT::Registry::NS; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
142
|
|
25
|
3
|
|
|
3
|
|
11
|
use YATT::Widget; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
100
|
|
26
|
3
|
|
|
3
|
|
10
|
use YATT::Util qw(checked_eval add_arg_order_in terse_dump coalesce); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
126
|
|
27
|
3
|
|
|
|
|
189
|
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
|
|
12
|
TEXT_TYPE ELEMENT_TYPE ENTITY_TYPE); |
|
3
|
|
|
|
|
4
|
|
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
3
|
|
1125
|
use YATT::LRXML::EntityPath; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
161
|
|
35
|
3
|
|
|
3
|
|
16
|
use YATT::Util::Taint; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
217
|
|
36
|
3
|
|
|
3
|
|
12
|
use YATT::Util::Symbol qw(declare_alias); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
4097
|
|
37
|
|
|
|
|
|
|
require YATT::ArgMacro; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#======================================== |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub qqvalue ($); |
42
|
|
|
|
|
|
|
sub qparen ($); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#======================================== |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub after_configure { |
47
|
14
|
|
|
14
|
0
|
28
|
my MY $trans = shift; |
48
|
14
|
|
|
|
|
64
|
$trans->SUPER::after_configure; |
49
|
14
|
|
50
|
|
|
87
|
$trans->{cf_type_map} ||= \%TYPE_MAP; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub emit { |
53
|
142
|
|
|
142
|
0
|
180
|
my MY $gen = shift; |
54
|
142
|
|
|
|
|
166
|
my $script = join "", @{$gen->{cf_product}}; |
|
142
|
|
|
|
|
480
|
|
55
|
142
|
|
|
|
|
277
|
$gen->{cf_product} = []; |
56
|
142
|
|
|
|
|
486
|
$script; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#======================================== |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub call_handler { |
62
|
31
|
|
|
31
|
0
|
92
|
(my MY $trans, my ($method, $widget_path)) = splice @_, 0, 3; |
63
|
31
|
50
|
|
|
|
150
|
my ($handler, $pkg) = $trans->get_handler_to |
64
|
|
|
|
|
|
|
($method, ref $widget_path ? @$widget_path : split /[:\.]/, $widget_path); |
65
|
11
|
|
|
|
|
44
|
&YATT::break_handler; |
66
|
11
|
|
|
|
|
3558
|
$handler->($pkg, @_); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub parse_elempath { |
70
|
161
|
|
|
161
|
0
|
280
|
my ($pack, @elpath) = @_; |
71
|
161
|
100
|
|
|
|
407
|
if (@elpath == 1) { |
72
|
142
|
50
|
|
|
|
284
|
if (ref $elpath[0]) { |
73
|
0
|
|
|
|
|
0
|
@elpath = @{$elpath[0]}; |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
} else { |
75
|
142
|
|
|
|
|
419
|
@elpath = split '/', $elpath[0]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# root dir should be ignored. |
80
|
161
|
50
|
33
|
|
|
792
|
shift @elpath if !defined $elpath[0] || $elpath[0] eq ''; |
81
|
|
|
|
|
|
|
|
82
|
161
|
|
|
|
|
376
|
@elpath; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_handler_to { |
86
|
161
|
|
|
161
|
0
|
445
|
(my MY $trans, my ($method)) = splice @_, 0, 2; |
87
|
161
|
|
|
|
|
445
|
my @elpath = $trans->parse_elempath(@_); |
88
|
|
|
|
|
|
|
|
89
|
161
|
|
|
|
|
150
|
my @result; |
90
|
161
|
50
|
|
|
|
294
|
if (wantarray) { |
91
|
161
|
|
|
|
|
364
|
@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
|
|
|
|
331
|
unless (@result) { |
97
|
0
|
|
|
|
|
0
|
croak "Can't find widget: " . join(":", @elpath); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
141
|
50
|
|
|
|
798
|
wantarray ? @result : $result[0]; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub lookup_handler_to { |
104
|
161
|
|
|
161
|
0
|
293
|
(my MY $trans, my ($method, @elpath)) = @_; |
105
|
|
|
|
|
|
|
|
106
|
161
|
|
|
|
|
303
|
$trans->{cf_mode} = $method; # XXX: local |
107
|
161
|
|
|
|
|
165
|
@{$trans->{cf_product}} = (); |
|
161
|
|
|
|
|
303
|
|
108
|
|
|
|
|
|
|
|
109
|
161
|
50
|
|
|
|
568
|
my Widget $widget = $trans->get_widget(@elpath) |
110
|
|
|
|
|
|
|
or return; |
111
|
|
|
|
|
|
|
|
112
|
156
|
|
|
|
|
574
|
$trans->ensure_widget_is_generated($widget); |
113
|
142
|
100
|
|
|
|
523
|
if (my $script = $trans->emit) { |
114
|
117
|
50
|
|
|
|
322
|
print STDERR $script if $trans->{cf_debug_translator}; |
115
|
117
|
|
|
|
|
519
|
$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
|
|
|
|
|
533
|
my ($pkg, $funcname) = $trans->get_funcname_to($method, $widget); |
125
|
141
|
|
|
|
|
1131
|
my $handler = $pkg->can($funcname); |
126
|
|
|
|
|
|
|
|
127
|
141
|
50
|
|
|
|
287
|
return $handler unless wantarray; |
128
|
141
|
|
|
|
|
311
|
($handler |
129
|
|
|
|
|
|
|
, scalar $trans->get_package_from_widget($widget) |
130
|
|
|
|
|
|
|
, $widget); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_funcname_to { |
134
|
436
|
|
|
436
|
0
|
698
|
(my MY $trans, my ($mode), my Widget $widget) = @_; |
135
|
436
|
|
|
|
|
828
|
my $pkg = $trans->get_package_from_widget($widget); |
136
|
436
|
|
|
|
|
871
|
my $fname = "${mode}_$$widget{cf_name}"; |
137
|
436
|
100
|
|
|
|
1396
|
wantarray ? ($pkg, $fname) : join("::", $pkg, $fname); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_package_from_widget { |
141
|
593
|
|
|
593
|
0
|
556
|
(my MY $trans, my Widget $widget) = @_; |
142
|
593
|
|
|
|
|
1575
|
my $primary = $trans->get_package |
143
|
|
|
|
|
|
|
(my Template $tmpl = $trans->nsobj($widget->{cf_template_nsid})); |
144
|
|
|
|
|
|
|
|
145
|
593
|
100
|
|
|
|
1746
|
return $primary unless wantarray; |
146
|
16
|
|
|
|
|
48
|
($primary, $trans->get_rc_package_from_template($tmpl)); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub get_rc_package_from_template { |
150
|
153
|
|
|
153
|
0
|
244
|
(my MY $trans, my Template $tmpl) = @_; |
151
|
153
|
|
|
|
|
437
|
$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
|
446
|
(my MY $gen, my Widget $widget) = @_; |
177
|
243
|
|
|
|
|
758
|
$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
|
416
|
(my MY $gen, my $id_or_obj) = @_; |
184
|
246
|
|
|
|
|
256
|
(my $tmplid, my Template $tmpl) = do { |
185
|
246
|
50
|
|
|
|
444
|
if (ref $id_or_obj) { |
186
|
0
|
|
|
|
|
0
|
($id_or_obj->cget('nsid'), $id_or_obj) |
187
|
|
|
|
|
|
|
} else { |
188
|
246
|
|
|
|
|
669
|
($id_or_obj, $gen->nsobj($id_or_obj)); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
}; |
191
|
246
|
100
|
|
|
|
712
|
if (my $baseid = $tmpl->{cf_base_template}) { |
192
|
3
|
|
|
|
|
10
|
$gen->ensure_template_is_generated($baseid); |
193
|
|
|
|
|
|
|
} |
194
|
246
|
100
|
|
|
|
1032
|
unless ($gen->{target_cache}{$tmplid}++) { |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# eval は? |
197
|
141
|
|
|
|
|
157
|
push @{$$gen{cf_product}} |
|
141
|
|
|
|
|
422
|
|
198
|
|
|
|
|
|
|
, $gen->generate_template($gen->nsobj($tmplid)); |
199
|
|
|
|
|
|
|
} |
200
|
232
|
50
|
|
|
|
287
|
if (my @delayed = keys %{$gen->{delayed_target}}) { |
|
232
|
|
|
|
|
1068
|
|
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
|
217
|
(my MY $gen, my $tmplid) = @_; |
211
|
146
|
50
|
|
|
|
704
|
$tmplid = $tmplid->cget('nsid') if ref $tmplid; |
212
|
146
|
50
|
|
|
|
635
|
delete $gen->{target_cache}{$tmplid} ? 1 : 0; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my %calling_conv; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub generate_template { |
218
|
141
|
|
|
141
|
0
|
196
|
(my MY $gen, my Template $tmpl) = @_; |
219
|
141
|
50
|
|
|
|
433
|
print STDERR "Generate: $tmpl->{cf_loadkey}\n" |
220
|
|
|
|
|
|
|
if $gen->{cf_debug_translator}; |
221
|
141
|
|
|
|
|
458
|
my $metainfo = $tmpl->metainfo; |
222
|
|
|
|
|
|
|
my @use = map { |
223
|
141
|
50
|
|
|
|
334
|
unless (defined $_) { |
|
141
|
|
|
|
|
359
|
|
224
|
|
|
|
|
|
|
() |
225
|
141
|
|
|
|
|
329
|
} else { |
226
|
0
|
0
|
|
|
|
0
|
map {"use $_;"} ref $_ ? @$_ : $_ |
|
0
|
|
|
|
|
0
|
|
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
} $gen->{cf_use}; |
229
|
141
|
|
|
|
|
205
|
my @file_scope = do { |
230
|
141
|
100
|
|
|
|
354
|
if ($gen->{cf_pagevars}) { |
231
|
1
|
|
|
|
|
5
|
$gen->checked_eval(qq{require $gen->{cf_pagevars}}); |
232
|
1
|
|
|
|
|
5
|
push @use, "use $gen->{cf_pagevars} (qw($tmpl->{cf_name}), 1);"; |
233
|
1
|
|
|
|
|
7
|
($gen->{cf_pagevars}->build_scope_for($gen, $tmpl->{cf_name}) |
234
|
|
|
|
|
|
|
, [\%calling_conv]); |
235
|
|
|
|
|
|
|
} else { |
236
|
140
|
|
|
|
|
329
|
\%calling_conv; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
}; |
239
|
141
|
|
|
|
|
167
|
my @script; |
240
|
141
|
|
|
|
|
154
|
foreach my $widget (@{$tmpl->widget_list}) { |
|
141
|
|
|
|
|
491
|
|
241
|
220
|
|
|
|
|
747
|
push @script, $gen->generate_widget($widget, $metainfo, \@file_scope); |
242
|
|
|
|
|
|
|
} |
243
|
127
|
|
|
|
|
538
|
join("", q{package } . $gen->get_package($tmpl) . ';' |
244
|
|
|
|
|
|
|
, join("",@use) |
245
|
|
|
|
|
|
|
, @script); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub generate_lineinfo { |
249
|
406
|
|
|
406
|
0
|
724
|
(my MY $gen, my Widget $widget, my ($start, $prefix)) = @_; |
250
|
406
|
100
|
|
|
|
1482
|
return if $gen->{cf_no_lineinfo}; |
251
|
50
|
|
100
|
|
|
300
|
sprintf qq{%s#line %d "%s"\n}, $prefix || '' |
252
|
|
|
|
|
|
|
, $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
|
364
|
(my MY $gen, my Widget $widget, my ($metainfo, $file_scope)) = @_; |
262
|
220
|
|
|
|
|
545
|
local $gen->{generating_widget}[0] = $widget; |
263
|
220
|
|
|
|
|
826
|
my @body = $gen->generate_body |
264
|
|
|
|
|
|
|
([{}, $widget->widget_scope($file_scope)] |
265
|
|
|
|
|
|
|
, $widget->cursor(metainfo => $metainfo->clone |
266
|
|
|
|
|
|
|
(startline => $widget->{cf_body_start} |
267
|
|
|
|
|
|
|
, caller_widget => $widget))); |
268
|
|
|
|
|
|
|
# body が空の場合もありうる。 |
269
|
206
|
100
|
|
|
|
1991
|
return unless @body; |
270
|
203
|
|
|
|
|
657
|
my ($pkg, $funcname) = $gen->get_funcname_to($gen->{cf_mode}, $widget); |
271
|
203
|
|
|
|
|
698
|
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
|
|
|
|
|
|
|
, $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
|
280
|
(my MY $gen, my Widget $widget, my ($metainfo)) = @_; |
284
|
203
|
|
|
|
|
765
|
$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
|
309
|
(my MY $gen, my Widget $widget) = @_; |
299
|
203
|
|
|
|
|
443
|
my @args = qw($this $args); |
300
|
203
|
100
|
66
|
|
|
538
|
if ($widget->{arg_order} && @{$widget->{arg_order}}) { |
|
161
|
|
|
|
|
625
|
|
301
|
161
|
|
|
|
|
206
|
foreach my $name (@{$widget->{arg_order}}) { |
|
161
|
|
|
|
|
362
|
|
302
|
391
|
|
|
|
|
682
|
push @args, $widget->{arg_dict}{$name}->as_lvalue |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
203
|
|
|
|
|
1139
|
sprintf q{getargs_%s(\@_, my (%s))} |
306
|
|
|
|
|
|
|
, $$widget{cf_name}, join(", ", @args); |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub generate_body { |
310
|
285
|
|
|
285
|
0
|
766
|
(my MY $gen, my ($scope, $cursor)) = @_; |
311
|
285
|
|
|
|
|
404
|
my @code; |
312
|
285
|
|
|
|
|
713
|
for (; $cursor->readable; $cursor->next) { |
313
|
850
|
50
|
|
|
|
1629
|
if (my $sub = $gen->can("trans_" . (my $t = $cursor->node_type_name))) { |
314
|
850
|
|
|
|
|
1568
|
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
|
|
|
|
|
816
|
@code; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub as_sub { |
323
|
444
|
|
|
444
|
0
|
688
|
my ($gen, $func_name) = splice @_, 0, 2; |
324
|
444
|
|
|
|
|
976
|
"sub $func_name ". $gen->as_block(@_); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub as_block { |
328
|
460
|
|
|
460
|
0
|
556
|
my ($gen) = shift; |
329
|
460
|
50
|
|
|
|
743
|
return '{}' unless @_; |
330
|
460
|
|
|
|
|
494
|
my $last = pop; |
331
|
460
|
|
|
|
|
341
|
$last .= do { |
332
|
460
|
100
|
|
|
|
2217
|
if ($last =~ s/(\n+)$//) { |
333
|
326
|
|
|
|
|
838
|
"}$1"; |
334
|
|
|
|
|
|
|
} else { |
335
|
134
|
|
|
|
|
223
|
'}'; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
}; |
338
|
460
|
|
|
|
|
3024
|
'{ '.join("; ", @_, $last); |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub as_join { |
342
|
14
|
|
|
14
|
0
|
22
|
my MY $gen = shift; |
343
|
14
|
|
|
|
|
18
|
my (@result); |
344
|
14
|
|
|
|
|
30
|
foreach my $trans (@_) { |
345
|
35
|
50
|
|
|
|
49
|
if (ref $trans) { |
346
|
0
|
|
|
|
|
0
|
push @result, qq(YATT::capture {$$trans}); |
347
|
|
|
|
|
|
|
} else { |
348
|
35
|
|
|
|
|
49
|
push @result, $trans; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
} |
351
|
14
|
|
|
|
|
124
|
sprintf q{join('', %s)}, join ", ", @result; |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
use YATT::Types |
355
|
3
|
|
|
3
|
|
15
|
[queued_joiner => [qw(queue printable last_ws)]]; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
24
|
|
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::joiner { |
358
|
|
|
|
|
|
|
# 行が変わらない限り、一つの print に入れる。 |
359
|
|
|
|
|
|
|
# 行が変われば、別の print にする。 |
360
|
|
|
|
|
|
|
# 印字可能要素が無いなら、空白をそのまま入れる。 |
361
|
279
|
|
|
279
|
0
|
459
|
(my queued_joiner $me, my ($head)) = splice @_, 0, 2; |
362
|
279
|
|
|
|
|
476
|
my ($line, $prenl, @result, $argc, $nlines) = ('', ''); |
363
|
279
|
|
|
|
|
449
|
foreach my $i (@_) { |
364
|
590
|
100
|
|
|
|
1253
|
unless ($i =~ /\S/) { |
365
|
44
|
50
|
|
|
|
181
|
push @result, $i |
366
|
|
|
|
|
|
|
and next; |
367
|
|
|
|
|
|
|
} |
368
|
546
|
100
|
|
|
|
766
|
if ($line eq '') { |
369
|
|
|
|
|
|
|
# 先頭 |
370
|
306
|
100
|
|
|
|
953
|
if ($i =~ s/^(\s+)//) { |
371
|
86
|
|
|
|
|
174
|
$prenl .= $1; |
372
|
|
|
|
|
|
|
} |
373
|
306
|
50
|
|
|
|
525
|
if ($i ne '') { |
374
|
306
|
|
|
|
|
557
|
$line .= $prenl . $head . $i; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
} else { |
377
|
|
|
|
|
|
|
# 残り |
378
|
240
|
|
|
|
|
360
|
$line .= ', ' . $i; |
379
|
|
|
|
|
|
|
} |
380
|
546
|
100
|
|
|
|
1068
|
if ($i =~ /\n/) { |
381
|
246
|
|
|
|
|
350
|
push @result, $line; |
382
|
246
|
|
|
|
|
262
|
$line = ''; |
383
|
246
|
|
|
|
|
371
|
$prenl = ''; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
279
|
100
|
|
|
|
591
|
push @result, $line if $line ne ''; |
387
|
279
|
|
|
|
|
495
|
@result; |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::add { |
391
|
689
|
|
|
689
|
0
|
658
|
(my queued_joiner $me, my $str) = @_; |
392
|
689
|
|
|
|
|
488
|
push @{$me->{queue}}, $str; |
|
689
|
|
|
|
|
1033
|
|
393
|
689
|
100
|
|
|
|
1709
|
if ($str =~ /\S/) { |
394
|
546
|
|
|
|
|
660
|
$me->{printable}++; |
395
|
546
|
|
|
|
|
787
|
undef $me->{last_ws}; |
396
|
|
|
|
|
|
|
} else { |
397
|
143
|
|
|
|
|
275
|
$me->{last_ws} = 1; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub YATT::Translator::Perl::queued_joiner::emit_to { |
402
|
406
|
|
|
406
|
0
|
405
|
(my queued_joiner $me, my ($result)) = @_; |
403
|
406
|
100
|
|
|
|
607
|
if ($me->{printable}) { |
404
|
279
|
100
|
|
|
|
278
|
my $ws; $ws = pop @{$me->{queue}} if $me->{last_ws}; |
|
279
|
|
|
|
|
513
|
|
|
20
|
|
|
|
|
53
|
|
405
|
279
|
50
|
|
|
|
293
|
push @$result, $me->joiner('print ', @{$me->{queue}}) if @{$me->{queue}}; |
|
279
|
|
|
|
|
693
|
|
|
279
|
|
|
|
|
773
|
|
406
|
279
|
100
|
|
|
|
552
|
$result->[-1] .= $ws if $me->{last_ws}; |
407
|
|
|
|
|
|
|
} else { |
408
|
127
|
100
|
|
|
|
325
|
push @$result, @{$me->{queue}} if $me->{queue}; |
|
87
|
|
|
|
|
157
|
|
409
|
|
|
|
|
|
|
} |
410
|
406
|
|
|
|
|
407
|
undef @{$me->{queue}}; |
|
406
|
|
|
|
|
628
|
|
411
|
406
|
|
|
|
|
480
|
undef $me->{printable}; |
412
|
406
|
|
|
|
|
466
|
undef $me->{last_ws}; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub as_statement_list { |
416
|
256
|
|
|
256
|
0
|
290
|
my MY $gen = shift; |
417
|
256
|
|
|
|
|
1248
|
my queued_joiner $queue = queued_joiner->new; |
418
|
256
|
|
|
|
|
255
|
my (@result); |
419
|
256
|
|
|
|
|
443
|
foreach my $trans (@_) { |
420
|
839
|
100
|
|
|
|
1051
|
if (ref $trans) { |
421
|
150
|
|
|
|
|
366
|
$queue->emit_to(\@result); |
422
|
150
|
|
|
|
|
262
|
push @result, $$trans; |
423
|
|
|
|
|
|
|
} else { |
424
|
689
|
|
|
|
|
1150
|
$queue->add($trans); |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
} |
427
|
256
|
|
|
|
|
435
|
$queue->emit_to(\@result); |
428
|
256
|
50
|
|
|
|
1094
|
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
|
698
|
(my MY $trans, my ($scope, $node)) = @_; |
441
|
527
|
|
|
|
|
1067
|
my $body = $node->current; |
442
|
527
|
|
|
|
|
833
|
my ($pre, $post) = ('', ''); |
443
|
527
|
|
|
|
|
1274
|
my $CRLF = qr{\r?\n}; |
444
|
527
|
100
|
|
|
|
1112
|
if ($node->node_is_beginning) { |
|
|
100
|
|
|
|
|
|
445
|
233
|
100
|
|
|
|
2256
|
$pre = $1 if $body =~ s/^($CRLF+)//; |
446
|
|
|
|
|
|
|
} elsif ($node->node_is_end) { |
447
|
211
|
100
|
100
|
|
|
520
|
if (not $node->has_parent |
448
|
|
|
|
|
|
|
and $node->metainfo->caller_widget->no_last_newline) { |
449
|
35
|
|
|
|
|
346
|
$body =~ s/($CRLF+)$//s; |
450
|
|
|
|
|
|
|
} else { |
451
|
176
|
100
|
|
|
|
1354
|
$post = $2 if $body =~ s/($CRLF)($CRLF+)$/$1/s; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
} |
454
|
527
|
|
|
|
|
614
|
$pre.do { |
455
|
527
|
100
|
|
|
|
1943
|
if ($body eq '') { |
|
|
100
|
|
|
|
|
|
456
|
146
|
|
|
|
|
816
|
'' |
457
|
|
|
|
|
|
|
} elsif ($body =~ /^$CRLF$/) { |
458
|
129
|
|
|
|
|
381
|
sprintf qq{"%s"\n}, qcrlf($body); |
459
|
|
|
|
|
|
|
} else { |
460
|
252
|
|
|
|
|
467
|
qparen($body); |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
}.$post; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
sub trans_pi { |
466
|
17
|
|
|
17
|
0
|
31
|
(my MY $trans, my ($scope, $node)) = @_; |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# XXX: 処理を許すかどうか、選べるようにすべき。あるいは、mapping が欲しい。 |
469
|
17
|
50
|
|
|
|
58
|
if ($node->node_nsname ne 'perl') { |
470
|
0
|
|
|
|
|
0
|
return ''; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
17
|
|
|
|
|
66
|
my $body = $trans->genexpr_node($scope, 0, $node->open); |
474
|
17
|
100
|
|
|
|
188
|
unless ($body =~ s/^(=+)//) { |
|
|
100
|
|
|
|
|
|
475
|
3
|
|
|
|
|
14
|
\ $body; |
476
|
|
|
|
|
|
|
} elsif (length($1) >= 3) { |
477
|
|
|
|
|
|
|
# print without escaping. |
478
|
6
|
|
|
|
|
27
|
\ qq{print $body}; |
479
|
|
|
|
|
|
|
} else { |
480
|
8
|
|
|
|
|
42
|
qq{YATT::escape(do {$body})} |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub genexpr_node { |
485
|
34
|
|
|
34
|
0
|
68
|
(my MY $trans, my ($scope, $early_escaped, $node)) = @_; |
486
|
34
|
100
|
|
|
|
113
|
join("", map { ref $_ ? $$_ : $trans->dots_for_arrows(my $cp = $_) } |
|
53
|
|
|
|
|
191
|
|
487
|
|
|
|
|
|
|
$trans->mark_vars($scope, $early_escaped, $node)); |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
#======================================== |
491
|
|
|
|
|
|
|
|
492
|
3
|
|
|
3
|
|
14
|
use YATT::Util::Enum -prefix => 'ENT_', qw(RAW ESCAPED PRINTED); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
24
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
sub trans_entity { |
495
|
158
|
|
|
158
|
0
|
307
|
(my MY $trans, my ($scope, $node)) = @_; |
496
|
158
|
|
|
|
|
492
|
$trans->generate_entref($scope, ENT_PRINTED, $node); |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub trans_html { |
500
|
11
|
|
|
11
|
0
|
19
|
(my MY $trans, my ($scope, $node)) = @_; |
501
|
11
|
|
|
|
|
31
|
my $tag = $node->node_name; |
502
|
11
|
|
|
|
|
19
|
my ($string, $tagc, $end) = do { |
503
|
11
|
100
|
|
|
|
27
|
if ($node->is_empty_element) { |
504
|
9
|
|
|
|
|
25
|
("<$tag", " />", ''); |
505
|
|
|
|
|
|
|
} else { |
506
|
2
|
|
|
|
|
9
|
("<$tag", ">", "$tag>"); |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
}; |
509
|
|
|
|
|
|
|
|
510
|
11
|
|
|
|
|
29
|
my $item = $node->open; |
511
|
11
|
|
|
|
|
20
|
my @script; |
512
|
11
|
|
|
|
|
24
|
for (; $item->readable; $item->next) { |
513
|
24
|
100
|
|
|
|
43
|
last unless $item->is_primary_attribute; |
514
|
22
|
|
|
|
|
62
|
my $name = $item->node_name; |
515
|
22
|
50
|
|
|
|
55
|
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
|
|
|
|
|
30
|
$string .= ' '; |
521
|
22
|
|
|
|
|
50
|
my ($open, $close) = $item->node_attribute_format; |
522
|
22
|
|
|
|
|
25
|
$string .= $open; |
523
|
|
|
|
|
|
|
# XXX: quote されてないとき、変数推測をしても良いかも。 |
524
|
22
|
|
|
|
|
47
|
for (my $frag = $item->open; $frag->readable; $frag->next) { |
525
|
27
|
|
|
|
|
49
|
my $type = $frag->node_type; |
526
|
27
|
100
|
|
|
|
51
|
if ($type == TEXT_TYPE) { |
|
|
50
|
|
|
|
|
|
527
|
12
|
|
|
|
|
31
|
$string .= $frag->current; |
528
|
|
|
|
|
|
|
} elsif ($type == ENTITY_TYPE) { |
529
|
|
|
|
|
|
|
# should be entity |
530
|
15
|
|
|
|
|
30
|
push @script, qparen($string) |
531
|
|
|
|
|
|
|
, $trans->generate_entref($scope, ENT_ESCAPED, $frag); |
532
|
15
|
|
|
|
|
44
|
$string = ''; |
533
|
|
|
|
|
|
|
} else { |
534
|
0
|
|
|
|
|
0
|
die $trans->node_error($frag, "Invalid node in html attribute"); |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
} |
537
|
22
|
|
|
|
|
86
|
$string .= $close; |
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
|
540
|
11
|
50
|
|
|
|
33
|
$string .= $tagc if $tagc ne ''; |
541
|
11
|
|
|
|
|
25
|
for (; $item->readable; $item->next) { |
542
|
4
|
100
|
|
|
|
8
|
if ($item->node_type == TEXT_TYPE) { |
543
|
2
|
|
|
|
|
7
|
$string .= $item->current; |
544
|
|
|
|
|
|
|
} else { |
545
|
2
|
|
|
|
|
5
|
push @script, qparen($string), $trans->generate_body($scope, $item); |
546
|
2
|
|
|
|
|
6
|
$string = ''; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
} |
549
|
11
|
100
|
|
|
|
21
|
$string .= $end if $end; |
550
|
11
|
50
|
|
|
|
36
|
push @script, qparen($string) if $string ne ''; |
551
|
11
|
|
|
|
|
61
|
@script; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
#======================================== |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
my %control = (if => undef, unless => undef); |
557
|
|
|
|
|
|
|
sub trans_element { |
558
|
137
|
|
|
137
|
0
|
258
|
(my MY $trans, my ($scope, $node)) = @_; |
559
|
137
|
|
|
|
|
611
|
my $tmpl = $trans->get_template_from_node($node); |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# ■ 最初に要素マクロ ← RC から検索。 |
562
|
137
|
100
|
|
|
|
526
|
if (my $macro = $trans->has_element_macro($tmpl, $node, $node->node_path)) { |
563
|
|
|
|
|
|
|
# XXX: ssri:foreach → yatt:foreach も。 |
564
|
23
|
|
|
|
|
65
|
return $macro->($trans, $scope, $node->open); |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# ■ 次に if/unless/else, |
568
|
114
|
100
|
|
|
|
397
|
if (my @arm = $trans->collect_arms($node, else => \%control)) { |
569
|
5
|
|
|
|
|
20
|
return $trans->gencall_conditional($scope, @arm); |
570
|
|
|
|
|
|
|
} |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# ■ 無条件呼び出し |
573
|
109
|
|
|
|
|
340
|
$trans->gencall_always($scope, $node); |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
sub gencall_conditional { |
577
|
5
|
|
|
5
|
0
|
13
|
(my MY $trans, my ($scope, $ifunless, @elses)) = @_; |
578
|
5
|
|
|
|
|
8
|
my $pkg; |
579
|
5
|
|
|
|
|
6
|
my $script = do { |
580
|
5
|
|
|
|
|
7
|
my ($cond, $action) = @$ifunless; # (node, cursor) |
581
|
5
|
|
|
|
|
21
|
sprintf(q{%s (%s) {%s}} |
582
|
|
|
|
|
|
|
, $cond->node_name |
583
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0, $cond->open) |
584
|
5
|
|
|
|
|
15
|
, ${ $trans->gencall_always($scope, $action->make_wrapped) }); |
585
|
|
|
|
|
|
|
}; |
586
|
|
|
|
|
|
|
|
587
|
5
|
|
|
|
|
36
|
foreach my $arm (@elses) { |
588
|
5
|
|
|
|
|
9
|
my ($cond, $action) = @$arm; |
589
|
5
|
|
|
|
|
6
|
$script .= do { |
590
|
5
|
100
|
|
|
|
12
|
if ($cond) { |
591
|
2
|
|
|
|
|
8
|
sprintf q{ elsif (%s) } |
592
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0, $cond->open); |
593
|
|
|
|
|
|
|
} else { |
594
|
3
|
|
|
|
|
7
|
q{ else } |
595
|
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
|
}; |
597
|
5
|
|
|
|
|
15
|
$script .= sprintf q{{%s}} |
598
|
5
|
|
|
|
|
11
|
, ${ $trans->gencall_always($scope, $action->make_wrapped) }; |
599
|
|
|
|
|
|
|
} |
600
|
5
|
|
|
|
|
49
|
\ $script; |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub gencall_always { |
604
|
119
|
|
|
119
|
0
|
180
|
(my MY $trans, my ($scope, $node)) = @_; |
605
|
|
|
|
|
|
|
|
606
|
119
|
|
|
|
|
325
|
my $tmpl = $trans->get_template_from_node($node); |
607
|
119
|
50
|
|
|
|
339
|
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
|
|
|
|
399
|
if (my $codevar = $trans->find_codearg($scope, @elempath)) { |
613
|
|
|
|
|
|
|
# ← 特に、親の call の body の中で、 で |
614
|
|
|
|
|
|
|
# 呼ばれるとき, だよね? |
615
|
30
|
|
|
|
|
106
|
return $codevar->gen_call($trans, $scope, $node); |
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
# ■ さもなければ、通常の Widget の呼び出し |
619
|
89
|
|
|
|
|
316
|
my Widget $widget = $trans->get_widget_from_template($tmpl, @elempath); |
620
|
89
|
100
|
|
|
|
265
|
unless ($widget) { |
621
|
2
|
|
|
|
|
9
|
die $trans->node_error($node, "No such widget"); |
622
|
|
|
|
|
|
|
} |
623
|
87
|
|
|
|
|
305
|
$trans->gencall($widget, $scope, $node->open); |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
sub has_unique_argmacro { |
627
|
87
|
|
|
87
|
0
|
194
|
(my MY $trans, my Widget $callee, my Widget $caller) = @_; |
628
|
87
|
100
|
|
|
|
403
|
return unless $callee->{argmacro_dict}; |
629
|
|
|
|
|
|
|
# 現状では、name の重複は無いはず。 |
630
|
19
|
|
|
|
|
32
|
my %suppress; $suppress{$_->call_spec} = 1 for @{$caller->{argmacro_order}}; |
|
19
|
|
|
|
|
31
|
|
|
19
|
|
|
|
|
83
|
|
631
|
19
|
100
|
|
|
|
44
|
my @order = grep {not $suppress{$_->call_spec}} @{$callee->{argmacro_order}} |
|
16
|
|
|
|
|
70
|
|
|
19
|
|
|
|
|
71
|
|
632
|
|
|
|
|
|
|
or return; |
633
|
11
|
|
|
|
|
18
|
my %dict; |
634
|
11
|
|
|
|
|
21
|
foreach my $arg (keys %{$callee->{argmacro_dict}}) { |
|
11
|
|
|
|
|
70
|
|
635
|
45
|
|
|
|
|
94
|
$dict{$arg} = $callee->{argmacro_dict}{$arg}; |
636
|
|
|
|
|
|
|
} |
637
|
11
|
|
|
|
|
67
|
(\%dict, \@order); |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub gencall { |
641
|
87
|
|
|
87
|
0
|
227
|
(my MY $trans, my Widget $widget, my ($scope, $node)) = @_; |
642
|
87
|
|
|
|
|
312
|
$trans->ensure_widget_is_generated($widget); |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
# 引数マクロの抜き出し |
645
|
87
|
100
|
|
|
|
305
|
if (my ($dict, $order) = $trans->has_unique_argmacro |
646
|
|
|
|
|
|
|
($widget, $node->metainfo->caller_widget)) { |
647
|
11
|
|
|
|
|
85
|
$node = YATT::ArgMacro->expand_all_macros |
648
|
|
|
|
|
|
|
($trans, $scope, $node, $widget, $dict, $order); |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
87
|
|
|
|
|
365
|
my $func = $trans->get_funcname_to($trans->{cf_mode}, $widget); |
652
|
|
|
|
|
|
|
# actual 一覧の作成 |
653
|
87
|
|
|
|
|
365
|
my ($post, @args) = $trans->genargs_static |
654
|
|
|
|
|
|
|
($scope, $node, $widget->arg_specs); |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
# XXX: calling convention 周り |
657
|
127
|
100
|
|
|
|
1027
|
return \ sprintf(' %s($this, [%s])%s', $func |
658
|
83
|
|
|
|
|
295
|
, join(", ", map {defined $_ ? $_ : 'undef'} @args) |
659
|
|
|
|
|
|
|
, $post); |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
sub has_single_bare_varexpr { |
663
|
6
|
|
|
6
|
0
|
13
|
(my MY $trans, my ($scope, $node)) = @_; |
664
|
6
|
|
|
|
|
21
|
my $clone = $node->clone($node->clone_path); |
665
|
6
|
|
|
|
|
21
|
my $parent = $clone->parent; |
666
|
6
|
100
|
66
|
|
|
20
|
return unless $parent->is_bare_attribute and $parent->node_size == 1; |
667
|
1
|
|
|
|
|
5
|
my (@expr) = ($trans->mark_vars($scope, ENT_RAW, $clone)); |
668
|
1
|
50
|
33
|
|
|
7
|
return unless @expr and ref $expr[0] eq 'SCALAR'; |
669
|
1
|
|
|
|
|
6
|
$expr[0]; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
sub has_pass_through_var { |
673
|
133
|
|
|
133
|
0
|
250
|
(my MY $trans, my ($scope, $args, $name)) = @_; |
674
|
133
|
100
|
|
|
|
424
|
return if $args->node_size >= 2; |
675
|
118
|
100
|
100
|
|
|
214
|
if ($args->node_size == 1 and ($args->node_flag || 0) == 0) { |
|
|
100
|
100
|
|
|
|
|
676
|
|
|
|
|
|
|
# bareword 渡し。 |
677
|
20
|
|
|
|
|
58
|
$trans->find_var($scope, $args->node_body); |
678
|
|
|
|
|
|
|
} elsif ($args->node_size == 0) { |
679
|
|
|
|
|
|
|
# value less 渡し |
680
|
43
|
|
|
|
|
74
|
$trans->find_var($scope, $name); |
681
|
|
|
|
|
|
|
} |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
sub genargs_static { |
685
|
117
|
|
|
117
|
0
|
216
|
(my MY $trans, my ($scope, $args, $arg_dict, $arg_order, $delegate_vars)) = @_; |
686
|
117
|
|
|
|
|
325
|
my ($body, @actual) = $args->variant_builder; |
687
|
117
|
|
|
|
|
483
|
my ($postnl, $startline) = ('', $args->linenum); |
688
|
117
|
|
|
|
|
427
|
for (my $nth = 0; $args->readable; $args->next) { |
689
|
177
|
100
|
|
|
|
378
|
unless ($args->is_attribute) { |
690
|
75
|
|
|
|
|
148
|
$body->add_node($args->current); |
691
|
75
|
|
|
|
|
156
|
next; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
|
694
|
102
|
|
|
|
|
292
|
my ($name, $typename) = $trans->arg_name_types($args); |
695
|
102
|
100
|
|
|
|
208
|
unless (defined $name) { |
696
|
2
|
50
|
|
|
|
8
|
$name = $arg_order->[$nth++] |
697
|
|
|
|
|
|
|
or die $trans->node_error($args, "Too many args"); |
698
|
|
|
|
|
|
|
} |
699
|
102
|
|
|
|
|
173
|
my $argdecl = $arg_dict->{$name}; |
700
|
102
|
50
|
|
|
|
204
|
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
|
|
|
|
|
109
|
$actual[$argdecl->argno] = do { |
707
|
102
|
100
|
|
|
|
287
|
if (my $var = $trans->has_pass_through_var($scope, $args, $name)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
708
|
|
|
|
|
|
|
# XXX: early_escaped が一致するか、検査せよ。 |
709
|
38
|
100
|
|
|
|
102
|
$argdecl->early_escaped ? $var->as_escaped : $var->as_lvalue; |
710
|
|
|
|
|
|
|
} elsif (defined $args->node_body) { |
711
|
60
|
|
|
|
|
263
|
$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
|
|
|
|
|
5
|
die $trans->node_error($args, "valueless arg '%s'", $name); |
716
|
|
|
|
|
|
|
} |
717
|
|
|
|
|
|
|
}; |
718
|
|
|
|
|
|
|
} |
719
|
116
|
100
|
66
|
|
|
390
|
if ($body->array_size |
720
|
|
|
|
|
|
|
and my $bodydecl = $arg_dict->{body}) { |
721
|
|
|
|
|
|
|
# if $actual[$bodydecl->argno]; なら、エラーを報告すべきでは? |
722
|
|
|
|
|
|
|
# code か、html か。 |
723
|
35
|
|
|
|
|
133
|
$actual[$bodydecl->argno] |
724
|
|
|
|
|
|
|
= $bodydecl->gen_assignable_node($trans, $scope, $body, 1); |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
114
|
|
|
|
|
410
|
for (my $i = 0; $i < @$arg_order; $i++) { |
728
|
212
|
100
|
|
|
|
486
|
next if defined $actual[$i]; |
729
|
79
|
|
|
|
|
122
|
my $name = $arg_order->[$i]; |
730
|
79
|
100
|
|
|
|
371
|
if ($delegate_vars->{$name}) { |
|
|
100
|
|
|
|
|
|
731
|
|
|
|
|
|
|
# delegate 宣言では、型は同じになるはず。 |
732
|
|
|
|
|
|
|
# XXX: 引数rename |
733
|
17
|
|
|
|
|
38
|
$actual[$i] = $arg_dict->{$name}->as_lvalue; |
734
|
|
|
|
|
|
|
} elsif ($arg_dict->{$name}->is_required) { |
735
|
1
|
|
|
|
|
5
|
die $trans->node_error($args->parent |
736
|
|
|
|
|
|
|
, "Argument '%s' is missing", $name); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
|
740
|
113
|
100
|
|
|
|
374
|
if ($args->parent->is_empty_element) { |
741
|
80
|
|
|
|
|
200
|
my $diff = $args->parent->linenum(+1) |
742
|
|
|
|
|
|
|
- $startline - $args->count_lines_of(@actual); |
743
|
80
|
100
|
|
|
|
290
|
$postnl = "\n" x $diff if $diff; |
744
|
|
|
|
|
|
|
} else { |
745
|
|
|
|
|
|
|
# XXX: どうする? |
746
|
|
|
|
|
|
|
} |
747
|
113
|
|
|
|
|
699
|
($postnl, @actual); |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
sub collect_arms { |
751
|
114
|
|
|
114
|
0
|
188
|
my ($pack, $call, $key, $dict) = @_; |
752
|
114
|
|
|
|
|
466
|
my ($type, $name) = $call->node_headings; |
753
|
114
|
|
|
|
|
306
|
my $args = $call->open; |
754
|
114
|
|
|
|
|
439
|
my ($cond, $body) = $pack->consume_arm($args, $dict, $type, $name |
755
|
|
|
|
|
|
|
, primary_only => 1); |
756
|
114
|
100
|
|
|
|
903
|
return unless $cond; |
757
|
5
|
|
|
|
|
16
|
my @case = [$cond, $body]; |
758
|
5
|
|
|
|
|
15
|
for (; $args->readable; $args->next) { |
759
|
9
|
100
|
66
|
|
|
23
|
if ($args->is_attribute && $args->node_name eq $key) { |
760
|
5
|
|
|
|
|
17
|
push @case, [$pack->consume_arm($args->open, $dict, $type, $name)]; |
761
|
|
|
|
|
|
|
} else { |
762
|
|
|
|
|
|
|
# XXX: 多分、$case[0] (== $body) |
763
|
4
|
|
|
|
|
17
|
$case[-1][-1]->add_node($args->current); |
764
|
|
|
|
|
|
|
} |
765
|
|
|
|
|
|
|
} |
766
|
5
|
|
|
|
|
30
|
@case; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
sub consume_arm { |
770
|
119
|
|
|
119
|
0
|
252
|
my ($trans, $node, $dict, $type, $name, @opts) = @_; |
771
|
119
|
|
|
|
|
341
|
my $arm = $node->variant_builder($type, $name); |
772
|
119
|
|
|
|
|
567
|
my @cond = $arm->filter_or_add_from($node, $dict, @opts); |
773
|
119
|
50
|
|
|
|
348
|
if (@cond >= 2) { |
774
|
0
|
|
|
|
|
0
|
die $trans->node_error |
775
|
|
|
|
|
|
|
($node, "Too many condtitions: %s" |
776
|
0
|
|
|
|
|
0
|
, join("", map {stringify_node($_)} @cond)); |
777
|
|
|
|
|
|
|
} |
778
|
|
|
|
|
|
|
# $cond[0] は undef かもしれない。 ex. <:else/> |
779
|
|
|
|
|
|
|
|
780
|
119
|
100
|
|
|
|
125
|
my $cond; $cond = $trans->fake_cursor_from($arm, $cond[0]) if defined $cond[0]; |
|
119
|
|
|
|
|
246
|
|
781
|
119
|
|
|
|
|
303
|
($cond, $arm); |
782
|
|
|
|
|
|
|
} |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
#---------------------------------------- |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
sub has_element_macro { |
787
|
137
|
|
|
137
|
0
|
340
|
(my MY $trans, my Template $tmpl, my ($node, @elempath)) = @_; |
788
|
|
|
|
|
|
|
# XXX: macro の一覧は、ちゃんと取り出せるか? |
789
|
|
|
|
|
|
|
|
790
|
137
|
50
|
|
|
|
435
|
if (@elempath > 2) { |
791
|
|
|
|
|
|
|
# Not implemented. |
792
|
0
|
|
|
|
|
0
|
return; |
793
|
|
|
|
|
|
|
} |
794
|
|
|
|
|
|
|
|
795
|
137
|
|
|
|
|
410
|
my $pkg = $trans->get_rc_package_from_template($tmpl); |
796
|
137
|
|
|
|
|
177
|
my $ns; |
797
|
137
|
|
|
|
|
265
|
foreach my $shift (0, 1) { |
798
|
251
|
100
|
|
|
|
659
|
$ns = $trans->strip_ns(\@elempath) if $shift; |
799
|
251
|
|
|
|
|
433
|
my $macro_name = join("_", macro => @elempath); |
800
|
251
|
100
|
66
|
|
|
3029
|
if (my $sub = $pkg->can($macro_name) || $trans->can($macro_name)) { |
801
|
23
|
|
|
|
|
81
|
return $sub; |
802
|
|
|
|
|
|
|
} |
803
|
|
|
|
|
|
|
} |
804
|
|
|
|
|
|
|
} |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
#======================================== |
807
|
|
|
|
|
|
|
# 宣言関連 |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
# XXX: use は perl 固有だから、ここに持たせるのは理にかなう。 |
810
|
0
|
|
|
0
|
0
|
0
|
sub declare_use { |
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
sub attr_declare_delegate { |
814
|
7
|
|
|
7
|
0
|
31
|
(my MY $trans, my ($widget, $args, $argname, $subtype, @param)) = @_; |
815
|
7
|
100
|
|
|
|
28
|
my @elempath = $subtype ? @$subtype : $argname; |
816
|
7
|
|
|
|
|
29
|
my Template $tmpl = $trans->get_template_from_node($args); |
817
|
7
|
|
|
|
|
33
|
my Widget $base = $trans->get_widget_from_template($tmpl, @elempath); |
818
|
7
|
50
|
|
|
|
19
|
unless ($base) { |
819
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "No such widget %s" |
820
|
|
|
|
|
|
|
, join(":", @elempath)); |
821
|
|
|
|
|
|
|
} |
822
|
7
|
50
|
|
|
|
33
|
if ($tmpl->{cf_nsid} != $base->template_nsid) { |
823
|
0
|
|
|
|
|
0
|
$trans->mark_delayed_target($base); |
824
|
|
|
|
|
|
|
} |
825
|
|
|
|
|
|
|
|
826
|
7
|
100
|
|
|
|
24
|
if ($base->{arg_dict}{$argname}) { |
827
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
12
|
my %vars; $vars{$_} = 1 for $widget->copy_specs_from($base); |
|
6
|
|
|
|
|
27
|
|
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
# |
837
|
|
|
|
|
|
|
# arg とは別の、コンパイル時のみの仮想的な変数として登録。 |
838
|
|
|
|
|
|
|
# |
839
|
6
|
50
|
|
|
|
26
|
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
|
|
|
|
|
27
|
($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
|
215
|
(my MY $trans, my ($target)) = @_; |
851
|
173
|
100
|
|
|
|
419
|
unless ($target->has_arg('body')) { |
852
|
154
|
|
|
|
|
440
|
$target->add_arg(body => $trans->create_var('code')); |
853
|
|
|
|
|
|
|
} |
854
|
173
|
|
|
|
|
313
|
$trans; |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
sub decode_decl_entpath { |
858
|
16
|
|
|
16
|
0
|
27
|
(my MY $trans, my $node) = @_; |
859
|
16
|
|
|
|
|
56
|
my ($has_body, @entpath) |
860
|
|
|
|
|
|
|
= $trans->decode_entpath($node, my $entns = [$node->node_path]); |
861
|
|
|
|
|
|
|
|
862
|
16
|
100
|
|
|
|
51
|
unless ($has_body) { |
863
|
10
|
|
|
|
|
39
|
return $node->node_nsname('', '_'); |
864
|
|
|
|
|
|
|
} |
865
|
|
|
|
|
|
|
|
866
|
6
|
|
|
|
|
11
|
my (@macro_name, $rename_spec); |
867
|
6
|
|
|
|
|
20
|
while (@entpath) { |
868
|
6
|
|
|
|
|
9
|
my ($type, $name, @args) = @{shift @entpath}; |
|
6
|
|
|
|
|
20
|
|
869
|
6
|
50
|
|
|
|
28
|
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
|
|
|
|
|
13
|
push @macro_name, $name; |
878
|
6
|
|
|
|
|
14
|
foreach my $arg (@args) { |
879
|
6
|
|
|
|
|
12
|
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
|
|
|
|
|
50
|
$rename_spec = [split /=/, $name, 2]; |
886
|
|
|
|
|
|
|
} |
887
|
|
|
|
|
|
|
} |
888
|
|
|
|
|
|
|
} else { |
889
|
0
|
|
|
|
|
0
|
die $trans->nimpl($node); |
890
|
|
|
|
|
|
|
} |
891
|
|
|
|
|
|
|
} |
892
|
|
|
|
|
|
|
|
893
|
6
|
|
|
|
|
27
|
(join("_", @macro_name), $rename_spec); |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
# For ArgMacro |
897
|
|
|
|
|
|
|
sub add_decl_entity { |
898
|
51
|
|
|
51
|
0
|
90
|
(my MY $trans, my Widget $widget, my ($node)) = @_; |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
# Widget の configure を呼ぶだけ、のケース ← config(value) でどう? |
901
|
|
|
|
|
|
|
{ |
902
|
51
|
|
|
|
|
97
|
my $is_sysns = $trans->shift_ns_by(yatt => |
|
51
|
|
|
|
|
206
|
|
903
|
|
|
|
|
|
|
my $entns = [$node->node_path]); |
904
|
51
|
100
|
66
|
|
|
267
|
if ($is_sysns && @$entns == 1) { |
905
|
35
|
50
|
|
|
|
141
|
if ($widget->can_configure($entns->[0])) { |
906
|
35
|
|
|
|
|
117
|
$widget->configure($entns->[0], 1); |
907
|
35
|
|
|
|
|
125
|
return; |
908
|
|
|
|
|
|
|
} |
909
|
|
|
|
|
|
|
} |
910
|
|
|
|
|
|
|
} |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
{ |
913
|
16
|
|
|
|
|
30
|
my ($macro_name, @args) = $trans->decode_decl_entpath($node); |
|
16
|
|
|
|
|
50
|
|
914
|
|
|
|
|
|
|
|
915
|
16
|
|
|
|
|
72
|
foreach my $pkg ($trans->get_package_from_widget($widget)) { |
916
|
16
|
|
|
|
|
23
|
my $macro_class = do { |
917
|
16
|
50
|
|
|
|
283
|
my $sub = $pkg->can($macro_name) |
918
|
|
|
|
|
|
|
or next; |
919
|
16
|
|
|
|
|
59
|
$sub->(); |
920
|
|
|
|
|
|
|
}; |
921
|
16
|
50
|
|
|
|
148
|
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
|
|
|
|
|
102
|
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
|
|
|
|
|
16
|
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
|
|
15
|
, qw(:export_alias); |
|
3
|
|
|
|
|
4
|
|
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
sub find_var { |
944
|
414
|
|
|
414
|
0
|
746
|
(my MY $trans, my ($scope, $varName)) = @_; |
945
|
414
|
|
|
|
|
942
|
for (; $scope; $scope = $scope->[1]) { |
946
|
987
|
50
|
|
|
|
1248
|
croak "Undefined varName!" unless defined $varName; |
947
|
987
|
100
|
|
|
|
2623
|
if (defined (my $value = $scope->[0]{$varName})) { |
948
|
275
|
|
|
|
|
778
|
return $value; |
949
|
|
|
|
|
|
|
} |
950
|
|
|
|
|
|
|
} |
951
|
139
|
|
|
|
|
655
|
return; |
952
|
|
|
|
|
|
|
} |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
sub find_codearg { |
955
|
145
|
|
|
145
|
0
|
318
|
(my MY $trans, my ($scope, @elempath)) = @_; |
956
|
145
|
50
|
|
|
|
361
|
return if @elempath >= 3; |
957
|
145
|
|
|
|
|
481
|
$trans->strip_ns(\@elempath); |
958
|
145
|
50
|
|
|
|
392
|
return unless @elempath == 1; |
959
|
145
|
100
|
|
|
|
463
|
my $var = $trans->find_var($scope, $elempath[0]) |
960
|
|
|
|
|
|
|
or return; |
961
|
40
|
100
|
66
|
|
|
311
|
return unless ref $var and $var->can('arg_specs'); |
962
|
38
|
|
|
|
|
102
|
$var; |
963
|
|
|
|
|
|
|
} |
964
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
sub gen_getargs_static { |
966
|
203
|
|
|
203
|
0
|
230
|
(my MY $gen, my Widget $widget, my ($metainfo)) = @_; |
967
|
203
|
|
|
|
|
204
|
my (@args, %scope); |
968
|
203
|
100
|
|
|
|
519
|
foreach my $name ($widget->{arg_order} ? @{$widget->{arg_order}} : ()) { |
|
161
|
|
|
|
|
409
|
|
969
|
391
|
|
|
|
|
681
|
my VarType $var = $widget->{arg_dict}{$name}; |
970
|
391
|
|
|
|
|
542
|
$scope{$name} = $var; |
971
|
391
|
|
|
|
|
797
|
my $decl = sprintf q{my %s = $_[%d]}, $var->as_lvalue, $$var{cf_argno}; |
972
|
391
|
|
|
|
|
1447
|
my $value = $var->gen_getarg |
973
|
|
|
|
|
|
|
($gen, [\%scope], $widget, $metainfo, qq{\$args->[$$var{cf_argno}]}); |
974
|
391
|
|
|
|
|
986
|
push @args, "$decl = $value;\n"; |
975
|
|
|
|
|
|
|
} |
976
|
203
|
|
|
|
|
829
|
join "", @args; |
977
|
|
|
|
|
|
|
} |
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
sub gen_getargs_dynamic { |
980
|
203
|
|
|
203
|
0
|
984
|
''; |
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
|
166
|
(my MY $trans, my ($scope, $early_escaped, $node)) = @_; |
1026
|
102
|
|
|
|
|
115
|
my @result; |
1027
|
102
|
|
|
|
|
295
|
for (; $node->readable; $node->next) { |
1028
|
149
|
100
|
|
|
|
330
|
if ($node->node_type == TEXT_TYPE) { |
|
|
50
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
# XXX: dots_for_arrows |
1030
|
109
|
|
|
|
|
216
|
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
|
|
|
|
|
237
|
push @result, \ $trans->generate_entref($scope, $early_escaped, $node); |
1035
|
|
|
|
|
|
|
} |
1036
|
|
|
|
|
|
|
} |
1037
|
102
|
|
|
|
|
349
|
@result; |
1038
|
|
|
|
|
|
|
} |
1039
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
sub feed_array_if { |
1041
|
283
|
|
|
283
|
0
|
311
|
(my MY $trans, my ($name, $array)) = @_; |
1042
|
283
|
50
|
|
|
|
408
|
return unless @$array >= 1; |
1043
|
283
|
100
|
|
|
|
831
|
return unless $array->[0][0] eq $name; |
1044
|
90
|
|
|
|
|
97
|
my $desc = shift @$array; |
1045
|
90
|
50
|
|
|
|
192
|
wantarray ? @{$desc}[1..$#$desc] : $desc; |
|
90
|
|
|
|
|
299
|
|
1046
|
|
|
|
|
|
|
} |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
# $node の情報を借りながら、@_ を generate. |
1049
|
|
|
|
|
|
|
sub gen_entref_list { |
1050
|
32
|
|
|
32
|
0
|
70
|
(my MY $trans, my ($scope, $node)) = splice @_, 0, 3; |
1051
|
32
|
|
|
|
|
40
|
my @result; |
1052
|
32
|
|
|
|
|
60
|
foreach my $item (@_) { |
1053
|
50
|
100
|
|
|
|
112
|
push @result, $trans->gen_entref_path |
1054
|
|
|
|
|
|
|
($scope, $node |
1055
|
|
|
|
|
|
|
, is_nested_entpath($item) ? @$item : $item); |
1056
|
|
|
|
|
|
|
} |
1057
|
32
|
|
|
|
|
115
|
@result; |
1058
|
|
|
|
|
|
|
} |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
sub gen_entref_path { |
1061
|
90
|
|
|
90
|
0
|
173
|
(my MY $trans, my ($scope, $node)) = splice @_, 0, 3; |
1062
|
90
|
|
|
|
|
112
|
my $var; |
1063
|
90
|
|
|
|
|
82
|
my @expr = do { |
1064
|
90
|
100
|
|
|
|
215
|
if (my ($name, @args) = $trans->feed_array_if(call => \@_)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1065
|
16
|
|
|
|
|
72
|
my $pkg = $trans->get_package_from_node($node); |
1066
|
16
|
|
|
|
|
28
|
my $dont_call; |
1067
|
16
|
|
|
|
|
19
|
my $call = do { |
1068
|
|
|
|
|
|
|
# XXX: codevar は、path の先頭だけ。 |
1069
|
|
|
|
|
|
|
# 引数にも現れるから、 |
1070
|
16
|
100
|
|
|
|
148
|
if ($pkg->can(my $en = "entity_$name")) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1071
|
8
|
|
|
|
|
38
|
sprintf('%s->%s', $pkg, $en); |
1072
|
|
|
|
|
|
|
} elsif ($var = $trans->find_codearg($scope, $name)) { |
1073
|
1
|
|
|
|
|
3
|
sprintf('%1$s && %1$s->', $var->as_lvalue); |
1074
|
|
|
|
|
|
|
} elsif ($var = $trans->find_var($scope, $name)) { |
1075
|
1
|
50
|
|
|
|
4
|
if (my $handler = $var->can("entmacro_")) { |
1076
|
1
|
|
|
|
|
3
|
$dont_call++; |
1077
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
9
|
$dont_call++; |
1088
|
6
|
|
|
|
|
27
|
$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
|
|
|
108
|
($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
|
|
|
|
115
|
unless ($var = $trans->find_var($scope, $name)) { |
1099
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "No such variable '%s'", $name); |
1100
|
|
|
|
|
|
|
} else { |
1101
|
35
|
|
|
|
|
100
|
$var->as_lvalue; |
1102
|
|
|
|
|
|
|
} |
1103
|
|
|
|
|
|
|
} elsif (($name) = $trans->feed_array_if(expr => \@_)) { |
1104
|
11
|
|
|
|
|
29
|
$name; |
1105
|
|
|
|
|
|
|
} elsif (my @items = $trans->feed_array_if(array => \@_)) { |
1106
|
2
|
|
|
|
|
8
|
'['.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
|
|
|
|
|
48
|
qqvalue($name); |
1112
|
|
|
|
|
|
|
} else { |
1113
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "NIMPL(%s)", terse_dump(@_)); |
1114
|
|
|
|
|
|
|
} |
1115
|
|
|
|
|
|
|
}; |
1116
|
|
|
|
|
|
|
|
1117
|
90
|
|
|
|
|
234
|
while (@_) { |
1118
|
33
|
|
|
|
|
42
|
my $item = shift; |
1119
|
33
|
|
|
|
|
39
|
push @expr, do { |
1120
|
33
|
|
|
|
|
58
|
my ($type, $name, @args) = @$item; |
1121
|
33
|
100
|
|
|
|
101
|
if ($type eq 'call') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
# 先頭の変数が確定している場合の、特殊処理。 |
1123
|
|
|
|
|
|
|
# XXX: 同じ名前のメソッドが呼べなくなる、というデメリットが有る。 |
1124
|
20
|
100
|
33
|
|
|
223
|
if ($var and not ref $name |
|
|
|
66
|
|
|
|
|
1125
|
|
|
|
|
|
|
and my $handler = $var->can("entmacro_$name")) { |
1126
|
|
|
|
|
|
|
# ここまでの式を reset する必要が有る時がある。 |
1127
|
19
|
|
|
|
|
68
|
$handler->($var, $trans, $scope, $node, \@_, \@expr, @args); |
1128
|
|
|
|
|
|
|
} else { |
1129
|
1
|
|
|
|
|
4
|
sprintf q{%s(%s)}, $name, join ", " |
1130
|
|
|
|
|
|
|
, $trans->gen_entref_list($scope, $node, @args); |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
} elsif ($type eq 'var') { |
1133
|
2
|
50
|
|
|
|
7
|
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
|
|
|
|
38
|
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
|
|
|
|
277
|
@expr > 1 ? join("->", @expr) : $expr[0]; |
1148
|
|
|
|
|
|
|
} |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
sub find_if_codearg { |
1151
|
156
|
|
|
156
|
0
|
310
|
(my MY $trans, my ($scope, $node, $entpath)) = @_; |
1152
|
156
|
|
|
|
|
430
|
my @entns = $node->node_path; |
1153
|
156
|
100
|
|
|
|
453
|
return unless $trans->strip_ns(\@entns); |
1154
|
155
|
100
|
|
|
|
712
|
return if @entns; |
1155
|
24
|
100
|
|
|
|
77
|
return unless @$entpath == 1; |
1156
|
18
|
50
|
|
|
|
60
|
return unless $entpath->[0][0] eq 'call'; |
1157
|
18
|
|
|
|
|
24
|
my ($op, $name, @args) = @{$entpath->[0]}; |
|
18
|
|
|
|
|
53
|
|
1158
|
18
|
100
|
|
|
|
59
|
my $codearg = $trans->find_codearg($scope, $name) |
1159
|
|
|
|
|
|
|
or return; |
1160
|
7
|
|
|
|
|
26
|
($codearg, @args); |
1161
|
|
|
|
|
|
|
} |
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
sub decode_entpath { |
1164
|
229
|
|
|
229
|
0
|
348
|
(my MY $trans, my ($node, $entns)) = @_; |
1165
|
229
|
|
|
|
|
317
|
my $has_entns = defined $entns; |
1166
|
229
|
100
|
|
|
|
425
|
unless ($has_entns) { |
1167
|
213
|
|
|
|
|
481
|
$trans->strip_ns($entns = [$node->node_path]); |
1168
|
|
|
|
|
|
|
} |
1169
|
229
|
|
|
|
|
689
|
my $body = $node->node_body; |
1170
|
229
|
100
|
100
|
|
|
678
|
substr($body, 0, 0) = ':' if defined $body and not defined $node->node_name; |
1171
|
229
|
|
|
|
|
460
|
my @entpath = $trans->parse_entpath(join('', map {':'.$_} @$entns) |
|
194
|
|
|
|
|
875
|
|
1172
|
|
|
|
|
|
|
. coalesce($body, '') |
1173
|
|
|
|
|
|
|
, $trans, $node); |
1174
|
|
|
|
|
|
|
|
1175
|
227
|
100
|
|
|
|
447
|
my $has_body = $body ? 1 : 0; |
1176
|
|
|
|
|
|
|
|
1177
|
227
|
100
|
|
|
|
677
|
$has_entns ? ($has_body, @entpath) : ($entns, $has_body, @entpath); |
1178
|
|
|
|
|
|
|
} |
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
sub generate_entref { |
1181
|
213
|
|
|
213
|
0
|
332
|
(my MY $trans, my ($scope, $escaped, $node)) = @_; |
1182
|
|
|
|
|
|
|
|
1183
|
213
|
|
|
|
|
511
|
my ($entns, $has_body, @entpath) = $trans->decode_entpath($node); |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
# 特例。&yatt:codevar(); は、副作用で print. |
1186
|
211
|
100
|
100
|
|
|
980
|
if ($escaped == ENT_PRINTED |
1187
|
|
|
|
|
|
|
and my ($codearg, @args) |
1188
|
|
|
|
|
|
|
= $trans->find_if_codearg($scope, $node, \@entpath)) { |
1189
|
0
|
|
|
|
|
0
|
return \ sprintf('%1$s && %1$s->(%2$s)', $codearg->as_lvalue |
1190
|
|
|
|
|
|
|
, join(", ", map { |
1191
|
7
|
|
|
|
|
17
|
$trans->gen_entref_path($scope, $node, $_) |
1192
|
|
|
|
|
|
|
} @args)); |
1193
|
|
|
|
|
|
|
# 引数。 |
1194
|
|
|
|
|
|
|
} |
1195
|
204
|
100
|
66
|
|
|
802
|
if ($has_body || @$entns > 1) { |
1196
|
|
|
|
|
|
|
# path が有る。 |
1197
|
40
|
|
|
|
|
158
|
my $expr = $trans->gen_entref_path($scope, $node, @entpath); |
1198
|
|
|
|
|
|
|
# XXX: sub { print } なら \ $expr にすべきだが、 |
1199
|
|
|
|
|
|
|
# sub { value } などは、むしろ YATT::escape(do {$expr}) すべき。 |
1200
|
40
|
100
|
|
|
|
116
|
return $expr if ref $expr; |
1201
|
38
|
100
|
|
|
|
277
|
return $escaped ? qq(YATT::escape($expr)) : $expr; |
1202
|
|
|
|
|
|
|
} |
1203
|
|
|
|
|
|
|
|
1204
|
164
|
|
|
|
|
242
|
my $varName = shift @$entns; |
1205
|
164
|
100
|
|
|
|
395
|
unless (my $vardecl = $trans->find_var($scope, $varName)) { |
1206
|
7
|
|
|
|
|
31
|
die $trans->node_error($node, "No such variable '%s'", $varName); |
1207
|
|
|
|
|
|
|
} else { |
1208
|
157
|
100
|
|
|
|
458
|
$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
|
5
|
(my MY $trans, my ($type, $scope, $baseNC, $targetNode)) = @_; |
1236
|
2
|
50
|
|
|
|
5
|
my $node = $targetNode ? $trans->fake_cursor_from($baseNC, $targetNode) |
1237
|
|
|
|
|
|
|
: $baseNC; |
1238
|
2
|
50
|
|
|
|
9
|
my $sub = $trans->can("t_$type") |
1239
|
|
|
|
|
|
|
or die $trans->node_error($node, "No such argtype: %s", $type); |
1240
|
2
|
|
|
|
|
13
|
$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
|
668
|
(my VarType $var, my MY $gen |
1259
|
|
|
|
|
|
|
, my ($scope, $widget, $metainfo, $actual)) = @_; |
1260
|
391
|
100
|
100
|
|
|
1376
|
return $actual unless defined $var->{cf_default} |
1261
|
|
|
|
|
|
|
and defined (my $mode = $var->{cf_default_mode}); |
1262
|
|
|
|
|
|
|
|
1263
|
12
|
100
|
|
|
|
63
|
if ($mode eq "!") { |
1264
|
2
|
|
|
|
|
14
|
return qq{defined $actual ? $actual : } |
1265
|
|
|
|
|
|
|
. qq{die "Argument '$var->{cf_varname}' is undef!"} |
1266
|
|
|
|
|
|
|
} |
1267
|
|
|
|
|
|
|
|
1268
|
10
|
|
|
|
|
12
|
my ($cond) = do { |
1269
|
10
|
100
|
|
|
|
32
|
if ($mode eq "|") { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1270
|
2
|
|
|
|
|
4
|
qq{$actual} |
1271
|
|
|
|
|
|
|
} elsif ($mode eq "?") { |
1272
|
6
|
|
|
|
|
21
|
qq{defined $actual && $actual ne ""} |
1273
|
|
|
|
|
|
|
} elsif ($mode eq "/") { |
1274
|
2
|
|
|
|
|
4
|
qq{defined $actual} |
1275
|
|
|
|
|
|
|
} else { |
1276
|
0
|
|
|
|
|
0
|
die "Unknown defaulting mode: $mode" |
1277
|
|
|
|
|
|
|
} |
1278
|
|
|
|
|
|
|
}; |
1279
|
|
|
|
|
|
|
|
1280
|
10
|
100
|
|
|
|
54
|
my $default = $var->gen_assignable_node |
1281
|
|
|
|
|
|
|
($gen, $scope |
1282
|
|
|
|
|
|
|
, $gen->fake_cursor($widget, $metainfo |
1283
|
10
|
|
|
|
|
26
|
, map {ref $_ ? @$_ : $_} $var->{cf_default}) |
1284
|
|
|
|
|
|
|
, 1); |
1285
|
|
|
|
|
|
|
|
1286
|
10
|
|
|
|
|
70
|
qq{($cond ? $actual : $default)}; |
1287
|
|
|
|
|
|
|
} |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::gen_assignable_node { |
1290
|
67
|
|
|
67
|
0
|
135
|
(my VarType $var, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1291
|
|
|
|
|
|
|
# early escaped な変数への代入値は、代入前に escape される。 |
1292
|
67
|
|
|
|
|
214
|
my $escaped = $var->early_escaped; |
1293
|
67
|
100
|
|
|
|
237
|
$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
|
80
|
my VarType $var = shift; |
1299
|
62
|
100
|
|
|
|
350
|
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
|
185
|
sub YATT::Translator::Perl::VarType::early_escaped { 0 } |
1304
|
929
|
|
|
929
|
0
|
3292
|
sub YATT::Translator::Perl::VarType::lvalue_format {'$%s'} |
1305
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_lvalue { |
1306
|
956
|
|
|
956
|
0
|
771
|
my VarType $var = shift; |
1307
|
956
|
|
|
|
|
1409
|
sprintf $var->lvalue_format, $var->{cf_varname}; |
1308
|
|
|
|
|
|
|
} |
1309
|
|
|
|
|
|
|
|
1310
|
107
|
|
|
107
|
0
|
834
|
sub YATT::Translator::Perl::VarType::escaped_format {'YATT::escape($%s)'} |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
sub YATT::Translator::Perl::VarType::as_escaped { |
1313
|
123
|
|
|
123
|
0
|
148
|
my VarType $var = shift; |
1314
|
123
|
|
|
|
|
293
|
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
|
0
|
0
|
|
|
|
0
|
$spec .= join "", map { |
|
|
0
|
|
|
|
|
|
1328
|
0
|
|
|
|
|
0
|
ref $_ ? map(ref $_ ? stringify_node($_) : $_, @$_) : $_ |
1329
|
|
|
|
|
|
|
} $default; |
1330
|
|
|
|
|
|
|
} |
1331
|
|
|
|
|
|
|
} |
1332
|
0
|
|
|
|
|
0
|
$spec; |
1333
|
|
|
|
|
|
|
} |
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
use YATT::ArgTypes |
1336
|
3
|
|
|
|
|
51
|
(-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
|
|
923
|
); |
|
3
|
|
|
|
|
5
|
|
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
|
|
46
|
shift; |
1359
|
45
|
|
|
|
|
47
|
my ($nvars); |
1360
|
|
|
|
|
|
|
my @items = map { |
1361
|
45
|
100
|
|
|
|
136
|
if (ref $_) { |
|
53
|
|
|
|
|
88
|
|
1362
|
7
|
|
|
|
|
12
|
$nvars++; |
1363
|
7
|
|
|
|
|
17
|
$$_ |
1364
|
|
|
|
|
|
|
} else { |
1365
|
|
|
|
|
|
|
# $var is prohibited. |
1366
|
46
|
|
|
|
|
99
|
qparen($_); |
1367
|
|
|
|
|
|
|
} |
1368
|
|
|
|
|
|
|
} @_; |
1369
|
45
|
100
|
100
|
|
|
212
|
if (@items == 1 && !$nvars) { |
1370
|
39
|
|
|
|
|
183
|
$items[0]; |
1371
|
|
|
|
|
|
|
} else { |
1372
|
6
|
|
|
|
|
36
|
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
|
|
197
|
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
|
|
14
|
(my VarType $var, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1386
|
|
|
|
|
|
|
# XXX: フラグがダサい。 |
1387
|
6
|
100
|
|
|
|
24
|
my $n = $is_opened ? $node : $node->open; |
1388
|
6
|
100
|
|
|
|
23
|
if (my $expr = $trans->has_single_bare_varexpr($scope, $n)) { |
1389
|
1
|
|
|
|
|
5
|
t_scalar->quote_assignable($expr); |
1390
|
|
|
|
|
|
|
} else { |
1391
|
5
|
|
|
|
|
13
|
$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
|
|
3
|
(my t_attr $var, my MY $trans |
1403
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1404
|
1
|
50
|
|
|
|
3
|
if (@$restExpr) { |
1405
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "attr() should be last call."); |
1406
|
|
|
|
|
|
|
} |
1407
|
1
|
50
|
|
|
|
3
|
if (ref $var->{cf_subtype}) { |
1408
|
0
|
|
|
|
|
0
|
die $trans->node_error($node, "nested subtype for attr"); |
1409
|
|
|
|
|
|
|
} |
1410
|
1
|
|
|
|
|
4
|
my @expr = $trans->gen_entref_list($scope, $node, @args); |
1411
|
1
|
|
33
|
|
|
7
|
sprintf(q{YATT::attr('%s', %s)} |
1412
|
|
|
|
|
|
|
, $var->{cf_subtype} || $var->{cf_varname} |
1413
|
|
|
|
|
|
|
, join(", ", $var->as_lvalue, @expr)); |
1414
|
|
|
|
|
|
|
} |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_attr::as_escaped { |
1417
|
4
|
|
|
4
|
|
6
|
my t_attr $var = shift; |
1418
|
4
|
50
|
|
|
|
9
|
if (ref $var->{cf_subtype}) { |
1419
|
0
|
|
|
|
|
0
|
die "nested subtype for attr: $var->{cf_varname}"; |
1420
|
|
|
|
|
|
|
} |
1421
|
4
|
|
|
|
|
18
|
my $realvar = sprintf $var->lvalue_format, $var->{cf_varname}; |
1422
|
4
|
|
33
|
|
|
28
|
sprintf(q{YATT::named_attr('%s', %s)} |
1423
|
|
|
|
|
|
|
, $var->{cf_subtype} || $var->{cf_varname} |
1424
|
|
|
|
|
|
|
, $realvar); |
1425
|
|
|
|
|
|
|
} |
1426
|
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_scalar::quote_assignable { |
1428
|
13
|
|
|
13
|
|
19
|
shift; |
1429
|
13
|
100
|
|
|
|
35
|
'scalar(do {'.join("", map { ref $_ ? $$_ : $_ } @_).'})'; |
|
21
|
|
|
|
|
121
|
|
1430
|
|
|
|
|
|
|
} |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::quote_assignable { |
1433
|
13
|
|
|
13
|
|
28
|
shift; |
1434
|
13
|
100
|
|
|
|
36
|
'['.join("", map { ref $_ ? $$_ : $_ } @_).']'; |
|
25
|
|
|
|
|
148
|
|
1435
|
|
|
|
|
|
|
} |
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_expand { |
1438
|
17
|
|
|
17
|
|
42
|
(my t_list $var, my MY $trans |
1439
|
|
|
|
|
|
|
, my ($scope, $node, $restExpr, $queue, @args)) = @_; |
1440
|
17
|
|
|
|
|
60
|
my $was = join "->", splice @$queue, 0; |
1441
|
17
|
|
|
|
|
84
|
sprintf q{map($_ ? @$_ : (), %s)}, $was; |
1442
|
|
|
|
|
|
|
} |
1443
|
|
|
|
|
|
|
|
1444
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_list::entmacro_size { |
1445
|
2
|
|
|
2
|
|
6
|
(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
|
|
|
|
|
8
|
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
|
|
55
|
(my t_code $argdecl, my MY $trans, my ($scope, $node)) = @_; |
1469
|
25
|
|
|
|
|
84
|
my ($post, @args) = $trans->genargs_static |
1470
|
|
|
|
|
|
|
($scope, $node->open, $argdecl->arg_specs); |
1471
|
|
|
|
|
|
|
# XXX: こっちを () しなくて済むのはなぜ? => の call だから? |
1472
|
25
|
|
|
|
|
115
|
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
|
|
67
|
my t_code $argdecl = shift; |
1478
|
31
|
|
100
|
|
|
267
|
($argdecl->{arg_dict} ||= {}, $argdecl->{arg_order} ||= []); |
|
|
|
100
|
|
|
|
|
1479
|
|
|
|
|
|
|
} |
1480
|
|
|
|
|
|
|
|
1481
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_args { |
1482
|
39
|
|
|
39
|
|
46
|
(my t_code $argdecl) = @_; |
1483
|
16
|
|
|
|
|
102
|
return unless $argdecl->{arg_order} |
1484
|
39
|
100
|
100
|
|
|
200
|
&& (my @args = @{$argdecl->{arg_order}}); |
1485
|
10
|
|
|
|
|
42
|
\ sprintf('my (%s) = @_', join(", ", map { |
1486
|
9
|
|
|
|
|
26
|
$argdecl->{arg_dict}{$_}->as_lvalue; |
1487
|
|
|
|
|
|
|
} @args)); |
1488
|
|
|
|
|
|
|
} |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_body { |
1491
|
40
|
|
|
40
|
|
96
|
(my t_code $argdecl, my MY $trans, my ($scope, $is_expr, $node)) = @_; |
1492
|
40
|
50
|
|
|
|
96
|
return unless $node->array_size; |
1493
|
40
|
100
|
|
|
|
73
|
if ($is_expr) { |
1494
|
1
|
|
|
|
|
4
|
$trans->genexpr_node($scope, ENT_RAW, $node); |
1495
|
|
|
|
|
|
|
} else { |
1496
|
39
|
|
|
|
|
93
|
$trans->as_statement_list |
1497
|
|
|
|
|
|
|
($argdecl->gen_args |
1498
|
|
|
|
|
|
|
, $trans->generate_body([{}, [$argdecl->{arg_dict}, $scope]], $node)); |
1499
|
|
|
|
|
|
|
} |
1500
|
|
|
|
|
|
|
} |
1501
|
|
|
|
|
|
|
|
1502
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::gen_assignable_node { |
1503
|
40
|
|
|
40
|
|
87
|
(my t_code $argdecl, my MY $trans, my ($scope, $node, $is_opened)) = @_; |
1504
|
40
|
|
100
|
|
|
107
|
my $is_expr = !$is_opened && !$node->is_quoted_by_element; |
1505
|
40
|
100
|
|
|
|
142
|
$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
|
|
20
|
(my t_code $argdecl, my ($name)) = @_; |
1511
|
12
|
|
|
|
|
42
|
defined $argdecl->{arg_dict}{$name}; |
1512
|
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::add_arg { |
1515
|
13
|
|
|
13
|
|
26
|
(my t_code $codevar, my ($name, $arg)) = @_; |
1516
|
13
|
|
|
|
|
59
|
add_arg_order_in($codevar->{arg_dict}, $codevar->{arg_order}, $name, $arg); |
1517
|
13
|
|
|
|
|
52
|
$codevar; |
1518
|
|
|
|
|
|
|
} |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_code::clone { |
1521
|
6
|
|
|
6
|
|
12
|
(my t_code $orig) = @_; |
1522
|
6
|
|
|
|
|
27
|
my t_code $new = $orig->SUPER::clone; |
1523
|
6
|
|
|
|
|
29
|
my ($dict, $order) = $orig->arg_specs; |
1524
|
6
|
|
|
|
|
16
|
foreach my $name (@$order) { |
1525
|
1
|
|
|
|
|
6
|
$new->add_arg($name, $dict->{$name}->clone); |
1526
|
|
|
|
|
|
|
} |
1527
|
|
|
|
|
|
|
$new |
1528
|
6
|
|
|
|
|
21
|
} |
1529
|
|
|
|
|
|
|
|
1530
|
|
|
|
|
|
|
# code 型の変数宣言の生成 |
1531
|
|
|
|
|
|
|
sub create_var_code { |
1532
|
172
|
|
|
172
|
0
|
266
|
(my MY $trans, my ($node, @param)) = @_; |
1533
|
172
|
|
|
|
|
1158
|
my t_code $codevar = $trans->t_code->new(@param); |
1534
|
172
|
100
|
|
|
|
360
|
$trans->define_args($codevar, $node->open) if $node; |
1535
|
172
|
|
|
|
|
653
|
$codevar; |
1536
|
|
|
|
|
|
|
} |
1537
|
|
|
|
|
|
|
|
1538
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_delegate::gen_call { |
1539
|
5
|
|
|
5
|
|
16
|
(my t_delegate $argdecl, my MY $trans, my ($scope, $node)) = @_; |
1540
|
5
|
|
|
|
|
20
|
my $func = $trans->get_funcname_to($trans->{cf_mode} |
1541
|
|
|
|
|
|
|
, $argdecl->{cf_base_widget}); |
1542
|
|
|
|
|
|
|
# XXX: テストを書け。body が code か html か、だ。 |
1543
|
|
|
|
|
|
|
# my $body_dict = $argdecl->{cf_base_widget}->get_arg_spec(body => undef); |
1544
|
5
|
|
|
|
|
14
|
my $body_spec = $argdecl->{cf_base_widget}->{arg_dict}->{body}; |
1545
|
5
|
|
|
|
|
7
|
my $body_scope = do { |
1546
|
5
|
50
|
|
|
|
25
|
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
|
|
|
|
|
17
|
my ($post, @args) = $trans->genargs_static |
1553
|
|
|
|
|
|
|
([{}, $body_scope] |
1554
|
|
|
|
|
|
|
, $node->open, $argdecl->arg_specs); |
1555
|
18
|
50
|
|
|
|
65
|
return \ sprintf(' %s($this, [%s])%s', $func |
1556
|
5
|
|
|
|
|
22
|
, join(", ", map {defined $_ ? $_ : 'undef'} @args) |
1557
|
|
|
|
|
|
|
, $post); |
1558
|
|
|
|
|
|
|
} |
1559
|
|
|
|
|
|
|
|
1560
|
|
|
|
|
|
|
sub YATT::Translator::Perl::t_delegate::arg_specs { |
1561
|
5
|
|
|
5
|
|
11
|
my t_delegate $argdecl = shift; |
1562
|
5
|
|
|
|
|
27
|
($argdecl->{cf_base_widget}->arg_specs |
1563
|
|
|
|
|
|
|
, $argdecl->{cf_delegate_vars}); |
1564
|
|
|
|
|
|
|
} |
1565
|
|
|
|
|
|
|
|
1566
|
|
|
|
|
|
|
#======================================== |
1567
|
|
|
|
|
|
|
|
1568
|
|
|
|
|
|
|
sub make_arg_spec { |
1569
|
7
|
|
|
7
|
0
|
13
|
my ($dict, $order) = splice @_, 0, 2; |
1570
|
7
|
|
|
|
|
8
|
foreach my $name (@_) { |
1571
|
19
|
|
|
|
|
26
|
$dict->{$name} = @$order; |
1572
|
19
|
|
|
|
|
27
|
push @$order, $name; |
1573
|
|
|
|
|
|
|
} |
1574
|
|
|
|
|
|
|
} |
1575
|
|
|
|
|
|
|
|
1576
|
|
|
|
|
|
|
sub arg_name_types { |
1577
|
109
|
|
|
109
|
0
|
136
|
(my MY $trans, my ($args)) = @_; |
1578
|
109
|
|
|
|
|
281
|
my (@path) = $args->node_path; |
1579
|
109
|
100
|
66
|
|
|
250
|
if ($args->is_attribute and $args->is_quoted_by_element) { |
1580
|
8
|
|
|
|
|
13
|
shift @path; |
1581
|
|
|
|
|
|
|
} |
1582
|
109
|
|
|
|
|
215
|
my ($name) = shift @path; |
1583
|
109
|
50
|
|
|
|
367
|
@path >= 2 ? ($name, \@path) : ($name, $path[0]); |
1584
|
|
|
|
|
|
|
} |
1585
|
|
|
|
|
|
|
|
1586
|
|
|
|
|
|
|
# macro の、 my:type=var など専用。 |
1587
|
|
|
|
|
|
|
sub feed_arg_spec { |
1588
|
14
|
|
|
14
|
0
|
34
|
(my MY $trans, my ($args, $arg_dict, $arg_order)) = splice @_, 0, 4; |
1589
|
14
|
|
|
|
|
21
|
my $found; |
1590
|
14
|
|
|
|
|
50
|
for (my $nth = 0; $args->readable; $args->next) { |
1591
|
31
|
100
|
|
|
|
62
|
last unless $args->is_primary_attribute; |
1592
|
17
|
|
|
|
|
38
|
my ($name, @ext) = $args->node_path; |
1593
|
17
|
100
|
|
|
|
38
|
unless (defined $name) { |
1594
|
4
|
50
|
|
|
|
16
|
$name = $arg_order->[$nth++] |
1595
|
|
|
|
|
|
|
or die $trans->node_error($args, "Too many args"); |
1596
|
|
|
|
|
|
|
} |
1597
|
17
|
50
|
|
|
|
49
|
defined (my $argno = $arg_dict->{$name}) |
1598
|
|
|
|
|
|
|
or die $trans->node_error($args, "Unknown arg '%s'", $name); |
1599
|
|
|
|
|
|
|
|
1600
|
17
|
|
|
|
|
35
|
$_[$argno] = $args->current; |
1601
|
17
|
|
|
|
|
46
|
$found++; |
1602
|
|
|
|
|
|
|
} |
1603
|
14
|
|
|
|
|
37
|
$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
|
12
|
(my MY $trans, my ($scope, $args, $fragment)) = @_; |
1614
|
|
|
|
|
|
|
|
1615
|
6
|
50
|
|
|
|
28
|
$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
|
|
|
|
15
|
unless (defined $list) { |
1620
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "no list= is given"); |
1621
|
|
|
|
|
|
|
} |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
# $ith をまだ使っていない。 |
1624
|
6
|
|
|
|
|
8
|
my %local; |
1625
|
6
|
|
|
|
|
6
|
my $loopvar = do { |
1626
|
6
|
100
|
|
|
|
14
|
if ($my) { |
1627
|
5
|
|
|
|
|
16
|
my ($x, @type) = node_path($my); |
1628
|
5
|
|
|
|
|
15
|
my $varname = node_body($my); |
1629
|
5
|
|
50
|
|
|
35
|
$local{$varname} = $trans->create_var |
1630
|
|
|
|
|
|
|
($type[0] || '', undef, varname => $varname); |
1631
|
5
|
|
|
|
|
14
|
'my $' . $varname; |
1632
|
|
|
|
|
|
|
} else { |
1633
|
|
|
|
|
|
|
# _ は? entity 自体に処理させるか… |
1634
|
1
|
|
|
|
|
2
|
'' |
1635
|
|
|
|
|
|
|
} |
1636
|
|
|
|
|
|
|
}; |
1637
|
|
|
|
|
|
|
|
1638
|
6
|
|
|
|
|
9
|
my $fmt = q{foreach %1$s (%2$s) %3$s}; |
1639
|
6
|
|
|
|
|
14
|
my $listexpr = do { |
1640
|
6
|
|
|
|
|
8
|
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
|
|
|
|
23
|
if (my $var = $trans->has_pass_through_var |
1648
|
|
|
|
|
|
|
($scope, my $fc = $trans->fake_cursor_from($args, $list), 'list')) { |
1649
|
3
|
100
|
|
|
|
14
|
unless ($var->type_name eq 'list') { |
1650
|
1
|
|
|
|
|
4
|
my $path = $args->parent->node_path; |
1651
|
1
|
|
|
|
|
7
|
die $trans->node_error($fc, "$path - should be list type") |
1652
|
|
|
|
|
|
|
} |
1653
|
2
|
|
|
|
|
8
|
'@'.$var->as_lvalue; |
1654
|
|
|
|
|
|
|
} else { |
1655
|
3
|
|
|
|
|
13
|
$trans->genexpr_node($scope, 0, $args->adopter_for($list)); |
1656
|
|
|
|
|
|
|
} |
1657
|
|
|
|
|
|
|
}; |
1658
|
5
|
|
|
|
|
40
|
my @statements = $trans->as_statement_list |
1659
|
|
|
|
|
|
|
($trans->generate_body([\%local, $scope], $args)); |
1660
|
|
|
|
|
|
|
|
1661
|
5
|
50
|
|
|
|
17
|
if ($fragment) { |
1662
|
0
|
|
|
|
|
0
|
($fmt, $loopvar, $listexpr, \@statements); |
1663
|
|
|
|
|
|
|
} else { |
1664
|
5
|
|
|
|
|
18
|
\ 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
|
20
|
(my MY $trans, my ($scope, $primary, $pkg, $if, $unless, $body)) = @_; |
1675
|
8
|
|
|
|
|
7
|
my $header = do { |
1676
|
8
|
100
|
|
|
|
14
|
if ($primary) { |
1677
|
5
|
|
|
|
|
5
|
my ($kw, $cond) = do { |
1678
|
5
|
50
|
|
|
|
12
|
if ($if) { (if => $if) } |
|
5
|
0
|
|
|
|
13
|
|
1679
|
0
|
|
|
|
|
0
|
elsif ($unless) { (unless => $unless) } |
1680
|
0
|
|
|
|
|
0
|
else { die "??" } |
1681
|
|
|
|
|
|
|
}; |
1682
|
5
|
|
|
|
|
24
|
sprintf q{%s (%s) }, $kw |
1683
|
|
|
|
|
|
|
, $trans->genexpr_node($scope, 0 |
1684
|
|
|
|
|
|
|
, $trans->fake_cursor_from($body, $cond, 1)); |
1685
|
|
|
|
|
|
|
} else { |
1686
|
3
|
|
|
|
|
4
|
my ($cond, $true) = do { |
1687
|
3
|
100
|
|
|
|
8
|
if ($if) { ($if, 1) } |
|
1
|
50
|
|
|
|
3
|
|
1688
|
0
|
|
|
|
|
0
|
elsif ($unless) { ($unless, 0) } |
1689
|
|
|
|
|
|
|
else {} |
1690
|
|
|
|
|
|
|
}; |
1691
|
3
|
100
|
|
|
|
8
|
unless (defined $cond) { |
1692
|
2
|
|
|
|
|
4
|
q{else } |
1693
|
|
|
|
|
|
|
} else { |
1694
|
1
|
|
|
|
|
4
|
my $expr = $trans->genexpr_node |
1695
|
|
|
|
|
|
|
($scope, 0 |
1696
|
|
|
|
|
|
|
, $trans->fake_cursor_from($body, $cond, 1)); |
1697
|
1
|
50
|
|
|
|
7
|
sprintf q{elsif (%s) }, $true ? $expr : qq{not($expr)}; |
1698
|
|
|
|
|
|
|
} |
1699
|
|
|
|
|
|
|
} |
1700
|
|
|
|
|
|
|
}; |
1701
|
8
|
|
|
|
|
29
|
$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
|
10
|
(my MY $trans, my ($scope, $args)) = @_; |
1709
|
|
|
|
|
|
|
|
1710
|
5
|
|
|
|
|
8
|
my @case = do { |
1711
|
5
|
50
|
|
|
|
23
|
$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
|
|
|
|
|
14
|
([$if, $unless, $args->variant_builder]); |
1715
|
|
|
|
|
|
|
}; |
1716
|
5
|
|
|
|
|
20
|
for (; $args->readable; $args->next) { |
1717
|
12
|
100
|
66
|
|
|
22
|
if ($args->is_attribute && $args->node_name eq 'else') { |
1718
|
3
|
|
|
|
|
8
|
my $kid = $args->open; |
1719
|
3
|
|
|
|
|
10
|
$trans->feed_arg_spec($kid, \%arg_dict, \@arg_order |
1720
|
|
|
|
|
|
|
, my ($if, $unless)); |
1721
|
3
|
|
|
|
|
9
|
push @case, [$if, $unless, $kid]; |
1722
|
|
|
|
|
|
|
} else { |
1723
|
|
|
|
|
|
|
# XXX: 多分、$case[0] |
1724
|
9
|
|
|
|
|
22
|
$case[-1][-1]->add_node($args->current); |
1725
|
|
|
|
|
|
|
} |
1726
|
|
|
|
|
|
|
} |
1727
|
|
|
|
|
|
|
|
1728
|
5
|
|
|
|
|
19
|
my $pkg = $trans->get_package_from_node($args); |
1729
|
5
|
|
|
|
|
10
|
my @script = $trans->gen_macro_if_arm($scope, 1, $pkg, @{shift @case}); |
|
5
|
|
|
|
|
20
|
|
1730
|
5
|
|
|
|
|
31
|
while (my $arm = shift @case) { |
1731
|
3
|
|
|
|
|
10
|
push @script, $trans->gen_macro_if_arm($scope, 0, $pkg, @$arm); |
1732
|
|
|
|
|
|
|
} |
1733
|
5
|
|
|
|
|
29
|
\ join " ", @script; |
1734
|
|
|
|
|
|
|
} |
1735
|
|
|
|
|
|
|
} |
1736
|
|
|
|
|
|
|
|
1737
|
|
|
|
|
|
|
{ |
1738
|
|
|
|
|
|
|
declare_alias macro_yatt_block => \¯o_block; |
1739
|
|
|
|
|
|
|
sub macro_block { |
1740
|
3
|
|
|
3
|
0
|
6
|
(my MY $trans, my ($scope, $args)) = @_; |
1741
|
3
|
|
|
|
|
9
|
\ $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
|
11
|
(my MY $trans, my ($scope, $args)) = @_; |
1749
|
6
|
|
|
|
|
8
|
my @assign; |
1750
|
6
|
|
|
|
|
15
|
my $filename = $args->metainfo->filename; |
1751
|
6
|
|
|
|
|
16
|
for (; $args->readable; $args->next) { |
1752
|
8
|
100
|
|
|
|
19
|
last unless $args->is_primary_attribute; |
1753
|
7
|
|
|
|
|
20
|
my ($name, $typename) = $trans->arg_name_types($args); |
1754
|
7
|
100
|
66
|
|
|
38
|
$typename ||= $args->next_is_body ? 'html' : 'text'; |
1755
|
7
|
50
|
|
|
|
25
|
if (my VarType $old = $scope->[0]{$name}) { |
1756
|
0
|
|
0
|
|
|
0
|
die $trans->node_error |
|
|
|
0
|
|
|
|
|
1757
|
|
|
|
|
|
|
($args, "Variable '%s' redefined (previously at file %s line %s)" |
1758
|
|
|
|
|
|
|
, $name, $old->{cf_filename} || '(unknown)' |
1759
|
|
|
|
|
|
|
, $old->{cf_linenum} || '(unknown)'); |
1760
|
|
|
|
|
|
|
} |
1761
|
7
|
|
|
|
|
21
|
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
|
|
|
|
23
|
push @assign, [$var, $args->node_size |
1768
|
|
|
|
|
|
|
? $var->gen_assignable_node($trans, $scope, $args) |
1769
|
|
|
|
|
|
|
: ()]; |
1770
|
|
|
|
|
|
|
} |
1771
|
|
|
|
|
|
|
|
1772
|
6
|
100
|
|
|
|
14
|
if ($args->readable) { |
1773
|
1
|
|
|
|
|
3
|
my $var = $assign[-1][0]; |
1774
|
1
|
|
33
|
|
|
9
|
$assign[-1][1] ||= $var->gen_assignable_node($trans, $scope, $args, 1); |
1775
|
|
|
|
|
|
|
} |
1776
|
|
|
|
|
|
|
|
1777
|
6
|
|
|
|
|
7
|
my @script; |
1778
|
6
|
|
|
|
|
8
|
foreach my $desc (@assign) { |
1779
|
7
|
|
|
|
|
11
|
my ($var, $value) = @$desc; |
1780
|
7
|
|
|
|
|
14
|
my $script = sprintf q{my %s}, $var->as_lvalue; |
1781
|
7
|
100
|
|
|
|
19
|
$script .= q{ = } . $value if defined $value; |
1782
|
7
|
|
|
|
|
17
|
push @script, \ $script; |
1783
|
|
|
|
|
|
|
} |
1784
|
6
|
|
|
|
|
24
|
@script; |
1785
|
|
|
|
|
|
|
} |
1786
|
|
|
|
|
|
|
} |
1787
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
{ |
1789
|
|
|
|
|
|
|
declare_alias macro_yatt_format => \¯o_format; |
1790
|
|
|
|
|
|
|
sub macro_format { |
1791
|
3
|
|
|
3
|
0
|
6
|
(my MY $trans, my ($scope, $args)) = @_; |
1792
|
|
|
|
|
|
|
|
1793
|
3
|
50
|
33
|
|
|
7
|
unless ($args->readable && $args->is_primary_attribute) { |
1794
|
0
|
|
|
|
|
0
|
die $trans->node_error($args, "format parameter is missing"); |
1795
|
|
|
|
|
|
|
} |
1796
|
|
|
|
|
|
|
|
1797
|
3
|
|
|
|
|
8
|
my $name = $args->node_name; |
1798
|
|
|
|
|
|
|
|
1799
|
3
|
|
|
|
|
3
|
my $format = do { |
1800
|
3
|
100
|
|
|
|
15
|
if (my $var = $trans->has_pass_through_var($scope, $args, $name)) { |
1801
|
1
|
|
|
|
|
4
|
$var->as_lvalue; |
1802
|
|
|
|
|
|
|
} else { |
1803
|
2
|
|
|
|
|
9
|
$trans->faked_gentype(text => $scope, $args); |
1804
|
|
|
|
|
|
|
} |
1805
|
|
|
|
|
|
|
}; |
1806
|
|
|
|
|
|
|
|
1807
|
3
|
|
|
|
|
13
|
$args->next; |
1808
|
|
|
|
|
|
|
|
1809
|
3
|
|
|
|
|
9
|
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
|
11
|
my ($this, $trans |
1851
|
|
|
|
|
|
|
, $scope, $node, $restExpr, $queue, @args) = @_; |
1852
|
|
|
|
|
|
|
# XXX: $cond を文字列にするのは不便。 |
1853
|
4
|
|
|
|
|
16
|
my ($cond, $then, $else) |
1854
|
|
|
|
|
|
|
= $trans->gen_entref_list($scope, $node, @args); |
1855
|
|
|
|
|
|
|
# XXX: 三項演算だと、狂いが出そうな。 |
1856
|
12
|
50
|
|
|
|
45
|
sprintf q{((%s) ? %s : %s)} |
1857
|
4
|
|
50
|
|
|
16
|
, map {ref $_ ? $$_ : $_} $cond, $then, $else || q{''}; |
1858
|
|
|
|
|
|
|
}; |
1859
|
|
|
|
|
|
|
|
1860
|
|
|
|
|
|
|
sub entmacro_render { |
1861
|
2
|
|
|
2
|
0
|
5
|
my ($this, $trans |
1862
|
|
|
|
|
|
|
, $scope, $node, $restExpr, $queue, @args) = @_; |
1863
|
2
|
|
|
|
|
7
|
my ($type, @expr) |
1864
|
|
|
|
|
|
|
= $trans->gen_entref_list($scope, $node, @args); |
1865
|
2
|
|
|
|
|
11
|
\ sprintf q{__PACKAGE__->can('render_'.%s)->($this, [%s])} |
1866
|
|
|
|
|
|
|
, $type, join(", ", @expr); |
1867
|
|
|
|
|
|
|
}; |
1868
|
|
|
|
|
|
|
#======================================== |
1869
|
|
|
|
|
|
|
|
1870
|
|
|
|
|
|
|
sub paren_escape ($) { |
1871
|
352
|
50
|
|
352
|
0
|
605
|
unless (defined $_[0]) { |
1872
|
0
|
|
|
|
|
0
|
confess "Undefined text"; |
1873
|
|
|
|
|
|
|
} |
1874
|
352
|
|
|
|
|
592
|
$_[0] =~ s{([\(\)\\])}{\\$1}g; |
1875
|
352
|
|
|
|
|
1738
|
$_[0] |
1876
|
|
|
|
|
|
|
} |
1877
|
|
|
|
|
|
|
|
1878
|
|
|
|
|
|
|
sub qparen ($) { |
1879
|
352
|
|
|
352
|
0
|
844
|
'q('.paren_escape($_[0]).')' |
1880
|
|
|
|
|
|
|
} |
1881
|
|
|
|
|
|
|
|
1882
|
|
|
|
|
|
|
sub qqvalue ($) { |
1883
|
26
|
|
|
26
|
0
|
56
|
'q'.qparen($_[0]); |
1884
|
|
|
|
|
|
|
} |
1885
|
|
|
|
|
|
|
|
1886
|
|
|
|
|
|
|
{ |
1887
|
|
|
|
|
|
|
my %map = ("\r", "r", "\n", "n"); |
1888
|
|
|
|
|
|
|
sub qcrlf ($) { |
1889
|
129
|
|
|
129
|
0
|
171
|
my ($crlf) = @_; |
1890
|
129
|
|
|
|
|
820
|
$crlf =~ s{([\r\n])}{\\$map{$1}}g; |
1891
|
129
|
|
|
|
|
955
|
$crlf; |
1892
|
|
|
|
|
|
|
} |
1893
|
|
|
|
|
|
|
} |
1894
|
|
|
|
|
|
|
|
1895
|
|
|
|
|
|
|
sub dots_for_arrows { |
1896
|
31
|
|
|
31
|
0
|
45
|
shift; |
1897
|
31
|
50
|
|
|
|
66
|
return unless defined $_[0]; |
1898
|
31
|
|
|
|
|
97
|
$_[0] =~ s{\b\.(?=\w+\()}{->}g; |
1899
|
31
|
|
|
|
|
107
|
$_[0]; |
1900
|
|
|
|
|
|
|
} |
1901
|
|
|
|
|
|
|
|
1902
|
|
|
|
|
|
|
1; |