line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011-2012 Yuki Izumi. ( anneli AT cpan DOT org ) |
2
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
3
|
|
|
|
|
|
|
# same terms as Perl itself. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Erlang::Parser::Node::Def; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
10
|
use Moose; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
12
|
|
8
|
|
|
|
|
|
|
with 'Erlang::Parser::Node'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'def' => (is => 'rw', required => 1, isa => 'Str'); |
11
|
|
|
|
|
|
|
has 'args' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); |
12
|
|
|
|
|
|
|
has 'whens' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node::WhenList'); |
13
|
|
|
|
|
|
|
has 'stmts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub print { |
16
|
3238
|
|
|
3238
|
1
|
3391
|
my ($self, $fh, $depth) = @_; |
17
|
3238
|
|
50
|
|
|
8244
|
$depth ||= 0; |
18
|
|
|
|
|
|
|
|
19
|
3238
|
|
|
|
|
79336
|
print $fh $self->def, '('; |
20
|
|
|
|
|
|
|
|
21
|
3238
|
|
|
|
|
3327
|
my $first = 1; |
22
|
3238
|
|
|
|
|
2515
|
foreach (@{$self->args}) { |
|
3238
|
|
|
|
|
75792
|
|
23
|
4618
|
100
|
|
|
|
6153
|
if ($first) { $first = 0 } else { print $fh ', ' } |
|
2836
|
|
|
|
|
2376
|
|
|
1782
|
|
|
|
|
1813
|
|
24
|
4618
|
|
|
|
|
9635
|
$_->print($fh, $depth); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
3238
|
|
|
|
|
3135
|
$depth++; |
28
|
|
|
|
|
|
|
|
29
|
3238
|
|
|
|
|
3111
|
print $fh ") "; |
30
|
|
|
|
|
|
|
|
31
|
3238
|
|
|
|
|
77136
|
$self->whens->print($fh, $depth); |
32
|
|
|
|
|
|
|
|
33
|
3238
|
|
|
|
|
6098
|
print $fh "->\n", "\t" x $depth; |
34
|
3238
|
|
|
|
|
2737
|
$first = 1; |
35
|
3238
|
|
|
|
|
2561
|
foreach (@{$self->stmts}) { |
|
3238
|
|
|
|
|
76739
|
|
36
|
5564
|
100
|
|
|
|
7948
|
if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth } |
|
3238
|
|
|
|
|
2962
|
|
|
2326
|
|
|
|
|
3903
|
|
37
|
5564
|
|
|
|
|
13297
|
$_->print($fh, $depth); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
3238
|
|
|
|
|
7385
|
$depth--; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Erlang::Parser::Node::Def - a match in a function definition |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Contains a single pattern match and guard expr/seq list, with the body of the |
52
|
|
|
|
|
|
|
function. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 Accessors |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item C<def> |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The name of the function. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item C<args> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
A list of L<Erlang::Parser::Node>s which constitute the argument patterns to be |
65
|
|
|
|
|
|
|
matched. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item C<whens> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The L<Erlang::Parser::Node::WhenList> containing guard expressions/sequences. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item C<stmts> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
A list of L<Erlang::Parser::Node>s; the body for the function. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 Methods |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item C<print> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Pretty-prints the node to its filehandle argument. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 EXAMPLE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
x(Y) -> |
90
|
|
|
|
|
|
|
Z = Y + Y, |
91
|
|
|
|
|
|
|
Z * 2 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# vim: set sw=4 ts=4: |