| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| |
| 3 |
|
| #include "EXTERN.h" |
| 4 |
|
| #include "perl.h" |
| 5 |
|
| #include "XSUB.h" |
| 6 |
|
| |
| 7 |
|
| #include "XSParseInfix.h" |
| 8 |
|
| |
| 9 |
|
| #define sv_defined(sv) (sv && (SvIOK(sv) || SvNOK(sv) || SvPOK(sv) || SvROK(sv))) |
| 10 |
|
| |
| 11 |
92 |
| static bool test_pp_matches( pTHX_ SV *a, SV *b ) |
| 12 |
|
| { |
| 13 |
92 |
| dSP; |
| 14 |
|
| dTARG; |
| 15 |
|
| |
| 16 |
92 |
| SvGETMAGIC( a ); |
| 17 |
92 |
| SvGETMAGIC( b ); |
| 18 |
|
| |
| 19 |
92 |
▶ | if ( ! sv_defined( b ) ) { |
Branch: 5 branches
| Branch | True | False | Total |
| if ( ! sv_defined( b ) ) { |
92 |
0 |
92 |
| if ( ! sv_defined( b ) ) { |
92 |
0 |
92 |
| if ( ! sv_defined( b ) ) { |
92 |
0 |
92 |
| if ( ! sv_defined( b ) ) { |
68 |
24 |
92 |
| if ( ! sv_defined( b ) ) { |
22 |
46 |
68 |
|
| 20 |
22 |
▶ | return( sv_defined( a ) ? FALSE : TRUE ); |
Branch: 5 branches
| Branch | True | False | Total |
| return( sv_defined( a ) ? FALSE : TRUE ); |
22 |
0 |
22 |
| return( sv_defined( a ) ? FALSE : TRUE ); |
16 |
6 |
22 |
| return( sv_defined( a ) ? FALSE : TRUE ); |
16 |
0 |
16 |
| return( sv_defined( a ) ? FALSE : TRUE ); |
12 |
4 |
16 |
| return( sv_defined( a ) ? FALSE : TRUE ); |
4 |
8 |
12 |
|
| 21 |
|
| } |
| 22 |
|
| |
| 23 |
70 |
▶ | else if ( ! SvROK( b ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( ! SvROK( b ) ) { |
24 |
46 |
70 |
|
| 24 |
24 |
| return( sv_eq( a, b ) ? TRUE : FALSE ); |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
46 |
▶ | else if ( sv_isobject( b ) && sv_derived_from( b, "Type::Tiny" ) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( sv_isobject( b ) && sv_derived_from( b, "Type::Tiny" ) ) { |
28 |
18 |
46 |
| else if ( sv_isobject( b ) && sv_derived_from( b, "Type::Tiny" ) ) { |
2 |
26 |
28 |
|
| 28 |
|
| int count; |
| 29 |
|
| SV *ret; |
| 30 |
|
| bool ret_truth; |
| 31 |
2 |
| ENTER; |
| 32 |
2 |
| SAVETMPS; |
| 33 |
2 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
2 |
2 |
|
| 34 |
2 |
▶ | XPUSHs(b); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(b); |
0 |
2 |
2 |
|
| 35 |
2 |
▶ | XPUSHs(a); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(a); |
0 |
2 |
2 |
|
| 36 |
2 |
| PUTBACK; |
| 37 |
2 |
| count = call_method( "check", G_SCALAR ); |
| 38 |
2 |
| SPAGAIN; |
| 39 |
2 |
| ret = POPs; |
| 40 |
2 |
| ret_truth = SvTRUE( ret ); |
| 41 |
2 |
| PUTBACK; |
| 42 |
2 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
2 |
0 |
2 |
|
| 43 |
2 |
| LEAVE; |
| 44 |
|
| |
| 45 |
2 |
| return( ret_truth ); |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
|
| else { |
| 49 |
|
| int count; |
| 50 |
|
| bool r; |
| 51 |
44 |
| ENTER; |
| 52 |
44 |
| SAVETMPS; |
| 53 |
44 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
44 |
44 |
|
| 54 |
44 |
▶ | XPUSHs( a ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( a ); |
0 |
44 |
44 |
|
| 55 |
44 |
▶ | XPUSHs( b ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( b ); |
0 |
44 |
44 |
|
| 56 |
44 |
| PUTBACK; |
| 57 |
44 |
| count = call_pv( "match::simple::match", G_SCALAR ); |
| 58 |
42 |
| SPAGAIN; |
| 59 |
42 |
| r = POPi; |
| 60 |
42 |
| PUTBACK; |
| 61 |
42 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
0 |
42 |
42 |
|
| 62 |
42 |
| LEAVE; |
| 63 |
|
| |
| 64 |
42 |
| return( r != 0 ? TRUE : FALSE ); |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| // Shouldn't happen |
| 68 |
|
| return FALSE; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
48 |
| static OP *pp_matches( pTHX ) |
| 72 |
|
| { |
| 73 |
48 |
| dSP; |
| 74 |
|
| dTARG; |
| 75 |
48 |
| SV *b = TOPs, *a = TOPm1s; |
| 76 |
48 |
| POPs; |
| 77 |
48 |
▶ | SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_yes : &PL_sv_no ); |
Branch: 1 branch
| Branch | True | False | Total |
| SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_yes : &PL_sv_no ); |
15 |
31 |
46 |
|
| 78 |
46 |
| RETURN; |
| 79 |
|
| } |
| 80 |
|
| |
| 81 |
44 |
| static OP *pp_mismatches( pTHX ) |
| 82 |
|
| { |
| 83 |
44 |
| dSP; |
| 84 |
|
| dTARG; |
| 85 |
44 |
| SV *b = TOPs, *a = TOPm1s; |
| 86 |
44 |
| POPs; |
| 87 |
44 |
▶ | SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_no : &PL_sv_yes ); |
Branch: 1 branch
| Branch | True | False | Total |
| SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_no : &PL_sv_yes ); |
14 |
30 |
44 |
|
| 88 |
44 |
| RETURN; |
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| static const struct XSParseInfixHooks hooks_matches = { |
| 92 |
|
| .cls = XPI_CLS_MATCH_MISC, |
| 93 |
|
| .permit_hintkey = "Syntax::Operator::Matches/matches", |
| 94 |
|
| .ppaddr = &pp_matches, |
| 95 |
|
| }; |
| 96 |
|
| |
| 97 |
|
| static const struct XSParseInfixHooks hooks_mismatches = { |
| 98 |
|
| .cls = XPI_CLS_MATCH_MISC, |
| 99 |
|
| .permit_hintkey = "Syntax::Operator::Matches/mismatches", |
| 100 |
|
| .ppaddr = &pp_mismatches, |
| 101 |
|
| }; |
| 102 |
|
| |
| 103 |
|
| MODULE = Syntax::Operator::Matches PACKAGE = Syntax::Operator::Matches |
| 104 |
|
| |
| 105 |
|
| BOOT: |
| 106 |
4 |
| boot_xs_parse_infix( 0.26 ); |
| 107 |
4 |
| register_xs_parse_infix( "matches", &hooks_matches, NULL ); |
| 108 |
4 |
| register_xs_parse_infix( "mismatches", &hooks_mismatches, NULL ); |