| 1 |
|
| #include "dds_engine.h" |
| 2 |
|
| |
| 3 |
|
| /* |
| 4 |
|
| * Breadth-first analysis |
| 5 |
|
| * |
| 6 |
|
| * Scalar slots and their referents have distinct catalogue roles. Queue depths |
| 7 |
|
| * count both visits. Depth buckets choose canonical names at minimum depth |
| 8 |
|
| * before depth-first emission chooses where to construct referents. |
| 9 |
|
| * |
| 10 |
|
| * Seed every root, drain the shallowest pending queue level, then reconcile |
| 11 |
|
| * discovered closure roots. New roots or improved names restart analysis |
| 12 |
|
| * before the catalogue is published. |
| 13 |
|
| */ |
| 14 |
|
| |
| 15 |
|
| /* Record a scalar slot's canonical name, depth and alias properties when it |
| 16 |
|
| * may be shared; forced roots are always catalogued. |
| 17 |
|
| */ |
| 18 |
11818 |
| static void dds_register_slot(pTHX_ dds_ctx *ctx, SV *sv, UV depth, SV *name, UV count, bool force) |
| 19 |
|
| { |
| 20 |
|
| dds_node *node; |
| 21 |
|
| dds_role *role; |
| 22 |
|
| |
| 23 |
11818 |
▶ | if (!force && !dds_candidate(aTHX_ sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!force && !dds_candidate(aTHX_ sv)) |
9861 |
1957 |
11818 |
| if (!force && !dds_candidate(aTHX_ sv)) |
8583 |
1278 |
9861 |
|
| 24 |
8583 |
| return; |
| 25 |
|
| |
| 26 |
3235 |
| node = dds_find(aTHX_ ctx, sv, TRUE); |
| 27 |
3235 |
| role = &node->slot; |
| 28 |
3235 |
▶ | if (!role->present) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!role->present) { |
2621 |
614 |
3235 |
|
| 29 |
2621 |
| SV *clean = dds_clean_name(aTHX_ name); |
| 30 |
|
| |
| 31 |
2621 |
| role->present = TRUE; |
| 32 |
2621 |
| role->name = newSVsv(clean); |
| 33 |
2621 |
▶ | if (sv_cmp(clean, name)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_cmp(clean, name)) |
148 |
2473 |
2621 |
|
| 34 |
148 |
| role->original = newSVsv(name); |
| 35 |
2621 |
| role->depth = depth; |
| 36 |
2621 |
| role->count = count; |
| 37 |
2621 |
| role->readonly = cBOOL(SvREADONLY(sv)); |
| 38 |
2621 |
▶ | role->weak = SvROK(sv) && SvWEAKREF(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| role->weak = SvROK(sv) && SvWEAKREF(sv); |
1616 |
1005 |
2621 |
| role->weak = SvROK(sv) && SvWEAKREF(sv); |
46 |
1570 |
1616 |
|
| 39 |
|
| } else { |
| 40 |
1228 |
▶ | const char *old = DDS_PV(role->name), *new_name = DDS_PV(name); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *old = DDS_PV(role->name), *new_name = DDS_PV(name); |
614 |
0 |
614 |
|
| 41 |
|
| |
| 42 |
|
| /* Prefer a direct slot name over an equally deep dereference. */ |
| 43 |
614 |
▶ | if (role->depth == depth && old[0] == '$' && |
Branch: 2 branches
| Branch | True | False | Total |
| if (role->depth == depth && old[0] == '$' && |
367 |
247 |
614 |
| if (role->depth == depth && old[0] == '$' && |
359 |
8 |
367 |
|
| 44 |
359 |
▶ | (old[1] == '$' || (old[1] == '{' && old[2] == '$')) && |
Branch: 3 branches
| Branch | True | False | Total |
| (old[1] == '$' || (old[1] == '{' && old[2] == '$')) && |
347 |
12 |
359 |
| (old[1] == '$' || (old[1] == '{' && old[2] == '$')) && |
0 |
347 |
347 |
| (old[1] == '$' || (old[1] == '{' && old[2] == '$')) && |
0 |
0 |
0 |
|
| 45 |
12 |
▶ | !(new_name[0] == '$' && |
Branch: 1 branch
| Branch | True | False | Total |
| !(new_name[0] == '$' && |
12 |
0 |
12 |
|
| 46 |
12 |
▶ | (new_name[1] == '$' || (new_name[1] == '{' && new_name[2] == '$')))) |
Branch: 3 branches
| Branch | True | False | Total |
| (new_name[1] == '$' || (new_name[1] == '{' && new_name[2] == '$')))) |
12 |
0 |
12 |
| (new_name[1] == '$' || (new_name[1] == '{' && new_name[2] == '$')))) |
0 |
12 |
12 |
| (new_name[1] == '$' || (new_name[1] == '{' && new_name[2] == '$')))) |
0 |
0 |
0 |
|
| 47 |
12 |
| sv_setsv(role->name, name); |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
3235 |
| role->encounters++; |
| 51 |
|
| } |
| 52 |
|
| |
| 53 |
|
| /* Queue a borrowed value at its traversal depth, owning a copy of its path and |
| 54 |
|
| * retaining the value if callbacks have already been enabled. |
| 55 |
|
| */ |
| 56 |
10796 |
| static void dds_enqueue(pTHX_ dds_ctx *ctx, SV *sv, UV depth, SV *name, bool direct) |
| 57 |
|
| { |
| 58 |
|
| dds_queue_entry *entry; |
| 59 |
|
| dds_queue_level *level; |
| 60 |
10796 |
| UV position = ctx->queue_count; |
| 61 |
10796 |
| bool empty = ctx->queue_head == ctx->queue_count; |
| 62 |
|
| |
| 63 |
10796 |
▶ | if (ctx->queue_count == ctx->queue_capacity) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->queue_count == ctx->queue_capacity) { |
702 |
10094 |
10796 |
|
| 64 |
702 |
▶ | ctx->queue_capacity = ctx->queue_capacity ? ctx->queue_capacity * 2 : 64; |
Branch: 1 branch
| Branch | True | False | Total |
| ctx->queue_capacity = ctx->queue_capacity ? ctx->queue_capacity * 2 : 64; |
62 |
640 |
702 |
|
| 65 |
702 |
▶ | Renew(ctx->queue, ctx->queue_capacity, dds_queue_entry); |
Branch: 1 branch
| Branch | True | False | Total |
| Renew(ctx->queue, ctx->queue_capacity, dds_queue_entry); |
0 |
702 |
702 |
|
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
10796 |
| entry = &ctx->queue[ctx->queue_count++]; |
| 69 |
10796 |
| entry->sv = sv; |
| 70 |
10796 |
| entry->depth = depth; |
| 71 |
10796 |
| entry->name = newSVsv(name); |
| 72 |
10796 |
| entry->direct = direct; |
| 73 |
10796 |
| entry->next = 0; |
| 74 |
|
| |
| 75 |
10796 |
▶ | if (depth >= ctx->queue_level_capacity) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (depth >= ctx->queue_level_capacity) { |
659 |
10137 |
10796 |
|
| 76 |
659 |
▶ | UV old = ctx->queue_level_capacity, capacity = old ? old : 16; |
Branch: 1 branch
| Branch | True | False | Total |
| UV old = ctx->queue_level_capacity, capacity = old ? old : 16; |
19 |
640 |
659 |
|
| 77 |
|
| |
| 78 |
678 |
▶ | while (capacity <= depth) |
Branch: 1 branch
| Branch | True | False | Total |
| while (capacity <= depth) |
19 |
659 |
678 |
|
| 79 |
19 |
| capacity *= 2; |
| 80 |
659 |
▶ | Renew(ctx->queue_levels, capacity, dds_queue_level); |
Branch: 1 branch
| Branch | True | False | Total |
| Renew(ctx->queue_levels, capacity, dds_queue_level); |
0 |
659 |
659 |
|
| 81 |
659 |
▶ | Zero(ctx->queue_levels + old, capacity - old, dds_queue_level); |
Branch: 1 branch
| Branch | True | False | Total |
| Zero(ctx->queue_levels + old, capacity - old, dds_queue_level); |
0 |
659 |
659 |
|
| 82 |
659 |
| ctx->queue_level_capacity = capacity; |
| 83 |
|
| } |
| 84 |
|
| |
| 85 |
|
| /* Glob slots add a different depth offset from ordinary children. |
| 86 |
|
| * FIFO within each depth keeps first-name ties stable while ensuring |
| 87 |
|
| * that no referent expands before a shorter queued route to it. */ |
| 88 |
10796 |
| level = &ctx->queue_levels[depth]; |
| 89 |
10796 |
▶ | if (level->tail) |
Branch: 1 branch
| Branch | True | False | Total |
| if (level->tail) |
6854 |
3942 |
10796 |
|
| 90 |
6854 |
| ctx->queue[level->tail - 1].next = position + 1; |
| 91 |
|
| else |
| 92 |
3942 |
| level->head = position + 1; |
| 93 |
10796 |
| level->tail = position + 1; |
| 94 |
|
| |
| 95 |
10796 |
▶ | if (empty || depth < ctx->queue_depth) |
Branch: 2 branches
| Branch | True | False | Total |
| if (empty || depth < ctx->queue_depth) |
7581 |
3215 |
10796 |
| if (empty || depth < ctx->queue_depth) |
6 |
7575 |
7581 |
|
| 96 |
3221 |
| ctx->queue_depth = depth; |
| 97 |
10796 |
▶ | if (ctx->queue_count - ctx->queue_head > ctx->queue_peak) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->queue_count - ctx->queue_head > ctx->queue_peak) |
6208 |
4588 |
10796 |
|
| 98 |
6208 |
| ctx->queue_peak = ctx->queue_count - ctx->queue_head; |
| 99 |
|
| |
| 100 |
10796 |
▶ | if (ctx->callbacks) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->callbacks) |
730 |
10066 |
10796 |
|
| 101 |
730 |
| av_push(ctx->keepalive, SvREFCNT_inc(sv)); |
| 102 |
10796 |
| } |
| 103 |
|
| |
| 104 |
|
| /* Remove the next item from the shallowest nonempty depth bucket, preserving |
| 105 |
|
| * FIFO order among paths at that depth. |
| 106 |
|
| */ |
| 107 |
10796 |
| static UV dds_dequeue(dds_ctx *ctx) |
| 108 |
|
| { |
| 109 |
|
| dds_queue_level *level; |
| 110 |
|
| UV position; |
| 111 |
|
| |
| 112 |
12064 |
▶ | while (!ctx->queue_levels[ctx->queue_depth].head) |
Branch: 1 branch
| Branch | True | False | Total |
| while (!ctx->queue_levels[ctx->queue_depth].head) |
1268 |
10796 |
12064 |
|
| 113 |
1268 |
| ctx->queue_depth++; |
| 114 |
10796 |
| level = &ctx->queue_levels[ctx->queue_depth]; |
| 115 |
10796 |
| position = level->head - 1; |
| 116 |
10796 |
| level->head = ctx->queue[position].next; |
| 117 |
10796 |
▶ | if (!level->head) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!level->head) |
3942 |
6854 |
10796 |
|
| 118 |
3942 |
| level->tail = 0; |
| 119 |
10796 |
| ctx->queue_head++; |
| 120 |
|
| |
| 121 |
10796 |
| return position; |
| 122 |
|
| } |
| 123 |
|
| |
| 124 |
|
| /* Return the borrowed scalar, hash, array, code or format slot selected from a |
| 125 |
|
| * glob, without creating an absent slot. |
| 126 |
|
| */ |
| 127 |
665 |
| static SV *dds_glob_slot(pTHX_ GV *gv, UV slot) |
| 128 |
|
| { |
| 129 |
665 |
| switch (slot) { |
| 130 |
133 |
| case 0: |
| 131 |
133 |
| return GvSV(gv); |
| 132 |
133 |
| case 1: |
| 133 |
133 |
| return (SV *)GvHV(gv); |
| 134 |
133 |
| case 2: |
| 135 |
133 |
| return (SV *)GvAV(gv); |
| 136 |
133 |
| case 3: |
| 137 |
133 |
| return (SV *)GvCV(gv); |
| 138 |
133 |
| case 4: |
| 139 |
133 |
| return (SV *)GvFORM(gv); |
| 140 |
|
| } |
| 141 |
0 |
| return NULL; |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
|
| /* Schedule a reference or magical scalar for inspection, or schedule the |
| 145 |
|
| * enabled slots of a directly encountered glob. |
| 146 |
|
| */ |
| 147 |
11848 |
| static void dds_enqueue_value(pTHX_ dds_ctx *ctx, SV *sv, UV depth, SV *name) |
| 148 |
|
| { |
| 149 |
11848 |
▶ | if (SvROK(sv) || SvGMAGICAL(sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(sv) || SvGMAGICAL(sv)) |
1211 |
10637 |
11848 |
| if (SvROK(sv) || SvGMAGICAL(sv)) |
9 |
1202 |
1211 |
|
| 150 |
10646 |
| dds_enqueue(aTHX_ ctx, sv, depth, name, FALSE); |
| 151 |
1202 |
▶ | else if (SvTYPE(sv) == SVt_PVGV && ctx->style.dumpglob) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (SvTYPE(sv) == SVt_PVGV && ctx->style.dumpglob) { |
136 |
1066 |
1202 |
| else if (SvTYPE(sv) == SVt_PVGV && ctx->style.dumpglob) { |
133 |
3 |
136 |
|
| 152 |
133 |
▶ | UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 5 : 3; |
Branch: 2 branches
| Branch | True | False | Total |
| UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 5 : 3; |
133 |
0 |
133 |
| UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 5 : 3; |
133 |
0 |
133 |
|
| 153 |
|
| static const char *slots[] = {"SCALAR", "HASH", "ARRAY", "CODE", "FORMAT"}; |
| 154 |
133 |
| SV *glob_name = dds_glob_name(aTHX_(GV *) sv); |
| 155 |
|
| |
| 156 |
133 |
▶ | if (strnEQ(DDS_PV(glob_name), "*Symbol::GEN", 12)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strnEQ(DDS_PV(glob_name), "*Symbol::GEN", 12)) { |
66 |
67 |
133 |
|
| 157 |
66 |
| SV *base = dds_underef(aTHX_ name); |
| 158 |
|
| |
| 159 |
66 |
▶ | glob_name = dds_child_name(aTHX_ base ? base : name, '*', NULL, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| glob_name = dds_child_name(aTHX_ base ? base : name, '*', NULL, 0); |
65 |
1 |
66 |
|
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
798 |
▶ | for (i = 0; i < limit; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < limit; i++) { |
665 |
133 |
798 |
|
| 163 |
665 |
| SV *value = dds_glob_slot(aTHX_(GV *) sv, i); |
| 164 |
|
| SV *path; |
| 165 |
|
| |
| 166 |
665 |
▶ | if (!value || (i == 0 && !SvOK(value))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!value || (i == 0 && !SvOK(value))) |
150 |
515 |
665 |
| if (!value || (i == 0 && !SvOK(value))) |
24 |
126 |
150 |
| if (!value || (i == 0 && !SvOK(value))) |
0 |
24 |
24 |
|
| 167 |
515 |
| continue; |
| 168 |
|
| |
| 169 |
150 |
| path = DDS_TEMP(newSVsv(glob_name)); |
| 170 |
150 |
| sv_catpvf(path, "{%s}", slots[i]); |
| 171 |
150 |
| dds_enqueue(aTHX_ ctx, value, depth + 1, path, TRUE); |
| 172 |
|
| } |
| 173 |
|
| } |
| 174 |
11848 |
| } |
| 175 |
|
| |
| 176 |
|
| /* Register a child scalar slot and queue its value using the corresponding |
| 177 |
|
| * path, with scratch values scoped to this visit. |
| 178 |
|
| */ |
| 179 |
9861 |
| static void dds_analyze_child(pTHX_ dds_ctx *ctx, SV *sv, UV depth, SV *parent, char kind, SV *key, |
| 180 |
|
| IV child_index) |
| 181 |
|
| { |
| 182 |
|
| SV *path; |
| 183 |
|
| |
| 184 |
9861 |
| ENTER; |
| 185 |
9861 |
| SAVETMPS; |
| 186 |
9861 |
| path = dds_child_name(aTHX_ parent, kind, key, child_index); |
| 187 |
9861 |
| dds_register_slot(aTHX_ ctx, sv, depth + 1, path, SvREFCNT(sv) + dds_weak_count(aTHX_ sv), |
| 188 |
|
| FALSE); |
| 189 |
9861 |
| dds_enqueue_value(aTHX_ ctx, sv, depth + 2, path); |
| 190 |
9861 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
9861 |
0 |
9861 |
|
| 191 |
9861 |
| LEAVE; |
| 192 |
9861 |
| } |
| 193 |
|
| |
| 194 |
|
| #if defined(class_object_to_hash) && defined(PERL_MAGIC_class_storage) |
| 195 |
|
| /* Choose a private class-field variable name that does not collide with any |
| 196 |
|
| * current root expression. |
| 197 |
|
| */ |
| 198 |
|
| static SV *dds_class_fields_name(pTHX_ dds_ctx *ctx) |
| 199 |
|
| { |
| 200 |
|
| SV *name = DDS_TEMP(newSV(0)); |
| 201 |
|
| bool conflict; |
| 202 |
|
| |
| 203 |
|
| do { |
| 204 |
|
| UV i; |
| 205 |
|
| const char *identifier; |
| 206 |
|
| |
| 207 |
|
| conflict = FALSE; |
| 208 |
|
| sv_setpvf(name, "$__DDS_class_fields_%" UVuf, ++ctx->class_serial); |
| 209 |
|
| identifier = DDS_PV(name) + 1; |
| 210 |
|
| |
| 211 |
|
| for (i = 0; i < ctx->root_count; i++) { |
| 212 |
|
| if (strstr(DDS_PV(ctx->roots[i].name), identifier)) { |
| 213 |
|
| conflict = TRUE; |
| 214 |
|
| break; |
| 215 |
|
| } |
| 216 |
|
| } |
| 217 |
|
| } while (conflict); |
| 218 |
|
| |
| 219 |
|
| return name; |
| 220 |
|
| } |
| 221 |
|
| |
| 222 |
|
| /* Snapshot XPerl class fields into owned metadata and queue that snapshot |
| 223 |
|
| * separately from the object's ordinary payload. |
| 224 |
|
| */ |
| 225 |
|
| static void dds_analyze_class(pTHX_ dds_ctx *ctx, dds_node *node, SV *target, UV depth) |
| 226 |
|
| { |
| 227 |
|
| MAGIC *storage; |
| 228 |
|
| SV *rv; |
| 229 |
|
| |
| 230 |
|
| if (!SvOBJECT(target) || !SvMAGICAL(target)) |
| 231 |
|
| return; |
| 232 |
|
| storage = mg_find(target, PERL_MAGIC_class_storage); |
| 233 |
|
| if (!storage || !storage->mg_obj) |
| 234 |
|
| return; |
| 235 |
|
| |
| 236 |
|
| /* The snapshot shares field slots with the object. Keep it separate |
| 237 |
|
| * from the public payload so alias fixups finish before hydration. */ |
| 238 |
|
| rv = DDS_TEMP(newRV_inc(target)); |
| 239 |
|
| node->class_fields = class_object_to_hash(rv); |
| 240 |
|
| (void)hv_delete((HV *)SvRV(node->class_fields), "$self", 5, G_DISCARD); |
| 241 |
|
| node->class_fields_name = newSVsv(dds_class_fields_name(aTHX_ ctx)); |
| 242 |
|
| if (strchr("@%&", DDS_PV(node->ref.name)[0])) |
| 243 |
|
| node->class_package = newSVsv(dds_class(aTHX_ target)); |
| 244 |
|
| |
| 245 |
|
| if (ctx->class_tail) |
| 246 |
|
| ctx->class_tail->class_next = node; |
| 247 |
|
| else |
| 248 |
|
| ctx->class_head = node; |
| 249 |
|
| ctx->class_tail = node; |
| 250 |
|
| |
| 251 |
|
| dds_enqueue(aTHX_ ctx, node->class_fields, depth + 2, node->class_fields_name, FALSE); |
| 252 |
|
| } |
| 253 |
|
| #endif |
| 254 |
|
| |
| 255 |
|
| /* Test object-address and class-name ignore policies before expanding a |
| 256 |
|
| * referent. |
| 257 |
|
| */ |
| 258 |
10793 |
| static bool dds_ignored(pTHX_ dds_ctx *ctx, SV *target) |
| 259 |
|
| { |
| 260 |
10793 |
| HV *style = dds_hash(aTHX_ ctx->object, "style", FALSE); |
| 261 |
10793 |
| HV *ignore = dds_hash(aTHX_ style, "ignore", FALSE); |
| 262 |
10793 |
| SV *address = DDS_TEMP(newSVpvf("#%" UVuf, PTR2UV(target))); |
| 263 |
10793 |
| SV *class_name = dds_class(aTHX_ target); |
| 264 |
|
| |
| 265 |
10793 |
▶ | if (SvTRUE(dds_hget_sv(aTHX_ ignore, address))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(dds_hget_sv(aTHX_ ignore, address))) |
0 |
10793 |
10793 |
|
| 266 |
0 |
| return TRUE; |
| 267 |
10793 |
▶ | if (SvOK(class_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) { |
523 |
10270 |
10793 |
|
| 268 |
523 |
| SV *key = DDS_TEMP(newSVpvs(".")); |
| 269 |
|
| |
| 270 |
523 |
| DDS_CAT(key, class_name); |
| 271 |
523 |
▶ | if (SvTRUE(dds_hget_sv(aTHX_ ignore, key))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(dds_hget_sv(aTHX_ ignore, key))) |
3 |
520 |
523 |
|
| 272 |
3 |
| return TRUE; |
| 273 |
|
| } |
| 274 |
10790 |
| return FALSE; |
| 275 |
|
| } |
| 276 |
|
| |
| 277 |
|
| /* Discover a closure's captured variables, choose distinct lexical names and |
| 278 |
|
| * queue their values for graph analysis. |
| 279 |
|
| */ |
| 280 |
53 |
| static void dds_collect_lexicals(pTHX_ dds_ctx *ctx, SV *target, HV *lexrefs, HV *names, HV *used) |
| 281 |
|
| { |
| 282 |
|
| SV *args[1], *result; |
| 283 |
|
| HV *values; |
| 284 |
|
| HE *he; |
| 285 |
|
| |
| 286 |
53 |
| args[0] = DDS_TEMP(newRV_inc(target)); |
| 287 |
53 |
| result = dds_call(aTHX_ ctx, "Data::Dump::Streamer::_get_lexicals", NULL, G_SCALAR, 1, args); |
| 288 |
53 |
▶ | if (!SvROK(result) || SvTYPE(SvRV(result)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(result) || SvTYPE(SvRV(result)) != SVt_PVHV) |
53 |
0 |
53 |
| if (!SvROK(result) || SvTYPE(SvRV(result)) != SVt_PVHV) |
0 |
53 |
53 |
|
| 289 |
0 |
| return; |
| 290 |
|
| |
| 291 |
53 |
| values = (HV *)SvRV(result); |
| 292 |
53 |
| hv_iterinit(values); |
| 293 |
137 |
▶ | while ((he = hv_iternext(values))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(values))) { |
84 |
53 |
137 |
|
| 294 |
84 |
| SV *name = hv_iterkeysv(he), *rv = HeVAL(he), *address; |
| 295 |
|
| STRLEN len, i; |
| 296 |
84 |
| const char *p = SvPV(name, len); |
| 297 |
84 |
| bool numeric = TRUE; |
| 298 |
|
| |
| 299 |
84 |
▶ | if (!SvROK(rv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(rv)) |
0 |
84 |
84 |
|
| 300 |
54 |
| continue; |
| 301 |
|
| |
| 302 |
128 |
▶ | for (i = 0; i < len; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) |
86 |
42 |
128 |
|
| 303 |
86 |
▶ | if (!isDIGIT_A(p[i])) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isDIGIT_A(p[i])) { |
42 |
44 |
86 |
|
| 304 |
42 |
| numeric = FALSE; |
| 305 |
42 |
| break; |
| 306 |
|
| } |
| 307 |
84 |
▶ | if (numeric) |
Branch: 1 branch
| Branch | True | False | Total |
| if (numeric) |
42 |
42 |
84 |
|
| 308 |
42 |
| continue; |
| 309 |
|
| |
| 310 |
42 |
| address = DDS_TEMP(newSVuv(PTR2UV(SvRV(rv)))); |
| 311 |
42 |
▶ | if (hv_exists_ent(lexrefs, address, 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(lexrefs, address, 0)) |
12 |
30 |
42 |
|
| 312 |
12 |
| continue; |
| 313 |
|
| |
| 314 |
30 |
▶ | if (hv_exists_ent(used, name, 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(used, name, 0)) { |
7 |
23 |
30 |
|
| 315 |
7 |
| HV *style = dds_hash(aTHX_ ctx->object, "style", FALSE); |
| 316 |
7 |
| SV *format = dds_hget(aTHX_ style, "eclipsename"); |
| 317 |
|
| SV *args2[3], *new_name; |
| 318 |
7 |
| UV n = SvUV(dds_hget_sv(aTHX_ used, name)) + 1; |
| 319 |
|
| |
| 320 |
7 |
| hv_store_ent(used, name, newSVuv(n), 0); |
| 321 |
7 |
| args2[0] = name; |
| 322 |
7 |
| args2[1] = format; |
| 323 |
7 |
| args2[2] = DDS_TEMP(newSVuv(n)); |
| 324 |
7 |
| new_name = dds_call(aTHX_ ctx, "Data::Dump::Streamer::_xs_eclipse_name", NULL, G_SCALAR, |
| 325 |
|
| 3, args2); |
| 326 |
7 |
| name = new_name; |
| 327 |
|
| } else |
| 328 |
23 |
| hv_store_ent(used, name, newSVuv(0), 0); |
| 329 |
|
| |
| 330 |
30 |
| hv_store_ent(lexrefs, address, newSVsv(rv), 0); |
| 331 |
30 |
| hv_store_ent(names, address, newSVsv(name), 0); |
| 332 |
30 |
| hv_store_ent(ctx->lexical_names, address, newSVsv(name), 0); |
| 333 |
30 |
| dds_enqueue_value(aTHX_ ctx, rv, 2, name); |
| 334 |
|
| } |
| 335 |
|
| } |
| 336 |
|
| |
| 337 |
|
| /* Visit existing array slots, counting all visits but registering and |
| 338 |
|
| * expanding only values that need graph analysis. |
| 339 |
|
| */ |
| 340 |
3146 |
| static void dds_analyze_array(pTHX_ dds_ctx *ctx, SV *target, UV depth, SV *name) |
| 341 |
|
| { |
| 342 |
|
| SSize_t k, last; |
| 343 |
|
| |
| 344 |
3146 |
▶ | if (SvTIED_mg(target, PERL_MAGIC_tied)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTIED_mg(target, PERL_MAGIC_tied)) |
284 |
2862 |
3146 |
| if (SvTIED_mg(target, PERL_MAGIC_tied)) |
1 |
283 |
284 |
|
| 345 |
1 |
| dds_callback_guard(aTHX_ ctx); |
| 346 |
3146 |
| last = av_len((AV *)target); |
| 347 |
10928 |
▶ | for (k = 0; k <= last; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k <= last; k++) { |
7782 |
3146 |
10928 |
|
| 348 |
7782 |
| SV **value = av_fetch((AV *)target, k, 0); |
| 349 |
|
| |
| 350 |
7782 |
▶ | if (!value) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value) |
0 |
7782 |
7782 |
|
| 351 |
0 |
| continue; |
| 352 |
|
| |
| 353 |
7782 |
| ctx->visits++; |
| 354 |
7782 |
▶ | if (!dds_candidate(aTHX_ * value) && !SvROK(*value) && !SvGMAGICAL(*value) && |
Branch: 3 branches
| Branch | True | False | Total |
| if (!dds_candidate(aTHX_ * value) && !SvROK(*value) && !SvGMAGICAL(*value) && |
7072 |
710 |
7782 |
| if (!dds_candidate(aTHX_ * value) && !SvROK(*value) && !SvGMAGICAL(*value) && |
1561 |
5511 |
7072 |
| if (!dds_candidate(aTHX_ * value) && !SvROK(*value) && !SvGMAGICAL(*value) && |
1558 |
3 |
1561 |
|
| 355 |
1558 |
▶ | SvTYPE(*value) != SVt_PVGV) |
Branch: 1 branch
| Branch | True | False | Total |
| SvTYPE(*value) != SVt_PVGV) |
1558 |
0 |
1558 |
|
| 356 |
1558 |
| continue; |
| 357 |
6224 |
| dds_analyze_child(aTHX_ ctx, *value, depth, name, '[', NULL, k); |
| 358 |
|
| } |
| 359 |
3146 |
| } |
| 360 |
|
| |
| 361 |
|
| /* Visit hash values in the selected key order, retaining any thaw action and |
| 362 |
|
| * measuring key widths for later alignment. |
| 363 |
|
| */ |
| 364 |
1716 |
| static void dds_analyze_hash(pTHX_ dds_ctx *ctx, dds_node *node, SV *target, UV depth, SV *name) |
| 365 |
|
| { |
| 366 |
1716 |
| SV *thaw = NULL; |
| 367 |
1716 |
| AV *keys = dds_keys(aTHX_ ctx, (HV *)target, 0, &thaw); |
| 368 |
|
| SSize_t k; |
| 369 |
1715 |
| UV max = 0, sum = 0, count = 0; |
| 370 |
|
| |
| 371 |
1715 |
▶ | if (thaw) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (thaw) { |
0 |
1715 |
1715 |
|
| 372 |
0 |
▶ | if (!node) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!node) |
0 |
0 |
0 |
|
| 373 |
0 |
| node = dds_find(aTHX_ ctx, target, TRUE); |
| 374 |
0 |
| SvREFCNT_dec(node->thaw); |
| 375 |
0 |
| node->thaw = newSVsv(thaw); |
| 376 |
|
| } |
| 377 |
|
| |
| 378 |
18464 |
▶ | for (k = 0; k <= av_len(keys); k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k <= av_len(keys); k++) { |
16749 |
1715 |
18464 |
|
| 379 |
16749 |
| SV **key = av_fetch(keys, k, 0); |
| 380 |
|
| HE *he; |
| 381 |
|
| SV *value; |
| 382 |
|
| |
| 383 |
16749 |
▶ | if (!key || !SvOK(*key)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!key || !SvOK(*key)) |
16749 |
0 |
16749 |
| if (!key || !SvOK(*key)) |
16749 |
0 |
16749 |
|
| 384 |
|
| break; |
| 385 |
16749 |
| he = hv_fetch_ent((HV *)target, *key, 0, 0); |
| 386 |
16749 |
▶ | value = he ? HeVAL(he) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| value = he ? HeVAL(he) : &PL_sv_undef; |
16749 |
0 |
16749 |
|
| 387 |
16749 |
| ctx->visits++; |
| 388 |
|
| |
| 389 |
16749 |
▶ | if (ctx->style.indentkeys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->style.indentkeys) { |
16749 |
0 |
16749 |
|
| 390 |
|
| STRLEN width; |
| 391 |
|
| |
| 392 |
16749 |
| ENTER; |
| 393 |
16749 |
| SAVETMPS; |
| 394 |
16749 |
| width = sv_len_utf8(dds_quote(aTHX_ * key, TRUE)); |
| 395 |
16749 |
| sum += width; |
| 396 |
16749 |
▶ | if (max < width) |
Branch: 1 branch
| Branch | True | False | Total |
| if (max < width) |
2000 |
14749 |
16749 |
|
| 397 |
2000 |
| max = width; |
| 398 |
16749 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
16749 |
0 |
16749 |
|
| 399 |
16749 |
| LEAVE; |
| 400 |
|
| } |
| 401 |
|
| |
| 402 |
16749 |
| count++; |
| 403 |
16749 |
▶ | if (!dds_candidate(aTHX_ value) && !SvROK(value) && !SvGMAGICAL(value) && |
Branch: 3 branches
| Branch | True | False | Total |
| if (!dds_candidate(aTHX_ value) && !SvROK(value) && !SvGMAGICAL(value) && |
16715 |
34 |
16749 |
| if (!dds_candidate(aTHX_ value) && !SvROK(value) && !SvGMAGICAL(value) && |
13814 |
2901 |
16715 |
| if (!dds_candidate(aTHX_ value) && !SvROK(value) && !SvGMAGICAL(value) && |
13812 |
2 |
13814 |
|
| 404 |
13812 |
▶ | SvTYPE(value) != SVt_PVGV) |
Branch: 1 branch
| Branch | True | False | Total |
| SvTYPE(value) != SVt_PVGV) |
13809 |
3 |
13812 |
|
| 405 |
13809 |
| continue; |
| 406 |
2940 |
| dds_analyze_child(aTHX_ ctx, value, depth, name, '{', *key, 0); |
| 407 |
|
| } |
| 408 |
|
| |
| 409 |
1715 |
▶ | if (node) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node) { |
999 |
716 |
1715 |
|
| 410 |
999 |
▶ | NV avg = count ? (NV)sum / count : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| NV avg = count ? (NV)sum / count : 0; |
985 |
14 |
999 |
|
| 411 |
|
| |
| 412 |
999 |
▶ | node->key_width = max > 8 && (2.0 / 3.0 * max) > avg ? (UV)(0.5 + avg) : max; |
Branch: 2 branches
| Branch | True | False | Total |
| node->key_width = max > 8 && (2.0 / 3.0 * max) > avg ? (UV)(0.5 + avg) : max; |
0 |
999 |
999 |
| node->key_width = max > 8 && (2.0 / 3.0 * max) > avg ? (UV)(0.5 + avg) : max; |
0 |
0 |
0 |
|
| 413 |
999 |
| node->key_count = count; |
| 414 |
|
| } |
| 415 |
1715 |
| } |
| 416 |
|
| |
| 417 |
|
| /* Analyze one queued value in its own temporary scope. Callback guards retain |
| 418 |
|
| * live traversal work before Perl code can mutate the graph. */ |
| 419 |
10796 |
| static void dds_analyze_entry(pTHX_ dds_ctx *ctx, UV position, UV pass, HV *lexrefs, HV *lexnames, |
| 420 |
|
| HV *used_names) |
| 421 |
|
| { |
| 422 |
10796 |
| dds_queue_entry entry = ctx->queue[position]; |
| 423 |
|
| dds_active active; |
| 424 |
10796 |
| SV *target, *name = entry.name; |
| 425 |
10796 |
| UV depth = entry.depth; |
| 426 |
10796 |
| dds_node *node = NULL; |
| 427 |
10796 |
| bool replacement = FALSE; |
| 428 |
|
| |
| 429 |
10796 |
| ENTER; |
| 430 |
10796 |
| SAVETMPS; |
| 431 |
|
| |
| 432 |
|
| /* Transfer this queue entry's name to the work-item scope. |
| 433 |
|
| * Nodes and newly queued entries take their own copies. */ |
| 434 |
10796 |
| ctx->queue[position].name = NULL; |
| 435 |
10796 |
| DDS_TEMP(name); |
| 436 |
10796 |
| Zero(&active, 1, dds_active); |
| 437 |
10796 |
| active.sv = entry.sv; |
| 438 |
10796 |
| ctx->active = &active; |
| 439 |
10796 |
| ctx->visits++; |
| 440 |
|
| |
| 441 |
10798 |
▶ | if (strnEQ(DDS_PV(name), "*DB::args", 9) && (DDS_PV(name)[9] == '\0' || DDS_PV(name)[9] == '{')) |
Branch: 3 branches
| Branch | True | False | Total |
| if (strnEQ(DDS_PV(name), "*DB::args", 9) && (DDS_PV(name)[9] == '\0' || DDS_PV(name)[9] == '{')) |
1 |
10795 |
10796 |
| if (strnEQ(DDS_PV(name), "*DB::args", 9) && (DDS_PV(name)[9] == '\0' || DDS_PV(name)[9] == '{')) |
1 |
0 |
1 |
| if (strnEQ(DDS_PV(name), "*DB::args", 9) && (DDS_PV(name)[9] == '\0' || DDS_PV(name)[9] == '{')) |
0 |
1 |
1 |
|
| 442 |
0 |
| goto entry_done; |
| 443 |
|
| |
| 444 |
10796 |
▶ | if (SvGMAGICAL(entry.sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvGMAGICAL(entry.sv)) { |
10 |
10786 |
10796 |
|
| 445 |
10 |
| av_push(ctx->keepalive, SvREFCNT_inc(entry.sv)); |
| 446 |
10 |
| dds_callback_guard(aTHX_ ctx); |
| 447 |
10 |
| mg_get(entry.sv); |
| 448 |
|
| } |
| 449 |
|
| |
| 450 |
10796 |
▶ | if (!entry.direct && !SvROK(entry.sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!entry.direct && !SvROK(entry.sv)) |
10646 |
150 |
10796 |
| if (!entry.direct && !SvROK(entry.sv)) |
3 |
10643 |
10646 |
|
| 451 |
3 |
| goto entry_done; |
| 452 |
10793 |
▶ | target = entry.direct ? entry.sv : SvRV(entry.sv); |
Branch: 1 branch
| Branch | True | False | Total |
| target = entry.direct ? entry.sv : SvRV(entry.sv); |
150 |
10643 |
10793 |
|
| 453 |
10793 |
▶ | if (dds_ignored(aTHX_ ctx, target)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dds_ignored(aTHX_ ctx, target)) |
3 |
10790 |
10793 |
|
| 454 |
3 |
| goto entry_done; |
| 455 |
|
| |
| 456 |
|
| /* Resolve a freezer once per object, then analyze its proxy. */ |
| 457 |
10790 |
▶ | if (SvOBJECT(target)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(target)) { |
520 |
10270 |
10790 |
|
| 458 |
|
| SV *args[1], *frozen; |
| 459 |
|
| |
| 460 |
520 |
| node = dds_find(aTHX_ ctx, target, TRUE); |
| 461 |
520 |
▶ | if (node->frozen) |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->frozen) |
180 |
340 |
520 |
|
| 462 |
190 |
| goto entry_done; |
| 463 |
340 |
| node->frozen = TRUE; |
| 464 |
340 |
▶ | args[0] = entry.direct ? DDS_TEMP(newRV_inc(target)) : entry.sv; |
Branch: 1 branch
| Branch | True | False | Total |
| args[0] = entry.direct ? DDS_TEMP(newRV_inc(target)) : entry.sv; |
27 |
313 |
340 |
|
| 465 |
340 |
| av_push(ctx->keepalive, SvREFCNT_inc(target)); |
| 466 |
340 |
| frozen = dds_freeze(aTHX_ ctx, args[0]); |
| 467 |
339 |
▶ | if (SvROK(frozen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(frozen)) { |
85 |
254 |
339 |
|
| 468 |
85 |
| AV *values = (AV *)SvRV(frozen); |
| 469 |
85 |
| SV **proxy = av_fetch(values, 0, 0); |
| 470 |
85 |
| SV **thaw = av_fetch(values, 1, 0); |
| 471 |
85 |
| SV **postop = av_fetch(values, 2, 0); |
| 472 |
|
| |
| 473 |
85 |
▶ | if (thaw && SvTRUE(*thaw)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (thaw && SvTRUE(*thaw)) |
32 |
53 |
85 |
| if (thaw && SvTRUE(*thaw)) |
4 |
28 |
32 |
|
| 474 |
4 |
| node->thaw = newSVsv(*thaw); |
| 475 |
85 |
▶ | if (postop && SvTRUE(*postop)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (postop && SvTRUE(*postop)) |
28 |
57 |
85 |
| if (postop && SvTRUE(*postop)) |
28 |
0 |
28 |
|
| 476 |
28 |
| node->postop = newSVsv(*postop); |
| 477 |
|
| |
| 478 |
85 |
▶ | if (proxy && SvOK(*proxy) && !SvROK(*proxy) && !SvTRUE(*proxy)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (proxy && SvOK(*proxy) && !SvROK(*proxy) && !SvTRUE(*proxy)) { |
82 |
3 |
85 |
| if (proxy && SvOK(*proxy) && !SvROK(*proxy) && !SvTRUE(*proxy)) { |
79 |
3 |
82 |
| if (proxy && SvOK(*proxy) && !SvROK(*proxy) && !SvTRUE(*proxy)) { |
10 |
69 |
79 |
| if (proxy && SvOK(*proxy) && !SvROK(*proxy) && !SvTRUE(*proxy)) { |
10 |
0 |
10 |
|
| 479 |
10 |
| node->ignored = TRUE; |
| 480 |
10 |
| goto entry_done; |
| 481 |
|
| } |
| 482 |
|
| |
| 483 |
75 |
▶ | if (proxy && SvOK(*proxy) && (!SvROK(*proxy) || SvRV(*proxy) != target)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (proxy && SvOK(*proxy) && (!SvROK(*proxy) || SvRV(*proxy) != target)) { |
72 |
3 |
75 |
| if (proxy && SvOK(*proxy) && (!SvROK(*proxy) || SvRV(*proxy) != target)) { |
69 |
3 |
72 |
| if (proxy && SvOK(*proxy) && (!SvROK(*proxy) || SvRV(*proxy) != target)) { |
69 |
0 |
69 |
| if (proxy && SvOK(*proxy) && (!SvROK(*proxy) || SvRV(*proxy) != target)) { |
69 |
0 |
69 |
|
| 484 |
69 |
| node->proxy = newSVsv(*proxy); |
| 485 |
69 |
▶ | if (!SvROK(*proxy)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(*proxy)) |
0 |
69 |
69 |
|
| 486 |
0 |
| goto entry_done; |
| 487 |
69 |
| target = SvRV(*proxy); |
| 488 |
69 |
| replacement = TRUE; |
| 489 |
69 |
| node = NULL; |
| 490 |
|
| } |
| 491 |
|
| } |
| 492 |
|
| } |
| 493 |
|
| |
| 494 |
|
| /* Only possible sharing needs a persistent catalogue entry. |
| 495 |
|
| * A unique ordinary referent can expand without one. */ |
| 496 |
10599 |
▶ | if (!node) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!node) { |
10339 |
260 |
10599 |
|
| 497 |
|
| /* One owned proxy RV can represent several occurrences |
| 498 |
|
| * of the original object, even with referent count one. */ |
| 499 |
20498 |
▶ | bool force = replacement || entry.direct || strchr("@%&", DDS_PV(name)[0]) != NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| bool force = replacement || entry.direct || strchr("@%&", DDS_PV(name)[0]) != NULL; |
10270 |
69 |
10339 |
| bool force = replacement || entry.direct || strchr("@%&", DDS_PV(name)[0]) != NULL; |
10159 |
111 |
10270 |
| bool force = replacement || entry.direct || strchr("@%&", DDS_PV(name)[0]) != NULL; |
115 |
10044 |
10159 |
|
| 500 |
|
| |
| 501 |
10339 |
▶ | if (!force && !entry.direct && dds_candidate(aTHX_ entry.sv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!force && !entry.direct && dds_candidate(aTHX_ entry.sv)) { |
10044 |
295 |
10339 |
| if (!force && !entry.direct && dds_candidate(aTHX_ entry.sv)) { |
10044 |
0 |
10044 |
| if (!force && !entry.direct && dds_candidate(aTHX_ entry.sv)) { |
2373 |
7671 |
10044 |
|
| 502 |
2373 |
| dds_node *slot = dds_find(aTHX_ ctx, entry.sv, FALSE); |
| 503 |
|
| |
| 504 |
2373 |
▶ | force = slot && slot->slot.original; |
Branch: 2 branches
| Branch | True | False | Total |
| force = slot && slot->slot.original; |
1679 |
694 |
2373 |
| force = slot && slot->slot.original; |
15 |
1664 |
1679 |
|
| 505 |
|
| } |
| 506 |
10339 |
▶ | if (force || dds_candidate(aTHX_ target)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (force || dds_candidate(aTHX_ target)) |
10029 |
310 |
10339 |
| if (force || dds_candidate(aTHX_ target)) |
6979 |
3050 |
10029 |
|
| 507 |
7289 |
| node = dds_find(aTHX_ ctx, target, TRUE); |
| 508 |
|
| } |
| 509 |
|
| |
| 510 |
10599 |
▶ | if (node) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node) { |
7549 |
3050 |
10599 |
|
| 511 |
7549 |
| dds_role *role = &node->ref; |
| 512 |
|
| |
| 513 |
7549 |
▶ | if (role->present) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (role->present) { |
4819 |
2730 |
7549 |
|
| 514 |
4819 |
| role->encounters++; |
| 515 |
4819 |
| ctx->repeats++; |
| 516 |
4819 |
| goto entry_done; |
| 517 |
|
| } |
| 518 |
|
| |
| 519 |
2730 |
| role->present = TRUE; |
| 520 |
2730 |
| role->name = newSVsv(name); |
| 521 |
2730 |
| role->depth = depth; |
| 522 |
2730 |
| role->count = SvREFCNT(target) + dds_weak_count(aTHX_ target); |
| 523 |
2730 |
| role->encounters = 1; |
| 524 |
2730 |
| node->expanded = TRUE; |
| 525 |
|
| } |
| 526 |
|
| |
| 527 |
|
| #if defined(class_object_to_hash) && defined(PERL_MAGIC_class_storage) |
| 528 |
|
| if (node) |
| 529 |
|
| dds_analyze_class(aTHX_ ctx, node, target, depth); |
| 530 |
|
| #endif |
| 531 |
|
| |
| 532 |
|
| /* Child slots are one level deeper; their referents add another. */ |
| 533 |
5780 |
▶ | if (SvTYPE(target) == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(target) == SVt_PVAV) { |
3146 |
2634 |
5780 |
|
| 534 |
3146 |
| dds_analyze_array(aTHX_ ctx, target, depth, name); |
| 535 |
2634 |
▶ | } else if (SvTYPE(target) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(target) == SVt_PVHV) { |
1716 |
918 |
2634 |
|
| 536 |
1716 |
| dds_analyze_hash(aTHX_ ctx, node, target, depth, name); |
| 537 |
918 |
▶ | } else if (SvTYPE(target) == SVt_PVCV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(target) == SVt_PVCV) { |
81 |
837 |
918 |
|
| 538 |
81 |
▶ | if (!pass) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pass) |
53 |
28 |
81 |
|
| 539 |
53 |
| dds_collect_lexicals(aTHX_ ctx, target, lexrefs, lexnames, used_names); |
| 540 |
837 |
▶ | } else if (SvTYPE(target) <= SVt_PVMG || SvTYPE(target) == SVt_PVGV) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (SvTYPE(target) <= SVt_PVMG || SvTYPE(target) == SVt_PVGV) { |
267 |
570 |
837 |
| } else if (SvTYPE(target) <= SVt_PVMG || SvTYPE(target) == SVt_PVGV) { |
140 |
127 |
267 |
|
| 541 |
697 |
| dds_analyze_child(aTHX_ ctx, target, depth, name, '$', NULL, 0); |
| 542 |
|
| } |
| 543 |
|
| |
| 544 |
140 |
| entry_done: |
| 545 |
10794 |
| ctx->active = NULL; |
| 546 |
10794 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
10794 |
0 |
10794 |
|
| 547 |
10794 |
| LEAVE; |
| 548 |
10794 |
| } |
| 549 |
|
| |
| 550 |
|
| /* Match discovered closure values to roots, then prepend any missing |
| 551 |
|
| * roots in lexical order. Return whether names or root membership changed. */ |
| 552 |
12 |
| static bool dds_add_lexical_roots(pTHX_ dds_ctx *ctx, HV *lexrefs, HV *lexnames) |
| 553 |
|
| { |
| 554 |
12 |
| AV *add = (AV *)DDS_TEMP((SV *)newAV()); |
| 555 |
12 |
| AV *unames = dds_array(aTHX_ ctx->object, "unames", TRUE); |
| 556 |
|
| HE *he; |
| 557 |
|
| UV i; |
| 558 |
12 |
| bool again = FALSE; |
| 559 |
|
| |
| 560 |
12 |
| hv_iterinit(lexrefs); |
| 561 |
42 |
▶ | while ((he = hv_iternext(lexrefs))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(lexrefs))) { |
30 |
12 |
42 |
|
| 562 |
30 |
| SV *address = hv_iterkeysv(he), *rv = HeVAL(he); |
| 563 |
30 |
| SV *lexname = dds_hget_sv(aTHX_ lexnames, address); |
| 564 |
30 |
| bool found = FALSE; |
| 565 |
|
| |
| 566 |
30 |
| hv_store_ent(ctx->lexical_names, address, newSVsv(lexname), 0); |
| 567 |
76 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
49 |
27 |
76 |
|
| 568 |
49 |
▶ | if (ctx->roots[i].sv == SvRV(rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->roots[i].sv == SvRV(rv)) { |
3 |
46 |
49 |
|
| 569 |
3 |
| SV **user = av_fetch(unames, i, 0); |
| 570 |
|
| |
| 571 |
3 |
| found = TRUE; |
| 572 |
3 |
▶ | if (!user || !SvTRUE(*user)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!user || !SvTRUE(*user)) { |
1 |
2 |
3 |
| if (!user || !SvTRUE(*user)) { |
0 |
1 |
1 |
|
| 573 |
2 |
| const char *p = DDS_PV(lexname); |
| 574 |
2 |
▶ | SV *n = DDS_TEMP(newSVpvf("%s%s", p[0] == '$' ? "" : "*", p + 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *n = DDS_TEMP(newSVpvf("%s%s", p[0] == '$' ? "" : "*", p + 1)); |
2 |
0 |
2 |
|
| 575 |
|
| |
| 576 |
2 |
| av_store(unames, i, newSVsv(n)); |
| 577 |
2 |
| again = TRUE; |
| 578 |
|
| } else { |
| 579 |
2 |
▶ | const char *p = DDS_PV(*user), *old = DDS_PV(lexname); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *p = DDS_PV(*user), *old = DDS_PV(lexname); |
1 |
0 |
1 |
|
| 580 |
1 |
▶ | SV *renamed = DDS_TEMP(newSVpvf("%c%s", old[0], p[0] == '*' ? p + 1 : p)); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *renamed = DDS_TEMP(newSVpvf("%c%s", old[0], p[0] == '*' ? p + 1 : p)); |
0 |
1 |
1 |
|
| 581 |
|
| |
| 582 |
1 |
| hv_store_ent(lexnames, address, newSVsv(renamed), 0); |
| 583 |
|
| } |
| 584 |
3 |
| break; |
| 585 |
|
| } |
| 586 |
|
| } |
| 587 |
30 |
▶ | if (!found) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!found) |
27 |
3 |
30 |
|
| 588 |
27 |
| av_push(add, newSVsv(lexname)); |
| 589 |
|
| } |
| 590 |
|
| |
| 591 |
12 |
▶ | if (av_len(add) >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(add) >= 0) { |
11 |
1 |
12 |
|
| 592 |
11 |
| UV n = av_len(add) + 1, old_count = ctx->root_count; |
| 593 |
|
| |
| 594 |
11 |
| sortsv(AvARRAY(add), n, Perl_sv_cmp); |
| 595 |
11 |
▶ | Renew(ctx->roots, old_count + n, dds_root); |
Branch: 1 branch
| Branch | True | False | Total |
| Renew(ctx->roots, old_count + n, dds_root); |
0 |
11 |
11 |
|
| 596 |
11 |
▶ | Move(ctx->roots, ctx->roots + n, old_count, dds_root); |
Branch: 1 branch
| Branch | True | False | Total |
| Move(ctx->roots, ctx->roots + n, old_count, dds_root); |
0 |
11 |
11 |
|
| 597 |
11 |
▶ | Zero(ctx->roots, n, dds_root); |
Branch: 1 branch
| Branch | True | False | Total |
| Zero(ctx->roots, n, dds_root); |
0 |
11 |
11 |
|
| 598 |
11 |
| av_unshift(unames, n); |
| 599 |
|
| |
| 600 |
38 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
27 |
11 |
38 |
|
| 601 |
27 |
| SV *lexname = *av_fetch(add, i, 0), *rv = NULL; |
| 602 |
27 |
| const char *p = DDS_PV(lexname); |
| 603 |
|
| |
| 604 |
27 |
| hv_iterinit(lexnames); |
| 605 |
58 |
▶ | while ((he = hv_iternext(lexnames))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(lexnames))) { |
58 |
0 |
58 |
|
| 606 |
58 |
▶ | if (sv_cmp(HeVAL(he), lexname) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_cmp(HeVAL(he), lexname) == 0) { |
27 |
31 |
58 |
|
| 607 |
54 |
| rv = dds_hget(aTHX_ lexrefs, DDS_PV(hv_iterkeysv(he))); |
| 608 |
27 |
| break; |
| 609 |
|
| } |
| 610 |
|
| } |
| 611 |
|
| |
| 612 |
27 |
▶ | if (!rv || !SvROK(rv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!rv || !SvROK(rv)) |
27 |
0 |
27 |
| if (!rv || !SvROK(rv)) |
0 |
27 |
27 |
|
| 613 |
0 |
| croak("Lost closure root"); |
| 614 |
27 |
▶ | if (SvTYPE(SvRV(rv)) == SVt_PVAV || SvTYPE(SvRV(rv)) == SVt_PVHV || |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(SvRV(rv)) == SVt_PVAV || SvTYPE(SvRV(rv)) == SVt_PVHV || |
24 |
3 |
27 |
| if (SvTYPE(SvRV(rv)) == SVt_PVAV || SvTYPE(SvRV(rv)) == SVt_PVHV || |
24 |
0 |
24 |
|
| 615 |
24 |
▶ | SvTYPE(SvRV(rv)) == SVt_PVCV) |
Branch: 1 branch
| Branch | True | False | Total |
| SvTYPE(SvRV(rv)) == SVt_PVCV) |
0 |
24 |
24 |
|
| 616 |
3 |
| ctx->roots[i].sv = newSVsv(rv); |
| 617 |
|
| else |
| 618 |
24 |
| ctx->roots[i].sv = SvREFCNT_inc(SvRV(rv)); |
| 619 |
27 |
| ctx->roots[i].count = SvREFCNT(ctx->roots[i].sv); |
| 620 |
27 |
| ctx->roots[i].lexical = TRUE; |
| 621 |
27 |
▶ | av_store(unames, i, newSVpvf("%s%s", p[0] == '$' ? "" : "*", p + 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_store(unames, i, newSVpvf("%s%s", p[0] == '$' ? "" : "*", p + 1)); |
24 |
3 |
27 |
|
| 622 |
|
| } |
| 623 |
|
| |
| 624 |
11 |
| ctx->root_count = ctx->root_capacity = old_count + n; |
| 625 |
11 |
| again = TRUE; |
| 626 |
|
| } |
| 627 |
|
| |
| 628 |
12 |
| return again; |
| 629 |
|
| } |
| 630 |
|
| |
| 631 |
|
| /* Build the breadth-first catalogue of identities, minimum depths and |
| 632 |
|
| * canonical names, repeating when closure discovery adds or renames roots. |
| 633 |
|
| */ |
| 634 |
1514 |
| void dds_analyze(pTHX_ dds_ctx *ctx) |
| 635 |
|
| { |
| 636 |
1514 |
| UV pass = 0, i; |
| 637 |
1514 |
| HV *lexrefs = (HV *)DDS_TEMP((SV *)newHV()); |
| 638 |
1514 |
| HV *lexnames = (HV *)DDS_TEMP((SV *)newHV()); |
| 639 |
1514 |
| HV *used_names = (HV *)DDS_TEMP((SV *)newHV()); |
| 640 |
|
| bool again; |
| 641 |
|
| |
| 642 |
1514 |
| dds_load_style(aTHX_ ctx); |
| 643 |
|
| |
| 644 |
|
| do { |
| 645 |
1526 |
| again = FALSE; |
| 646 |
1526 |
| dds_clear_catalogue(aTHX_ ctx); |
| 647 |
|
| |
| 648 |
|
| /* Seed every root before expanding any referent. */ |
| 649 |
3483 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
1957 |
1526 |
3483 |
|
| 650 |
1957 |
| dds_root *root = &ctx->roots[i]; |
| 651 |
1957 |
| SV *name = dds_name(aTHX_ ctx, root->sv, i); |
| 652 |
|
| |
| 653 |
1957 |
| SvREFCNT_dec(root->name); |
| 654 |
1957 |
| root->name = newSVsv(name); |
| 655 |
1957 |
▶ | root->analyzed_ref = SvROK(root->sv) ? SvRV(root->sv) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| root->analyzed_ref = SvROK(root->sv) ? SvRV(root->sv) : NULL; |
1298 |
659 |
1957 |
|
| 656 |
1957 |
| dds_register_slot(aTHX_ ctx, root->sv, 1, name, root->count, TRUE); |
| 657 |
1957 |
| dds_enqueue_value(aTHX_ ctx, root->sv, 2, name); |
| 658 |
1957 |
▶ | if (root->lexical) |
Branch: 1 branch
| Branch | True | False | Total |
| if (root->lexical) |
27 |
1930 |
1957 |
|
| 659 |
27 |
| hv_store_ent(ctx->lexical_added, name, newSViv(1), 0); |
| 660 |
|
| } |
| 661 |
|
| |
| 662 |
12320 |
▶ | while (ctx->queue_head < ctx->queue_count) |
Branch: 1 branch
| Branch | True | False | Total |
| while (ctx->queue_head < ctx->queue_count) |
10796 |
1524 |
12320 |
|
| 663 |
10796 |
| dds_analyze_entry(aTHX_ ctx, dds_dequeue(ctx), pass, lexrefs, lexnames, used_names); |
| 664 |
|
| |
| 665 |
1524 |
| ctx->active = NULL; |
| 666 |
|
| |
| 667 |
|
| /* Closure discovery may add roots or improve their names. Rebuild |
| 668 |
|
| * the catalogue so those roots participate in minimum-depth naming. */ |
| 669 |
1524 |
▶ | if (!pass && HvTOTALKEYS(lexrefs)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!pass && HvTOTALKEYS(lexrefs)) |
1512 |
12 |
1524 |
| if (!pass && HvTOTALKEYS(lexrefs)) |
12 |
1500 |
1512 |
|
| 670 |
12 |
| again = dds_add_lexical_roots(aTHX_ ctx, lexrefs, lexnames); |
| 671 |
|
| |
| 672 |
1524 |
| pass++; |
| 673 |
1524 |
▶ | } while (again && pass < 3); |
Branch: 2 branches
| Branch | True | False | Total |
| } while (again && pass < 3); |
12 |
1512 |
1524 |
| } while (again && pass < 3); |
12 |
0 |
12 |
|
| 674 |
|
| |
| 675 |
|
| /* Publish the closure names used by the Perl deparser facade. */ |
| 676 |
|
| { |
| 677 |
|
| HE *he; |
| 678 |
1512 |
| HV *lexicals = dds_hash(aTHX_ ctx->object, "lexicals", TRUE); |
| 679 |
|
| |
| 680 |
1512 |
| hv_iterinit(lexnames); |
| 681 |
1542 |
▶ | while ((he = hv_iternext(lexnames))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(lexnames))) |
30 |
1512 |
1542 |
|
| 682 |
30 |
| hv_store_ent(ctx->lexical_names, hv_iterkeysv(he), newSVsv(HeVAL(he)), 0); |
| 683 |
1512 |
| hv_stores(lexicals, "a2n", newRV_inc((SV *)ctx->lexical_names)); |
| 684 |
1512 |
▶ | if (HvTOTALKEYS(ctx->lexical_added)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (HvTOTALKEYS(ctx->lexical_added)) |
11 |
1501 |
1512 |
|
| 685 |
11 |
| hv_stores(lexicals, "added", newRV_inc((SV *)ctx->lexical_added)); |
| 686 |
|
| } |
| 687 |
|
| |
| 688 |
1512 |
| ctx->cataloged = TRUE; |
| 689 |
1512 |
| hv_stores(ctx->object, "cataloged", newSViv(1)); |
| 690 |
1512 |
| } |