line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::CompileUnit::Constant; |
3
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
105
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
84
|
|
5
|
4
|
|
|
4
|
|
20
|
use RPerl::AfterSubclass; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
529
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.002_000; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
4
|
|
|
4
|
|
27
|
use parent qw(RPerl::CompileUnit); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
30
|
|
10
|
4
|
|
|
4
|
|
242
|
use RPerl::CompileUnit; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
2333
|
|
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
|
|
|
|
|
|
|
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 CompileUnit::Constant->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my string $use_constant = $self->{children}->[0]; |
28
|
|
|
|
|
|
|
my string $name = $self->{children}->[1]; |
29
|
|
|
|
|
|
|
my string $fat_arrow = $self->{children}->[2]; |
30
|
|
|
|
|
|
|
my object $type_inner_constant = $self->{children}->[3]; |
31
|
|
|
|
|
|
|
my string $type_inner_constant_my = $type_inner_constant->{children}->[0]; |
32
|
|
|
|
|
|
|
my string $type_inner_constant_type |
33
|
|
|
|
|
|
|
= $type_inner_constant->{children}->[1]->{children}->[0]; |
34
|
|
|
|
|
|
|
my string $type_inner_constant_TYPED = $type_inner_constant->{children}->[2]; |
35
|
|
|
|
|
|
|
my string $type_inner_constant_name = $type_inner_constant->{children}->[3]; |
36
|
|
|
|
|
|
|
my string $type_inner_constant_equal = $type_inner_constant->{children}->[4]; |
37
|
|
|
|
|
|
|
my object $subexpression = $self->{children}->[4]; |
38
|
|
|
|
|
|
|
my string $semicolon = $self->{children}->[5]; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# CREATE SYMBOL TABLE ENTRY |
41
|
|
|
|
|
|
|
if ( exists $modes->{_symbol_table}->{ $modes->{_symbol_table}->{_namespace} }->{_global}->{$name} ) { |
42
|
|
|
|
|
|
|
die 'ERROR ECOGEASRP12, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: variable ' |
43
|
|
|
|
|
|
|
. $name |
44
|
|
|
|
|
|
|
. ' already declared in this scope, namespace ' |
45
|
|
|
|
|
|
|
. q{'} . $modes->{_symbol_table}->{_namespace} . q{'} |
46
|
|
|
|
|
|
|
. ', subroutine/method ' |
47
|
|
|
|
|
|
|
. q{'} . $modes->{_symbol_table}->{_subroutine} . q{()'} |
48
|
|
|
|
|
|
|
. ', dying' . "\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
$modes->{_symbol_table}->{ $modes->{_symbol_table}->{_namespace} }->{_global}->{$name} |
51
|
|
|
|
|
|
|
= { isa => 'RPerl::CompileUnit::Constant', type => $type_inner_constant_type }; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$rperl_source_group->{PMC} |
54
|
|
|
|
|
|
|
.= $use_constant . q{ } |
55
|
|
|
|
|
|
|
. $name . q{ } |
56
|
|
|
|
|
|
|
. $fat_arrow . q{ } |
57
|
|
|
|
|
|
|
. $type_inner_constant_my . q{ } |
58
|
|
|
|
|
|
|
. $type_inner_constant_type . q{ } |
59
|
|
|
|
|
|
|
. $type_inner_constant_TYPED |
60
|
|
|
|
|
|
|
. $type_inner_constant_name . q{ } |
61
|
|
|
|
|
|
|
. $type_inner_constant_equal . q{ }; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my string_hashref $rperl_source_subgroup = $subexpression->ast_to_rperl__generate($modes); |
64
|
|
|
|
|
|
|
RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$rperl_source_group->{PMC} .= $semicolon . "\n"; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $rperl_source_group; |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub { |
72
|
|
|
|
|
|
|
( my object $self, my string_hashref $modes) = @_; |
73
|
|
|
|
|
|
|
my string_hashref $cpp_source_group = { H => q{// <<< RP::CU::Co __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" }; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#... |
76
|
|
|
|
|
|
|
return $cpp_source_group; |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub { |
80
|
|
|
|
|
|
|
( my object $self, my string $package_name_underscores, my string_hashref $modes ) = @_; |
81
|
|
|
|
|
|
|
my string_hashref $cpp_source_group = { H => q{} }; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#RPerl::diag( 'in CompileUnit::Constant->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my string $name = $self->{children}->[1]; |
86
|
|
|
|
|
|
|
my string $type_inner_constant_type = $self->{children}->[3]->{children}->[1]->{children}->[0]; |
87
|
|
|
|
|
|
|
my object $subexpression = $self->{children}->[4]; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# CREATE SYMBOL TABLE ENTRY |
90
|
|
|
|
|
|
|
if ( exists $modes->{_symbol_table}->{ $modes->{_symbol_table}->{_namespace} }->{_global}->{$name} ) { |
91
|
|
|
|
|
|
|
die 'ERROR ECOGEASCP12, CODE GENERATOR, ABSTRACT SYNTAX TO C++: variable ' |
92
|
|
|
|
|
|
|
. $name |
93
|
|
|
|
|
|
|
. ' already declared in this scope, namespace ' |
94
|
|
|
|
|
|
|
. q{'} . $modes->{_symbol_table}->{_namespace} . q{'} |
95
|
|
|
|
|
|
|
. ', subroutine/method ' |
96
|
|
|
|
|
|
|
. q{'} . $modes->{_symbol_table}->{_subroutine} . q{()'} |
97
|
|
|
|
|
|
|
. ', dying' . "\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
$modes->{_symbol_table}->{ $modes->{_symbol_table}->{_namespace} }->{_global}->{$name} |
100
|
|
|
|
|
|
|
= { isa => 'RPerl::CompileUnit::Constant', type => $type_inner_constant_type }; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$cpp_source_group->{H} .= 'const ' . $type_inner_constant_type . q{ } . $package_name_underscores . '__' . $name . ' = '; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# RPerl::diag( 'in CompileUnit::Constant->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $subexpression = ' . "\n" . RPerl::Parser::rperl_ast__dump($subexpression) . "\n" ); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my string_hashref $cpp_source_subgroup = $subexpression->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes); |
107
|
|
|
|
|
|
|
$cpp_source_group->{H} .= $cpp_source_subgroup->{CPP}; |
108
|
|
|
|
|
|
|
$cpp_source_group->{H} .= ';' . "\n"; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# create shim |
111
|
|
|
|
|
|
|
if ( ( not exists $cpp_source_group->{_H_constants_shims} ) or ( not defined $cpp_source_group->{_H_constants_shims} ) ) { |
112
|
|
|
|
|
|
|
$cpp_source_group->{_H_constants_shims} = {}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif (( not exists $cpp_source_group->{_H_constants_shims}->{$package_name_underscores} ) |
115
|
|
|
|
|
|
|
or ( not defined $cpp_source_group->{_H_constants_shims}->{$package_name_underscores} ) ) |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
$cpp_source_group->{_H_constants_shims}->{$package_name_underscores} = q{}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
$cpp_source_group->{_H_constants_shims}->{$package_name_underscores} .= |
120
|
|
|
|
|
|
|
'const ' . $type_inner_constant_type . q{ } . $name . '() { return ' . $package_name_underscores . '__' . $name . '; }' . "\n"; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# RPerl::diag( 'in CompileUnit::Constant->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $cpp_source_group->{_H_constants_shims}->{$package_name_underscores} = ' . "\n" . $cpp_source_group->{_H_constants_shims}->{$package_name_underscores} . "\n" ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return $cpp_source_group; |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; # end of class |