Skip to content

Commit ddf9e90

Browse files
committed
ParseXS: refactor: remove misc xsub_foo fields
Remove the following fields from the ExtUtils::ParseXS class: xsub_map_overload_name_to_seen xsub_prototype and replace them with these new fields in the ExtUtils::ParseXS::Node::xsub class: overload_name_seen prototype
1 parent 7ca700f commit ddf9e90

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,7 @@ BEGIN {
235235

236236
'cur_xbody', # The Node::xbody currently being parsed
237237

238-
'xsub_prototype', # Str: is set to either the global PROTOTYPES
239-
# values (0 or 1), or to what's been
240-
# overridden for this XSUB with PROTOTYPE
241-
# "0": DISABLE
242-
# "1": ENABLE
243-
# "2": empty prototype
244-
# other: a specific prototype.
245-
246238
'xsub_SCOPE_enabled', # Bool: SCOPE ENABLEd
247-
248-
'xsub_map_overload_name_to_seen', # Hash: maps each overload method name
249-
# (such as '<=>') to a boolean indicating
250-
# whether that method has been listed by
251-
# OVERLOAD (for duplicate spotting).
252239
);
253240

254241
# do 'use fields', except: fields needs Hash::Util which is XS, which
@@ -578,9 +565,7 @@ EOM
578565

579566
# Initialize some per-XSUB instance variables:
580567

581-
$self->{xsub_prototype} = $self->{PROTOTYPES_value};
582568
$self->{xsub_SCOPE_enabled} = 0;
583-
$self->{xsub_map_overload_name_to_seen} = {};
584569

585570
# Process next line
586571

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ BEGIN { $build_subclass->('', # parent
238238
# name, map the short (PREFIX removed) name
239239
# to the original name.
240240

241+
'overload_name_seen', # Hash of bools: indicates overload method
242+
# names (such as '<=>') which have been
243+
# listed by OVERLOAD (for newXS boot code
244+
# emitting).
245+
241246
# Maintain the ATTRS parsing state across potentially multiple
242247
# ATTRS keywords and or lines:
243248

@@ -249,6 +254,17 @@ BEGIN { $build_subclass->('', # parent
249254

250255
'interface_macro', # Str: value of interface extraction macro.
251256
'interface_macro_set', # Str: value of interface setting macro.
257+
258+
# PROTOTYPE value
259+
260+
'prototype', # Str: is set to either the global PROTOTYPES
261+
# values (0 or 1), or to what's been
262+
# overridden for this XSUB with PROTOTYPE
263+
# "0": DISABLE
264+
# "1": ENABLE
265+
# "2": empty prototype
266+
# other: a specific prototype.
267+
252268
)};
253269

254270

@@ -258,6 +274,10 @@ sub parse {
258274

259275
$self->SUPER::parse($pxs); # set file/line_no
260276

277+
# Initially inherit the prototype behaviour for the XSUB from the
278+
# global PROTOTYPES default
279+
$self->{prototype} = $pxs->{PROTOTYPES_value};
280+
261281
# Parse the XSUB's declaration (return type, name, parameters)
262282

263283
my $decl = ExtUtils::ParseXS::Node::xsub_decl->new();
@@ -501,7 +521,7 @@ sub boot_code {
501521

502522
$proto_arg = "";
503523

504-
unless($pxs->{xsub_prototype}) {
524+
unless($self->{prototype}) {
505525
# no prototype
506526
$newXS = "newXS_deffile";
507527
$file_arg = "";
@@ -511,17 +531,17 @@ sub boot_code {
511531
$newXS = "newXSproto_portable";
512532
$file_arg = ", file";
513533

514-
if ($pxs->{xsub_prototype} eq 2) {
534+
if ($self->{prototype} eq 2) {
515535
# User has specified an empty prototype
516536
}
517-
elsif ($pxs->{xsub_prototype} eq 1) {
537+
elsif ($self->{prototype} eq 1) {
518538
# Protoype enabled, but to be auto-generated by us
519539
$proto_arg = $self->{decl}{params}->proto_string();
520540
$proto_arg =~ s{\\}{\\\\}g; # escape backslashes
521541
}
522542
else {
523543
# User has manually specified a prototype
524-
$proto_arg = $pxs->{xsub_prototype};
544+
$proto_arg = $self->{prototype};
525545
}
526546

527547
$proto_arg = qq{, "$proto_arg"};
@@ -608,7 +628,7 @@ EOF
608628
# For every overload operator, generate an additional newXS()
609629
# call to add an alias such as "Foo::(<=>" for this XSUB.
610630

611-
for my $operator (sort keys %{ $pxs->{xsub_map_overload_name_to_seen} })
631+
for my $operator (sort keys %{ $pxs->{cur_xsub}{overload_name_seen} })
612632
{
613633
$pxs->{map_overloaded_package_to_C_package}->{$pxs->{PACKAGE_name}}
614634
= $pxs->{PACKAGE_C_name};
@@ -3248,7 +3268,7 @@ BEGIN { $build_subclass->('multiline_merged', # parent
32483268

32493269
# Add all overload method names, like 'cmp', '<=>', etc, (possibly
32503270
# multiple ones per line) until the next keyword line, as 'seen' keys to
3251-
# the $self->{xsub_map_overload_name_to_seen} hash.
3271+
# the $xsub->{overload_name_seen} hash.
32523272

32533273
sub parse {
32543274
my __PACKAGE__ $self = shift;
@@ -3259,7 +3279,7 @@ sub parse {
32593279
my $s = $self->{text};
32603280
while ($s =~ s/^\s*([\w:"\\)\+\-\*\/\%\<\>\.\&\|\^\!\~\{\}\=]+)\s*//) {
32613281
$self->{ops}{$1} = 1;
3262-
$pxs->{xsub_map_overload_name_to_seen}->{$1} = 1;
3282+
$pxs->{cur_xsub}{overload_name_seen}{$1} = 1;
32633283
}
32643284
1;
32653285
}
@@ -3347,9 +3367,8 @@ sub parse {
33473367
# If no prototype specified, then assume empty prototype ""
33483368
$proto = 2 unless defined $proto;
33493369

3350-
$self->{prototype} = $proto;
3351-
$pxs->{xsub_prototype} = $proto;
3352-
3370+
$self->{prototype} = $proto;
3371+
$pxs->{cur_xsub}{prototype} = $proto;
33533372

33543373
$pxs->{proto_behaviour_specified} = 1;
33553374
1;

0 commit comments

Comments
 (0)