File Coverage

blib/lib/RPerl/CompileUnit/Include.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::CompileUnit::Include;
3 4     4   23 use strict;
  4         9  
  4         106  
4 4     4   21 use warnings;
  4         9  
  4         88  
5 4     4   24 use RPerl::AfterSubclass;
  4         8  
  4         490  
6             our $VERSION = 0.002_300;
7              
8             # [[[ OO INHERITANCE ]]]
9 4     4   26 use parent qw(RPerl::GrammarRule);
  4         10  
  4         21  
10 4     4   219 use RPerl::GrammarRule;
  4         9  
  4         2169  
11              
12             # [[[ CRITICS ]]]
13             ## no critic qw(ProhibitUselessNoInclude 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             our string_hashref::method $ast_to_rperl__generate = sub {
22             ( my object $self, my string_hashref $modes) = @_;
23             my string_hashref $rperl_source_group = { PMC => q{} };
24              
25             # RPerl::diag( 'in Include->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
26             # RPerl::diag( 'in Include->ast_to_rperl__generate(), have ::class($self) = ' . ::class($self) . "\n" );
27             if ( ref $self eq 'Include_41' ) {
28             # Include -> USE_OR_REQUIRE WordScoped ';'
29             my string $use_or_require_keyword = $self->{children}->[0];
30             my string $module_name
31             = $self->{children}->[1]->{children}->[0];
32             my string $semicolon = $self->{children}->[2];
33             $rperl_source_group->{PMC}
34             .= $use_or_require_keyword . q{ } . $module_name . $semicolon . "\n";
35              
36             # RPerl::diag( 'in Include->ast_to_rperl__generate(), have $module_name = ' . $module_name . "\n" );
37             }
38             elsif ( ref $self eq 'Include_42' ) {
39             # Include -> USE_OR_REQUIRE WordScoped OP01_QW ';'
40             my string $use_or_require_keyword = $self->{children}->[0];
41             my string $module_name
42             = $self->{children}->[1]->{children}->[0];
43             my string $qw = $self->{children}->[2];
44             my string $semicolon = $self->{children}->[3];
45             $rperl_source_group->{PMC}
46             .= $use_or_require_keyword . q{ }
47             . $module_name . q{ }
48             . $qw
49             . $semicolon . "\n";
50             }
51             else {
52             die RPerl::Parser::rperl_rule__replace(
53             'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
54             . ( ref $self )
55             . ' found where Include_41 or Include_42 expected, dying' )
56             . "\n";
57             }
58              
59             return $rperl_source_group;
60             };
61              
62             our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub {
63             ( my object $self, my string_hashref $modes) = @_;
64             my string_hashref $cpp_source_group
65             = { CPP => q{// <<< RP::CU::I __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>}
66             . "\n" };
67              
68             #...
69             return $cpp_source_group;
70             };
71              
72             our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub {
73             ( my object $self, my string $package_name_underscores, my string_hashref $modes) = @_;
74             # RPerl::diag( 'in Include->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
75             my string_hashref $cpp_source_group = { H => q{} };
76              
77             # NEED ANSWER: no difference between wholesale includes and selective includes in C++?
78             if (( ref $self eq 'Include_41' ) or ( ref $self eq 'Include_42' )) {
79             # Include -> USE_OR_REQUIRE WordScoped ...
80             # DEV NOTE: ignore manually included RPerl* and rperl* modules, presumably they will all be automatically included
81             my string $module_name = $self->{children}->[1]->{children}->[0];
82             if ( $module_name =~ /^\w+Perl::Config$/ ) { # DEV NOTE, CORRELATION #rp027: MathPerl::Config, PhysicsPerl::Config, etc
83             # RPerl::diag('in CompileUnit::Include->ast_to_cpp__generate__CPPOPS_CPPTYPES(), skipping system config file $module_name = ' . $module_name . "\n");
84             }
85             elsif (((substr $module_name, 0, 5) ne 'RPerl') and ((substr $module_name, 0, 5) ne 'rperl')) {
86             if ((not exists $cpp_source_group->{_PMC_includes}) or (not defined $cpp_source_group->{_PMC_includes})) {
87             $cpp_source_group->{_PMC_includes} = {};
88             }
89             elsif ((not exists $cpp_source_group->{_PMC_includes}->{$package_name_underscores})
90             or (not defined $cpp_source_group->{_PMC_includes}->{$package_name_underscores})) {
91             $cpp_source_group->{_PMC_includes}->{$package_name_underscores} = q{};
92             }
93             $cpp_source_group->{_PMC_includes}->{$package_name_underscores} .= 'require ' . $module_name . ';' . "\n";
94             $module_name =~ s/::/\//gxms;
95             $cpp_source_group->{H} .= q{#include "} . $module_name . q{.cpp"} . "\n";
96             # RPerl::diag( 'in Include->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $module_name = ' . $module_name . "\n" );
97             }
98             }
99             else {
100             die RPerl::Parser::rperl_rule__replace(
101             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
102             . ( ref $self )
103             . ' found where Include_41 or Include_42 expected, dying' )
104             . "\n";
105             }
106            
107             return $cpp_source_group;
108             };
109              
110             1; # end of class