File Coverage

blib/lib/RPerl/CompileUnit/Module.pm
Criterion Covered Total %
statement 71 87 81.6
branch 13 22 59.0
condition 6 12 50.0
subroutine 8 9 88.8
pod n/a
total 98 130 75.3


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::CompileUnit::Module;
3 3     3   21 use strict;
  3         7  
  3         91  
4 3     3   18 use warnings;
  3         7  
  3         81  
5 3     3   18 use RPerl::AfterSubclass;
  3         8  
  3         404  
6             our $VERSION = 0.003_000;
7              
8             # [[[ OO INHERITANCE ]]]
9             # <<< CHANGE_ME: leave as base class for no inheritance, or replace with real parent package name >>>
10 3     3   18 use parent qw(RPerl::CompileUnit);
  3         6  
  3         14  
11 3     3   154 use RPerl::CompileUnit;
  3         5  
  3         223  
12              
13             # [[[ CRITICS ]]]
14             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
15             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
16              
17             # [[[ INCLUDES ]]]
18             #use RPerl::Parser;
19             #eval 'require RPerl::Parser;';
20             eval {require RPerl::Parser;};
21             if ($EVAL_ERROR and ($EVAL_ERROR =~ /attempt to reload/i)){
22             delete $INC{'RPerl::Parser'};
23             require RPerl::Parser;
24             }
25             elsif ($EVAL_ERROR ne q{}) { die $EVAL_ERROR; }
26              
27 3     3   1025 use RPerl::Generator;
  3         10  
  3         2019  
28              
29             # [[[ OO PROPERTIES ]]]
30             our hashref $properties = {};
31              
32             # [[[ SUBROUTINES & OO METHODS ]]]
33              
34             sub ast_to_rperl__generate {
35 205     205   846 { my string_hashref::method $RETURN_TYPE };
  205         824  
36 205         1086 ( my object $self, my string_hashref $modes) = @ARG;
37 205         702 my string_hashref $rperl_source_group = {};
38              
39             # RPerl::diag('in Module->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n");
40             # RPerl::diag('in Module->ast_to_rperl__generate(), received $modes = ' . "\n" . Dumper($modes) . "\n");
41              
42 205         1133 my object_arrayref $modules_and_headers = $self->{children}->[0]->{children};
43 205         745 my string_hashref $rperl_source_subgroup;
44             my string $package_name_underscores; # get from Header to Class or Package
45 205         840 my boolean $header_started = 0;
46 205         697 my boolean $current_package_count = 0;
47              
48             # disable unused symbol table testing
49             # RPerl::diag('in Module->ast_to_rperl__generate(), have %RPerl::Generator:: symbol table = ' . "\n" . Dumper(\%RPerl::Generator::) . "\n");
50             # RPerl::diag('in Module->ast_to_rperl__generate(), have %RPerl::CompileUnit::Module::Header:: symbol table dumped = ' . "\n" . Dumper(\%RPerl::CompileUnit::Module::Header::) . "\n");
51             # RPerl::diag('in Module->ast_to_rperl__generate(), have %ModuleHeader_23:: symbol table dumped = ' . "\n" . Dumper(\%ModuleHeader_23::) . "\n");
52             # my $class = 'RPerl::CompileUnit::Module::Header';
53             # RPerl::diag('in Module->ast_to_rperl__generate(), have symtab entries for ' . $class . "\n" . RPerl::analyze_class_symtab_entries($class) . "\n\n");
54             # $class = 'ModuleHeader_23';
55             # RPerl::diag('in Module->ast_to_rperl__generate(), have symtab entries for ' . $class . "\n" . RPerl::analyze_class_symtab_entries($class) . "\n\n");
56              
57 205         562 foreach my object $header_or_module (@{$modules_and_headers}) {
  205         953  
58             # RPerl::diag('in Module->ast_to_rperl__generate(), have $header_or_module = ' . "\n" . RPerl::Parser::rperl_ast__dump($header_or_module) . "\n\n");
59 418 100 66     3165 if ((ref $header_or_module) eq 'ModuleHeader_23') {
    50          
60 209 50       1141 if ($header_started) {
61 0         0 die 'ERROR ECOGEASRP34, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: ModuleHeader found without first finding Module for previous ModuleHeader, dying' . "\n";
62             }
63             else {
64             # if ($current_package_count >= 1) { $rperl_source_group->{PMC} .= "\n\n"; } # DEV NOTE: extra spaces removed by perltidy???
65 209 50 66     1949 if (($current_package_count == 1) and ( $modes->{label} eq 'ON' )) {
66 0         0 $rperl_source_group->{PMC} .= '# [[[ ADDITIONAL CLASSES ]]]' . "\n\n";
67             }
68 209         650 $header_started = 1;
69 209         6003 $rperl_source_subgroup = $header_or_module->ast_to_rperl__generate($modes);
70 209         898 $package_name_underscores = $rperl_source_subgroup->{_package_name_underscores};
71 209         5649 RPerl::Generator::source_group_append($rperl_source_group, $rperl_source_subgroup);
72             }
73             }
74             elsif (((ref $header_or_module) eq 'Module_24') or ((ref $header_or_module) eq 'Module_25')) {
75 209 50       942 if ($header_started) {
76 209         6376 $rperl_source_subgroup = $header_or_module->ast_to_rperl__generate($package_name_underscores, $modes);
77 189         4103 RPerl::Generator::source_group_append($rperl_source_group, $rperl_source_subgroup);
78 189         458 $header_started = 0;
79 189         742 $current_package_count++;
80             }
81             else {
82 0         0 die 'ERROR ECOGEASRP35, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Module found without first finding ModuleHeader, dying' . "\n";
83             }
84             }
85             else {
86 0         0 die RPerl::Parser::rperl_rule__replace(
87             'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
88             . ( ref $header_or_module )
89             . ' found where ModuleHeader_23, Module_24, or Module_25 expected, dying' )
90             . "\n";
91             }
92             }
93 185         1808 return $rperl_source_group;
94             }
95              
96             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
97 0     0   0 { my string_hashref::method $RETURN_TYPE };
  0         0  
98 0         0 ( my object $self, my string_hashref $modes ) = @ARG;
99 0         0 my string_hashref $cpp_source_group = {
100             CPP =>
101             q{// <<< RP::CU::M __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>}
102             . "\n",
103             H =>
104             q{// <<< RP::CU::M __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>}
105             . "\n",
106             PMC =>
107             q{# <<< RP::CU::M __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>}
108             . "\n"
109             };
110              
111             #...
112 0         0 return $cpp_source_group;
113             }
114              
115             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
116 23     23   53 { my string_hashref::method $RETURN_TYPE };
  23         70  
117 23         78 ( my object $self, my string_hashref $modes ) = @ARG;
118 23         173 my string_hashref $cpp_source_group = { CPP => q{}, H => q{} };
119              
120             # RPerl::diag('in Module->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n");
121             # RPerl::diag('in Module->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $modes = ' . "\n" . Dumper($modes) . "\n");
122              
123 23         102 my object_arrayref $modules_and_headers = $self->{children}->[0]->{children};
124 23         88 my string_hashref $cpp_source_subgroup;
125             my string_hashref $cpp_source_subgroup_saved;
126 23         0 my string $package_name_underscores; # get from Header to Class or Package
127 23         45 my boolean $header_started = 0;
128 23         51 my boolean $current_package_count = 0;
129            
130 23         46 foreach my object $header_or_module (@{$modules_and_headers}) {
  23         93  
131             # RPerl::diag('in Module->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $header_or_module = ' . "\n" . RPerl::Parser::rperl_ast__dump($header_or_module) . "\n\n");
132             # C++ Module::Header wraps around Module, must call both *generate_begin*() and *generate_end*()
133 46 100 33     304 if ((ref $header_or_module) eq 'ModuleHeader_23') {
    50          
134 23 50       80 if ($header_started) {
135 0         0 die 'ERROR ECOGEASCP34, CODE GENERATOR, ABSTRACT SYNTAX TO C++, CPPOPS_CPPTYPES: ModuleHeader found without first finding Module for previous ModuleHeader, dying' . "\n";
136             }
137             else {
138 23 50       104 if ($current_package_count >= 1) {
139 0         0 $cpp_source_group->{CPP} .= "\n\n";
140 0         0 $cpp_source_group->{H} .= "\n\n";
141             }
142 23 50 33     118 if (($current_package_count == 1) and ( $modes->{label} eq 'ON' )) {
143 0         0 $cpp_source_group->{CPP} .= '// [[[ ADDITIONAL CLASSES ]]]' . "\n\n";
144 0         0 $cpp_source_group->{H} .= '// [[[ ADDITIONAL CLASSES ]]]' . "\n\n";
145             }
146 23         64 $header_started = 1;
147 23         671 $cpp_source_subgroup = $header_or_module->ast_to_cpp__generate_begin__CPPOPS_CPPTYPES($modes);
148 23         82 $package_name_underscores = $cpp_source_subgroup->{_package_name_underscores};
149 23         592 RPerl::Generator::source_group_append($cpp_source_group, $cpp_source_subgroup);
150 23         601 $cpp_source_subgroup_saved = $header_or_module->ast_to_cpp__generate_end__CPPOPS_CPPTYPES($modes);
151             }
152             }
153             elsif (((ref $header_or_module) eq 'Module_24') or ((ref $header_or_module) eq 'Module_25')) {
154 23 50       89 if ($header_started) {
155             # DEV NOTE, CORRELATION #rp043: no need to include RPerl.cpp multiple times in one file, need current package count for this purpose
156 23         52 $cpp_source_subgroup = $header_or_module->ast_to_cpp__generate__CPPOPS_CPPTYPES($package_name_underscores, {%{$modes}, current_package_count => $current_package_count});
  23         1162  
157 22         741 RPerl::Generator::source_group_append($cpp_source_group, $cpp_source_subgroup);
158 22         500 RPerl::Generator::source_group_append($cpp_source_group, $cpp_source_subgroup_saved);
159 22         42 $header_started = 0;
160 22         87 $cpp_source_group->{CPP} .= "\n" . '// end of class' . "\n";
161 22         50 $cpp_source_group->{H} .= "\n" . '// end of class' . "\n";
162 22         60 $current_package_count++;
163             }
164             else {
165 0         0 die 'ERROR ECOGEASCP35, CODE GENERATOR, ABSTRACT SYNTAX TO C++, CPPOPS_CPPTYPES: Module found without first finding ModuleHeader, dying' . "\n";
166             }
167             }
168             else {
169 0         0 die RPerl::Parser::rperl_rule__replace(
170             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++, CPPOPS_CPPTYPES: Grammar rule '
171             . ( ref $header_or_module )
172             . ' found where ModuleHeader_23, Module_24, or Module_25 expected, dying' )
173             . "\n";
174             }
175             }
176 22         321 return $cpp_source_group;
177             }
178              
179             1; # end of class