Teach B::Deparse about in-place reverse
Vincent Pit [Sun, 15 Nov 2009 00:16:44 +0000 (01:16 +0100)]
And bump the $VERSION.

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t
ext/B/t/concise-xs.t

index fbfee98..93e250f 100644 (file)
@@ -16,13 +16,14 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
         OPpTRANS_SQUASH OPpTRANS_DELETE OPpTRANS_COMPLEMENT OPpTARGET_MY
         OPpCONST_ARYBASE OPpEXISTS_SUB OPpSORT_NUMERIC OPpSORT_INTEGER
         OPpSORT_REVERSE OPpSORT_INPLACE OPpSORT_DESCEND OPpITER_REVERSED
+        OPpREVERSE_INPLACE
         SVf_IOK SVf_NOK SVf_ROK SVf_POK SVpad_OUR SVf_FAKE SVs_RMG SVs_SMG
          CVf_METHOD CVf_LVALUE
         PMf_KEEP PMf_GLOBAL PMf_CONTINUE PMf_EVAL PMf_ONCE
         PMf_MULTILINE PMf_SINGLELINE PMf_FOLD PMf_EXTENDED),
         ($] < 5.009 ? 'PMf_SKIPWHITE' : 'RXf_SKIPWHITE'),
         ($] < 5.011 ? 'CVf_LOCKED' : ());
-$VERSION = 0.92;
+$VERSION = 0.93;
 use strict;
 use vars qw/$AUTOLOAD/;
 use warnings ();
@@ -2308,6 +2309,9 @@ sub listop {
     for (; !null($kid); $kid = $kid->sibling) {
        push @exprs, $self->deparse($kid, 6);
     }
+    if ($name eq "reverse" && ($op->private & OPpREVERSE_INPLACE)) {
+       return "$exprs[0] = $name" . ($parens ? "($exprs[0])" : " $exprs[0]");
+    }
     if ($parens) {
        return "$name(" . join(", ", @exprs) . ")";
     } else {
index 12879fc..191324a 100644 (file)
@@ -17,7 +17,7 @@ BEGIN {
     require feature;
     feature->import(':5.10');
 }
-use Test::More tests => 81;
+use Test::More tests => 83;
 use Config ();
 
 use B::Deparse;
@@ -603,3 +603,15 @@ my $pi = 4;
 my $pi : = 4;
 >>>>
 my $pi = 4;
+####
+our @a;
+my @b;
+@a = sort @a;
+@b = sort @b;
+();
+####
+our @a;
+my @b;
+@a = reverse @a;
+@b = reverse @b;
+();
index d900113..8e51b88 100644 (file)
@@ -161,10 +161,10 @@ my $testpkgs = {
                     OPpENTERSUB_AMPER OPpEXISTS_SUB OPpITER_REVERSED
                     OPpLVAL_INTRO OPpOUR_INTRO OPpSLICE OPpSORT_DESCEND
                     OPpSORT_INPLACE OPpSORT_INTEGER OPpSORT_NUMERIC
-                    OPpSORT_REVERSE OPpTARGET_MY OPpTRANS_COMPLEMENT
-                    OPpTRANS_DELETE OPpTRANS_SQUASH PMf_CONTINUE
-                    PMf_EVAL PMf_EXTENDED PMf_FOLD PMf_GLOBAL PMf_KEEP
-                    PMf_MULTILINE PMf_ONCE PMf_SINGLELINE
+                    OPpSORT_REVERSE OPpREVERSE_INPLACE OPpTARGET_MY
+                    OPpTRANS_COMPLEMENT OPpTRANS_DELETE OPpTRANS_SQUASH
+                    PMf_CONTINUE PMf_EVAL PMf_EXTENDED PMf_FOLD PMf_GLOBAL
+                    PMf_KEEP PMf_MULTILINE PMf_ONCE PMf_SINGLELINE
                     POSTFIX SVf_FAKE SVf_IOK SVf_NOK SVf_POK SVf_ROK
                     SVpad_OUR SVs_RMG SVs_SMG SWAP_CHILDREN OPpPAD_STATE
                     /, $] > 5.009 ? ('RXf_SKIPWHITE') : ('PMf_SKIPWHITE'),