line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::Operation::Statement::Conditional; |
3
|
5
|
|
|
5
|
|
31
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
128
|
|
4
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
113
|
|
5
|
5
|
|
|
5
|
|
28
|
use RPerl::AfterSubclass; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
612
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.002_100; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
5
|
|
|
5
|
|
34
|
use parent qw(RPerl::Operation::Statement); |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
12
|
|
|
|
|
|
|
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator |
13
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
16
|
|
|
|
|
|
|
our hashref $properties = {}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our string_hashref::method $ast_to_rperl__generate = sub { |
21
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
22
|
|
|
|
|
|
|
my string_hashref $rperl_source_group = { PMC => q{} }; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my string $self_class = ref $self; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# unwrap Conditional_163 from Statement_152 |
29
|
|
|
|
|
|
|
if ( $self_class eq 'Statement_152' ) { # Statement -> Conditional |
30
|
|
|
|
|
|
|
$self = $self->{children}->[0]; |
31
|
|
|
|
|
|
|
$self_class = ref $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Conditional -> 'if' LPAREN SubExpression ')' CodeBlock STAR-38 OPTIONAL-40 |
37
|
|
|
|
|
|
|
if ( $self_class eq 'Conditional_163' ) { |
38
|
|
|
|
|
|
|
my string $if = $self->{children}->[0]; |
39
|
|
|
|
|
|
|
my string $left_paren = $self->{children}->[1]; |
40
|
|
|
|
|
|
|
my object $subexpression = $self->{children}->[2]; |
41
|
|
|
|
|
|
|
my string $right_paren = $self->{children}->[3]; |
42
|
|
|
|
|
|
|
my object $codeblock = $self->{children}->[4]; |
43
|
|
|
|
|
|
|
my object $elsif_star = $self->{children}->[5]; |
44
|
|
|
|
|
|
|
my object $else_optional = $self->{children}->[6]; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $if = ' . $if . "\n" ); |
47
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $left_paren = ' . $left_paren . "\n" ); |
48
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $subexpression ) = ' . ( ref $subexpression ) . "\n" ); |
49
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $right_paren = ' . $right_paren . "\n" ); |
50
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $codeblock ) = ' . ( ref $codeblock ) . "\n" ); |
51
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $elsif_star ) = ' . ( ref $elsif_star ) . "\n" ); |
52
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif_star = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_star) . "\n" ); |
53
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have ( ref $else_optional ) = ' . ( ref $else_optional ) . "\n" ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$rperl_source_group->{PMC} .= $if . q{ } . $left_paren . q{ }; |
56
|
|
|
|
|
|
|
my object $rperl_source_subgroup |
57
|
|
|
|
|
|
|
= $subexpression->ast_to_rperl__generate($modes); |
58
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, |
59
|
|
|
|
|
|
|
$rperl_source_subgroup ); |
60
|
|
|
|
|
|
|
$rperl_source_group->{PMC} .= q{ } . $right_paren . q{ }; |
61
|
|
|
|
|
|
|
$rperl_source_subgroup = $codeblock->ast_to_rperl__generate($modes); |
62
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, |
63
|
|
|
|
|
|
|
$rperl_source_subgroup ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# ('elsif' LPAREN SubExpression ')' CodeBlock)* |
66
|
|
|
|
|
|
|
# NEED FIX: destructive to AST!!! |
67
|
|
|
|
|
|
|
while ( exists $elsif_star->{children}->[0] ) { |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# DEV NOTE: 'elsif' and ')' are automatically dropped by EYAPP, presumably because they are hard-coded strings inside EYAPP parenthesis, possibly EYAPP bug? |
70
|
|
|
|
|
|
|
# my object $elsif = shift @{ $elsif_star->{children} }; |
71
|
|
|
|
|
|
|
my string $elsif = 'elsif'; |
72
|
|
|
|
|
|
|
my string $elsif_left_paren = shift @{ $elsif_star->{children} }; |
73
|
|
|
|
|
|
|
my object $elsif_subexpression |
74
|
|
|
|
|
|
|
= shift @{ $elsif_star->{children} }; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# my object $elsif_right_paren = shift @{ $elsif_star->{children} }; |
77
|
|
|
|
|
|
|
my string $elsif_right_paren = ')'; |
78
|
|
|
|
|
|
|
my object $elsif_codeblock = shift @{ $elsif_star->{children} }; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif) . "\n" ); |
81
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_rperl__generate(), have $elsif_left_paren = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_left_paren) . "\n" ); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$rperl_source_group->{PMC} |
84
|
|
|
|
|
|
|
.= $elsif . q{ } . $elsif_left_paren->{attr} . q{ }; |
85
|
|
|
|
|
|
|
$rperl_source_subgroup |
86
|
|
|
|
|
|
|
= $elsif_subexpression->ast_to_rperl__generate($modes); |
87
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, |
88
|
|
|
|
|
|
|
$rperl_source_subgroup ); |
89
|
|
|
|
|
|
|
$rperl_source_group->{PMC} .= q{ } . $elsif_right_paren . q{ }; |
90
|
|
|
|
|
|
|
$rperl_source_subgroup |
91
|
|
|
|
|
|
|
= $elsif_codeblock->ast_to_rperl__generate($modes); |
92
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, |
93
|
|
|
|
|
|
|
$rperl_source_subgroup ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# ('else' CodeBlock)? |
97
|
|
|
|
|
|
|
if ( exists $else_optional->{children}->[0] ) { |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# my string $else = $else_optional->{children}->[0]; |
100
|
|
|
|
|
|
|
my string $else = 'else'; |
101
|
|
|
|
|
|
|
my object $else_codeblock = $else_optional->{children}->[0]; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$rperl_source_group->{PMC} .= $else . q{ }; |
104
|
|
|
|
|
|
|
$rperl_source_subgroup |
105
|
|
|
|
|
|
|
= $else_codeblock->ast_to_rperl__generate($modes); |
106
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, |
107
|
|
|
|
|
|
|
$rperl_source_subgroup ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
|
|
|
|
|
|
die RPerl::Parser::rperl_rule__replace( |
112
|
|
|
|
|
|
|
'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule ' |
113
|
|
|
|
|
|
|
. $self_class |
114
|
|
|
|
|
|
|
. ' found where Conditional_163 expected, dying' ) |
115
|
|
|
|
|
|
|
. "\n"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
return $rperl_source_group; |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub { |
121
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
122
|
|
|
|
|
|
|
my string_hashref $cpp_source_group |
123
|
|
|
|
|
|
|
= { |
124
|
|
|
|
|
|
|
CPP => q{// <<< RP::O::S::C __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} |
125
|
|
|
|
|
|
|
. "\n" |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#... |
129
|
|
|
|
|
|
|
return $cpp_source_group; |
130
|
|
|
|
|
|
|
}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub { |
133
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
134
|
|
|
|
|
|
|
my string_hashref $cpp_source_group = { CPP => q{} }; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my string $self_class = ref $self; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# unwrap Conditional_163 from Statement_152 |
141
|
|
|
|
|
|
|
if ( $self_class eq 'Statement_152' ) { # Statement -> Conditional |
142
|
|
|
|
|
|
|
$self = $self->{children}->[0]; |
143
|
|
|
|
|
|
|
$self_class = ref $self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have possibly-unwrapped $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Conditional -> 'if' LPAREN SubExpression ')' CodeBlock STAR-38 OPTIONAL-40 |
149
|
|
|
|
|
|
|
if ( $self_class eq 'Conditional_163' ) { |
150
|
|
|
|
|
|
|
my string $if = $self->{children}->[0]; |
151
|
|
|
|
|
|
|
my string $left_paren = $self->{children}->[1]; |
152
|
|
|
|
|
|
|
my object $subexpression = $self->{children}->[2]; |
153
|
|
|
|
|
|
|
my string $right_paren = $self->{children}->[3]; |
154
|
|
|
|
|
|
|
my object $codeblock = $self->{children}->[4]; |
155
|
|
|
|
|
|
|
my object $elsif_star = $self->{children}->[5]; |
156
|
|
|
|
|
|
|
my object $else_optional = $self->{children}->[6]; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $if = ' . $if . "\n" ); |
159
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $left_paren = ' . $left_paren . "\n" ); |
160
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $subexpression ) = ' . ( ref $subexpression ) . "\n" ); |
161
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $right_paren = ' . $right_paren . "\n" ); |
162
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $codeblock ) = ' . ( ref $codeblock ) . "\n" ); |
163
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $elsif_star ) = ' . ( ref $elsif_star ) . "\n" ); |
164
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif_star = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_star) . "\n" ); |
165
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have ( ref $else_optional ) = ' . ( ref $else_optional ) . "\n" ); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$cpp_source_group->{CPP} .= $if . q{ } . $left_paren . q{ }; |
168
|
|
|
|
|
|
|
my object $cpp_source_subgroup |
169
|
|
|
|
|
|
|
= $subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes); |
170
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, |
171
|
|
|
|
|
|
|
$cpp_source_subgroup ); |
172
|
|
|
|
|
|
|
$cpp_source_group->{CPP} .= q{ } . $right_paren . q{ }; |
173
|
|
|
|
|
|
|
$cpp_source_subgroup = $codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label |
174
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, |
175
|
|
|
|
|
|
|
$cpp_source_subgroup ); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# ('elsif' LPAREN SubExpression ')' CodeBlock)* |
178
|
|
|
|
|
|
|
# NEED FIX: destructive to AST!!! |
179
|
|
|
|
|
|
|
while ( exists $elsif_star->{children}->[0] ) { |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# DEV NOTE: 'elsif' and ')' are automatically dropped by EYAPP, presumably because they are hard-coded strings inside EYAPP parenthesis, possibly EYAPP bug? |
182
|
|
|
|
|
|
|
# my object $elsif = shift @{ $elsif_star->{children} }; |
183
|
|
|
|
|
|
|
my string $elsif = 'else if'; |
184
|
|
|
|
|
|
|
my string $elsif_left_paren = shift @{ $elsif_star->{children} }; |
185
|
|
|
|
|
|
|
my object $elsif_subexpression |
186
|
|
|
|
|
|
|
= shift @{ $elsif_star->{children} }; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# my object $elsif_right_paren = shift @{ $elsif_star->{children} }; |
189
|
|
|
|
|
|
|
my string $elsif_right_paren = ')'; |
190
|
|
|
|
|
|
|
my object $elsif_codeblock = shift @{ $elsif_star->{children} }; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif) . "\n" ); |
193
|
|
|
|
|
|
|
# RPerl::diag( 'in Conditional->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $elsif_left_paren = ' . "\n" . RPerl::Parser::rperl_ast__dump($elsif_left_paren) . "\n" ); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$cpp_source_group->{CPP} |
196
|
|
|
|
|
|
|
.= $elsif . q{ } . $elsif_left_paren->{attr} . q{ }; |
197
|
|
|
|
|
|
|
$cpp_source_subgroup |
198
|
|
|
|
|
|
|
= $elsif_subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes); |
199
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, |
200
|
|
|
|
|
|
|
$cpp_source_subgroup ); |
201
|
|
|
|
|
|
|
$cpp_source_group->{CPP} .= q{ } . $elsif_right_paren . q{ }; |
202
|
|
|
|
|
|
|
$cpp_source_subgroup |
203
|
|
|
|
|
|
|
= $elsif_codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label |
204
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, |
205
|
|
|
|
|
|
|
$cpp_source_subgroup ); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# ('else' CodeBlock)? |
209
|
|
|
|
|
|
|
if ( exists $else_optional->{children}->[0] ) { |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# my string $else = $else_optional->{children}->[0]; |
212
|
|
|
|
|
|
|
my string $else = 'else'; |
213
|
|
|
|
|
|
|
my object $else_codeblock = $else_optional->{children}->[0]; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
$cpp_source_group->{CPP} .= $else . q{ }; |
216
|
|
|
|
|
|
|
$cpp_source_subgroup |
217
|
|
|
|
|
|
|
= $else_codeblock->ast_to_cpp__generate__CPPOPS_CPPTYPES(undef, $modes); # undef $loop_label |
218
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $cpp_source_group, |
219
|
|
|
|
|
|
|
$cpp_source_subgroup ); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
else { |
223
|
|
|
|
|
|
|
die RPerl::Parser::rperl_rule__replace( |
224
|
|
|
|
|
|
|
'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' |
225
|
|
|
|
|
|
|
. $self_class |
226
|
|
|
|
|
|
|
. ' found where Conditional_163 expected, dying' ) |
227
|
|
|
|
|
|
|
. "\n"; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
return $cpp_source_group; |
230
|
|
|
|
|
|
|
}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
1; # end of class |