line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::Operation::Expression::Operator::NamedUnary; |
3
|
5
|
|
|
5
|
|
33
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
142
|
|
4
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
132
|
|
5
|
5
|
|
|
5
|
|
36
|
use RPerl::AfterSubclass; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
663
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.002_500; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
5
|
|
|
5
|
|
35
|
use parent qw(RPerl::Operation::Expression::Operator); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
31
|
|
10
|
5
|
|
|
5
|
|
312
|
use RPerl::Operation::Expression::Operator; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
3014
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
13
|
|
|
|
|
|
|
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator |
14
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
17
|
|
|
|
|
|
|
our hashref $properties = {}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# [[[ OO PROPERTIES, CLASS PROPERTY AKA PACKAGE VARIABLE ]]] |
20
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp020: upon adding new named op file lib/RPerl/Operation/Expression/Operator/Named*/* also add in Named*.pm and rperloperations.* |
21
|
|
|
|
|
|
|
our string_hashref $NAMES = { |
22
|
|
|
|
|
|
|
'chdir' => 'RPerl::Operation::Expression::Operator::NamedUnary::ChangeDirectory', |
23
|
|
|
|
|
|
|
'cos' => 'RPerl::Operation::Expression::Operator::NamedUnary::Cosine', |
24
|
|
|
|
|
|
|
'defined' => 'RPerl::Operation::Expression::Operator::NamedUnary::Defined', |
25
|
|
|
|
|
|
|
'exists' => 'RPerl::Operation::Expression::Operator::NamedUnary::Exists', |
26
|
|
|
|
|
|
|
'-e' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileExists', |
27
|
|
|
|
|
|
|
'-r' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileReadable', |
28
|
|
|
|
|
|
|
'-f' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileRegular', |
29
|
|
|
|
|
|
|
'-T' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileText', |
30
|
|
|
|
|
|
|
'length' => 'RPerl::Operation::Expression::Operator::NamedUnary::Length', |
31
|
|
|
|
|
|
|
'log' => 'RPerl::Operation::Expression::Operator::NamedUnary::Log', |
32
|
|
|
|
|
|
|
'rand' => 'RPerl::Operation::Expression::Operator::NamedUnary::Random', |
33
|
|
|
|
|
|
|
'scalar' => 'RPerl::Operation::Expression::Operator::NamedUnary::Scalar', |
34
|
|
|
|
|
|
|
'sin' => 'RPerl::Operation::Expression::Operator::NamedUnary::Sine', |
35
|
|
|
|
|
|
|
'sqrt' => 'RPerl::Operation::Expression::Operator::NamedUnary::SquareRoot' |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our string_hashref::method $ast_to_rperl__generate = sub { |
41
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
42
|
|
|
|
|
|
|
my string_hashref $rperl_source_group = { PMC => q{} }; |
43
|
|
|
|
|
|
|
my string_hashref $rperl_source_subgroup; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my string $self_class = ref $self; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $self_class = ' . $self_class . "\n"); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my string $operator_name; |
52
|
|
|
|
|
|
|
if ( $self_class eq 'Operation_80' ) { # Statement -> OP01_NAMED_UNARY_SCOLON |
53
|
|
|
|
|
|
|
$operator_name = substr $self->{children}->[0], 0, -1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif (( $self_class eq 'Operator_99' ) or # Operator -> OP10_NAMED_UNARY SubExpression |
56
|
|
|
|
|
|
|
( $self_class eq 'Operator_100' ) |
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
{ # Operator -> OP10_NAMED_UNARY |
59
|
|
|
|
|
|
|
# strip trailing whitespace, caused by the need to have the grammar match some tokens with a trailing whitespace, as with 'scalar ', etc. |
60
|
|
|
|
|
|
|
$self->{children}->[0] =~ s/^([^\s]+)\s+$/$1/gxms; |
61
|
|
|
|
|
|
|
$operator_name = $self->{children}->[0]; |
62
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $self->{children}->[0] = ' . q{'} . $self->{children}->[0] . q{'} . "\n" ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
|
|
|
|
|
|
die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule ' |
66
|
|
|
|
|
|
|
. $self_class |
67
|
|
|
|
|
|
|
. ' found where Operation_80, Operator_99, or Operator_100 expected, dying' ) |
68
|
|
|
|
|
|
|
. "\n"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $operator_name = ' . q{'} . $operator_name . q{'} . "\n" ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if ( not exists $NAMES->{$operator_name} ) { |
74
|
|
|
|
|
|
|
die q{ERROR ECOGEASRP19, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: unsupported or unrecognized named operator '} |
75
|
|
|
|
|
|
|
. $operator_name |
76
|
|
|
|
|
|
|
. q{' found where } |
77
|
|
|
|
|
|
|
. ( join ', ', ( sort keys %{$NAMES} ) ) |
78
|
|
|
|
|
|
|
. ' expected, dying' . "\n"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
my string $operator_class = $NAMES->{$operator_name}; |
81
|
|
|
|
|
|
|
my object $operator_object = $operator_class->new(); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$rperl_source_subgroup = $operator_object->ast_to_rperl__generate( $self, $modes ); |
84
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $rperl_source_group; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub { |
90
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
91
|
|
|
|
|
|
|
my string_hashref $cpp_source_group = { CPP => q{// <<< RP::O::E::O::NU __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" }; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#... |
94
|
|
|
|
|
|
|
return $cpp_source_group; |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub { |
98
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
99
|
|
|
|
|
|
|
my string_hashref $cpp_source_group = { CPP => q{} }; |
100
|
|
|
|
|
|
|
my string_hashref $cpp_source_subgroup; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my string $self_class = ref $self; |
105
|
|
|
|
|
|
|
my string $operator_name; |
106
|
|
|
|
|
|
|
if ( $self_class eq 'Operation_80' ) { # Statement -> OP01_NAMED_UNARY_SCOLON |
107
|
|
|
|
|
|
|
$operator_name = substr $self->{children}->[0], 0, -1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif (( $self_class eq 'Operator_99' ) or # Operator -> OP10_NAMED_UNARY SubExpression |
110
|
|
|
|
|
|
|
( $self_class eq 'Operator_100' ) |
111
|
|
|
|
|
|
|
) |
112
|
|
|
|
|
|
|
{ # Operator -> OP10_NAMED_UNARY |
113
|
|
|
|
|
|
|
# strip trailing whitespace, caused by the need to have the grammar match some tokens with a trailing whitespace, as with 'scalar ', etc. |
114
|
|
|
|
|
|
|
$self->{children}->[0] =~ s/^([^\s]+)\s+$/$1/gxms; |
115
|
|
|
|
|
|
|
$operator_name = $self->{children}->[0]; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
|
|
|
|
|
|
die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' |
119
|
|
|
|
|
|
|
. $self_class |
120
|
|
|
|
|
|
|
. ' found where Operation_80, Operator_99 or Operator_100 expected, dying' ) |
121
|
|
|
|
|
|
|
. "\n"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# RPerl::diag( 'in Operator::NamedUnary->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $operator_name = ' . q{'} . $operator_name . q{'} . "\n" ); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
if ( not exists $NAMES->{$operator_name} ) { |
127
|
|
|
|
|
|
|
die q{ERROR ECOGEASRP19, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: unsupported or unrecognized named operator '} |
128
|
|
|
|
|
|
|
. $operator_name |
129
|
|
|
|
|
|
|
. q{' found where } |
130
|
|
|
|
|
|
|
. ( join ', ', ( sort keys %{$NAMES} ) ) |
131
|
|
|
|
|
|
|
. ' expected, dying' . "\n"; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
my string $operator_class = $NAMES->{$operator_name}; |
134
|
|
|
|
|
|
|
my object $operator_object = $operator_class->new(); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$cpp_source_subgroup = $operator_object->ast_to_cpp__generate__CPPOPS_CPPTYPES( $self, $modes ); |
137
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup ); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return $cpp_source_group; |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; # end of class |