line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of App-PythonToPerl |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2023 by Auto-Parallel Technologies, Inc. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
11
|
|
|
|
|
|
|
#use RPerl; |
12
|
|
|
|
|
|
|
package Python::Component; |
13
|
2
|
|
|
2
|
|
883
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
14
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.002_000; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
18
|
2
|
|
|
2
|
|
10
|
use parent qw(Perl::Type::Class); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
19
|
2
|
|
|
2
|
|
3335
|
use Perl::Type::Class; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
22
|
|
|
|
|
|
|
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print op |
23
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
24
|
|
|
|
|
|
|
## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers) # USER DEFAULT 3: allow constants |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# [[[ INCLUDES ]]] |
27
|
2
|
|
|
2
|
|
11
|
use Perl::Types; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
622
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# DEV NOTE: not actually used in this class, but needed so python_preparsed_to_perl_source() |
30
|
|
|
|
|
|
|
# can accept the same args as all Python::Component classes |
31
|
2
|
|
|
2
|
|
943
|
use OpenAI::API; |
|
2
|
|
|
|
|
881442
|
|
|
2
|
|
|
|
|
1086
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# [[[ ADDITIONAL CLASSES ]]] |
34
|
|
|
|
|
|
|
package Python::Component::arrayref; 1; |
35
|
|
|
|
|
|
|
package Python::Component::hashref; 1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
package Python::Component; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
40
|
|
|
|
|
|
|
our hashref $properties = { |
41
|
|
|
|
|
|
|
component_type => my string $TYPED_component_type = 'Python::Component', |
42
|
|
|
|
|
|
|
python_line_number_begin => my integer $TYPED_python_line_number_begin = undef, |
43
|
|
|
|
|
|
|
python_line_number_end => my integer $TYPED_python_line_number_end = undef, |
44
|
|
|
|
|
|
|
python_source_code => my string $TYPED_python_source_code = undef, |
45
|
|
|
|
|
|
|
perl_source_code => my string $TYPED_perl_source_code = undef, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# DEV NOTE: the below subroutines are meant to be inherited by the other Python::Component child classes |
51
|
|
|
|
|
|
|
# which do not need real de-parsing or translation algorithms, such as Python::Blank and Python::Whitespace, |
52
|
|
|
|
|
|
|
# or which are already translated during the pre-parse stage, such as Python::Comment etc. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# PYCP00x |
55
|
|
|
|
|
|
|
sub python_preparsed_to_python_source { |
56
|
|
|
|
|
|
|
# return Python source code for pre-parsed Python component |
57
|
63
|
|
|
63
|
0
|
82
|
{ my string $RETURN_TYPE }; |
|
63
|
|
|
|
|
103
|
|
58
|
63
|
|
|
|
|
89
|
( my Python::Component $self ) = @ARG; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# DEV NOTE, PYCP000: $openai not used in Python-to-Python de-parse round-tripping, no need to error check |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# error or warning if no Python source code |
63
|
63
|
50
|
33
|
|
|
252
|
if ((not exists $self->{python_source_code}) or |
|
|
50
|
66
|
|
|
|
|
64
|
|
|
|
|
|
|
(not defined $self->{python_source_code})) { |
65
|
0
|
|
|
|
|
0
|
croak 'ERROR EPYCP001: non-existent or undefined Python source code, croaking'; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif (($self->{python_source_code} eq q{}) and |
68
|
|
|
|
|
|
|
not $self->isa('Python::Blank')) { |
69
|
0
|
|
|
|
|
0
|
carp 'WARNING WPYCP001: empty Python source code'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# DEV NOTE, PYCP002: $self->{python_preparsed} may or may not be used by classes which inherit this subroutine, no need to error check |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# return original Python source code |
75
|
63
|
|
|
|
|
170
|
return $self->{python_source_code}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# PYCP01x |
80
|
|
|
|
|
|
|
sub python_preparsed_to_perl_source { |
81
|
|
|
|
|
|
|
# return translated Perl source code for pre-parsed Python component |
82
|
0
|
|
|
0
|
0
|
|
{ my string $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
( my Python::Component $self, my OpenAI::API $openai ) = @ARG; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# error if no OpenAI API |
86
|
0
|
0
|
|
|
|
|
if (not defined $openai) { |
87
|
0
|
|
|
|
|
|
croak 'ERROR EPYCP010: undefined OpenAI API, croaking'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# DEV NOTE, PYCP011: $self->{python_source_code} not used in this translation, no need to error check |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# DEV NOTE, PYCP012: $self->{python_preparsed} may or may not be used by classes which inherit this subroutine, no need to error check |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# error or warning if no Perl source code |
95
|
0
|
0
|
0
|
|
|
|
if ((not exists $self->{perl_source_code}) or |
|
|
0
|
0
|
|
|
|
|
96
|
|
|
|
|
|
|
(not defined $self->{perl_source_code})) { |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return '# DUMMY PERL SOURCE CODE, NEED TRANSLATE!'; # TEMPORARY DEBUG, NEED DELETE! |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
croak 'ERROR EPYCP013: non-existent or undefined Perl source code, croaking'; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif (($self->{perl_source_code} eq q{}) and |
103
|
|
|
|
|
|
|
not $self->isa('Python::Blank')) { |
104
|
0
|
|
|
|
|
|
carp 'WARNING WPYCP013: empty Perl source code'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# return Perl source code |
108
|
0
|
|
|
|
|
|
return $self->{perl_source_code}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# PYCP02x |
113
|
|
|
|
|
|
|
sub python_source_code_indentation { |
114
|
|
|
|
|
|
|
# return indentation of first line of Python source code |
115
|
0
|
|
|
0
|
0
|
|
{ my string $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
( my Python::Component $self ) = @ARG; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$self->{python_source_code} =~ m/^(\s*)[^\s]/; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
print 'in python_source_code_indentation(), about to return indentation $1 = \'', $1, '\'', "\n"; |
121
|
0
|
|
|
|
|
|
return $1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# PYCP03x |
126
|
|
|
|
|
|
|
sub python_source_code_without_indentation { |
127
|
|
|
|
|
|
|
# return first line of Python source code without indentation |
128
|
0
|
|
|
0
|
0
|
|
{ my string $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
( my Python::Component $self ) = @ARG; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$self->{python_source_code} =~ m/^\s*([^\s].*)$/; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
print 'in python_source_code_indentation(), about to return Python source code without indentation $1 = \'', $1, '\'', "\n"; |
134
|
0
|
|
|
|
|
|
return $1; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |