File Coverage

blib/lib/RPerl/DataStructure/Hash/Entry.pm
Criterion Covered Total %
statement 72 92 78.2
branch 16 30 53.3
condition 9 12 75.0
subroutine 7 8 87.5
pod n/a
total 104 142 73.2


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::DataStructure::Hash::Entry;
3 3     3   19 use strict;
  3         11  
  3         75  
4 3     3   13 use warnings;
  3         6  
  3         60  
5 3     3   13 use RPerl::AfterSubclass;
  3         5  
  3         380  
6             our $VERSION = 0.002_600;
7              
8             # [[[ OO INHERITANCE ]]]
9 3     3   19 use parent qw(RPerl::GrammarRule);
  3         7  
  3         13  
10 3     3   167 use RPerl::GrammarRule;
  3         6  
  3         2932  
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             # [[[ SUBROUTINES & OO METHODS ]]]
20              
21             sub ast_to_rperl__generate {
22 579     579   947 { my string_hashref::method $RETURN_TYPE };
  579         874  
23 579         1172 ( my object $self, my string_hashref $modes) = @ARG;
24 579         1480 my string_hashref $rperl_source_group = { PMC => q{} };
25 579         983 my string_hashref $rperl_source_subgroup;
26              
27             # RPerl::diag( 'in Hash::Entry->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
28              
29 579         1041 my string $self_class = ref $self;
30 579 50       1558 if ( $self_class eq 'HashEntry_218' ) { # HashEntry -> VarOrLitOrOpStrOrWord OP20_HASH_FATARROW OPTIONAL-48 SubExpression
    0          
31 579         1548 my string $key = $self->{children}->[0];
32 579         1049 my string $key_class = ref $key;
33 579         1153 my string $fat_arrow = $self->{children}->[1];
34 579         1049 my object $type_inner_optional = $self->{children}->[2];
35 579         971 my string $key_name = undef;
36              
37 579 100 100     2905 if ( ( $key_class eq 'VarOrLitOrOpStrOrWord_243' )
    50          
38             or ( $key_class eq 'VarOrLitOrOpStrOrWord_244' ) )
39             { # Variable or Literal
40 35         621 $rperl_source_subgroup = $key->ast_to_rperl__generate($modes);
41 35         696 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
42             }
43             elsif ( $key_class eq 'VarOrLitOrOpStrOrWord_245' ) { # OpStringOrWord
44 544         1944 $key_name = $key->{children}->[0]->{children}->[0];
45 544         2736 $key_name =~ s/^(\w+)\s*$/$1/gxms; # strip trailing whitespace, caused by grammar matching operator names with trailing spaces
46 544 50       1785 if ($key_name !~ /^[a-z]/) {
47 0         0 die 'ERROR ECOGEASRP23, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: invalid hash key ' . q{'}
48             . $key_name . q{'}
49             . ' does not start with a lowercase letter a-z, dying' . "\n";
50             }
51 544         1305 $rperl_source_group->{PMC} .= $key_name . q{ };
52             }
53             else {
54 0         0 die RPerl::Parser::rperl_rule__replace( q{ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '}
55             . ($key_class)
56             . q{' found where VarOrLitOrOpStrOrWord_243, VarOrLitOrOpStrOrWord_244, or VarOrLitOrOpStrOrWord_245 expected, dying} )
57             . "\n";
58             }
59              
60 579 100 100     2056 if ( ( exists $type_inner_optional->{children}->[0] ) and ( defined $key_name ) ) {
61 27         99 my string $type_inner_name = $type_inner_optional->{children}->[0]->{children}->[3]->{children}->[0];
62 27         115 $type_inner_name =~ s/^(\w+)\s*$/$1/gxms; # strip trailing whitespace, caused by grammar matching operator names with trailing spaces
63 27 50       468 if ( $type_inner_name !~ /$key_name$/xms ) {
64 0         0 die 'ERROR ECOGEASRP22, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: redundant name mismatch, inner type name ' . q{'}
65             . $type_inner_name . q{'}
66             . ' does not end with OO properties or hash key ' . q{'}
67             . $key_name . q{'}
68             . ', dying' . "\n";
69             }
70             }
71              
72 579         1256 $rperl_source_group->{PMC} .= $fat_arrow . q{ };
73              
74 579 100       1291 if ( exists $type_inner_optional->{children}->[0] ) {
75 29         662 $rperl_source_subgroup = $type_inner_optional->{children}->[0]->ast_to_rperl__generate($modes);
76 29         547 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
77             }
78              
79 579         1154 my object $subexpression = $self->{children}->[3];
80              
81 579         12261 $rperl_source_subgroup = $subexpression->ast_to_rperl__generate($modes);
82 579         11941 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
83             }
84             elsif ( $self_class eq 'HashEntry_220' ) { # HashEntry -> ENV
85 0         0 my string $env = $self->{children}->[0];
86 0         0 $rperl_source_group->{PMC} .= $env . "\n";
87             }
88             else {
89 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
90             . $self_class
91             . ' found where HashEntry_218 or HashEntry_220 expected, dying' )
92             . "\n";
93             }
94 579         3210 return $rperl_source_group;
95             }
96              
97             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
98 0     0   0 { my string_hashref::method $RETURN_TYPE };
  0         0  
99 0         0 ( my object $self, my string_hashref $modes) = @ARG;
100 0         0 my string_hashref $cpp_source_group = { CPP => q{// <<< RP::DS::H::E __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
101              
102             #...
103 0         0 return $cpp_source_group;
104             }
105              
106             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
107 20     20   36 { my string_hashref::method $RETURN_TYPE };
  20         29  
108 20         37 ( my object $self, my string_hashref $modes) = @ARG;
109 20         51 my string_hashref $cpp_source_group = { CPP => q{} };
110 20         31 my string_hashref $cpp_source_subgroup;
111              
112             # RPerl::diag( 'in Hash::Entry->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
113              
114 20         33 my string $self_class = ref $self;
115 20 50       47 if ( $self_class eq 'HashEntry_218' ) { # HashEntry -> VarOrLitOrOpStrOrWord OP20_HASH_FATARROW OPTIONAL-48 SubExpression
    0          
116              
117 20         65 my string $key = $self->{children}->[0];
118 20         39 my string $key_class = ref $key;
119 20         33 my object $type_inner_optional = $self->{children}->[2];
120 20         34 my string $key_name = undef;
121              
122 20         36 $cpp_source_group->{CPP} .= '{';
123              
124 20 100 66     108 if ( ( $key_class eq 'VarOrLitOrOpStrOrWord_243' )
    50          
125             or ( $key_class eq 'VarOrLitOrOpStrOrWord_244' ) )
126             { # Variable or Literal
127 10         188 $cpp_source_subgroup = $key->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
128 10         189 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
129             }
130             elsif ( $key_class eq 'VarOrLitOrOpStrOrWord_245' ) { # OpStringOrWord
131 10         44 $key_name = $key->{children}->[0]->{children}->[0];
132 10         49 $key_name =~ s/^(\w+)\s*$/$1/gxms; # strip trailing whitespace, caused by grammar matching operator names with trailing spaces
133 10 50       36 if ($key_name !~ /^[a-z]/) {
134 0         0 die 'ERROR ECOGEASCP23, CODE GENERATOR, ABSTRACT SYNTAX TO C++: invalid hash key ' . q{'}
135             . $key_name . q{'}
136             . ' does not start with a lowercase letter a-z, dying' . "\n";
137             }
138 10         26 $cpp_source_group->{CPP} .= q{"} . $key_name . q{" };
139             }
140             else {
141 0         0 die RPerl::Parser::rperl_rule__replace( q{ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '}
142             . ($key_class)
143             . q{' found where VarOrLitOrOpStrOrWord_243, VarOrLitOrOpStrOrWord_244, or VarOrLitOrOpStrOrWord_245 expected, dying} )
144             . "\n";
145             }
146              
147 20 50 33     77 if ( ( exists $type_inner_optional->{children}->[0] ) and ( defined $key_name ) ) {
148 0         0 my string $type_inner_name = $type_inner_optional->{children}->[0]->{children}->[3]->{children}->[0];
149 0         0 $type_inner_name =~ s/^(\w+)\s*$/$1/gxms; # strip trailing whitespace, caused by grammar matching operator names with trailing spaces
150 0 0       0 if ( $type_inner_name !~ /$key_name$/xms ) {
151 0         0 die 'ERROR ECOGEASCP22, CODE GENERATOR, ABSTRACT SYNTAX TO C++: redundant name mismatch, inner type name ' . q{'}
152             . $type_inner_name . q{'}
153             . ' does not end with OO properties or hash key ' . q{'}
154             . $key_name . q{'}
155             . ', dying' . "\n";
156             }
157             }
158              
159 20         34 $cpp_source_group->{CPP} .= q{, };
160              
161 20         40 my object $subexpression = $self->{children}->[3];
162              
163 20         393 $cpp_source_subgroup = $subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
164 20         437 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
165              
166 20         41 $cpp_source_group->{CPP} .= '}';
167             }
168             elsif ( $self_class eq 'HashEntry_220' ) { # HashEntry -> ENV
169 0         0 my string $env = $self->{children}->[0];
170 0         0 $cpp_source_group->{CPP} .= q{// <<< RP::DS::H::E __DUMMY_SOURCE_CODE CPPOPS_CPPTYPES >>>} . "\n";
171             }
172             else {
173 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
174             . $self_class
175             . ' found where HashEntry_218 or HashEntry_220 expected, dying' )
176             . "\n";
177             }
178 20         116 return $cpp_source_group;
179             }
180              
181             1; # end of class