| 1 |
|
| ################################################################################ |
| 2 |
|
| # |
| 3 |
|
| # Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved. |
| 4 |
|
| # This program is free software; you can redistribute it and/or modify |
| 5 |
|
| # it under the same terms as Perl itself. |
| 6 |
|
| # |
| 7 |
|
| ################################################################################ |
| 8 |
|
| |
| 9 |
|
| |
| 10 |
|
| ################################################################################ |
| 11 |
|
| # |
| 12 |
|
| # METHOD: tag / untag |
| 13 |
|
| # |
| 14 |
|
| # WRITTEN BY: Marcus Holland-Moritz ON: Dec 2004 |
| 15 |
|
| # CHANGED BY: ON: |
| 16 |
|
| # |
| 17 |
|
| ################################################################################ |
| 18 |
|
| |
| 19 |
|
| void |
| 20 |
|
| CBC::tag(type, ...) |
| 21 |
|
| const char *type |
| 22 |
|
| |
| 23 |
|
| ALIAS: |
| 24 |
|
| untag = 1 |
| 25 |
|
| |
| 26 |
|
| PREINIT: |
| 27 |
19656 |
| CBC_METHOD_VAR; |
| 28 |
|
| TagTypeInfo tti; |
| 29 |
|
| CtTagList *taglist; |
| 30 |
|
| |
| 31 |
|
| CODE: |
| 32 |
19656 |
| switch (ix) |
| 33 |
|
| { |
| 34 |
19627 |
| case 0: |
| 35 |
19627 |
| CBC_METHOD_SET("tag"); |
| 36 |
19627 |
| break; |
| 37 |
|
| |
| 38 |
29 |
| case 1: |
| 39 |
29 |
| CBC_METHOD_SET("untag"); |
| 40 |
29 |
| break; |
| 41 |
|
| |
| 42 |
0 |
| default: |
| 43 |
0 |
| fatal("Invalid alias (%d) for tag method", ix); |
| 44 |
|
| break; |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
|
| CT_DEBUG_METHOD1("'%s'", type); |
| 48 |
|
| |
| 49 |
19656 |
▶ | if (ix == 0 && items <= 3 && GIMME_V == G_VOID) |
Branch: 3 branches
| Branch | True | False | Total |
| if (ix == 0 && items <= 3 && GIMME_V == G_VOID) |
19627 |
29 |
19656 |
| if (ix == 0 && items <= 3 && GIMME_V == G_VOID) |
384 |
19243 |
19627 |
| if (ix == 0 && items <= 3 && GIMME_V == G_VOID) |
24 |
360 |
384 |
|
| 50 |
|
| { |
| 51 |
24 |
▶ | WARN_VOID_CONTEXT; |
Branch: 1 branch
| Branch | True | False | Total |
| WARN_VOID_CONTEXT; |
16 |
8 |
24 |
|
| 52 |
24 |
| XSRETURN_EMPTY; |
| 53 |
|
| } |
| 54 |
|
| |
| 55 |
19632 |
▶ | NEED_PARSE_DATA; |
Branch: 2 branches
| Branch | True | False | Total |
| NEED_PARSE_DATA; |
19622 |
10 |
19632 |
| NEED_PARSE_DATA; |
9 |
19613 |
19622 |
|
| 56 |
|
| |
| 57 |
19632 |
| tti.type = type; |
| 58 |
|
| |
| 59 |
19632 |
▶ | if (!get_member_info(aTHX_ THIS, type, &tti.mi, 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!get_member_info(aTHX_ THIS, type, &tti.mi, 0)) |
12 |
19620 |
19632 |
|
| 60 |
12 |
| Perl_croak(aTHX_ "Cannot find '%s'", type); |
| 61 |
|
| |
| 62 |
19620 |
▶ | if (tti.mi.level != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tti.mi.level != 0) |
24 |
19596 |
19620 |
|
| 63 |
24 |
| Perl_croak(aTHX_ "Cannot tag array members"); |
| 64 |
|
| |
| 65 |
58335 |
| taglist = tti.mi.pDecl ? &tti.mi.pDecl->tags |
| 66 |
19596 |
▶ | : find_taglist_ptr(tti.mi.type.ptr); |
Branch: 1 branch
| Branch | True | False | Total |
| : find_taglist_ptr(tti.mi.type.ptr); |
19143 |
453 |
19596 |
|
| 67 |
|
| |
| 68 |
|
| assert(taglist != NULL); |
| 69 |
|
| |
| 70 |
19596 |
▶ | if (ix == 0) /* tag */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 0) /* tag */ |
19573 |
23 |
19596 |
|
| 71 |
|
| { |
| 72 |
19573 |
▶ | if (items == 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 2) |
118 |
19455 |
19573 |
|
| 73 |
118 |
| ST(0) = get_tags(aTHX_ &tti, *taglist); |
| 74 |
19455 |
▶ | else if (items == 3) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (items == 3) |
236 |
19219 |
19455 |
|
| 75 |
236 |
| handle_tag(aTHX_ &tti, taglist, ST(2), NULL, &ST(0)); |
| 76 |
19219 |
▶ | else if (items % 2 == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (items % 2 == 0) |
19213 |
6 |
19219 |
|
| 77 |
|
| { |
| 78 |
|
| int i; |
| 79 |
38252 |
▶ | for (i = 2; i < items; i += 2) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i < items; i += 2) |
19245 |
19007 |
38252 |
|
| 80 |
19245 |
| handle_tag(aTHX_ &tti, taglist, ST(i), ST(i+1), NULL); |
| 81 |
|
| } |
| 82 |
|
| else |
| 83 |
6 |
| Perl_croak(aTHX_ "Invalid number of arguments to %s", method); |
| 84 |
|
| } |
| 85 |
|
| else /* untag */ |
| 86 |
|
| { |
| 87 |
23 |
▶ | if (items == 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 2) |
2 |
21 |
23 |
|
| 88 |
2 |
| delete_all_tags(taglist); |
| 89 |
|
| else |
| 90 |
|
| { |
| 91 |
|
| int i; |
| 92 |
36 |
▶ | for (i = 2; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i < items; i++) |
21 |
15 |
36 |
|
| 93 |
21 |
| handle_tag(aTHX_ &tti, taglist, ST(i), &PL_sv_undef, NULL); |
| 94 |
|
| } |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
19366 |
| XSRETURN(1); |
| 98 |
|
| |