perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

add OPpCONST_LINE flag to aid deparsing

Open iabyn opened this issue 1 year ago • 1 comments

Code like

my $line = __LINE__;

was being deparsed as

my $line = '42';

because LINE is converted by the lexer into an ordinary OP_CONST whose SV is just a plain string holding the line number.

This commit adds a flag, OPpCONST_LINE, to OP_CONST, which is set to indicate that this OP_CONST was created from a LINE construct.

Deparse.pm then uses this new flag to print out the literal string "LINE" rather than the constant's actual value.

This fixes one failing test file under cd t; ./TEST -deparse and removes one (but not all) sources of failure from three others.

iabyn avatar Feb 19 '24 11:02 iabyn

I've now updated the commit so that it uses two bits of OP_CONST's op_private to deparse all three of LINE, FILE, PACKAGE.

iabyn avatar Feb 21 '24 11:02 iabyn

Yeah, I meant to update the test but forgot. Done now, and rebased and repushed.

iabyn avatar Feb 22 '24 00:02 iabyn