This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Macro for common OP checks: "is this X or was it before NULLing?"
authorSteffen Mueller <smueller@cpan.org>
Fri, 21 Feb 2014 17:58:04 +0000 (18:58 +0100)
committerSteffen Mueller <smueller@cpan.org>
Wed, 26 Feb 2014 20:05:27 +0000 (21:05 +0100)
commit11ee9dd668c24ff655cfec47610c8939e74a8506
tree03d1c62d215de5ed152f0baee1cfe8219e1329a8
parent1472fa3142752a63cd8ba4fe348df51f378213e6
Macro for common OP checks: "is this X or was it before NULLing?"

For example,

    if (OP_TYPE_IS_OR_WAS(o, OP_LIST))
        ...

is now available instead of either of the following:

    if ( o
         && ( o->op_type == OP_LIST
              || (o->op_type == OP_NULL
                  && o->op_targ == OP_LIST) ) )
        ...

    if ( o &&
         (o->op_type == OP_NULL ? o->op_targ ? o->op_type) == OP_LIST )
        ...

In case the above logic is a bit unclear: It checks whether that OP is
an OP_LIST or used to be one before being NULLed using op_null.
(FTR, the resulting OP_NULLs have their op_targ set to the old OP type).

This sort of check (and it's reverse "isn't and didn't use to be") are a
relatively common pattern in the part of op.c that tries to intuit
structures from optimization-mangled OP trees. Hopefully, using these
macros will make some code a fair amount clearer.
op.c
op.h