| 1 |
|
| /* You may distribute under the terms of either the GNU General Public License |
| 2 |
|
| * or the Artistic License (the same terms as Perl itself) |
| 3 |
|
| * |
| 4 |
|
| * (C) Paul Evans, 2024 -- leonerd@leonerd.org.uk |
| 5 |
|
| */ |
| 6 |
|
| #define PERL_NO_GET_CONTEXT |
| 7 |
|
| |
| 8 |
|
| #include "EXTERN.h" |
| 9 |
|
| #include "perl.h" |
| 10 |
|
| #include "XSUB.h" |
| 11 |
|
| |
| 12 |
|
| #include "XSParseInfix.h" |
| 13 |
|
| #include "object_pad.h" |
| 14 |
|
| |
| 15 |
|
| #define HAVE_PERL_VERSION(R, V, S) \ |
| 16 |
|
| (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S)))))) |
| 17 |
|
| |
| 18 |
|
| #include "newOP_CUSTOM.c.inc" |
| 19 |
|
| |
| 20 |
4 |
| static OP *pp_of(pTHX) |
| 21 |
|
| { |
| 22 |
4 |
| dSP; |
| 23 |
4 |
| FieldMeta *fieldmeta = (FieldMeta *)cUNOP_AUX->op_aux; |
| 24 |
4 |
| SV *instance = POPs; |
| 25 |
|
| |
| 26 |
4 |
| ClassMeta *classmeta = NULL; |
| 27 |
|
| |
| 28 |
4 |
| SV *field = get_obj_fieldsv(instance, fieldmeta); |
| 29 |
|
| |
| 30 |
|
| /* TODO: consider if we should clone a copy of it, if not OPf_REF? */ |
| 31 |
4 |
| PUSHs(field); |
| 32 |
4 |
| RETURN; |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
2 |
| static OP *new_op_of(pTHX_ U32 flags, OP *lhs, OP *rhs, SV **parsedata, void *hookdata) |
| 36 |
|
| { |
| 37 |
2 |
| OP *fieldexpr = lhs; |
| 38 |
2 |
| OP *instanceexpr = rhs; |
| 39 |
|
| |
| 40 |
2 |
▶ | if(fieldexpr->op_type != OP_PADSV) |
Branch: 1 branch
| Branch | True | False | Total |
| if(fieldexpr->op_type != OP_PADSV) |
0 |
2 |
2 |
|
| 41 |
0 |
| croak("Expected FIELD operand to 'of' expression to be a field variable"); |
| 42 |
2 |
| PADOFFSET fieldexpr_padix = fieldexpr->op_targ; |
| 43 |
|
| |
| 44 |
2 |
| op_free(fieldexpr); |
| 45 |
|
| |
| 46 |
2 |
| FieldMeta *fieldmeta = get_field_for_padix(fieldexpr_padix); |
| 47 |
2 |
▶ | if(!fieldmeta) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!fieldmeta) |
0 |
2 |
2 |
|
| 48 |
0 |
| croak("Unsure what field this expression refers to"); |
| 49 |
|
| |
| 50 |
2 |
| return newUNOP_AUX_CUSTOM(&pp_of, flags, instanceexpr, (UNOP_AUX_item *)fieldmeta); |
| 51 |
|
| } |
| 52 |
|
| |
| 53 |
|
| static const struct XSParseInfixHooks hooks_of = { |
| 54 |
|
| .cls = XPI_CLS_HIGH_MISC, |
| 55 |
|
| .new_op = &new_op_of, |
| 56 |
|
| }; |
| 57 |
|
| |
| 58 |
|
| MODULE = Object::Pad::Operator::Of PACKAGE = Object::Pad::Operator::Of |
| 59 |
|
| |
| 60 |
|
| BOOT: |
| 61 |
2 |
| boot_xs_parse_infix(0.44); |
| 62 |
|
| |
| 63 |
2 |
| register_xs_parse_infix("Object::Pad::Operator::Of::of", &hooks_of, NULL); |