1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
my $class = shift; |
4 |
|
|
my $curclass = ""; |
5 |
root |
1.3 |
my (@scalar_member, @array_member); |
6 |
root |
1.1 |
|
7 |
|
|
for my $file (@ARGV) { |
8 |
|
|
open my $fh, "<:utf8", $file |
9 |
|
|
or die "$file: $!"; |
10 |
|
|
|
11 |
|
|
while (<$fh>) { |
12 |
root |
1.3 |
while (/ACC\s*\(R([WO])\s*,\s*([^)\]]+)(?:\[(\S+)\])?\)/g) { |
13 |
root |
1.1 |
next unless $curclass eq $class; |
14 |
|
|
|
15 |
root |
1.3 |
if ($3) { |
16 |
|
|
push @array_member, [$1, $2, $3]; |
17 |
|
|
} else { |
18 |
|
|
push @scalar_member, [$1, $2]; |
19 |
|
|
} |
20 |
root |
1.1 |
} |
21 |
|
|
while (/ACC_CLASS\s*\((\S+)\)/g) { |
22 |
|
|
$curclass = $1; |
23 |
|
|
} |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
|
27 |
root |
1.3 |
if (@scalar_member) { |
28 |
|
|
print "SV *$scalar_member[0][1] ($class *self, SV *newval = 0)\n"; |
29 |
|
|
print "\tPROTOTYPE: \$;\$\n"; |
30 |
|
|
|
31 |
|
|
if (@scalar_member > 1) { |
32 |
|
|
print "\tALIAS:\n"; |
33 |
|
|
for (1 .. $#scalar_member) { |
34 |
|
|
print "\t\t$scalar_member[$_][1]\t= $_\n"; |
35 |
|
|
} |
36 |
|
|
} |
37 |
root |
1.1 |
|
38 |
root |
1.3 |
print "\tCODE:\n"; |
39 |
|
|
|
40 |
|
|
# read |
41 |
|
|
print "\tif (GIMME_V == G_VOID)\n", |
42 |
|
|
"\t RETVAL = &PL_sv_undef;\n", |
43 |
|
|
"\telse\n", |
44 |
|
|
"\t switch (ix)\n", |
45 |
|
|
"\t {\n", |
46 |
|
|
(map "\t case $_: RETVAL = to_sv (self->$scalar_member[$_][1]); break;\n", |
47 |
|
|
0 .. $#scalar_member), |
48 |
|
|
"\t default: croak (\"scalar_member is write-only\");\n", |
49 |
|
|
"\t };\n"; |
50 |
root |
1.1 |
|
51 |
root |
1.3 |
# write |
52 |
|
|
print "\tif (newval)\n", |
53 |
|
|
"\t switch (ix)\n", |
54 |
|
|
"\t {\n", |
55 |
|
|
(map "\t case $_: sv_to (newval, self->$scalar_member[$_][1]); break;\n", |
56 |
|
|
grep $scalar_member[$_][0] eq "W", |
57 |
|
|
0 .. $#scalar_member), |
58 |
|
|
"\t default: croak (\"scalar_member is read-only\");\n", |
59 |
|
|
"\t };\n"; |
60 |
|
|
|
61 |
|
|
print "\tOUTPUT: RETVAL\n\n"; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
if (@array_member) { |
65 |
|
|
print "SV *$array_member[0][1] ($class *self, int idx, SV *newval = 0)\n"; |
66 |
|
|
print "\tPROTOTYPE: \$;\$\n"; |
67 |
|
|
|
68 |
|
|
if (@array_member > 1) { |
69 |
|
|
print "\tALIAS:\n"; |
70 |
|
|
for (1 .. $#array_member) { |
71 |
|
|
print "\t\t$array_member[$_][1]\t= $_\n"; |
72 |
|
|
} |
73 |
root |
1.1 |
} |
74 |
|
|
|
75 |
root |
1.3 |
print "\tCODE:\n"; |
76 |
|
|
|
77 |
|
|
print "\tif (idx < 0) croak (\"negative array index\");\n"; |
78 |
|
|
|
79 |
|
|
# range |
80 |
|
|
print "\t switch (ix)\n", |
81 |
|
|
"\t {\n", |
82 |
|
|
(map "\t case $_: if (idx >= $array_member[$_][2]) croak (\"array index out of bounds\"); break;\n", |
83 |
|
|
0 .. $#array_member), |
84 |
|
|
"\t };\n"; |
85 |
root |
1.1 |
|
86 |
|
|
# read |
87 |
root |
1.3 |
print "\tif (GIMME_V == G_VOID)\n", |
88 |
|
|
"\t RETVAL = &PL_sv_undef;\n", |
89 |
|
|
"\telse\n", |
90 |
|
|
"\t switch (ix)\n", |
91 |
|
|
"\t {\n", |
92 |
|
|
(map "\t case $_: RETVAL = to_sv (self->$array_member[$_][1] [idx]); break;\n", |
93 |
|
|
0 .. $#array_member), |
94 |
|
|
"\t default: croak (\"array_member is write-only\");\n", |
95 |
|
|
"\t };\n"; |
96 |
root |
1.1 |
|
97 |
|
|
# write |
98 |
root |
1.3 |
print "\tif (newval)\n", |
99 |
|
|
"\t switch (ix)\n", |
100 |
|
|
"\t {\n", |
101 |
|
|
(map "\t case $_: sv_to (newval, self->$array_member[$_][1] [idx]); break;\n", |
102 |
|
|
grep $array_member[$_][0] eq "W", |
103 |
|
|
0 .. $#array_member), |
104 |
|
|
"\t default: croak (\"array_member is read-only\");\n", |
105 |
|
|
"\t };\n"; |
106 |
root |
1.1 |
|
107 |
root |
1.3 |
print "\tOUTPUT: RETVAL\n\n"; |
108 |
|
|
} |
109 |
root |
1.1 |
|