| 1 |
|
| #include "dds_engine.h" |
| 2 |
|
| |
| 3 |
|
| /* Emission continuations live on the heap, independently of the C stack. */ |
| 4 |
|
| typedef enum { |
| 5 |
|
| DDS_FRAME_SV, |
| 6 |
|
| DDS_FRAME_REF, |
| 7 |
|
| DDS_FRAME_ARRAY, |
| 8 |
|
| DDS_FRAME_HASH |
| 9 |
|
| } dds_frame_kind; |
| 10 |
|
| |
| 11 |
|
| typedef enum { |
| 12 |
|
| DDS_STAGE_INITIAL = 0, |
| 13 |
|
| DDS_STAGE_CHILD, |
| 14 |
|
| DDS_STAGE_SCALAR_REF |
| 15 |
|
| } dds_frame_stage; |
| 16 |
|
| |
| 17 |
|
| /* Frames borrow graph SVs and catalogue roles. name, class_name, keys, |
| 18 |
|
| * hidden and temporary_sv own references released by |
| 19 |
|
| * dds_release_frame. The embedded temporary node lives only as long as |
| 20 |
|
| * this frame and must never be stored in a deferred fixup. */ |
| 21 |
|
| struct dds_frame { |
| 22 |
|
| struct dds_frame *parent; |
| 23 |
|
| dds_frame_kind kind; |
| 24 |
|
| dds_frame_stage stage; |
| 25 |
|
| SV *sv, *name, *temporary_sv; |
| 26 |
|
| UV depth; |
| 27 |
|
| IV indent; |
| 28 |
|
| dds_mark *mark; |
| 29 |
|
| bool is_ref; |
| 30 |
|
| dds_result result; |
| 31 |
|
| dds_active active; |
| 32 |
|
| dds_node *node, temporary; |
| 33 |
|
| dds_role *role; |
| 34 |
|
| bool add_do; |
| 35 |
|
| SV *class_name, *thaw; |
| 36 |
|
| AV *hidden, *keys; |
| 37 |
|
| bool overloaded, add_bless, add_lock, fix_lock, inline_thaw, function_thaw; |
| 38 |
|
| SSize_t k, last, run; |
| 39 |
|
| UV width; |
| 40 |
|
| IV last_n; |
| 41 |
|
| }; |
| 42 |
|
| |
| 43 |
|
| /* |
| 44 |
|
| * Traversal continuations |
| 45 |
|
| * |
| 46 |
|
| * Each heap frame owns only the values needed across a child visit. Its stage |
| 47 |
|
| * selects where execution resumes when that child completes. |
| 48 |
|
| */ |
| 49 |
|
| |
| 50 |
|
| /* Push a heap continuation for one traversal step, borrowing graph data and |
| 51 |
|
| * retaining its name and any fetched temporary. |
| 52 |
|
| */ |
| 53 |
41788 |
| static void dds_push_frame(pTHX_ dds_ctx *ctx, dds_frame_kind kind, SV *sv, UV depth, |
| 54 |
|
| dds_mark *mark, SV *name, IV indent, bool is_ref) |
| 55 |
|
| { |
| 56 |
|
| struct dds_frame *frame; |
| 57 |
|
| |
| 58 |
41788 |
▶ | if (depth > 16384) |
Branch: 1 branch
| Branch | True | False | Total |
| if (depth > 16384) |
0 |
41788 |
41788 |
|
| 59 |
0 |
| croak("DDS maximum traversal depth (16384) exceeded"); |
| 60 |
|
| |
| 61 |
41788 |
▶ | if ((frame = ctx->free_frames)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((frame = ctx->free_frames)) |
30299 |
11489 |
41788 |
|
| 62 |
30299 |
| ctx->free_frames = frame->parent; |
| 63 |
|
| else |
| 64 |
11489 |
| Newx(frame, 1, struct dds_frame); |
| 65 |
|
| |
| 66 |
41788 |
| Zero(frame, 1, struct dds_frame); |
| 67 |
41788 |
| frame->parent = ctx->frames; |
| 68 |
41788 |
| ctx->frames = frame; |
| 69 |
41788 |
| frame->kind = kind; |
| 70 |
41788 |
| frame->sv = sv; |
| 71 |
41788 |
| frame->depth = depth; |
| 72 |
|
| |
| 73 |
|
| /* Tied fetches may return mortals created by the parent step. Ordinary |
| 74 |
|
| * graph SVs are borrowed without changing their reference counts. */ |
| 75 |
41788 |
▶ | if (SvTEMP(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTEMP(sv)) |
1098 |
40690 |
41788 |
|
| 76 |
1098 |
| frame->temporary_sv = SvREFCNT_inc(sv); |
| 77 |
|
| |
| 78 |
41788 |
| frame->mark = mark; |
| 79 |
41788 |
| frame->name = SvREFCNT_inc(name); |
| 80 |
41788 |
| frame->indent = indent; |
| 81 |
41788 |
| frame->is_ref = is_ref; |
| 82 |
|
| |
| 83 |
41788 |
| frame->active.parent = ctx->active; |
| 84 |
41788 |
| frame->active.sv = sv; |
| 85 |
41788 |
| ctx->active = &frame->active; |
| 86 |
41788 |
| } |
| 87 |
|
| |
| 88 |
|
| /* Release and clear the SV references owned by a frame without releasing its |
| 89 |
|
| * borrowed graph values or catalogue records. |
| 90 |
|
| */ |
| 91 |
53276 |
| static void dds_release_frame(pTHX_ struct dds_frame *frame) |
| 92 |
|
| { |
| 93 |
|
| /* Only these fields own SV references. Graph values remain borrowed |
| 94 |
|
| * from the live graph or callback keepalive. Clear before release |
| 95 |
|
| * so exception cleanup cannot release the same ownership twice. */ |
| 96 |
|
| #define RELEASE(field) \ |
| 97 |
|
| STMT_START \ |
| 98 |
|
| { \ |
| 99 |
|
| SV *owned = (SV *)frame->field; \ |
| 100 |
|
| frame->field = NULL; \ |
| 101 |
|
| SvREFCNT_dec(owned); \ |
| 102 |
|
| } \ |
| 103 |
|
| STMT_END |
| 104 |
53276 |
| RELEASE(name); |
| 105 |
53276 |
| RELEASE(class_name); |
| 106 |
53276 |
| RELEASE(temporary_sv); |
| 107 |
53276 |
| RELEASE(hidden); |
| 108 |
53276 |
| RELEASE(keys); |
| 109 |
|
| #undef RELEASE |
| 110 |
53276 |
| } |
| 111 |
|
| |
| 112 |
|
| /* Destroy active and reusable continuation frames, including any owned values |
| 113 |
|
| * left by an interrupted traversal. |
| 114 |
|
| */ |
| 115 |
5766 |
| void dds_clear_frames(pTHX_ dds_ctx *ctx) |
| 116 |
|
| { |
| 117 |
|
| struct dds_frame *frame; |
| 118 |
|
| |
| 119 |
5767 |
▶ | while ((frame = ctx->frames)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((frame = ctx->frames)) { |
1 |
5766 |
5767 |
|
| 120 |
1 |
| dds_release_frame(aTHX_ frame); |
| 121 |
1 |
| ctx->frames = frame->parent; |
| 122 |
1 |
| Safefree(frame); |
| 123 |
|
| } |
| 124 |
17254 |
▶ | while ((frame = ctx->free_frames)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((frame = ctx->free_frames)) { |
11488 |
5766 |
17254 |
|
| 125 |
11488 |
| dds_release_frame(aTHX_ frame); |
| 126 |
11488 |
| ctx->free_frames = frame->parent; |
| 127 |
11488 |
| Safefree(frame); |
| 128 |
|
| } |
| 129 |
5766 |
| } |
| 130 |
|
| |
| 131 |
|
| /* Build a mortal string from a C prefix, an optional SV value and a C suffix. */ |
| 132 |
5165 |
| static SV *dds_concat(pTHX_ const char *prefix, SV *value, const char *suffix) |
| 133 |
|
| { |
| 134 |
5165 |
| SV *out = DDS_TEMP(newSVpv(prefix, 0)); |
| 135 |
|
| |
| 136 |
5165 |
▶ | if (value) |
Branch: 1 branch
| Branch | True | False | Total |
| if (value) |
5165 |
0 |
5165 |
|
| 137 |
5165 |
| DDS_CAT(out, value); |
| 138 |
5165 |
| sv_catpv(out, suffix); |
| 139 |
5165 |
| return out; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
|
| /* |
| 143 |
|
| * Deferred graph construction |
| 144 |
|
| * |
| 145 |
|
| * Completion marks describe available destinations. Typed fixups wait for |
| 146 |
|
| * those marks before assigning aliases, restoring class fields or running |
| 147 |
|
| * thaws. |
| 148 |
|
| */ |
| 149 |
|
| |
| 150 |
|
| /* Allocate a not-yet-ready completion mark owned by the current emission. */ |
| 151 |
2145 |
| dds_mark *dds_new_mark(pTHX_ dds_ctx *ctx) |
| 152 |
|
| { |
| 153 |
|
| dds_mark *mark; |
| 154 |
|
| |
| 155 |
2145 |
| Newxz(mark, 1, dds_mark); |
| 156 |
2145 |
| mark->next = ctx->marks; |
| 157 |
2145 |
| ctx->marks = mark; |
| 158 |
2145 |
| return mark; |
| 159 |
|
| } |
| 160 |
|
| |
| 161 |
|
| /* Allocate a deferred action, copying its destination expression and borrowing |
| 162 |
|
| * its stable catalogue node. |
| 163 |
|
| */ |
| 164 |
5689 |
| dds_fix *dds_new_fix(pTHX_ dds_fix_kind kind, SV *lhs, dds_node *node) |
| 165 |
|
| { |
| 166 |
|
| dds_fix *fix; |
| 167 |
|
| |
| 168 |
5689 |
| Newxz(fix, 1, dds_fix); |
| 169 |
5689 |
| fix->kind = kind; |
| 170 |
5689 |
▶ | fix->lhs = lhs ? newSVsv(lhs) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| fix->lhs = lhs ? newSVsv(lhs) : NULL; |
5650 |
39 |
5689 |
|
| 171 |
5689 |
| fix->node = node; |
| 172 |
5689 |
| return fix; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
|
| /* Queue a deferred action and count pending alias dependencies, placing |
| 176 |
|
| * variable introductions ahead of actions that may use them. |
| 177 |
|
| */ |
| 178 |
5689 |
| void dds_add_fix(pTHX_ dds_ctx *ctx, dds_fix *fix) |
| 179 |
|
| { |
| 180 |
|
| /* Introduce named variables before fixups that may refer to them. */ |
| 181 |
5689 |
▶ | if (fix->kind == DDS_FIX_VAR) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fix->kind == DDS_FIX_VAR) { |
0 |
5689 |
5689 |
|
| 182 |
0 |
| fix->next = ctx->fix_head; |
| 183 |
0 |
| ctx->fix_head = fix; |
| 184 |
0 |
▶ | if (!ctx->fix_tail) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->fix_tail) |
0 |
0 |
0 |
|
| 185 |
0 |
| ctx->fix_tail = fix; |
| 186 |
|
| } else { |
| 187 |
5689 |
▶ | if (ctx->fix_tail) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->fix_tail) |
5258 |
431 |
5689 |
|
| 188 |
5258 |
| ctx->fix_tail->next = fix; |
| 189 |
|
| else |
| 190 |
431 |
| ctx->fix_head = fix; |
| 191 |
5689 |
| ctx->fix_tail = fix; |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
5689 |
| ctx->fixes++; |
| 195 |
5689 |
▶ | if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
Branch: 3 branches
| Branch | True | False | Total |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
5578 |
111 |
5689 |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
1245 |
4333 |
5578 |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
0 |
1245 |
1245 |
|
| 196 |
4444 |
| ctx->pending_aliases++; |
| 197 |
5689 |
| } |
| 198 |
|
| |
| 199 |
|
| /* Queue a generated helper call, recording its alias destination when class |
| 200 |
|
| * hydration needs dependency tracking. |
| 201 |
|
| */ |
| 202 |
1065 |
| static void dds_call_fix(pTHX_ dds_ctx *ctx, const char *function, SV *args, dds_node *source, |
| 203 |
|
| SV *path) |
| 204 |
|
| { |
| 205 |
1065 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_CALL, args, source); |
| 206 |
|
| |
| 207 |
1065 |
| fix->text = newSVpv(function, 0); |
| 208 |
1065 |
▶ | if (ctx->class_head && path) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->class_head && path) |
0 |
1065 |
1065 |
| if (ctx->class_head && path) |
0 |
0 |
0 |
|
| 209 |
0 |
| fix->path = newSVsv(path); |
| 210 |
1065 |
| dds_add_fix(aTHX_ ctx, fix); |
| 211 |
1065 |
| } |
| 212 |
|
| |
| 213 |
|
| /* Release a completed deferred action and every output value or glob reference |
| 214 |
|
| * it owns. |
| 215 |
|
| */ |
| 216 |
5688 |
| static void dds_free_fix(pTHX_ dds_fix *fix) |
| 217 |
|
| { |
| 218 |
5688 |
| SvREFCNT_dec(fix->lhs); |
| 219 |
5688 |
| SvREFCNT_dec(fix->text); |
| 220 |
5688 |
| SvREFCNT_dec(fix->class_name); |
| 221 |
5688 |
| SvREFCNT_dec(fix->args); |
| 222 |
5688 |
| SvREFCNT_dec(fix->glob); |
| 223 |
5688 |
| SvREFCNT_dec(fix->path); |
| 224 |
5688 |
| Safefree(fix); |
| 225 |
5688 |
| } |
| 226 |
|
| |
| 227 |
|
| /* Build a mortal reference expression for a canonical name, adding a reference |
| 228 |
|
| * operator or blessing when required. |
| 229 |
|
| */ |
| 230 |
132 |
| static SV *dds_ref_expression(pTHX_ dds_ctx *ctx, SV *name, SV *class_name) |
| 231 |
|
| { |
| 232 |
132 |
| const char *p = DDS_PV(name); |
| 233 |
132 |
| SV *out = DDS_TEMP(newSVpvs("")); |
| 234 |
|
| |
| 235 |
132 |
▶ | if (SvOK(class_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) { |
44 |
88 |
132 |
|
| 236 |
44 |
| sv_catpvs(out, "bless("); |
| 237 |
44 |
| DDS_CAT(out, ctx->style.space); |
| 238 |
|
| } |
| 239 |
132 |
▶ | if (strchr("@%&", p[0])) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strchr("@%&", p[0])) |
132 |
0 |
132 |
|
| 240 |
132 |
| sv_catpvs(out, "\\"); |
| 241 |
132 |
| DDS_CAT(out, name); |
| 242 |
132 |
▶ | if (SvOK(class_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) { |
44 |
88 |
132 |
|
| 243 |
44 |
| sv_catpvs(out, ","); |
| 244 |
44 |
| DDS_CAT(out, ctx->style.space); |
| 245 |
44 |
| DDS_CAT(out, dds_quote(aTHX_ class_name, FALSE)); |
| 246 |
44 |
| DDS_CAT(out, ctx->style.space); |
| 247 |
44 |
| sv_catpvs(out, ")"); |
| 248 |
|
| } |
| 249 |
132 |
| return out; |
| 250 |
|
| } |
| 251 |
|
| |
| 252 |
|
| /* Emit a deferred restricted-hash lock, including placeholder keys that must |
| 253 |
|
| * remain legal. |
| 254 |
|
| */ |
| 255 |
8 |
| static void dds_lock_fix_output(pTHX_ dds_ctx *ctx, dds_fix *fix) |
| 256 |
|
| { |
| 257 |
|
| SSize_t i; |
| 258 |
8 |
| SV *name = fix->node->ref.name; |
| 259 |
8 |
▶ | bool hidden = fix->args && av_len(fix->args) >= 0; |
Branch: 2 branches
| Branch | True | False | Total |
| bool hidden = fix->args && av_len(fix->args) >= 0; |
8 |
0 |
8 |
| bool hidden = fix->args && av_len(fix->args) >= 0; |
4 |
4 |
8 |
|
| 260 |
|
| |
| 261 |
8 |
▶ | dds_put(aTHX_ ctx, hidden ? "lock_keys_plus( " : "lock_keys( "); |
Branch: 1 branch
| Branch | True | False | Total |
| dds_put(aTHX_ ctx, hidden ? "lock_keys_plus( " : "lock_keys( "); |
4 |
4 |
8 |
|
| 262 |
8 |
| dds_write(aTHX_ ctx, name); |
| 263 |
8 |
▶ | if (hidden) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hidden) { |
4 |
4 |
8 |
|
| 264 |
4 |
| dds_put(aTHX_ ctx, ", "); |
| 265 |
12 |
▶ | for (i = 0; i <= av_len(fix->args); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(fix->args); i++) { |
8 |
4 |
12 |
|
| 266 |
8 |
▶ | if (i) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) |
4 |
4 |
8 |
|
| 267 |
4 |
| dds_put(aTHX_ ctx, ", "); |
| 268 |
8 |
| dds_write(aTHX_ ctx, dds_quote(aTHX_ * av_fetch(fix->args, i, 0), FALSE)); |
| 269 |
|
| } |
| 270 |
4 |
| dds_put(aTHX_ ctx, ");\n"); |
| 271 |
|
| } else |
| 272 |
4 |
| dds_put(aTHX_ ctx, " );\n"); |
| 273 |
8 |
| } |
| 274 |
|
| |
| 275 |
|
| /* Emit a deferred thaw as a method, function or arbitrary code block, making |
| 276 |
|
| * its referent available to dependent fixups. |
| 277 |
|
| */ |
| 278 |
3 |
| static void dds_thaw_output(pTHX_ dds_ctx *ctx, dds_fix *fix) |
| 279 |
|
| { |
| 280 |
3 |
| SV *name = fix->node->ref.name; |
| 281 |
3 |
| const char *p = DDS_PV(fix->text), *method = p; |
| 282 |
3 |
| STRLEN len = strlen(p), i; |
| 283 |
3 |
▶ | bool simple = TRUE, function = len >= 2 && strEQ(p + len - 2, "()"); |
Branch: 2 branches
| Branch | True | False | Total |
| bool simple = TRUE, function = len >= 2 && strEQ(p + len - 2, "()"); |
3 |
0 |
3 |
| bool simple = TRUE, function = len >= 2 && strEQ(p + len - 2, "()"); |
1 |
2 |
3 |
|
| 284 |
|
| |
| 285 |
3 |
▶ | if (method[0] == '-' && method[1] == '>') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (method[0] == '-' && method[1] == '>') { |
0 |
3 |
3 |
| if (method[0] == '-' && method[1] == '>') { |
0 |
0 |
0 |
|
| 286 |
0 |
| method += 2; |
| 287 |
0 |
| len -= 2; |
| 288 |
|
| } |
| 289 |
27 |
▶ | for (i = 0; i < len - (function ? 2 : 0); i++) |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < len - (function ? 2 : 0); i++) |
9 |
18 |
27 |
| for (i = 0; i < len - (function ? 2 : 0); i++) |
24 |
3 |
27 |
|
| 290 |
24 |
▶ | if (!isALNUMC_A(method[i]) && method[i] != '_' && method[i] != ':') |
Branch: 3 branches
| Branch | True | False | Total |
| if (!isALNUMC_A(method[i]) && method[i] != '_' && method[i] != ':') |
2 |
22 |
24 |
| if (!isALNUMC_A(method[i]) && method[i] != '_' && method[i] != ':') |
0 |
2 |
2 |
| if (!isALNUMC_A(method[i]) && method[i] != '_' && method[i] != ':') |
0 |
0 |
0 |
|
| 291 |
0 |
| simple = FALSE; |
| 292 |
3 |
▶ | if (fix->node->ref.done) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fix->node->ref.done) |
3 |
0 |
3 |
|
| 293 |
3 |
| fix->node->ref.done->ready = TRUE; |
| 294 |
3 |
▶ | if (!simple) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!simple) { |
0 |
3 |
3 |
|
| 295 |
0 |
| SV *text = DDS_TEMP(newSVsv(fix->text)); |
| 296 |
|
| STRLEN n, at; |
| 297 |
0 |
| const char *s = SvPV(text, n); |
| 298 |
|
| |
| 299 |
0 |
| dds_put(aTHX_ ctx, "for ("); |
| 300 |
0 |
| dds_write(aTHX_ ctx, name); |
| 301 |
0 |
| dds_put(aTHX_ ctx, ") {\n"); |
| 302 |
0 |
▶ | for (at = 0; at < n; at++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (at = 0; at < n; at++) { |
0 |
0 |
0 |
|
| 303 |
0 |
▶ | if (s[at] == '\t' && (!at || s[at - 1] == '\n')) |
Branch: 3 branches
| Branch | True | False | Total |
| if (s[at] == '\t' && (!at || s[at - 1] == '\n')) |
0 |
0 |
0 |
| if (s[at] == '\t' && (!at || s[at - 1] == '\n')) |
0 |
0 |
0 |
| if (s[at] == '\t' && (!at || s[at - 1] == '\n')) |
0 |
0 |
0 |
|
| 304 |
0 |
| continue; |
| 305 |
0 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(s + at, 1))); |
| 306 |
|
| } |
| 307 |
0 |
| dds_put(aTHX_ ctx, "\n}\n"); |
| 308 |
3 |
▶ | } else if (function) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (function) { |
1 |
2 |
3 |
|
| 309 |
1 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(method, len - 2))); |
| 310 |
1 |
| dds_put(aTHX_ ctx, "( "); |
| 311 |
1 |
| dds_write(aTHX_ ctx, name); |
| 312 |
1 |
| dds_put(aTHX_ ctx, " );\n"); |
| 313 |
|
| } else { |
| 314 |
2 |
| dds_write(aTHX_ ctx, name); |
| 315 |
2 |
| dds_put(aTHX_ ctx, "->"); |
| 316 |
2 |
| dds_put(aTHX_ ctx, method); |
| 317 |
2 |
| dds_put(aTHX_ ctx, "();\n"); |
| 318 |
|
| } |
| 319 |
3 |
| } |
| 320 |
|
| |
| 321 |
|
| /* Match whole expressions or descendants, not similarly prefixed names. */ |
| 322 |
0 |
| static bool dds_path_contains(pTHX_ SV *parent, SV *path) |
| 323 |
|
| { |
| 324 |
|
| STRLEN plen, len; |
| 325 |
0 |
▶ | const char *p = SvPV(parent, plen), *s = SvPV(path, len); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *p = SvPV(parent, plen), *s = SvPV(path, len); |
0 |
0 |
0 |
|
| 326 |
|
| |
| 327 |
0 |
▶ | return len >= plen && memEQ(p, s, plen) && |
Branch: 2 branches
| Branch | True | False | Total |
| return len >= plen && memEQ(p, s, plen) && |
0 |
0 |
0 |
| return len >= plen && memEQ(p, s, plen) && |
0 |
0 |
0 |
|
| 328 |
0 |
▶ | (len == plen || s[plen] == '-' || s[plen] == '{' || s[plen] == '['); |
Branch: 4 branches
| Branch | True | False | Total |
| (len == plen || s[plen] == '-' || s[plen] == '{' || s[plen] == '['); |
0 |
0 |
0 |
| (len == plen || s[plen] == '-' || s[plen] == '{' || s[plen] == '['); |
0 |
0 |
0 |
| (len == plen || s[plen] == '-' || s[plen] == '{' || s[plen] == '['); |
0 |
0 |
0 |
| (len == plen || s[plen] == '-' || s[plen] == '{' || s[plen] == '['); |
0 |
0 |
0 |
|
| 329 |
|
| } |
| 330 |
|
| |
| 331 |
|
| /* Check that no pending alias can replace a field snapshot slot or the object |
| 332 |
|
| * destination before class hydration. |
| 333 |
|
| */ |
| 334 |
0 |
| static bool dds_class_fields_ready(pTHX_ dds_ctx *ctx, dds_node *node) |
| 335 |
|
| { |
| 336 |
|
| dds_fix *fix; |
| 337 |
|
| /* Slot replacement must precede hydration, which shares the final |
| 338 |
|
| * field SVs. Ordinary thaws can make those replacements ready. */ |
| 339 |
0 |
▶ | if (!ctx->pending_aliases) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->pending_aliases) |
0 |
0 |
0 |
|
| 340 |
0 |
| return TRUE; |
| 341 |
0 |
▶ | for (fix = ctx->fix_head; fix; fix = fix->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (fix = ctx->fix_head; fix; fix = fix->next) { |
0 |
0 |
0 |
|
| 342 |
0 |
▶ | SV *path = fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF ? fix->lhs : fix->path; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *path = fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF ? fix->lhs : fix->path; |
0 |
0 |
0 |
| SV *path = fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF ? fix->lhs : fix->path; |
0 |
0 |
0 |
|
| 343 |
|
| |
| 344 |
0 |
▶ | if (path && (dds_path_contains(aTHX_ node->class_fields_name, path) || |
Branch: 1 branch
| Branch | True | False | Total |
| if (path && (dds_path_contains(aTHX_ node->class_fields_name, path) || |
0 |
0 |
0 |
|
| 345 |
0 |
| dds_path_contains(aTHX_ path, node->ref.name))) |
| 346 |
0 |
| return FALSE; |
| 347 |
|
| } |
| 348 |
0 |
| return TRUE; |
| 349 |
|
| } |
| 350 |
|
| |
| 351 |
|
| /* Emit XPerl field hydration using the reconstructed object as $self, then |
| 352 |
|
| * mark its class storage restored. |
| 353 |
|
| */ |
| 354 |
0 |
| static void dds_restore_class(pTHX_ dds_ctx *ctx, dds_node *node) |
| 355 |
|
| { |
| 356 |
0 |
| dds_write(aTHX_ ctx, node->class_fields_name); |
| 357 |
0 |
| dds_put(aTHX_ ctx, "->{'$self'} = "); |
| 358 |
0 |
| dds_write(aTHX_ ctx, |
| 359 |
|
| dds_ref_expression(aTHX_ ctx, node->ref.name, |
| 360 |
0 |
▶ | node->class_package ? node->class_package : &PL_sv_undef)); |
Branch: 1 branch
| Branch | True | False | Total |
| node->class_package ? node->class_package : &PL_sv_undef)); |
0 |
0 |
0 |
|
| 361 |
0 |
| dds_put(aTHX_ ctx, ";\nbuiltin::class_object_from_hash("); |
| 362 |
0 |
| dds_write(aTHX_ ctx, node->class_fields_name); |
| 363 |
0 |
| dds_put(aTHX_ ctx, ");\n"); |
| 364 |
0 |
| node->class_restored = TRUE; |
| 365 |
0 |
| } |
| 366 |
|
| |
| 367 |
|
| /* Emit ready deferred actions until no more progress is possible; final mode |
| 368 |
|
| * also permits blessing, thaws and class hydration. |
| 369 |
|
| */ |
| 370 |
4958 |
| void dds_apply_fixes(pTHX_ dds_ctx *ctx, bool final) |
| 371 |
|
| { |
| 372 |
|
| bool glob_work, progress; |
| 373 |
|
| |
| 374 |
|
| /* A completed fixup can unlock another. Drain to a fixed point; |
| 375 |
|
| * glob emission may itself queue more ordinary fixups. */ |
| 376 |
|
| do { |
| 377 |
5532 |
| dds_fix **link = &ctx->fix_head; |
| 378 |
5532 |
| dds_fix **glob_tail = &ctx->glob_head; |
| 379 |
|
| |
| 380 |
5532 |
| glob_work = FALSE; |
| 381 |
5532 |
| progress = FALSE; |
| 382 |
|
| |
| 383 |
14165 |
▶ | while (*link) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (*link) { |
8633 |
5532 |
14165 |
|
| 384 |
8633 |
| dds_fix *fix = *link; |
| 385 |
8633 |
| bool ready = FALSE; |
| 386 |
5134 |
▶ | dds_role *role = fix->node ? (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_CALL |
Branch: 1 branch
| Branch | True | False | Total |
| dds_role *role = fix->node ? (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_CALL |
395 |
4739 |
5134 |
|
| 387 |
698 |
| ? &fix->node->slot |
| 388 |
10571 |
▶ | : &fix->node->ref) |
Branch: 1 branch
| Branch | True | False | Total |
| : &fix->node->ref) |
5134 |
303 |
5437 |
|
| 389 |
14070 |
▶ | : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| : NULL; |
5437 |
3196 |
8633 |
|
| 390 |
|
| |
| 391 |
8633 |
| switch (fix->kind) { |
| 392 |
4930 |
| case DDS_FIX_SLOT: |
| 393 |
|
| case DDS_FIX_REF: |
| 394 |
4930 |
▶ | ready = role && role->done && role->done->ready; |
Branch: 3 branches
| Branch | True | False | Total |
| ready = role && role->done && role->done->ready; |
4930 |
0 |
4930 |
| ready = role && role->done && role->done->ready; |
4542 |
388 |
4930 |
| ready = role && role->done && role->done->ready; |
4444 |
98 |
4542 |
|
| 395 |
4930 |
▶ | if (ready) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) { |
4444 |
486 |
4930 |
|
| 396 |
4444 |
| SV *lhs = fix->lhs, *rhs = role->name, *underef; |
| 397 |
|
| |
| 398 |
4444 |
▶ | if (fix->kind == DDS_FIX_SLOT && (underef = dds_underef(aTHX_ lhs))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (fix->kind == DDS_FIX_SLOT && (underef = dds_underef(aTHX_ lhs))) { |
111 |
4333 |
4444 |
| if (fix->kind == DDS_FIX_SLOT && (underef = dds_underef(aTHX_ lhs))) { |
111 |
0 |
111 |
|
| 399 |
111 |
| lhs = underef; |
| 400 |
111 |
| rhs = dds_concat(aTHX_ "\\", rhs, ""); |
| 401 |
8666 |
▶ | } else if (fix->kind == DDS_FIX_REF && strchr("@%&", DDS_PV(rhs)[0])) |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (fix->kind == DDS_FIX_REF && strchr("@%&", DDS_PV(rhs)[0])) |
4333 |
0 |
4333 |
| } else if (fix->kind == DDS_FIX_REF && strchr("@%&", DDS_PV(rhs)[0])) |
36 |
4297 |
4333 |
|
| 402 |
36 |
| rhs = dds_ref_expression(aTHX_ ctx, rhs, |
| 403 |
36 |
▶ | fix->class_name ? fix->class_name : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| fix->class_name ? fix->class_name : &PL_sv_undef); |
12 |
24 |
36 |
|
| 404 |
4444 |
| dds_write(aTHX_ ctx, lhs); |
| 405 |
4444 |
| dds_put(aTHX_ ctx, " = "); |
| 406 |
4444 |
| dds_write(aTHX_ ctx, rhs); |
| 407 |
4444 |
| dds_put(aTHX_ ctx, ";\n"); |
| 408 |
4444 |
▶ | if (fix->mark) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fix->mark) |
111 |
4333 |
4444 |
|
| 409 |
111 |
| fix->mark->ready = TRUE; |
| 410 |
|
| } |
| 411 |
4930 |
| break; |
| 412 |
3450 |
| case DDS_FIX_CALL: |
| 413 |
6816 |
▶ | ready = (!role || (role->done && role->done->ready)) && |
Branch: 3 branches
| Branch | True | False | Total |
| ready = (!role || (role->done && role->done->ready)) && |
395 |
3055 |
3450 |
| ready = (!role || (role->done && role->done->ready)) && |
311 |
84 |
395 |
| ready = (!role || (role->done && role->done->ready)) && |
311 |
0 |
311 |
|
| 414 |
6732 |
▶ | (!strEQ(DDS_PV(fix->text), "weaken") || (final && ctx->final_weakening)); |
Branch: 3 branches
| Branch | True | False | Total |
| (!strEQ(DDS_PV(fix->text), "weaken") || (final && ctx->final_weakening)); |
3046 |
320 |
3366 |
| (!strEQ(DDS_PV(fix->text), "weaken") || (final && ctx->final_weakening)); |
1490 |
1556 |
3046 |
| (!strEQ(DDS_PV(fix->text), "weaken") || (final && ctx->final_weakening)); |
745 |
745 |
1490 |
|
| 415 |
3450 |
▶ | if (ready) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) { |
1065 |
2385 |
3450 |
|
| 416 |
1065 |
| dds_write(aTHX_ ctx, fix->text); |
| 417 |
1065 |
| dds_put(aTHX_ ctx, "("); |
| 418 |
1065 |
| dds_write(aTHX_ ctx, fix->lhs); |
| 419 |
1065 |
▶ | if (role) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (role) { |
311 |
754 |
1065 |
|
| 420 |
311 |
| dds_put(aTHX_ ctx, ", "); |
| 421 |
311 |
| dds_write(aTHX_ ctx, role->name); |
| 422 |
|
| } |
| 423 |
1065 |
| dds_put(aTHX_ ctx, ");\n"); |
| 424 |
|
| } |
| 425 |
3450 |
| break; |
| 426 |
96 |
| case DDS_FIX_BLESS: |
| 427 |
96 |
| ready = final; |
| 428 |
96 |
▶ | if (ready) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) { |
28 |
68 |
96 |
|
| 429 |
|
| STRLEN len; |
| 430 |
28 |
| const char *p = SvPV(ctx->style.bless, len); |
| 431 |
|
| |
| 432 |
28 |
▶ | dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p, len ? len - 1 : 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p, len ? len - 1 : 0))); |
28 |
0 |
28 |
|
| 433 |
28 |
| dds_put(aTHX_ ctx, " "); |
| 434 |
28 |
| dds_write(aTHX_ ctx, role->name); |
| 435 |
28 |
| dds_put(aTHX_ ctx, ", "); |
| 436 |
28 |
| dds_write(aTHX_ ctx, dds_quote(aTHX_ fix->text, FALSE)); |
| 437 |
28 |
| dds_put(aTHX_ ctx, " "); |
| 438 |
28 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
28 |
0 |
28 |
|
| 439 |
28 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p + len - 1, 1))); |
| 440 |
28 |
| dds_put(aTHX_ ctx, ";\n"); |
| 441 |
|
| } |
| 442 |
96 |
| break; |
| 443 |
8 |
| case DDS_FIX_LOCK: |
| 444 |
8 |
▶ | ready = role && role->done && role->done->ready; |
Branch: 3 branches
| Branch | True | False | Total |
| ready = role && role->done && role->done->ready; |
8 |
0 |
8 |
| ready = role && role->done && role->done->ready; |
8 |
0 |
8 |
| ready = role && role->done && role->done->ready; |
8 |
0 |
8 |
|
| 445 |
8 |
▶ | if (ready) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) |
8 |
0 |
8 |
|
| 446 |
8 |
| dds_lock_fix_output(aTHX_ ctx, fix); |
| 447 |
8 |
| break; |
| 448 |
8 |
| case DDS_FIX_THAW: |
| 449 |
8 |
▶ | ready = final && (!fix->node->class_fields || fix->node->class_restored); |
Branch: 3 branches
| Branch | True | False | Total |
| ready = final && (!fix->node->class_fields || fix->node->class_restored); |
3 |
5 |
8 |
| ready = final && (!fix->node->class_fields || fix->node->class_restored); |
0 |
3 |
3 |
| ready = final && (!fix->node->class_fields || fix->node->class_restored); |
0 |
0 |
0 |
|
| 450 |
8 |
▶ | if (ready) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) |
3 |
5 |
8 |
|
| 451 |
3 |
| dds_thaw_output(aTHX_ ctx, fix); |
| 452 |
8 |
| break; |
| 453 |
0 |
| case DDS_FIX_CLASS: |
| 454 |
0 |
▶ | ready = final && dds_class_fields_ready(aTHX_ ctx, fix->node); |
Branch: 2 branches
| Branch | True | False | Total |
| ready = final && dds_class_fields_ready(aTHX_ ctx, fix->node); |
0 |
0 |
0 |
| ready = final && dds_class_fields_ready(aTHX_ ctx, fix->node); |
0 |
0 |
0 |
|
| 455 |
0 |
▶ | if (ready) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ready) |
0 |
0 |
0 |
|
| 456 |
0 |
| dds_restore_class(aTHX_ ctx, fix->node); |
| 457 |
0 |
| break; |
| 458 |
141 |
| case DDS_FIX_GLOB: |
| 459 |
141 |
| ready = TRUE; |
| 460 |
141 |
| break; |
| 461 |
0 |
| case DDS_FIX_VAR: |
| 462 |
0 |
| ready = TRUE; |
| 463 |
0 |
▶ | if (ctx->style.declare) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->style.declare) |
0 |
0 |
0 |
|
| 464 |
0 |
| dds_put(aTHX_ ctx, "my "); |
| 465 |
0 |
| dds_write(aTHX_ ctx, fix->lhs); |
| 466 |
0 |
| dds_put(aTHX_ ctx, " = "); |
| 467 |
0 |
| dds_write(aTHX_ ctx, |
| 468 |
|
| dds_ref_expression(aTHX_ ctx, fix->text, |
| 469 |
0 |
▶ | fix->class_name ? fix->class_name : &PL_sv_undef)); |
Branch: 1 branch
| Branch | True | False | Total |
| fix->class_name ? fix->class_name : &PL_sv_undef)); |
0 |
0 |
0 |
|
| 470 |
0 |
| dds_put(aTHX_ ctx, ";\n"); |
| 471 |
0 |
| break; |
| 472 |
|
| } |
| 473 |
|
| |
| 474 |
8633 |
▶ | if (!ready) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ready) { |
2944 |
5689 |
8633 |
|
| 475 |
2944 |
| link = &fix->next; |
| 476 |
2944 |
| continue; |
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
5689 |
| progress = TRUE; |
| 480 |
5689 |
▶ | if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
Branch: 3 branches
| Branch | True | False | Total |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
5578 |
111 |
5689 |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
1245 |
4333 |
5578 |
| if (fix->kind == DDS_FIX_SLOT || fix->kind == DDS_FIX_REF || fix->path) |
0 |
1245 |
1245 |
|
| 481 |
4444 |
| ctx->pending_aliases--; |
| 482 |
5689 |
| *link = fix->next; |
| 483 |
5689 |
▶ | if (fix == ctx->fix_tail) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fix == ctx->fix_tail) |
504 |
5185 |
5689 |
|
| 484 |
504 |
| ctx->fix_tail = NULL; |
| 485 |
5689 |
▶ | if (fix->kind == DDS_FIX_GLOB) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fix->kind == DDS_FIX_GLOB) { |
141 |
5548 |
5689 |
|
| 486 |
141 |
| fix->next = NULL; |
| 487 |
141 |
| *glob_tail = fix; |
| 488 |
141 |
| glob_tail = &fix->next; |
| 489 |
|
| } else |
| 490 |
5548 |
| dds_free_fix(aTHX_ fix); |
| 491 |
|
| } |
| 492 |
|
| |
| 493 |
5532 |
▶ | if (ctx->fix_head) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->fix_head) { |
477 |
5055 |
5532 |
|
| 494 |
477 |
| ctx->fix_tail = ctx->fix_head; |
| 495 |
2944 |
▶ | while (ctx->fix_tail->next) |
Branch: 1 branch
| Branch | True | False | Total |
| while (ctx->fix_tail->next) |
2467 |
477 |
2944 |
|
| 496 |
2467 |
| ctx->fix_tail = ctx->fix_tail->next; |
| 497 |
|
| } |
| 498 |
|
| |
| 499 |
5672 |
▶ | while (ctx->glob_head) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (ctx->glob_head) { |
141 |
5531 |
5672 |
|
| 500 |
141 |
| dds_fix *fix = ctx->glob_head; |
| 501 |
|
| |
| 502 |
141 |
| dds_emit_glob(aTHX_ ctx, fix->glob, fix->lhs, fix->depth); |
| 503 |
140 |
| ctx->glob_head = fix->next; |
| 504 |
140 |
| dds_free_fix(aTHX_ fix); |
| 505 |
140 |
| glob_work = TRUE; |
| 506 |
|
| } |
| 507 |
5531 |
▶ | } while (glob_work || progress); |
Branch: 2 branches
| Branch | True | False | Total |
| } while (glob_work || progress); |
121 |
5410 |
5531 |
| } while (glob_work || progress); |
453 |
4957 |
5410 |
|
| 508 |
4957 |
| } |
| 509 |
|
| |
| 510 |
|
| /* Emit an opening or closing container delimiter with the selected spacing, |
| 511 |
|
| * returning the indentation for its contents or parent. |
| 512 |
|
| */ |
| 513 |
9528 |
| static IV dds_brace(pTHX_ dds_ctx *ctx, SV *name, char type, bool multiline, IV indent, UV children) |
| 514 |
|
| { |
| 515 |
9528 |
| bool open = strchr("{[(", type) != NULL; |
| 516 |
9528 |
| const char *p = DDS_PV(name); |
| 517 |
9528 |
▶ | char brace = p[0] == '%' || p[0] == '@' ? (open ? '(' : ')') : type; |
Branch: 3 branches
| Branch | True | False | Total |
| char brace = p[0] == '%' || p[0] == '@' ? (open ? '(' : ')') : type; |
9416 |
112 |
9528 |
| char brace = p[0] == '%' || p[0] == '@' ? (open ? '(' : ')') : type; |
164 |
9252 |
9416 |
| char brace = p[0] == '%' || p[0] == '@' ? (open ? '(' : ')') : type; |
138 |
138 |
276 |
|
| 518 |
|
| |
| 519 |
9528 |
▶ | if (multiline) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (multiline) { |
4538 |
4990 |
9528 |
|
| 520 |
4538 |
▶ | indent += open ? ctx->style.indentcols : -ctx->style.indentcols; |
Branch: 1 branch
| Branch | True | False | Total |
| indent += open ? ctx->style.indentcols : -ctx->style.indentcols; |
2269 |
2269 |
4538 |
|
| 521 |
4538 |
▶ | if (!open) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!open) { |
2269 |
2269 |
4538 |
|
| 522 |
2269 |
| dds_put(aTHX_ ctx, "\n"); |
| 523 |
2269 |
| dds_spaces(aTHX_ ctx, indent); |
| 524 |
|
| } |
| 525 |
4538 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(&brace, 1))); |
| 526 |
4538 |
▶ | if (open) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (open) { |
2269 |
2269 |
4538 |
|
| 527 |
2269 |
| dds_put(aTHX_ ctx, "\n"); |
| 528 |
2269 |
| dds_spaces(aTHX_ ctx, indent); |
| 529 |
|
| } |
| 530 |
|
| } else { |
| 531 |
4990 |
▶ | if (!open && children) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!open && children) |
2495 |
2495 |
4990 |
| if (!open && children) |
2449 |
46 |
2495 |
|
| 532 |
2449 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 533 |
4990 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(&brace, 1))); |
| 534 |
4990 |
▶ | if (open && children) |
Branch: 2 branches
| Branch | True | False | Total |
| if (open && children) |
2495 |
2495 |
4990 |
| if (open && children) |
2449 |
46 |
2495 |
|
| 535 |
2449 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 536 |
|
| } |
| 537 |
9528 |
| return indent; |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
|
| /* Decide whether repeating a scalar literal is safe for RLE, excluding |
| 541 |
|
| * references, magic, readonly values and known aliases. |
| 542 |
|
| */ |
| 543 |
7457 |
| static bool dds_rle_eligible(pTHX_ dds_ctx *ctx, SV *sv) |
| 544 |
|
| { |
| 545 |
|
| dds_node *node; |
| 546 |
|
| |
| 547 |
7457 |
▶ | if (SvROK(sv) || SvREADONLY(sv) || SvGMAGICAL(sv)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvROK(sv) || SvREADONLY(sv) || SvGMAGICAL(sv)) |
2413 |
5044 |
7457 |
| if (SvROK(sv) || SvREADONLY(sv) || SvGMAGICAL(sv)) |
2404 |
9 |
2413 |
| if (SvROK(sv) || SvREADONLY(sv) || SvGMAGICAL(sv)) |
3 |
2401 |
2404 |
|
| 548 |
5056 |
| return FALSE; |
| 549 |
|
| |
| 550 |
2401 |
▶ | node = dds_candidate(aTHX_ sv) ? dds_find(aTHX_ ctx, sv, FALSE) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| node = dds_candidate(aTHX_ sv) ? dds_find(aTHX_ ctx, sv, FALSE) : NULL; |
226 |
2175 |
2401 |
|
| 551 |
2401 |
▶ | return !node || !node->slot.present || node->slot.encounters == 1; |
Branch: 3 branches
| Branch | True | False | Total |
| return !node || !node->slot.present || node->slot.encounters == 1; |
226 |
2175 |
2401 |
| return !node || !node->slot.present || node->slot.encounters == 1; |
226 |
0 |
226 |
| return !node || !node->slot.present || node->slot.encounters == 1; |
6 |
220 |
226 |
|
| 552 |
|
| } |
| 553 |
|
| |
| 554 |
|
| /* |
| 555 |
|
| * Container traversal |
| 556 |
|
| * |
| 557 |
|
| * Array and hash continuations emit one child at a time, retaining layout |
| 558 |
|
| * state and recording aliases after the child returns. |
| 559 |
|
| */ |
| 560 |
|
| |
| 561 |
|
| /* Advance an array continuation through one child or completion, preserving |
| 562 |
|
| * layout, RLE state and deferred element aliases. |
| 563 |
|
| */ |
| 564 |
10699 |
| static bool dds_step_array(pTHX_ dds_ctx *ctx, struct dds_frame *f) |
| 565 |
|
| { |
| 566 |
10699 |
| AV *av = (AV *)f->sv; |
| 567 |
10699 |
| UV depth = f->depth; |
| 568 |
10699 |
| dds_mark *mark = f->mark; |
| 569 |
10699 |
| SV *name = f->name; |
| 570 |
10699 |
| IV indent = f->indent; |
| 571 |
10699 |
| SSize_t k = 0, last; |
| 572 |
|
| |
| 573 |
10699 |
▶ | if (f->stage != DDS_STAGE_INITIAL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage != DDS_STAGE_INITIAL) |
7607 |
3092 |
10699 |
|
| 574 |
7607 |
| last = f->last; |
| 575 |
|
| else { |
| 576 |
3092 |
▶ | if (SvTIED_mg((SV *)av, PERL_MAGIC_tied)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTIED_mg((SV *)av, PERL_MAGIC_tied)) |
283 |
2809 |
3092 |
| if (SvTIED_mg((SV *)av, PERL_MAGIC_tied)) |
1 |
282 |
283 |
|
| 577 |
1 |
| dds_callback_guard(aTHX_ ctx); |
| 578 |
3092 |
| last = av_len(av); |
| 579 |
|
| } |
| 580 |
10699 |
▶ | bool multiline = ctx->style.indent && last > 0; |
Branch: 2 branches
| Branch | True | False | Total |
| bool multiline = ctx->style.indent && last > 0; |
7669 |
3030 |
10699 |
| bool multiline = ctx->style.indent && last > 0; |
7185 |
484 |
7669 |
|
| 581 |
10699 |
| bool full = ctx->style.indent > 1; |
| 582 |
10699 |
| IV last_n = 0; |
| 583 |
|
| |
| 584 |
10699 |
▶ | if (f->stage == DDS_STAGE_INITIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage == DDS_STAGE_INITIAL) { |
3092 |
7607 |
10699 |
|
| 585 |
3092 |
| indent = dds_brace(aTHX_ ctx, name, '[', multiline, indent, last + 1); |
| 586 |
3092 |
| f->indent = indent; |
| 587 |
3092 |
| f->last = last; |
| 588 |
|
| } |
| 589 |
10699 |
| k = f->k; |
| 590 |
10699 |
| last_n = f->last_n; |
| 591 |
|
| |
| 592 |
18306 |
▶ | while (k <= last) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (k <= last) { |
15214 |
3092 |
18306 |
|
| 593 |
15214 |
▶ | SV **entry = f->stage != DDS_STAGE_INITIAL ? NULL : av_fetch(av, k, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SV **entry = f->stage != DDS_STAGE_INITIAL ? NULL : av_fetch(av, k, 0); |
7607 |
7607 |
15214 |
|
| 594 |
15214 |
▶ | SV *value = entry ? *entry : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *value = entry ? *entry : &PL_sv_undef; |
7607 |
7607 |
15214 |
|
| 595 |
15214 |
| SSize_t count = 1; |
| 596 |
|
| bool newline; |
| 597 |
|
| dds_result result; |
| 598 |
|
| |
| 599 |
15214 |
▶ | if (f->stage != DDS_STAGE_INITIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage != DDS_STAGE_INITIAL) { |
7607 |
7607 |
15214 |
|
| 600 |
7607 |
| count = f->run; |
| 601 |
7607 |
| goto child_done; |
| 602 |
|
| } |
| 603 |
|
| |
| 604 |
|
| /* Count a run before yielding to its first element. RLE must |
| 605 |
|
| * preserve value flags as well as the printable string value. */ |
| 606 |
7607 |
| f->active.sv = value; |
| 607 |
7607 |
▶ | if (ctx->style.rle && dds_rle_eligible(aTHX_ ctx, value)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->style.rle && dds_rle_eligible(aTHX_ ctx, value)) { |
6387 |
1220 |
7607 |
| if (ctx->style.rle && dds_rle_eligible(aTHX_ ctx, value)) { |
1469 |
4918 |
6387 |
|
| 608 |
1524 |
▶ | while (k + count <= last) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (k + count <= last) { |
1070 |
454 |
1524 |
|
| 609 |
1070 |
| SV **next = av_fetch(av, k + count, 0); |
| 610 |
1070 |
▶ | SV *v = next ? *next : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *v = next ? *next : &PL_sv_undef; |
1070 |
0 |
1070 |
|
| 611 |
|
| |
| 612 |
1782 |
▶ | if (!dds_rle_eligible(aTHX_ ctx, v) || cBOOL(SvOK(value)) != cBOOL(SvOK(v)) || |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dds_rle_eligible(aTHX_ ctx, v) || cBOOL(SvOK(value)) != cBOOL(SvOK(v)) || |
712 |
358 |
1070 |
|
| 613 |
712 |
| cBOOL(SvTRUE(value)) != cBOOL(SvTRUE(v))) |
| 614 |
|
| break; |
| 615 |
692 |
▶ | if (cBOOL(SvUTF8(value)) != cBOOL(SvUTF8(v))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cBOOL(SvUTF8(value)) != cBOOL(SvUTF8(v))) |
1 |
691 |
692 |
|
| 616 |
1 |
| break; |
| 617 |
691 |
▶ | if (ctx->style.dualvars) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->style.dualvars) { |
691 |
0 |
691 |
|
| 618 |
691 |
▶ | if (cBOOL(SvNIOK(value)) != cBOOL(SvNIOK(v))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cBOOL(SvNIOK(value)) != cBOOL(SvNIOK(v))) |
7 |
684 |
691 |
|
| 619 |
7 |
| break; |
| 620 |
684 |
▶ | if (SvNIOK(value) && SvNIOK(v)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvNIOK(value) && SvNIOK(v)) { |
554 |
130 |
684 |
| if (SvNIOK(value) && SvNIOK(v)) { |
554 |
0 |
554 |
|
| 621 |
554 |
▶ | if (cBOOL(SvIOK(value)) != cBOOL(SvIOK(v))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cBOOL(SvIOK(value)) != cBOOL(SvIOK(v))) |
1 |
553 |
554 |
|
| 622 |
1 |
| break; |
| 623 |
553 |
▶ | if (SvIOK(value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIOK(value)) { |
552 |
1 |
553 |
|
| 624 |
552 |
▶ | if (cBOOL(SvIsUV(value)) != cBOOL(SvIsUV(v))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cBOOL(SvIsUV(value)) != cBOOL(SvIsUV(v))) |
0 |
552 |
552 |
|
| 625 |
0 |
| break; |
| 626 |
552 |
▶ | if (SvIsUV(value) ? SvUV(value) != SvUV(v) : SvIV(value) != SvIV(v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIsUV(value) ? SvUV(value) != SvUV(v) : SvIV(value) != SvIV(v)) |
1 |
551 |
552 |
| if (SvIsUV(value) ? SvUV(value) != SvUV(v) : SvIV(value) != SvIV(v)) |
502 |
50 |
552 |
|
| 627 |
502 |
| break; |
| 628 |
1 |
▶ | } else if (SvNV(value) != SvNV(v)) |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvNV(value) != SvNV(v)) |
1 |
0 |
1 |
|
| 629 |
1 |
| break; |
| 630 |
|
| } |
| 631 |
|
| } |
| 632 |
180 |
▶ | if (SvOK(value) && sv_cmp(value, v)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvOK(value) && sv_cmp(value, v)) |
180 |
0 |
180 |
| if (SvOK(value) && sv_cmp(value, v)) |
125 |
55 |
180 |
|
| 633 |
125 |
| break; |
| 634 |
55 |
| count++; |
| 635 |
|
| } |
| 636 |
|
| } |
| 637 |
|
| |
| 638 |
7607 |
▶ | newline = multiline && (!last_n || SvROK(value)); |
Branch: 3 branches
| Branch | True | False | Total |
| newline = multiline && (!last_n || SvROK(value)); |
5857 |
1750 |
7607 |
| newline = multiline && (!last_n || SvROK(value)); |
0 |
5857 |
5857 |
| newline = multiline && (!last_n || SvROK(value)); |
0 |
0 |
0 |
|
| 639 |
7607 |
▶ | if (k) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (k) { |
4545 |
3062 |
7607 |
|
| 640 |
4545 |
| dds_write(aTHX_ ctx, ctx->style.arysep); |
| 641 |
4545 |
▶ | if (newline) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (newline) { |
4529 |
16 |
4545 |
|
| 642 |
4529 |
| dds_put(aTHX_ ctx, "\n"); |
| 643 |
4529 |
| dds_spaces(aTHX_ ctx, indent); |
| 644 |
4529 |
| ctx->column = 0; |
| 645 |
|
| } else { |
| 646 |
16 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 647 |
16 |
▶ | if (!ctx->style.rle && !SvTRUE(ctx->style.space) && ctx->column > 1024) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!ctx->style.rle && !SvTRUE(ctx->style.space) && ctx->column > 1024) { |
1 |
15 |
16 |
| if (!ctx->style.rle && !SvTRUE(ctx->style.space) && ctx->column > 1024) { |
1 |
0 |
1 |
| if (!ctx->style.rle && !SvTRUE(ctx->style.space) && ctx->column > 1024) { |
1 |
0 |
1 |
|
| 648 |
1 |
| dds_put(aTHX_ ctx, "\n"); |
| 649 |
1 |
| ctx->column = 0; |
| 650 |
|
| } |
| 651 |
|
| } |
| 652 |
|
| } |
| 653 |
|
| |
| 654 |
7607 |
▶ | if (count > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) { |
19 |
7588 |
7607 |
|
| 655 |
19 |
| dds_put(aTHX_ ctx, "("); |
| 656 |
19 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 657 |
19 |
| ctx->column += 2; |
| 658 |
|
| } |
| 659 |
|
| |
| 660 |
|
| /* Save the continuation before a child frame becomes active. */ |
| 661 |
7607 |
| f->stage = DDS_STAGE_CHILD; |
| 662 |
7607 |
| f->k = k; |
| 663 |
7607 |
| f->run = count; |
| 664 |
7607 |
| f->last_n = last_n; |
| 665 |
7607 |
| dds_push_frame(aTHX_ ctx, DDS_FRAME_SV, value, depth + 1, mark, |
| 666 |
|
| dds_child_name(aTHX_ name, '[', NULL, k), indent, FALSE); |
| 667 |
7607 |
| return FALSE; |
| 668 |
|
| |
| 669 |
7607 |
| child_done: |
| 670 |
7607 |
| result = f->result; |
| 671 |
7607 |
| f->stage = DDS_STAGE_INITIAL; |
| 672 |
7607 |
▶ | last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
Branch: 3 branches
| Branch | True | False | Total |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
1522 |
6085 |
7607 |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
23 |
1499 |
1522 |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
20 |
3 |
23 |
|
| 673 |
|
| |
| 674 |
7607 |
▶ | if (result.alias) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (result.alias) { |
301 |
7306 |
7607 |
|
| 675 |
301 |
| SV *args = DDS_TEMP(newSVsv(dds_child_name(aTHX_ name, '@', NULL, 0))); |
| 676 |
|
| |
| 677 |
301 |
| sv_catpvf(args, ", %" IVdf, (IV)k); |
| 678 |
301 |
| dds_call_fix(aTHX_ ctx, "alias_av", args, result.alias, |
| 679 |
301 |
▶ | ctx->class_head ? dds_child_name(aTHX_ name, '[', NULL, k) : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| ctx->class_head ? dds_child_name(aTHX_ name, '[', NULL, k) : NULL); |
0 |
301 |
301 |
|
| 680 |
|
| } |
| 681 |
7607 |
▶ | if (count > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) { |
19 |
7588 |
7607 |
|
| 682 |
19 |
| SV *text = DDS_TEMP(newSVsv(ctx->style.space)); |
| 683 |
|
| |
| 684 |
19 |
| sv_catpvs(text, ")"); |
| 685 |
19 |
| DDS_CAT(text, ctx->style.space); |
| 686 |
19 |
| sv_catpvs(text, "x"); |
| 687 |
19 |
| DDS_CAT(text, ctx->style.space); |
| 688 |
19 |
| sv_catpvf(text, "%" IVdf, (IV)count); |
| 689 |
19 |
| ctx->column += sv_len_utf8(text); |
| 690 |
19 |
| dds_write(aTHX_ ctx, text); |
| 691 |
|
| } |
| 692 |
|
| |
| 693 |
7607 |
| k += count; |
| 694 |
7607 |
| f->active.sv = (SV *)av; |
| 695 |
|
| } |
| 696 |
|
| |
| 697 |
3092 |
| dds_brace(aTHX_ ctx, name, ']', multiline, indent, last + 1); |
| 698 |
3092 |
| Zero(&f->result, 1, dds_result); |
| 699 |
3092 |
| return TRUE; |
| 700 |
|
| } |
| 701 |
|
| |
| 702 |
|
| /* Advance a hash continuation through one value or completion, preserving key |
| 703 |
|
| * order, alignment and deferred value aliases. |
| 704 |
|
| */ |
| 705 |
18379 |
| static bool dds_step_hash(pTHX_ dds_ctx *ctx, struct dds_frame *f) |
| 706 |
|
| { |
| 707 |
18379 |
| HV *hv = (HV *)f->sv; |
| 708 |
18379 |
| UV depth = f->depth; |
| 709 |
18379 |
| dds_mark *mark = f->mark; |
| 710 |
18379 |
| SV *name = f->name; |
| 711 |
18379 |
| IV indent = f->indent; |
| 712 |
18379 |
| dds_node *node = f->node; |
| 713 |
18379 |
| AV *keys = f->keys; |
| 714 |
|
| |
| 715 |
18379 |
▶ | if (!keys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!keys) { |
1672 |
16707 |
18379 |
|
| 716 |
1672 |
| keys = dds_keys(aTHX_ ctx, hv, 1, NULL); |
| 717 |
1672 |
| f->keys = (AV *)SvREFCNT_inc((SV *)keys); |
| 718 |
|
| } |
| 719 |
18379 |
| UV count = av_len(keys) + 1, width = 0, sum = 0, max = 0; |
| 720 |
|
| SSize_t k; |
| 721 |
18379 |
| IV child_indent, last_n = 0; |
| 722 |
18379 |
| bool full = ctx->style.indent > 1; |
| 723 |
18379 |
▶ | bool multiline = ctx->style.indent && count > 1; |
Branch: 2 branches
| Branch | True | False | Total |
| bool multiline = ctx->style.indent && count > 1; |
17458 |
921 |
18379 |
| bool multiline = ctx->style.indent && count > 1; |
16622 |
836 |
17458 |
|
| 724 |
|
| |
| 725 |
18379 |
▶ | if (node && node->key_count) |
Branch: 2 branches
| Branch | True | False | Total |
| if (node && node->key_count) |
17226 |
1153 |
18379 |
| if (node && node->key_count) |
16236 |
990 |
17226 |
|
| 726 |
16236 |
▶ | multiline = ctx->style.indent && node->key_count > 1; |
Branch: 2 branches
| Branch | True | False | Total |
| multiline = ctx->style.indent && node->key_count > 1; |
16236 |
0 |
16236 |
| multiline = ctx->style.indent && node->key_count > 1; |
15992 |
244 |
16236 |
|
| 727 |
|
| |
| 728 |
|
| /* Reuse analysis widths when available; otherwise measure this hash. */ |
| 729 |
18379 |
▶ | if (f->stage == DDS_STAGE_INITIAL && ctx->style.indentkeys && multiline) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (f->stage == DDS_STAGE_INITIAL && ctx->style.indentkeys && multiline) { |
1672 |
16707 |
18379 |
| if (f->stage == DDS_STAGE_INITIAL && ctx->style.indentkeys && multiline) { |
1672 |
0 |
1672 |
| if (f->stage == DDS_STAGE_INITIAL && ctx->style.indentkeys && multiline) { |
941 |
731 |
1672 |
|
| 730 |
941 |
▶ | if (node && node->key_count) |
Branch: 2 branches
| Branch | True | False | Total |
| if (node && node->key_count) |
878 |
63 |
941 |
| if (node && node->key_count) |
873 |
5 |
878 |
|
| 731 |
873 |
| width = node->key_width; |
| 732 |
|
| else { |
| 733 |
630 |
▶ | for (k = 0; k <= av_len(keys); k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k <= av_len(keys); k++) { |
562 |
68 |
630 |
|
| 734 |
562 |
| UV len = sv_len_utf8(dds_quote(aTHX_ * av_fetch(keys, k, 0), TRUE)); |
| 735 |
|
| |
| 736 |
562 |
| sum += len; |
| 737 |
562 |
▶ | if (max < len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (max < len) |
114 |
448 |
562 |
|
| 738 |
114 |
| max = len; |
| 739 |
|
| } |
| 740 |
72 |
▶ | width = max > 8 && (2.0 / 3.0 * max) > ((NV)sum / count) ? (UV)(0.5 + (NV)sum / count) |
Branch: 1 branch
| Branch | True | False | Total |
| width = max > 8 && (2.0 / 3.0 * max) > ((NV)sum / count) ? (UV)(0.5 + (NV)sum / count) |
2 |
2 |
4 |
|
| 741 |
72 |
▶ | : max; |
Branch: 1 branch
| Branch | True | False | Total |
| : max; |
4 |
64 |
68 |
|
| 742 |
|
| } |
| 743 |
|
| } |
| 744 |
|
| |
| 745 |
18379 |
▶ | if (f->stage == DDS_STAGE_INITIAL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage == DDS_STAGE_INITIAL) |
1672 |
16707 |
18379 |
|
| 746 |
1672 |
| indent = dds_brace(aTHX_ ctx, name, '{', multiline, indent, count); |
| 747 |
|
| else |
| 748 |
16707 |
| width = f->width; |
| 749 |
|
| |
| 750 |
18379 |
| child_indent = |
| 751 |
18379 |
| indent + |
| 752 |
18379 |
▶ | (width ? width + 2 * sv_len_utf8(ctx->style.space) + sv_len_utf8(ctx->style.hashsep) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| (width ? width + 2 * sv_len_utf8(ctx->style.space) + sv_len_utf8(ctx->style.hashsep) : 0); |
16622 |
1757 |
18379 |
|
| 753 |
18379 |
| last_n = f->last_n; |
| 754 |
|
| |
| 755 |
35086 |
▶ | for (k = f->k; k <= av_len(keys); k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = f->k; k <= av_len(keys); k++) { |
33414 |
1672 |
35086 |
|
| 756 |
33414 |
| SV *key = *av_fetch(keys, k, 0), *quoted; |
| 757 |
|
| HE *he; |
| 758 |
|
| SV *value; |
| 759 |
|
| dds_result result; |
| 760 |
|
| |
| 761 |
33414 |
▶ | if (f->stage != DDS_STAGE_INITIAL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage != DDS_STAGE_INITIAL) |
16707 |
16707 |
33414 |
|
| 762 |
16707 |
| goto child_done; |
| 763 |
16707 |
▶ | if (!SvOK(key)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(key)) |
0 |
16707 |
16707 |
|
| 764 |
0 |
| break; |
| 765 |
16707 |
| he = hv_fetch_ent(hv, key, 0, 0); |
| 766 |
16707 |
▶ | value = he ? HeVAL(he) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| value = he ? HeVAL(he) : &PL_sv_undef; |
16707 |
0 |
16707 |
|
| 767 |
16707 |
| f->active.sv = value; |
| 768 |
16707 |
▶ | if (SvROK(value)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(value)) |
2861 |
13846 |
16707 |
|
| 769 |
2861 |
| last_n = 0; |
| 770 |
16707 |
▶ | if (k) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (k) { |
15051 |
1656 |
16707 |
|
| 771 |
15051 |
▶ | bool newline = multiline && !last_n; |
Branch: 2 branches
| Branch | True | False | Total |
| bool newline = multiline && !last_n; |
14740 |
311 |
15051 |
| bool newline = multiline && !last_n; |
14740 |
0 |
14740 |
|
| 772 |
|
| |
| 773 |
15051 |
| dds_write(aTHX_ ctx, ctx->style.pairsep); |
| 774 |
15051 |
| ctx->column++; |
| 775 |
15051 |
▶ | if (newline) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (newline) { |
14740 |
311 |
15051 |
|
| 776 |
14740 |
| dds_put(aTHX_ ctx, "\n"); |
| 777 |
14740 |
| dds_spaces(aTHX_ ctx, indent); |
| 778 |
14740 |
| ctx->column = 0; |
| 779 |
|
| } else { |
| 780 |
311 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 781 |
311 |
▶ | if (!SvTRUE(ctx->style.space) && ctx->column > 1024) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvTRUE(ctx->style.space) && ctx->column > 1024) { |
311 |
0 |
311 |
| if (!SvTRUE(ctx->style.space) && ctx->column > 1024) { |
2 |
309 |
311 |
|
| 782 |
2 |
| dds_put(aTHX_ ctx, "\n"); |
| 783 |
2 |
| ctx->column = 0; |
| 784 |
|
| } |
| 785 |
|
| } |
| 786 |
|
| } |
| 787 |
|
| |
| 788 |
16707 |
| quoted = dds_quote(aTHX_ key, TRUE); |
| 789 |
16707 |
| dds_write(aTHX_ ctx, quoted); |
| 790 |
16707 |
▶ | if (width) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (width) { |
15681 |
1026 |
16707 |
|
| 791 |
15681 |
| UV len = sv_len_utf8(quoted); |
| 792 |
|
| |
| 793 |
15681 |
▶ | if (len <= width) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len <= width) |
15673 |
8 |
15681 |
|
| 794 |
15673 |
| dds_spaces(aTHX_ ctx, width - len); |
| 795 |
|
| else { |
| 796 |
8 |
| dds_put(aTHX_ ctx, "\n"); |
| 797 |
8 |
| dds_spaces(aTHX_ ctx, indent + width); |
| 798 |
|
| } |
| 799 |
|
| } |
| 800 |
16707 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 801 |
16707 |
| dds_write(aTHX_ ctx, ctx->style.hashsep); |
| 802 |
16707 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 803 |
16707 |
▶ | ctx->column += (width ? width : sv_len_utf8(quoted)) + 2 * sv_len_utf8(ctx->style.space) + |
Branch: 1 branch
| Branch | True | False | Total |
| ctx->column += (width ? width : sv_len_utf8(quoted)) + 2 * sv_len_utf8(ctx->style.space) + |
1026 |
15681 |
16707 |
|
| 804 |
16707 |
| sv_len_utf8(ctx->style.hashsep); |
| 805 |
|
| |
| 806 |
|
| /* The resumed frame finishes alias handling for this same key. */ |
| 807 |
16707 |
| f->stage = DDS_STAGE_CHILD; |
| 808 |
16707 |
| f->keys = keys; |
| 809 |
16707 |
| f->k = k; |
| 810 |
16707 |
| f->last_n = last_n; |
| 811 |
16707 |
| f->width = width; |
| 812 |
16707 |
| f->indent = indent; |
| 813 |
16707 |
| dds_push_frame(aTHX_ ctx, DDS_FRAME_SV, value, depth + 1, mark, |
| 814 |
|
| dds_child_name(aTHX_ name, '{', key, 0), child_indent, FALSE); |
| 815 |
16707 |
| return FALSE; |
| 816 |
|
| |
| 817 |
16707 |
| child_done: |
| 818 |
16707 |
| result = f->result; |
| 819 |
16707 |
| f->stage = DDS_STAGE_INITIAL; |
| 820 |
16707 |
▶ | last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
Branch: 3 branches
| Branch | True | False | Total |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
616 |
16091 |
16707 |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
308 |
308 |
616 |
| last_n = !full && !ctx->do_nl && ctx->column < 60 ? last_n + 1 : 0; |
28 |
280 |
308 |
|
| 821 |
|
| |
| 822 |
16707 |
▶ | if (result.alias) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (result.alias) { |
10 |
16697 |
16707 |
|
| 823 |
10 |
| SV *args = DDS_TEMP(newSVsv(dds_child_name(aTHX_ name, '%', NULL, 0))); |
| 824 |
|
| |
| 825 |
10 |
| sv_catpvs(args, ", "); |
| 826 |
10 |
| DDS_CAT(args, dds_quote(aTHX_ key, FALSE)); |
| 827 |
10 |
| dds_call_fix(aTHX_ ctx, "alias_hv", args, result.alias, |
| 828 |
10 |
▶ | ctx->class_head ? dds_child_name(aTHX_ name, '{', key, 0) : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| ctx->class_head ? dds_child_name(aTHX_ name, '{', key, 0) : NULL); |
0 |
10 |
10 |
|
| 829 |
|
| } |
| 830 |
16707 |
| f->active.sv = (SV *)hv; |
| 831 |
|
| } |
| 832 |
|
| |
| 833 |
1672 |
| dds_brace(aTHX_ ctx, name, '}', multiline, indent, count); |
| 834 |
1672 |
| Zero(&f->result, 1, dds_result); |
| 835 |
1672 |
| return TRUE; |
| 836 |
|
| } |
| 837 |
|
| |
| 838 |
|
| /* Test whether an object reference has active overload behavior that requires |
| 839 |
|
| * deferred blessing. |
| 840 |
|
| */ |
| 841 |
5601 |
| static bool dds_overloaded(pTHX_ SV *rv) |
| 842 |
|
| { |
| 843 |
5601 |
▶ | return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
Branch: 13 branches
| Branch | True | False | Total |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
5601 |
0 |
5601 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
268 |
5333 |
5601 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
268 |
0 |
268 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
268 |
0 |
268 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
31 |
237 |
268 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
31 |
0 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
31 |
0 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
0 |
31 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
0 |
0 |
0 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
31 |
0 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
0 |
31 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
31 |
0 |
31 |
| return SvROK(rv) && SvOBJECT(SvRV(rv)) && SvAMAGIC(rv) && Gv_AMG(SvSTASH(SvRV(rv))); |
3 |
28 |
31 |
|
| 844 |
|
| } |
| 845 |
|
| |
| 846 |
|
| /* Check ignore policies and emit an ignored-object description when selected, |
| 847 |
|
| * returning whether the referent was handled. |
| 848 |
|
| */ |
| 849 |
10106 |
| static bool dds_emit_ignored(pTHX_ dds_ctx *ctx, SV *rv, SV *target, bool forced) |
| 850 |
|
| { |
| 851 |
10106 |
| HV *style = dds_hash(aTHX_ ctx->object, "style", FALSE); |
| 852 |
10106 |
| HV *ignore = dds_hash(aTHX_ style, "ignore", FALSE); |
| 853 |
10106 |
| SV *key = DDS_TEMP(newSVpvf("#%" UVuf, PTR2UV(target))); |
| 854 |
10106 |
| SV *class_name = dds_class(aTHX_ target); |
| 855 |
10106 |
▶ | bool ignored = forced || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
Branch: 2 branches
| Branch | True | False | Total |
| bool ignored = forced || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
10097 |
9 |
10106 |
| bool ignored = forced || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
0 |
10097 |
10097 |
|
| 856 |
|
| |
| 857 |
10106 |
▶ | if (SvOK(class_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) { |
362 |
9744 |
10106 |
|
| 858 |
362 |
| key = dds_concat(aTHX_ ".", class_name, ""); |
| 859 |
362 |
▶ | ignored = ignored || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
Branch: 2 branches
| Branch | True | False | Total |
| ignored = ignored || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
353 |
9 |
362 |
| ignored = ignored || SvTRUE(dds_hget_sv(aTHX_ ignore, key)); |
4 |
349 |
353 |
|
| 860 |
|
| } |
| 861 |
|
| |
| 862 |
10106 |
▶ | if (ignored) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ignored) { |
13 |
10093 |
10106 |
|
| 863 |
13 |
| SV *text = DDS_TEMP(newSVpvs("Ignored Obj [")); |
| 864 |
13 |
| SV *plain = DDS_TEMP(newSV(0)); |
| 865 |
|
| |
| 866 |
13 |
| sv_setpvf(plain, "%s(0x%" UVxf ")", sv_reftype(target, TRUE), PTR2UV(target)); |
| 867 |
13 |
▶ | if (SvOBJECT(target)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(target)) { |
13 |
0 |
13 |
|
| 868 |
26 |
| sv_setpvf(plain, "%s=%s(0x%" UVxf ")", DDS_PV(class_name), sv_reftype(target, FALSE), |
| 869 |
|
| PTR2UV(target)); |
| 870 |
|
| } |
| 871 |
13 |
| DDS_CAT(text, plain); |
| 872 |
13 |
| sv_catpvs(text, "]"); |
| 873 |
13 |
| dds_write(aTHX_ ctx, dds_quote(aTHX_ text, FALSE)); |
| 874 |
|
| PERL_UNUSED_ARG(rv); |
| 875 |
|
| } |
| 876 |
10106 |
| return ignored; |
| 877 |
|
| } |
| 878 |
|
| |
| 879 |
|
| /* Emit a gensym expression and queue its enabled glob slots once, loading |
| 880 |
|
| * Symbol lazily in the generated code. |
| 881 |
|
| */ |
| 882 |
74 |
| static void dds_emit_symbol(pTHX_ dds_ctx *ctx, GV *gv, SV *name, UV depth, bool deref) |
| 883 |
|
| { |
| 884 |
74 |
| dds_node *node = dds_find(aTHX_ ctx, (SV *)gv, TRUE); |
| 885 |
|
| |
| 886 |
74 |
▶ | if (deref) |
Branch: 1 branch
| Branch | True | False | Total |
| if (deref) |
1 |
73 |
74 |
|
| 887 |
1 |
| dds_put(aTHX_ ctx, "*{ "); |
| 888 |
74 |
▶ | if (!ctx->symbol_required) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->symbol_required) { |
60 |
14 |
74 |
|
| 889 |
60 |
| dds_put(aTHX_ ctx, "do{ require Symbol; Symbol::gensym }"); |
| 890 |
60 |
| ctx->symbol_required = TRUE; |
| 891 |
|
| } else |
| 892 |
14 |
| dds_put(aTHX_ ctx, "Symbol::gensym"); |
| 893 |
74 |
▶ | if (deref) |
Branch: 1 branch
| Branch | True | False | Total |
| if (deref) |
1 |
73 |
74 |
|
| 894 |
1 |
| dds_put(aTHX_ ctx, " }"); |
| 895 |
|
| |
| 896 |
74 |
▶ | if (ctx->style.dumpglob && !node->glob_dumped) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->style.dumpglob && !node->glob_dumped) { |
74 |
0 |
74 |
| if (ctx->style.dumpglob && !node->glob_dumped) { |
74 |
0 |
74 |
|
| 897 |
|
| dds_fix *fix = |
| 898 |
74 |
| dds_new_fix(aTHX_ DDS_FIX_GLOB, dds_child_name(aTHX_ name, '*', NULL, 0), NULL); |
| 899 |
|
| |
| 900 |
74 |
| node->glob_dumped = TRUE; |
| 901 |
74 |
| fix->glob = (GV *)SvREFCNT_inc((SV *)gv); |
| 902 |
74 |
| fix->depth = depth + 1; |
| 903 |
74 |
| dds_add_fix(aTHX_ ctx, fix); |
| 904 |
|
| } |
| 905 |
74 |
| } |
| 906 |
|
| |
| 907 |
|
| /* |
| 908 |
|
| * Scalar slots |
| 909 |
|
| * |
| 910 |
|
| * Slot aliasing is independent of referent sharing. Resolve the slot first, |
| 911 |
|
| * then emit its literal or yield to reference construction. |
| 912 |
|
| */ |
| 913 |
|
| |
| 914 |
|
| /* Advance a scalar-slot continuation, handling aliases, root assignments, |
| 915 |
|
| * literals and references before queuing readonly or weak fixups. |
| 916 |
|
| */ |
| 917 |
37024 |
| static bool dds_step_sv(pTHX_ dds_ctx *ctx, struct dds_frame *f) |
| 918 |
|
| { |
| 919 |
37024 |
| SV *sv = f->sv, *name = f->name; |
| 920 |
37024 |
| UV depth = f->depth; |
| 921 |
37024 |
| dds_mark *mark = f->mark; |
| 922 |
37024 |
| IV indent = f->indent; |
| 923 |
37024 |
| bool is_ref = f->is_ref; |
| 924 |
37024 |
| dds_result result = {NULL, NULL}; |
| 925 |
37024 |
▶ | dds_node *node = dds_candidate(aTHX_ sv) ? dds_find(aTHX_ ctx, sv, FALSE) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| dds_node *node = dds_candidate(aTHX_ sv) ? dds_find(aTHX_ ctx, sv, FALSE) : NULL; |
6607 |
30417 |
37024 |
|
| 926 |
37024 |
▶ | dds_role *role = node && node->slot.present ? &node->slot : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| dds_role *role = node && node->slot.present ? &node->slot : NULL; |
4727 |
32297 |
37024 |
| dds_role *role = node && node->slot.present ? &node->slot : NULL; |
4713 |
14 |
4727 |
|
| 927 |
37024 |
▶ | SV *clean = SvOK(name) ? dds_clean_name(aTHX_ name) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *clean = SvOK(name) ? dds_clean_name(aTHX_ name) : &PL_sv_undef; |
37024 |
0 |
37024 |
|
| 928 |
37024 |
▶ | bool readonly = role ? role->readonly : cBOOL(SvREADONLY(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| bool readonly = role ? role->readonly : cBOOL(SvREADONLY(sv)); |
4713 |
32311 |
37024 |
|
| 929 |
|
| bool add_do, is_ro; |
| 930 |
|
| |
| 931 |
37024 |
▶ | if (f->stage != DDS_STAGE_INITIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage != DDS_STAGE_INITIAL) { |
10106 |
26918 |
37024 |
|
| 932 |
10106 |
| role = f->role; |
| 933 |
10106 |
| add_do = f->add_do; |
| 934 |
10106 |
| goto child_done; |
| 935 |
|
| } |
| 936 |
|
| |
| 937 |
26918 |
| ctx->do_nl = FALSE; |
| 938 |
26918 |
▶ | if (SvGMAGICAL(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvGMAGICAL(sv)) { |
9 |
26909 |
26918 |
|
| 939 |
9 |
| dds_callback_guard(aTHX_ ctx); |
| 940 |
9 |
| av_push(ctx->keepalive, SvREFCNT_inc(sv)); |
| 941 |
9 |
| mg_get(sv); |
| 942 |
|
| } |
| 943 |
|
| |
| 944 |
|
| /* A scalar slot can be aliased independently of its referent. Resolve |
| 945 |
|
| * that relationship before choosing how to print the slot's value. */ |
| 946 |
26918 |
▶ | if (role) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (role) { |
3104 |
23814 |
26918 |
|
| 947 |
3104 |
| bool different = |
| 948 |
3453 |
▶ | role->depth == depth && sv_cmp(role->name, clean) && DDS_PV(name)[0] != '&'; |
Branch: 3 branches
| Branch | True | False | Total |
| role->depth == depth && sv_cmp(role->name, clean) && DDS_PV(name)[0] != '&'; |
2849 |
255 |
3104 |
| role->depth == depth && sv_cmp(role->name, clean) && DDS_PV(name)[0] != '&'; |
349 |
2500 |
2849 |
| role->depth == depth && sv_cmp(role->name, clean) && DDS_PV(name)[0] != '&'; |
349 |
0 |
349 |
|
| 949 |
|
| |
| 950 |
3104 |
▶ | if (!role->original && (role->done || role->depth < depth || different)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!role->original && (role->done || role->depth < depth || different)) { |
2938 |
166 |
3104 |
| if (!role->original && (role->done || role->depth < depth || different)) { |
2515 |
423 |
2938 |
| if (!role->original && (role->done || role->depth < depth || different)) { |
2374 |
141 |
2515 |
| if (!role->original && (role->done || role->depth < depth || different)) { |
12 |
2362 |
2374 |
|
| 951 |
576 |
| SV *text = DDS_TEMP(newSVpvs("")); |
| 952 |
|
| |
| 953 |
576 |
▶ | if (is_ref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_ref) { |
221 |
355 |
576 |
|
| 954 |
221 |
▶ | if ((role->depth == 1 && !ctx->style.declare) || |
Branch: 2 branches
| Branch | True | False | Total |
| if ((role->depth == 1 && !ctx->style.declare) || |
104 |
117 |
221 |
| if ((role->depth == 1 && !ctx->style.declare) || |
34 |
70 |
104 |
|
| 955 |
151 |
▶ | (role->done && role->done->ready) || !ctx->style.purity) { |
Branch: 3 branches
| Branch | True | False | Total |
| (role->done && role->done->ready) || !ctx->style.purity) { |
53 |
98 |
151 |
| (role->done && role->done->ready) || !ctx->style.purity) { |
19 |
34 |
53 |
| (role->done && role->done->ready) || !ctx->style.purity) { |
6 |
111 |
117 |
|
| 956 |
110 |
| sv_catpvs(text, "\\"); |
| 957 |
110 |
| DDS_CAT(text, role->name); |
| 958 |
|
| } else { |
| 959 |
111 |
| bool need_do = strnEQ(DDS_PV(name), "$$$", 3); |
| 960 |
|
| dds_fix *fix; |
| 961 |
|
| |
| 962 |
111 |
▶ | if (need_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_do) { |
4 |
107 |
111 |
|
| 963 |
4 |
| sv_catpvs(text, "do"); |
| 964 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 965 |
4 |
| sv_catpvs(text, "{"); |
| 966 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 967 |
4 |
| sv_catpvs(text, "my"); |
| 968 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 969 |
4 |
| sv_catpvs(text, "$f"); |
| 970 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 971 |
4 |
| sv_catpvs(text, "="); |
| 972 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 973 |
|
| } |
| 974 |
111 |
▶ | DDS_CAT(text, |
Branch: 1 branch
| Branch | True | False | Total |
| DDS_CAT(text, |
111 |
0 |
111 |
|
| 975 |
|
| ctx->style.verbose |
| 976 |
|
| ? dds_quote(aTHX_ dds_concat(aTHX_ "R: ", role->name, ""), FALSE) |
| 977 |
|
| : DDS_TEMP(newSVpvs("'R'"))); |
| 978 |
111 |
| result.deferred = dds_new_mark(aTHX_ ctx); |
| 979 |
111 |
| fix = dds_new_fix(aTHX_ DDS_FIX_SLOT, name, node); |
| 980 |
111 |
| fix->mark = result.deferred; |
| 981 |
111 |
| dds_add_fix(aTHX_ ctx, fix); |
| 982 |
111 |
▶ | if (need_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_do) { |
4 |
107 |
111 |
|
| 983 |
4 |
| DDS_CAT(text, ctx->style.space); |
| 984 |
4 |
| sv_catpvs(text, "}"); |
| 985 |
|
| } |
| 986 |
|
| } |
| 987 |
355 |
▶ | } else if (depth == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (depth == 1) { |
36 |
319 |
355 |
|
| 988 |
36 |
▶ | if (ctx->style.declare && !ctx->class_head) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->style.declare && !ctx->class_head) { |
0 |
36 |
36 |
| if (ctx->style.declare && !ctx->class_head) { |
0 |
0 |
0 |
|
| 989 |
0 |
| sv_catpvs(text, "my "); |
| 990 |
0 |
| DDS_CAT(text, name); |
| 991 |
0 |
| sv_catpvs(text, ";\n"); |
| 992 |
|
| } |
| 993 |
36 |
| sv_catpvs(text, "alias_ref(\\"); |
| 994 |
36 |
| DDS_CAT(text, name); |
| 995 |
36 |
| sv_catpvs(text, ",\\"); |
| 996 |
36 |
| DDS_CAT(text, role->name); |
| 997 |
36 |
| sv_catpvs(text, ")"); |
| 998 |
319 |
▶ | } else if (ctx->style.purity) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (ctx->style.purity) { |
311 |
8 |
319 |
|
| 999 |
311 |
▶ | DDS_CAT(text, ctx->style.verbose |
Branch: 1 branch
| Branch | True | False | Total |
| DDS_CAT(text, ctx->style.verbose |
311 |
0 |
311 |
|
| 1000 |
|
| ? dds_quote(aTHX_ dds_concat(aTHX_ "A: ", role->name, ""), FALSE) |
| 1001 |
|
| : DDS_TEMP(newSVpvs("'A'"))); |
| 1002 |
311 |
| result.alias = node; |
| 1003 |
|
| } else { |
| 1004 |
8 |
| sv_catpvs(text, "alias_to("); |
| 1005 |
8 |
| DDS_CAT(text, role->name); |
| 1006 |
8 |
| sv_catpvs(text, ")"); |
| 1007 |
|
| } |
| 1008 |
576 |
| ctx->column += sv_len_utf8(text); |
| 1009 |
576 |
| dds_write(aTHX_ ctx, text); |
| 1010 |
576 |
| f->result = result; |
| 1011 |
576 |
| return TRUE; |
| 1012 |
|
| } |
| 1013 |
2528 |
▶ | if (!role->done) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!role->done) |
2517 |
11 |
2528 |
|
| 1014 |
2517 |
| role->done = mark; |
| 1015 |
|
| } |
| 1016 |
|
| |
| 1017 |
|
| /* Root assignments introduce names; nested values only emit an RHS. */ |
| 1018 |
26342 |
▶ | if (depth == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (depth == 1) { |
1901 |
24441 |
26342 |
|
| 1019 |
2046 |
▶ | if (role && sv_cmp(name, clean) && DDS_PV(name)[0] != '*' && role->count > 1) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (role && sv_cmp(name, clean) && DDS_PV(name)[0] != '*' && role->count > 1) { |
1894 |
7 |
1901 |
| if (role && sv_cmp(name, clean) && DDS_PV(name)[0] != '*' && role->count > 1) { |
145 |
1749 |
1894 |
| if (role && sv_cmp(name, clean) && DDS_PV(name)[0] != '*' && role->count > 1) { |
145 |
0 |
145 |
| if (role && sv_cmp(name, clean) && DDS_PV(name)[0] != '*' && role->count > 1) { |
145 |
0 |
145 |
|
| 1020 |
145 |
▶ | if (node->ref.present) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->ref.present) { |
19 |
126 |
145 |
|
| 1021 |
19 |
| SV *other = dds_child_name(aTHX_ node->ref.name, '$', NULL, 0); |
| 1022 |
|
| |
| 1023 |
19 |
| sv_setsv(role->name, other); |
| 1024 |
|
| } |
| 1025 |
145 |
| role->done = NULL; |
| 1026 |
|
| } |
| 1027 |
3703 |
▶ | if (!ctx->style.terse && DDS_PV(name)[0] != '&') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!ctx->style.terse && DDS_PV(name)[0] != '&') { |
1802 |
99 |
1901 |
| if (!ctx->style.terse && DDS_PV(name)[0] != '&') { |
1795 |
7 |
1802 |
|
| 1028 |
1795 |
| SV *prefix = DDS_TEMP(newSVpvs("")); |
| 1029 |
|
| |
| 1030 |
2173 |
▶ | if (ctx->style.declare && !ctx->class_head && DDS_PV(name)[0] != '*' && |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->style.declare && !ctx->class_head && DDS_PV(name)[0] != '*' && |
189 |
1606 |
1795 |
| if (ctx->style.declare && !ctx->class_head && DDS_PV(name)[0] != '*' && |
189 |
0 |
189 |
|
| 1031 |
189 |
| !hv_exists_ent(ctx->lexical_added, name, 0)) { |
| 1032 |
189 |
| sv_catpvs(prefix, "my"); |
| 1033 |
189 |
| DDS_CAT(prefix, ctx->style.space); |
| 1034 |
|
| } |
| 1035 |
1795 |
| DDS_CAT(prefix, name); |
| 1036 |
1795 |
| DDS_CAT(prefix, ctx->style.space); |
| 1037 |
1795 |
| sv_catpvs(prefix, "="); |
| 1038 |
1795 |
| DDS_CAT(prefix, ctx->style.space); |
| 1039 |
1795 |
| indent = sv_len_utf8(prefix); |
| 1040 |
1795 |
| dds_write(aTHX_ ctx, prefix); |
| 1041 |
1794 |
| ctx->column = 0; |
| 1042 |
|
| } else |
| 1043 |
106 |
| indent = 0; |
| 1044 |
|
| } |
| 1045 |
|
| |
| 1046 |
26341 |
▶ | if (is_ref) |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_ref) |
354 |
25987 |
26341 |
|
| 1047 |
354 |
| dds_put(aTHX_ ctx, "\\"); |
| 1048 |
|
| |
| 1049 |
|
| /* A mutable scalar reference needs storage. The do block supplies |
| 1050 |
|
| * a private scalar instead of taking a reference to a constant. */ |
| 1051 |
26341 |
| add_do = |
| 1052 |
26243 |
▶ | ctx->style.purity && !readonly && is_ref && !(SvROK(sv) && SvOBJECT(SvRV(sv))) && |
Branch: 4 branches
| Branch | True | False | Total |
| ctx->style.purity && !readonly && is_ref && !(SvROK(sv) && SvOBJECT(SvRV(sv))) && |
26184 |
59 |
26243 |
| ctx->style.purity && !readonly && is_ref && !(SvROK(sv) && SvOBJECT(SvRV(sv))) && |
299 |
25885 |
26184 |
| ctx->style.purity && !readonly && is_ref && !(SvROK(sv) && SvOBJECT(SvRV(sv))) && |
199 |
100 |
299 |
| ctx->style.purity && !readonly && is_ref && !(SvROK(sv) && SvOBJECT(SvRV(sv))) && |
178 |
21 |
199 |
|
| 1053 |
52800 |
▶ | SvTYPE(sv) != SVt_PVGV && |
Branch: 2 branches
| Branch | True | False | Total |
| SvTYPE(sv) != SVt_PVGV && |
26243 |
98 |
26341 |
| SvTYPE(sv) != SVt_PVGV && |
216 |
62 |
278 |
|
| 1054 |
216 |
▶ | (!SvROK(sv) || (SvTYPE(SvRV(sv)) <= SVt_PVMG && !SvROK(SvRV(sv)) && !SvREADONLY(SvRV(sv)))); |
Branch: 4 branches
| Branch | True | False | Total |
| (!SvROK(sv) || (SvTYPE(SvRV(sv)) <= SVt_PVMG && !SvROK(SvRV(sv)) && !SvREADONLY(SvRV(sv)))); |
178 |
38 |
216 |
| (!SvROK(sv) || (SvTYPE(SvRV(sv)) <= SVt_PVMG && !SvROK(SvRV(sv)) && !SvREADONLY(SvRV(sv)))); |
83 |
95 |
178 |
| (!SvROK(sv) || (SvTYPE(SvRV(sv)) <= SVt_PVMG && !SvROK(SvRV(sv)) && !SvREADONLY(SvRV(sv)))); |
32 |
51 |
83 |
| (!SvROK(sv) || (SvTYPE(SvRV(sv)) <= SVt_PVMG && !SvROK(SvRV(sv)) && !SvREADONLY(SvRV(sv)))); |
4 |
28 |
32 |
|
| 1055 |
26341 |
▶ | if (add_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (add_do) { |
42 |
26299 |
26341 |
|
| 1056 |
42 |
| dds_put(aTHX_ ctx, "do"); |
| 1057 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1058 |
42 |
| dds_put(aTHX_ ctx, "{"); |
| 1059 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1060 |
42 |
| dds_put(aTHX_ ctx, "my"); |
| 1061 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1062 |
42 |
| dds_put(aTHX_ ctx, "$v"); |
| 1063 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1064 |
42 |
| dds_put(aTHX_ ctx, "="); |
| 1065 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1066 |
42 |
| ctx->column += 13; |
| 1067 |
|
| } |
| 1068 |
|
| |
| 1069 |
26341 |
▶ | is_ro = ctx->style.readonly && readonly && !is_ref; |
Branch: 3 branches
| Branch | True | False | Total |
| is_ro = ctx->style.readonly && readonly && !is_ref; |
26341 |
0 |
26341 |
| is_ro = ctx->style.readonly && readonly && !is_ref; |
63 |
26278 |
26341 |
| is_ro = ctx->style.readonly && readonly && !is_ref; |
12 |
51 |
63 |
|
| 1070 |
26341 |
▶ | if (SvROK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) { |
10106 |
16235 |
26341 |
|
| 1071 |
10106 |
| ctx->do_nl = TRUE; |
| 1072 |
10106 |
| f->stage = DDS_STAGE_CHILD; |
| 1073 |
10106 |
| f->role = role; |
| 1074 |
10106 |
| f->add_do = add_do; |
| 1075 |
10106 |
| dds_push_frame(aTHX_ ctx, DDS_FRAME_REF, sv, depth + 1, mark, name, indent, |
| 1076 |
10106 |
▶ | is_ref && !add_do); |
Branch: 2 branches
| Branch | True | False | Total |
| is_ref && !add_do); |
204 |
9902 |
10106 |
| is_ref && !add_do); |
200 |
4 |
204 |
|
| 1077 |
10106 |
| return FALSE; |
| 1078 |
16235 |
▶ | } else if (!SvOK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (!SvOK(sv)) { |
116 |
16119 |
16235 |
|
| 1079 |
116 |
| dds_put(aTHX_ ctx, "undef"); |
| 1080 |
116 |
| ctx->column += 5; |
| 1081 |
|
| } else { |
| 1082 |
16119 |
▶ | if (is_ro && !ctx->style.purity && !ctx->style.terse) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (is_ro && !ctx->style.purity && !ctx->style.terse) { |
11 |
16108 |
16119 |
| if (is_ro && !ctx->style.purity && !ctx->style.terse) { |
1 |
10 |
11 |
| if (is_ro && !ctx->style.purity && !ctx->style.terse) { |
1 |
0 |
1 |
|
| 1083 |
1 |
| dds_put(aTHX_ ctx, "make_ro("); |
| 1084 |
1 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1085 |
|
| } |
| 1086 |
16119 |
▶ | if (SvTYPE(sv) == SVt_PVGV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) == SVt_PVGV) { |
71 |
16048 |
16119 |
|
| 1087 |
71 |
| SV *glob = dds_glob_name(aTHX_(GV *) sv); |
| 1088 |
|
| |
| 1089 |
71 |
▶ | if (strnEQ(DDS_PV(glob), "*Symbol::GEN", 12)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strnEQ(DDS_PV(glob), "*Symbol::GEN", 12)) |
1 |
70 |
71 |
|
| 1090 |
1 |
| dds_emit_symbol(aTHX_ ctx, (GV *)sv, name, depth, TRUE); |
| 1091 |
|
| else { |
| 1092 |
|
| dds_node *gnode; |
| 1093 |
|
| |
| 1094 |
70 |
| dds_write(aTHX_ ctx, glob); |
| 1095 |
70 |
| ctx->column += sv_len_utf8(glob); |
| 1096 |
70 |
▶ | gnode = ctx->style.dumpglob ? dds_find(aTHX_ ctx, sv, TRUE) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| gnode = ctx->style.dumpglob ? dds_find(aTHX_ ctx, sv, TRUE) : NULL; |
67 |
3 |
70 |
|
| 1097 |
70 |
▶ | if (gnode && !gnode->glob_dumped) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (gnode && !gnode->glob_dumped) { |
67 |
3 |
70 |
| if (gnode && !gnode->glob_dumped) { |
67 |
0 |
67 |
|
| 1098 |
67 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_GLOB, glob, NULL); |
| 1099 |
|
| |
| 1100 |
67 |
| gnode->glob_dumped = TRUE; |
| 1101 |
67 |
| fix->glob = (GV *)SvREFCNT_inc(sv); |
| 1102 |
67 |
| fix->depth = depth + 1; |
| 1103 |
67 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1104 |
|
| } |
| 1105 |
|
| } |
| 1106 |
|
| } else { |
| 1107 |
16048 |
| SV *quoted = NULL; |
| 1108 |
|
| |
| 1109 |
16048 |
▶ | if (ctx->style.dualvars && SvNIOK(sv) && SvPOK(sv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ctx->style.dualvars && SvNIOK(sv) && SvPOK(sv)) { |
16046 |
2 |
16048 |
| if (ctx->style.dualvars && SvNIOK(sv) && SvPOK(sv)) { |
13957 |
2089 |
16046 |
| if (ctx->style.dualvars && SvNIOK(sv) && SvPOK(sv)) { |
7 |
13950 |
13957 |
|
| 1110 |
|
| SV *number = |
| 1111 |
7 |
▶ | DDS_TEMP(SvIOK(sv) ? (SvIsUV(sv) ? newSVuv(SvUV(sv)) : newSViv(SvIV(sv))) |
Branch: 2 branches
| Branch | True | False | Total |
| DDS_TEMP(SvIOK(sv) ? (SvIsUV(sv) ? newSVuv(SvUV(sv)) : newSViv(SvIV(sv))) |
7 |
0 |
7 |
| DDS_TEMP(SvIOK(sv) ? (SvIsUV(sv) ? newSVuv(SvUV(sv)) : newSViv(SvIV(sv))) |
2 |
5 |
7 |
|
| 1112 |
|
| : newSVnv(SvNV(sv))); |
| 1113 |
|
| |
| 1114 |
7 |
▶ | if (sv_cmp(number, sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_cmp(number, sv)) { |
7 |
0 |
7 |
|
| 1115 |
7 |
| quoted = DDS_TEMP(newSVpvs("dualvar( ")); |
| 1116 |
7 |
| DDS_CAT(quoted, number); |
| 1117 |
7 |
| sv_catpvs(quoted, ","); |
| 1118 |
7 |
| DDS_CAT(quoted, ctx->style.space); |
| 1119 |
7 |
| DDS_CAT(quoted, dds_quote(aTHX_ sv, FALSE)); |
| 1120 |
7 |
| DDS_CAT(quoted, ctx->style.space); |
| 1121 |
7 |
| sv_catpvs(quoted, ")"); |
| 1122 |
|
| } |
| 1123 |
|
| } |
| 1124 |
16048 |
▶ | if (!quoted && ctx->style.compress && SvTRUE(ctx->style.compressor) && |
Branch: 3 branches
| Branch | True | False | Total |
| if (!quoted && ctx->style.compress && SvTRUE(ctx->style.compressor) && |
16041 |
7 |
16048 |
| if (!quoted && ctx->style.compress && SvTRUE(ctx->style.compressor) && |
9 |
16032 |
16041 |
| if (!quoted && ctx->style.compress && SvTRUE(ctx->style.compressor) && |
9 |
0 |
9 |
|
| 1125 |
9 |
▶ | (ctx->style.compress < 0 || sv_len_utf8(sv) > (UV)ctx->style.compress)) { |
Branch: 2 branches
| Branch | True | False | Total |
| (ctx->style.compress < 0 || sv_len_utf8(sv) > (UV)ctx->style.compress)) { |
0 |
9 |
9 |
| (ctx->style.compress < 0 || sv_len_utf8(sv) > (UV)ctx->style.compress)) { |
0 |
0 |
0 |
|
| 1126 |
|
| SV *args[3]; |
| 1127 |
|
| |
| 1128 |
9 |
| args[0] = sv; |
| 1129 |
9 |
| args[1] = ctx->owner; |
| 1130 |
9 |
| quoted = dds_invoke(aTHX_ ctx, ctx->style.compressor, FALSE, G_SCALAR, 2, args); |
| 1131 |
|
| } |
| 1132 |
16048 |
▶ | if (!quoted) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!quoted) |
16032 |
16 |
16048 |
|
| 1133 |
16032 |
| quoted = dds_quote(aTHX_ sv, FALSE); |
| 1134 |
16048 |
| ctx->column += sv_len_utf8(quoted); |
| 1135 |
16048 |
| dds_write(aTHX_ ctx, quoted); |
| 1136 |
|
| } |
| 1137 |
16119 |
▶ | if (!ctx->style.terse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->style.terse) { |
16106 |
13 |
16119 |
|
| 1138 |
16106 |
▶ | if (is_ro && ctx->style.purity) |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_ro && ctx->style.purity) |
10 |
16096 |
16106 |
| if (is_ro && ctx->style.purity) |
9 |
1 |
10 |
|
| 1139 |
9 |
| dds_call_fix(aTHX_ ctx, "make_ro", name, NULL, NULL); |
| 1140 |
16097 |
▶ | else if (is_ro) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (is_ro) { |
1 |
16096 |
16097 |
|
| 1141 |
1 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1142 |
1 |
| dds_put(aTHX_ ctx, ")"); |
| 1143 |
|
| } |
| 1144 |
|
| } |
| 1145 |
16119 |
| ctx->do_nl = FALSE; |
| 1146 |
|
| } |
| 1147 |
|
| |
| 1148 |
26341 |
| child_done: |
| 1149 |
26341 |
▶ | if (add_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (add_do) { |
42 |
26299 |
26341 |
|
| 1150 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1151 |
42 |
| dds_put(aTHX_ ctx, "}"); |
| 1152 |
|
| } |
| 1153 |
26341 |
▶ | if ((role && role->weak) || (SvROK(sv) && SvWEAKREF(sv))) |
Branch: 4 branches
| Branch | True | False | Total |
| if ((role && role->weak) || (SvROK(sv) && SvWEAKREF(sv))) |
2527 |
23814 |
26341 |
| if ((role && role->weak) || (SvROK(sv) && SvWEAKREF(sv))) |
2481 |
46 |
2527 |
| if ((role && role->weak) || (SvROK(sv) && SvWEAKREF(sv))) |
10060 |
16235 |
26295 |
| if ((role && role->weak) || (SvROK(sv) && SvWEAKREF(sv))) |
699 |
9361 |
10060 |
|
| 1154 |
745 |
| dds_call_fix(aTHX_ ctx, "weaken", name, NULL, NULL); |
| 1155 |
26341 |
| f->result = result; |
| 1156 |
26341 |
| return TRUE; |
| 1157 |
|
| } |
| 1158 |
|
| |
| 1159 |
|
| /* Queue one postdump hook per original frozen object, owning a reference to |
| 1160 |
|
| * that original independently of any shared proxy. |
| 1161 |
|
| */ |
| 1162 |
7328 |
| static void dds_queue_postdump(pTHX_ dds_ctx *ctx, dds_node *node, SV *original) |
| 1163 |
|
| { |
| 1164 |
|
| dds_postop *postop; |
| 1165 |
|
| |
| 1166 |
7328 |
▶ | if (!node || node->ignored || node->postop_queued || !node->postop) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!node || node->ignored || node->postop_queued || !node->postop) |
7328 |
0 |
7328 |
| if (!node || node->ignored || node->postop_queued || !node->postop) |
7327 |
1 |
7328 |
| if (!node || node->ignored || node->postop_queued || !node->postop) |
7311 |
16 |
7327 |
| if (!node || node->ignored || node->postop_queued || !node->postop) |
7274 |
37 |
7311 |
|
| 1167 |
7291 |
| return; |
| 1168 |
|
| |
| 1169 |
|
| /* Completion belongs to the original frozen object, not its proxy: |
| 1170 |
|
| * distinct originals can share one reconstructed replacement. Own a |
| 1171 |
|
| * snapshot from the already-fetched referent. Copying a magical RV |
| 1172 |
|
| * here would FETCH again and could select a different object. */ |
| 1173 |
37 |
| Newxz(postop, 1, dds_postop); |
| 1174 |
37 |
| postop->node = node; |
| 1175 |
37 |
| node->postop_queued = TRUE; |
| 1176 |
37 |
▶ | if (ctx->postop_tail) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->postop_tail) |
17 |
20 |
37 |
|
| 1177 |
17 |
| ctx->postop_tail->next = postop; |
| 1178 |
|
| else |
| 1179 |
20 |
| ctx->postop_head = postop; |
| 1180 |
37 |
| ctx->postop_tail = postop; |
| 1181 |
37 |
| postop->invocant = newRV_inc(original); |
| 1182 |
|
| } |
| 1183 |
|
| |
| 1184 |
|
| /* Run queued hooks for original objects after graph output and fixups finish, |
| 1185 |
|
| * releasing each queued record before invoking Perl. |
| 1186 |
|
| */ |
| 1187 |
1511 |
| static void dds_run_postdump(pTHX_ dds_ctx *ctx) |
| 1188 |
|
| { |
| 1189 |
|
| /* A noncanonical occurrence may precede its proxy's construction. |
| 1190 |
|
| * Run restoration hooks only after all graph output and fixups are |
| 1191 |
|
| * complete, so hooks cannot change data still awaiting serialization. */ |
| 1192 |
1547 |
▶ | while (ctx->postop_head) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (ctx->postop_head) { |
37 |
1510 |
1547 |
|
| 1193 |
37 |
| dds_postop *postop = ctx->postop_head; |
| 1194 |
37 |
| dds_node *node = postop->node; |
| 1195 |
37 |
| SV *invocant = postop->invocant; |
| 1196 |
|
| |
| 1197 |
37 |
| ctx->postop_head = postop->next; |
| 1198 |
37 |
▶ | if (!ctx->postop_head) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->postop_head) |
20 |
17 |
37 |
|
| 1199 |
20 |
| ctx->postop_tail = NULL; |
| 1200 |
37 |
| Safefree(postop); |
| 1201 |
37 |
| DDS_TEMP(invocant); |
| 1202 |
37 |
| (void)dds_invoke(aTHX_ ctx, node->postop, !SvROK(node->postop), G_VOID | G_DISCARD, 1, |
| 1203 |
|
| &invocant); |
| 1204 |
|
| } |
| 1205 |
1510 |
| } |
| 1206 |
|
| |
| 1207 |
|
| /* Resolution borrows source/proxy values and catalogue records. This state |
| 1208 |
|
| * lives only during the initial step. Continuations retain their owned |
| 1209 |
|
| * strings and borrowed stable metadata in the emission frame. */ |
| 1210 |
|
| typedef struct { |
| 1211 |
|
| SV *rv, *target, *class_name, *thaw; |
| 1212 |
|
| dds_node *node; |
| 1213 |
|
| dds_role *role; |
| 1214 |
|
| dds_mark *mark; |
| 1215 |
|
| bool replacement; |
| 1216 |
|
| } dds_ref_value; |
| 1217 |
|
| |
| 1218 |
|
| /* |
| 1219 |
|
| * Referent construction |
| 1220 |
|
| * |
| 1221 |
|
| * Resolve freezer proxies and select canonical metadata before deciding |
| 1222 |
|
| * whether to reuse a value or construct it. New values pass through begin, |
| 1223 |
|
| * payload and finish phases. |
| 1224 |
|
| */ |
| 1225 |
|
| |
| 1226 |
|
| /* Follow freezer replacements to an emit-ready value, queueing original-object |
| 1227 |
|
| * hooks; return false when ignored or textual output already handled it. |
| 1228 |
|
| */ |
| 1229 |
10106 |
| static bool dds_resolve_ref(pTHX_ dds_ctx *ctx, struct dds_frame *f, dds_ref_value *value) |
| 1230 |
|
| { |
| 1231 |
10106 |
| UV proxy_limit = 0; |
| 1232 |
|
| |
| 1233 |
10106 |
| Zero(value, 1, dds_ref_value); |
| 1234 |
10106 |
| value->rv = f->sv; |
| 1235 |
10106 |
| value->mark = f->mark; |
| 1236 |
10106 |
| value->target = SvRV(value->rv); |
| 1237 |
|
| |
| 1238 |
129 |
| while (1) { |
| 1239 |
10235 |
| bool force = value->replacement; |
| 1240 |
|
| |
| 1241 |
10235 |
▶ | if (dds_candidate(aTHX_ value->rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (dds_candidate(aTHX_ value->rv)) { |
2542 |
7693 |
10235 |
|
| 1242 |
2542 |
| dds_node *slot = dds_find(aTHX_ ctx, value->rv, FALSE); |
| 1243 |
|
| |
| 1244 |
2542 |
▶ | force = force || (slot && slot->slot.original); |
Branch: 3 branches
| Branch | True | False | Total |
| force = force || (slot && slot->slot.original); |
2542 |
0 |
2542 |
| force = force || (slot && slot->slot.original); |
1615 |
927 |
2542 |
| force = force || (slot && slot->slot.original); |
166 |
1449 |
1615 |
|
| 1245 |
|
| } |
| 1246 |
|
| |
| 1247 |
9940 |
▶ | value->node = force || dds_candidate(aTHX_ value->target) || SvOBJECT(value->target) || |
Branch: 2 branches
| Branch | True | False | Total |
| value->node = force || dds_candidate(aTHX_ value->target) || SvOBJECT(value->target) || |
2588 |
7352 |
9940 |
| value->node = force || dds_candidate(aTHX_ value->target) || SvOBJECT(value->target) || |
2588 |
0 |
2588 |
|
| 1248 |
2588 |
▶ | SvREADONLY(value->target) |
Branch: 1 branch
| Branch | True | False | Total |
| SvREADONLY(value->target) |
30 |
2558 |
2588 |
|
| 1249 |
7677 |
| ? dds_find(aTHX_ ctx, value->target, FALSE) |
| 1250 |
12793 |
▶ | : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| : NULL; |
9940 |
295 |
10235 |
|
| 1251 |
|
| |
| 1252 |
10235 |
▶ | if (value->node && value->node->ignored) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (value->node && value->node->ignored) { |
7325 |
2910 |
10235 |
| if (value->node && value->node->ignored) { |
9 |
7316 |
7325 |
|
| 1253 |
9 |
| (void)dds_emit_ignored(aTHX_ ctx, value->rv, value->target, TRUE); |
| 1254 |
9 |
| return FALSE; |
| 1255 |
|
| } |
| 1256 |
10226 |
▶ | if (value->node && (!value->node->proxy || SvROK(value->node->proxy))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (value->node && (!value->node->proxy || SvROK(value->node->proxy))) |
7316 |
2910 |
10226 |
| if (value->node && (!value->node->proxy || SvROK(value->node->proxy))) |
129 |
7187 |
7316 |
| if (value->node && (!value->node->proxy || SvROK(value->node->proxy))) |
129 |
0 |
129 |
|
| 1257 |
7316 |
| dds_queue_postdump(aTHX_ ctx, value->node, value->target); |
| 1258 |
|
| |
| 1259 |
10226 |
▶ | if (value->node && value->node->proxy) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (value->node && value->node->proxy) { |
7316 |
2910 |
10226 |
| if (value->node && value->node->proxy) { |
129 |
7187 |
7316 |
|
| 1260 |
129 |
▶ | if (!SvROK(value->node->proxy)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(value->node->proxy)) { |
0 |
129 |
129 |
|
| 1261 |
0 |
| dds_write(aTHX_ ctx, value->node->proxy); |
| 1262 |
0 |
| return FALSE; |
| 1263 |
|
| } |
| 1264 |
129 |
| value->thaw = value->node->thaw; |
| 1265 |
129 |
| value->rv = value->node->proxy; |
| 1266 |
129 |
| value->target = SvRV(value->rv); |
| 1267 |
129 |
| value->replacement = TRUE; |
| 1268 |
134 |
▶ | if (value->thaw && SvTRUE(value->thaw) && !strnEQ(DDS_PV(value->thaw), "->", 2)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (value->thaw && SvTRUE(value->thaw) && !strnEQ(DDS_PV(value->thaw), "->", 2)) |
5 |
124 |
129 |
| if (value->thaw && SvTRUE(value->thaw) && !strnEQ(DDS_PV(value->thaw), "->", 2)) |
5 |
0 |
5 |
| if (value->thaw && SvTRUE(value->thaw) && !strnEQ(DDS_PV(value->thaw), "->", 2)) |
4 |
1 |
5 |
|
| 1269 |
4 |
| value->mark = dds_new_mark(aTHX_ ctx); |
| 1270 |
129 |
▶ | if (++proxy_limit > 100) |
Branch: 1 branch
| Branch | True | False | Total |
| if (++proxy_limit > 100) |
0 |
129 |
129 |
|
| 1271 |
0 |
| croak("Cyclic freezer replacement"); |
| 1272 |
129 |
| continue; |
| 1273 |
|
| } |
| 1274 |
10097 |
| break; |
| 1275 |
|
| } |
| 1276 |
|
| |
| 1277 |
10097 |
▶ | if (dds_emit_ignored(aTHX_ ctx, value->rv, value->target, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dds_emit_ignored(aTHX_ ctx, value->rv, value->target, FALSE)) |
4 |
10093 |
10097 |
|
| 1278 |
4 |
| return FALSE; |
| 1279 |
10093 |
| return TRUE; |
| 1280 |
|
| } |
| 1281 |
|
| |
| 1282 |
|
| /* Choose persistent or frame-local referent metadata and its canonical |
| 1283 |
|
| * expression, suppressing redundant blessing for ordinary regexps. |
| 1284 |
|
| */ |
| 1285 |
10093 |
| static void dds_select_ref_role(pTHX_ dds_ctx *ctx, struct dds_frame *f, dds_ref_value *value) |
| 1286 |
|
| { |
| 1287 |
10093 |
| SV *name = f->name; |
| 1288 |
10093 |
| UV depth = f->depth; |
| 1289 |
|
| |
| 1290 |
10093 |
| value->class_name = dds_class(aTHX_ value->target); |
| 1291 |
10093 |
▶ | if (dds_is_regexp(aTHX_ value->target) && SvOK(value->class_name) && |
Branch: 2 branches
| Branch | True | False | Total |
| if (dds_is_regexp(aTHX_ value->target) && SvOK(value->class_name) && |
134 |
9959 |
10093 |
| if (dds_is_regexp(aTHX_ value->target) && SvOK(value->class_name) && |
134 |
0 |
134 |
|
| 1292 |
268 |
▶ | strEQ(DDS_PV(value->class_name), "Regexp")) |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(DDS_PV(value->class_name), "Regexp")) |
102 |
32 |
134 |
|
| 1293 |
102 |
| value->class_name = &PL_sv_undef; |
| 1294 |
|
| |
| 1295 |
10093 |
▶ | if (!value->node) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value->node) { |
2906 |
7187 |
10093 |
|
| 1296 |
2906 |
▶ | if (value->replacement || dds_candidate(aTHX_ value->target) || SvREADONLY(value->target) || |
Branch: 3 branches
| Branch | True | False | Total |
| if (value->replacement || dds_candidate(aTHX_ value->target) || SvREADONLY(value->target) || |
2906 |
0 |
2906 |
| if (value->replacement || dds_candidate(aTHX_ value->target) || SvREADONLY(value->target) || |
2588 |
318 |
2906 |
| if (value->replacement || dds_candidate(aTHX_ value->target) || SvREADONLY(value->target) || |
2558 |
30 |
2588 |
|
| 1297 |
2558 |
▶ | SvTYPE(value->target) == SVt_PVGV) { |
Branch: 1 branch
| Branch | True | False | Total |
| SvTYPE(value->target) == SVt_PVGV) { |
8 |
2550 |
2558 |
|
| 1298 |
356 |
| value->node = dds_find(aTHX_ ctx, value->target, TRUE); |
| 1299 |
356 |
▶ | if (!value->node->ref.present) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value->node->ref.present) { |
356 |
0 |
356 |
|
| 1300 |
356 |
| value->node->ref.present = TRUE; |
| 1301 |
356 |
| value->node->ref.name = newSVsv(name); |
| 1302 |
356 |
| value->node->ref.depth = depth; |
| 1303 |
|
| } |
| 1304 |
|
| } else { |
| 1305 |
|
| /* Unique values need only frame-local metadata. No fixup may |
| 1306 |
|
| * retain this embedded node after the frame completes. */ |
| 1307 |
2550 |
| f->temporary.address = PTR2UV(value->target); |
| 1308 |
2550 |
| f->temporary.ref.name = name; |
| 1309 |
2550 |
| f->temporary.ref.depth = depth; |
| 1310 |
2550 |
| value->node = &f->temporary; |
| 1311 |
|
| } |
| 1312 |
|
| } |
| 1313 |
|
| |
| 1314 |
10093 |
| value->role = &value->node->ref; |
| 1315 |
10093 |
▶ | if (!value->role->name) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value->role->name) { |
0 |
10093 |
10093 |
|
| 1316 |
0 |
| value->role->name = newSVsv(name); |
| 1317 |
0 |
| value->role->depth = depth; |
| 1318 |
0 |
| value->role->present = TRUE; |
| 1319 |
|
| } |
| 1320 |
10093 |
| } |
| 1321 |
|
| |
| 1322 |
|
| /* Emit a use of an already known canonical referent, or a placeholder and |
| 1323 |
|
| * deferred assignment; return false when this occurrence must construct it. |
| 1324 |
|
| */ |
| 1325 |
10093 |
| static bool dds_emit_ref_use(pTHX_ dds_ctx *ctx, struct dds_frame *f, dds_ref_value *value) |
| 1326 |
|
| { |
| 1327 |
10093 |
| SV *name = f->name, *target = value->target, *class_name = value->class_name; |
| 1328 |
10093 |
| dds_node *node = value->node; |
| 1329 |
10093 |
| dds_role *role = value->role; |
| 1330 |
10093 |
| bool add_do = f->is_ref; |
| 1331 |
|
| |
| 1332 |
10093 |
▶ | if (role->done && role->done->ready) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (role->done && role->done->ready) { |
2478 |
7615 |
10093 |
| if (role->done && role->done->ready) { |
179 |
2299 |
2478 |
|
| 1333 |
|
| SV *text; |
| 1334 |
|
| |
| 1335 |
358 |
▶ | if (strchr("@%&", DDS_PV(role->name)[0])) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strchr("@%&", DDS_PV(role->name)[0])) { |
58 |
121 |
179 |
|
| 1336 |
58 |
▶ | if (SvTYPE(target) == SVt_PVHV && SvREADONLY(target)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(target) == SVt_PVHV && SvREADONLY(target)) { |
38 |
20 |
58 |
| if (SvTYPE(target) == SVt_PVHV && SvREADONLY(target)) { |
4 |
34 |
38 |
|
| 1337 |
4 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_LOCK, NULL, node); |
| 1338 |
|
| |
| 1339 |
4 |
| fix->args = (AV *)SvREFCNT_inc((SV *)dds_hidden_keys(aTHX_(HV *) target)); |
| 1340 |
4 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1341 |
|
| } |
| 1342 |
58 |
| text = dds_ref_expression(aTHX_ ctx, role->name, class_name); |
| 1343 |
|
| } else |
| 1344 |
121 |
| text = role->name; |
| 1345 |
179 |
| dds_write(aTHX_ ctx, text); |
| 1346 |
179 |
| ctx->column += sv_len_utf8(text); |
| 1347 |
179 |
| return TRUE; |
| 1348 |
|
| } |
| 1349 |
|
| |
| 1350 |
|
| /* Glob-slot analysis and deferred emission have different frame |
| 1351 |
|
| * depths. The canonical expression, rather than that numeric depth, |
| 1352 |
|
| * decides which occurrence is allowed to construct the referent. */ |
| 1353 |
17529 |
| if (role->done || |
| 1354 |
11643 |
▶ | (sv_cmp(role->name, name) && DDS_PV(name)[0] != '&' && DDS_PV(role->name)[0] != '&')) { |
Branch: 2 branches
| Branch | True | False | Total |
| (sv_cmp(role->name, name) && DDS_PV(name)[0] != '&' && DDS_PV(role->name)[0] != '&')) { |
2014 |
0 |
2014 |
| (sv_cmp(role->name, name) && DDS_PV(name)[0] != '&' && DDS_PV(role->name)[0] != '&')) { |
2014 |
0 |
2014 |
|
| 1355 |
8626 |
▶ | if (strchr("@%&", DDS_PV(role->name)[0]) && !ctx->style.declare) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strchr("@%&", DDS_PV(role->name)[0]) && !ctx->style.declare) { |
74 |
4239 |
4313 |
| if (strchr("@%&", DDS_PV(role->name)[0]) && !ctx->style.declare) { |
38 |
36 |
74 |
|
| 1356 |
38 |
| SV *text = dds_ref_expression(aTHX_ ctx, role->name, class_name); |
| 1357 |
|
| |
| 1358 |
38 |
| dds_write(aTHX_ ctx, text); |
| 1359 |
38 |
| ctx->column += sv_len_utf8(text); |
| 1360 |
4275 |
▶ | } else if (!ctx->style.purity) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (!ctx->style.purity) { |
5 |
4270 |
4275 |
|
| 1361 |
5 |
| dds_write(aTHX_ ctx, role->name); |
| 1362 |
5 |
| ctx->column += sv_len_utf8(role->name); |
| 1363 |
|
| } else { |
| 1364 |
4270 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_REF, name, node); |
| 1365 |
8540 |
| SV *text = ctx->style.verbose |
| 1366 |
4270 |
| ? dds_quote(aTHX_ dds_concat(aTHX_ "V: ", role->name, ""), FALSE) |
| 1367 |
4270 |
▶ | : DDS_TEMP(newSVpvs("'V'")); |
Branch: 1 branch
| Branch | True | False | Total |
| : DDS_TEMP(newSVpvs("'V'")); |
4270 |
0 |
4270 |
|
| 1368 |
|
| |
| 1369 |
4270 |
▶ | if (SvOK(class_name)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) |
40 |
4230 |
4270 |
|
| 1370 |
40 |
| fix->class_name = newSVsv(class_name); |
| 1371 |
4270 |
▶ | if (add_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (add_do) { |
42 |
4228 |
4270 |
|
| 1372 |
42 |
| dds_put(aTHX_ ctx, "do { my $v = "); |
| 1373 |
42 |
| ctx->column += 12; |
| 1374 |
|
| } |
| 1375 |
4270 |
| dds_write(aTHX_ ctx, text); |
| 1376 |
4270 |
| ctx->column += sv_len_utf8(text); |
| 1377 |
4270 |
▶ | if (add_do) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (add_do) { |
42 |
4228 |
4270 |
|
| 1378 |
42 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1379 |
42 |
| dds_put(aTHX_ ctx, "}"); |
| 1380 |
42 |
| ctx->column += sv_len_utf8(ctx->style.space) + 1; |
| 1381 |
|
| } |
| 1382 |
4270 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1383 |
|
| } |
| 1384 |
4313 |
| return TRUE; |
| 1385 |
|
| } |
| 1386 |
5601 |
| return FALSE; |
| 1387 |
|
| } |
| 1388 |
|
| |
| 1389 |
|
| /* Begin a referent's construction wrappers and save blessing, locking and thaw |
| 1390 |
|
| * state needed after its payload completes. |
| 1391 |
|
| */ |
| 1392 |
5601 |
| static void dds_begin_ref(pTHX_ dds_ctx *ctx, struct dds_frame *f, dds_ref_value *value) |
| 1393 |
|
| { |
| 1394 |
5601 |
| SV *rv = value->rv, *target = value->target; |
| 1395 |
5601 |
| SV *name = f->name, *class_name = value->class_name; |
| 1396 |
5601 |
| SV *thaw = value->thaw; |
| 1397 |
5601 |
| dds_node *node = value->node; |
| 1398 |
5601 |
| dds_role *role = value->role; |
| 1399 |
5601 |
| dds_mark *mark = value->mark; |
| 1400 |
5601 |
| AV *hidden = NULL; |
| 1401 |
5601 |
| bool overloaded, add_bless, add_lock, fix_lock = FALSE; |
| 1402 |
5601 |
| bool inline_thaw = FALSE, function_thaw = FALSE; |
| 1403 |
|
| |
| 1404 |
5601 |
| role->done = mark; |
| 1405 |
5601 |
| overloaded = dds_overloaded(aTHX_ rv); |
| 1406 |
5601 |
▶ | if (!thaw) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!thaw) |
5597 |
4 |
5601 |
|
| 1407 |
5597 |
| thaw = node->thaw; |
| 1408 |
5601 |
▶ | if (thaw && SvTRUE(thaw)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (thaw && SvTRUE(thaw)) { |
4 |
5597 |
5601 |
| if (thaw && SvTRUE(thaw)) { |
4 |
0 |
4 |
|
| 1409 |
|
| STRLEN len; |
| 1410 |
4 |
| const char *p = SvPV(thaw, len); |
| 1411 |
4 |
| bool simple = TRUE; |
| 1412 |
|
| STRLEN i; |
| 1413 |
|
| |
| 1414 |
40 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
36 |
4 |
40 |
|
| 1415 |
36 |
▶ | if (!isALNUMC_A(p[i]) && !strchr("_:>()-", p[i])) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!isALNUMC_A(p[i]) && !strchr("_:>()-", p[i])) |
7 |
29 |
36 |
| if (!isALNUMC_A(p[i]) && !strchr("_:>()-", p[i])) |
0 |
7 |
7 |
|
| 1416 |
0 |
| simple = FALSE; |
| 1417 |
|
| } |
| 1418 |
4 |
▶ | inline_thaw = !node->class_fields && simple && strnEQ(p, "->", 2); |
Branch: 3 branches
| Branch | True | False | Total |
| inline_thaw = !node->class_fields && simple && strnEQ(p, "->", 2); |
4 |
0 |
4 |
| inline_thaw = !node->class_fields && simple && strnEQ(p, "->", 2); |
4 |
0 |
4 |
| inline_thaw = !node->class_fields && simple && strnEQ(p, "->", 2); |
1 |
3 |
4 |
|
| 1419 |
4 |
▶ | function_thaw = simple && len >= 2 && strEQ(p + len - 2, "()"); |
Branch: 3 branches
| Branch | True | False | Total |
| function_thaw = simple && len >= 2 && strEQ(p + len - 2, "()"); |
4 |
0 |
4 |
| function_thaw = simple && len >= 2 && strEQ(p + len - 2, "()"); |
4 |
0 |
4 |
| function_thaw = simple && len >= 2 && strEQ(p + len - 2, "()"); |
1 |
3 |
4 |
|
| 1420 |
4 |
▶ | if (inline_thaw && function_thaw) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (inline_thaw && function_thaw) { |
1 |
3 |
4 |
| if (inline_thaw && function_thaw) { |
0 |
1 |
1 |
|
| 1421 |
0 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p + 2, len - 4))); |
| 1422 |
0 |
| dds_put(aTHX_ ctx, "("); |
| 1423 |
0 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1424 |
|
| } |
| 1425 |
|
| } |
| 1426 |
|
| |
| 1427 |
5601 |
▶ | add_lock = SvTYPE(target) == SVt_PVHV && SvREADONLY(target); |
Branch: 2 branches
| Branch | True | False | Total |
| add_lock = SvTYPE(target) == SVt_PVHV && SvREADONLY(target); |
1672 |
3929 |
5601 |
| add_lock = SvTYPE(target) == SVt_PVHV && SvREADONLY(target); |
39 |
1633 |
1672 |
|
| 1428 |
5601 |
▶ | if (add_lock) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (add_lock) { |
39 |
5562 |
5601 |
|
| 1429 |
39 |
| hidden = dds_hidden_keys(aTHX_(HV *) target); |
| 1430 |
39 |
▶ | if (DDS_PV(name)[0] != '$') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (DDS_PV(name)[0] != '$') { |
8 |
31 |
39 |
|
| 1431 |
8 |
| fix_lock = TRUE; |
| 1432 |
8 |
| add_lock = FALSE; |
| 1433 |
|
| } else { |
| 1434 |
31 |
▶ | dds_put(aTHX_ ctx, av_len(hidden) >= 0 ? "lock_ref_keys_plus(" : "lock_ref_keys("); |
Branch: 1 branch
| Branch | True | False | Total |
| dds_put(aTHX_ ctx, av_len(hidden) >= 0 ? "lock_ref_keys_plus(" : "lock_ref_keys("); |
26 |
5 |
31 |
|
| 1435 |
31 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1436 |
|
| } |
| 1437 |
|
| } |
| 1438 |
|
| |
| 1439 |
5767 |
▶ | add_bless = SvOK(class_name) && !strchr("@%&", DDS_PV(name)[0]); |
Branch: 2 branches
| Branch | True | False | Total |
| add_bless = SvOK(class_name) && !strchr("@%&", DDS_PV(name)[0]); |
166 |
5435 |
5601 |
| add_bless = SvOK(class_name) && !strchr("@%&", DDS_PV(name)[0]); |
130 |
36 |
166 |
|
| 1440 |
5601 |
▶ | if (add_bless && !overloaded) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (add_bless && !overloaded) { |
130 |
5471 |
5601 |
| if (add_bless && !overloaded) { |
102 |
28 |
130 |
|
| 1441 |
|
| STRLEN len; |
| 1442 |
102 |
| const char *p = SvPV(ctx->style.bless, len); |
| 1443 |
|
| |
| 1444 |
102 |
▶ | dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p, len ? len - 1 : 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p, len ? len - 1 : 0))); |
102 |
0 |
102 |
|
| 1445 |
102 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1446 |
|
| } |
| 1447 |
|
| |
| 1448 |
|
| /* Only continuation state survives the child frame's temporary scope. */ |
| 1449 |
5601 |
| f->class_name = SvREFCNT_inc(class_name); |
| 1450 |
5601 |
| f->node = node; |
| 1451 |
5601 |
| f->role = role; |
| 1452 |
5601 |
| f->overloaded = overloaded; |
| 1453 |
5601 |
| f->add_bless = add_bless; |
| 1454 |
5601 |
| f->add_lock = add_lock; |
| 1455 |
5601 |
| f->fix_lock = fix_lock; |
| 1456 |
5601 |
| f->hidden = (AV *)SvREFCNT_inc((SV *)hidden); |
| 1457 |
5601 |
| f->thaw = thaw; |
| 1458 |
5601 |
| f->inline_thaw = inline_thaw; |
| 1459 |
5601 |
| f->function_thaw = function_thaw; |
| 1460 |
5601 |
| } |
| 1461 |
|
| |
| 1462 |
|
| /* Emit a referent payload or push a child continuation; return true when no |
| 1463 |
|
| * child traversal remains pending. |
| 1464 |
|
| */ |
| 1465 |
5601 |
| static bool dds_emit_ref_value(pTHX_ dds_ctx *ctx, struct dds_frame *f, dds_ref_value *value) |
| 1466 |
|
| { |
| 1467 |
5601 |
| SV *rv = value->rv, *target = value->target; |
| 1468 |
5601 |
| SV *name = f->name, *class_name = f->class_name; |
| 1469 |
5601 |
| dds_node *node = f->node; |
| 1470 |
5601 |
| dds_mark *mark = value->mark; |
| 1471 |
5601 |
| UV depth = f->depth; |
| 1472 |
5601 |
| IV indent = f->indent; |
| 1473 |
|
| |
| 1474 |
5601 |
| ctx->do_nl = TRUE; |
| 1475 |
5601 |
▶ | if (dds_is_regexp(aTHX_ target)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dds_is_regexp(aTHX_ target)) |
133 |
5468 |
5601 |
|
| 1476 |
133 |
| dds_write(aTHX_ ctx, dds_regex(aTHX_ ctx, rv)); |
| 1477 |
5468 |
▶ | else if (SvTYPE(target) == SVt_PVAV || SvTYPE(target) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (SvTYPE(target) == SVt_PVAV || SvTYPE(target) == SVt_PVHV) { |
2376 |
3092 |
5468 |
| else if (SvTYPE(target) == SVt_PVAV || SvTYPE(target) == SVt_PVHV) { |
1672 |
704 |
2376 |
|
| 1478 |
4764 |
| f->stage = DDS_STAGE_CHILD; |
| 1479 |
4764 |
▶ | dds_push_frame(aTHX_ ctx, SvTYPE(target) == SVt_PVAV ? DDS_FRAME_ARRAY : DDS_FRAME_HASH, |
Branch: 1 branch
| Branch | True | False | Total |
| dds_push_frame(aTHX_ ctx, SvTYPE(target) == SVt_PVAV ? DDS_FRAME_ARRAY : DDS_FRAME_HASH, |
3092 |
1672 |
4764 |
|
| 1480 |
|
| target, depth, mark, name, indent, FALSE); |
| 1481 |
4764 |
▶ | ctx->frames->node = node == &f->temporary ? NULL : node; |
Branch: 1 branch
| Branch | True | False | Total |
| ctx->frames->node = node == &f->temporary ? NULL : node; |
2336 |
2428 |
4764 |
|
| 1482 |
4764 |
| return FALSE; |
| 1483 |
758 |
▶ | } else if (SvTYPE(target) == SVt_PVCV || SvTYPE(target) == SVt_PVFM) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (SvTYPE(target) == SVt_PVCV || SvTYPE(target) == SVt_PVFM) { |
654 |
50 |
704 |
| } else if (SvTYPE(target) == SVt_PVCV || SvTYPE(target) == SVt_PVFM) { |
4 |
650 |
654 |
|
| 1484 |
|
| SV *args[4], *code; |
| 1485 |
|
| |
| 1486 |
54 |
| args[0] = rv; |
| 1487 |
54 |
| args[1] = name; |
| 1488 |
54 |
| args[2] = DDS_TEMP(newSViv(indent)); |
| 1489 |
54 |
| args[3] = class_name; |
| 1490 |
54 |
▶ | code = dds_call(aTHX_ ctx, SvTYPE(target) == SVt_PVCV ? "_xs_code_text" : "_xs_format_text", |
Branch: 1 branch
| Branch | True | False | Total |
| code = dds_call(aTHX_ ctx, SvTYPE(target) == SVt_PVCV ? "_xs_code_text" : "_xs_format_text", |
50 |
4 |
54 |
|
| 1491 |
|
| ctx->owner, G_SCALAR, 4, args); |
| 1492 |
54 |
| dds_write(aTHX_ ctx, code); |
| 1493 |
650 |
▶ | } else if (SvTYPE(target) == SVt_PVIO) |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(target) == SVt_PVIO) |
2 |
648 |
650 |
|
| 1494 |
2 |
| dds_put(aTHX_ ctx, "*{Symbol::gensym()}{IO}"); |
| 1495 |
648 |
▶ | else if (SvTYPE(target) == SVt_PVGV && |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvTYPE(target) == SVt_PVGV && |
135 |
513 |
648 |
|
| 1496 |
270 |
▶ | strnEQ(DDS_PV(dds_glob_name(aTHX_(GV *) target)), "*Symbol::GEN", 12)) |
Branch: 1 branch
| Branch | True | False | Total |
| strnEQ(DDS_PV(dds_glob_name(aTHX_(GV *) target)), "*Symbol::GEN", 12)) |
73 |
62 |
135 |
|
| 1497 |
73 |
| dds_emit_symbol(aTHX_ ctx, (GV *)target, name, depth, FALSE); |
| 1498 |
575 |
▶ | 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) { |
62 |
513 |
575 |
| else if (SvTYPE(target) <= SVt_PVMG || SvTYPE(target) == SVt_PVGV) { |
62 |
0 |
62 |
|
| 1499 |
575 |
| f->stage = DDS_STAGE_SCALAR_REF; |
| 1500 |
575 |
| dds_push_frame(aTHX_ ctx, DDS_FRAME_SV, target, depth + 1, mark, |
| 1501 |
|
| dds_child_name(aTHX_ name, '$', NULL, 0), indent, TRUE); |
| 1502 |
575 |
| return FALSE; |
| 1503 |
|
| } else |
| 1504 |
0 |
| croak("Cannot emit Perl SV type %d", (int)SvTYPE(target)); |
| 1505 |
262 |
| return TRUE; |
| 1506 |
|
| } |
| 1507 |
|
| |
| 1508 |
|
| /* Close construction wrappers and queue deferred blessing, locking or thaw |
| 1509 |
|
| * actions after a referent payload completes. |
| 1510 |
|
| */ |
| 1511 |
5601 |
| static void dds_finish_ref(pTHX_ dds_ctx *ctx, struct dds_frame *f) |
| 1512 |
|
| { |
| 1513 |
5601 |
| SV *class_name = f->class_name, *thaw = f->thaw; |
| 1514 |
5601 |
| dds_node *node = f->node; |
| 1515 |
5601 |
| AV *hidden = f->hidden; |
| 1516 |
|
| |
| 1517 |
5601 |
▶ | if (f->add_bless) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->add_bless) { |
130 |
5471 |
5601 |
|
| 1518 |
130 |
▶ | if (!f->overloaded) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f->overloaded) { |
102 |
28 |
130 |
|
| 1519 |
|
| STRLEN len; |
| 1520 |
102 |
| const char *p = SvPV(ctx->style.bless, len); |
| 1521 |
|
| |
| 1522 |
102 |
| dds_put(aTHX_ ctx, ","); |
| 1523 |
102 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1524 |
102 |
| dds_write(aTHX_ ctx, dds_quote(aTHX_ class_name, FALSE)); |
| 1525 |
102 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1526 |
102 |
▶ | if (len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) |
102 |
0 |
102 |
|
| 1527 |
102 |
| dds_write(aTHX_ ctx, DDS_TEMP(newSVpvn(p + len - 1, 1))); |
| 1528 |
|
| } else { |
| 1529 |
28 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_BLESS, NULL, node); |
| 1530 |
|
| |
| 1531 |
28 |
| fix->text = newSVsv(class_name); |
| 1532 |
28 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1533 |
|
| } |
| 1534 |
|
| } |
| 1535 |
|
| |
| 1536 |
5601 |
▶ | if (f->fix_lock && !SvOK(class_name)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (f->fix_lock && !SvOK(class_name)) { |
8 |
5593 |
5601 |
| if (f->fix_lock && !SvOK(class_name)) { |
4 |
4 |
8 |
|
| 1537 |
4 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_LOCK, NULL, node); |
| 1538 |
|
| |
| 1539 |
4 |
| fix->args = (AV *)SvREFCNT_inc((SV *)hidden); |
| 1540 |
4 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1541 |
|
| } |
| 1542 |
|
| |
| 1543 |
5601 |
▶ | if (f->add_lock) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->add_lock) { |
31 |
5570 |
5601 |
|
| 1544 |
|
| SSize_t i; |
| 1545 |
|
| |
| 1546 |
77 |
▶ | for (i = 0; i <= av_len(hidden); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(hidden); i++) { |
46 |
31 |
77 |
|
| 1547 |
46 |
| dds_put(aTHX_ ctx, ","); |
| 1548 |
46 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1549 |
46 |
| dds_write(aTHX_ ctx, dds_quote(aTHX_ * av_fetch(hidden, i, 0), FALSE)); |
| 1550 |
|
| } |
| 1551 |
31 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1552 |
31 |
| dds_put(aTHX_ ctx, ")"); |
| 1553 |
|
| } |
| 1554 |
|
| |
| 1555 |
5601 |
▶ | if (thaw && SvTRUE(thaw)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (thaw && SvTRUE(thaw)) { |
4 |
5597 |
5601 |
| if (thaw && SvTRUE(thaw)) { |
4 |
0 |
4 |
|
| 1556 |
4 |
▶ | if (f->inline_thaw) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->inline_thaw) { |
1 |
3 |
4 |
|
| 1557 |
1 |
▶ | if (f->function_thaw) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->function_thaw) { |
0 |
1 |
1 |
|
| 1558 |
0 |
| dds_write(aTHX_ ctx, ctx->style.space); |
| 1559 |
0 |
| dds_put(aTHX_ ctx, ")"); |
| 1560 |
|
| } else { |
| 1561 |
1 |
| dds_put(aTHX_ ctx, "->"); |
| 1562 |
1 |
| dds_put(aTHX_ ctx, DDS_PV(thaw) + 2); |
| 1563 |
1 |
| dds_put(aTHX_ ctx, "()"); |
| 1564 |
|
| } |
| 1565 |
|
| } else { |
| 1566 |
3 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_THAW, NULL, node); |
| 1567 |
|
| |
| 1568 |
3 |
| fix->text = newSVsv(thaw); |
| 1569 |
3 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1570 |
|
| } |
| 1571 |
|
| } |
| 1572 |
|
| |
| 1573 |
5601 |
| ctx->do_nl = TRUE; |
| 1574 |
5601 |
| Zero(&f->result, 1, dds_result); |
| 1575 |
5601 |
| } |
| 1576 |
|
| |
| 1577 |
|
| /* Coordinate reference resolution, canonical reuse, payload traversal and |
| 1578 |
|
| * completion across initial and resumed frame stages. |
| 1579 |
|
| */ |
| 1580 |
15445 |
| static bool dds_step_ref(pTHX_ dds_ctx *ctx, struct dds_frame *f) |
| 1581 |
|
| { |
| 1582 |
15445 |
▶ | if (f->stage == DDS_STAGE_INITIAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->stage == DDS_STAGE_INITIAL) { |
10106 |
5339 |
15445 |
|
| 1583 |
|
| dds_ref_value value; |
| 1584 |
|
| |
| 1585 |
10106 |
▶ | if (!dds_resolve_ref(aTHX_ ctx, f, &value)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dds_resolve_ref(aTHX_ ctx, f, &value)) |
13 |
10093 |
10106 |
|
| 1586 |
9844 |
| return TRUE; |
| 1587 |
|
| |
| 1588 |
10093 |
| dds_select_ref_role(aTHX_ ctx, f, &value); |
| 1589 |
10093 |
▶ | if (dds_emit_ref_use(aTHX_ ctx, f, &value)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dds_emit_ref_use(aTHX_ ctx, f, &value)) |
4492 |
5601 |
10093 |
|
| 1590 |
4492 |
| return TRUE; |
| 1591 |
|
| |
| 1592 |
5601 |
| dds_begin_ref(aTHX_ ctx, f, &value); |
| 1593 |
5601 |
▶ | if (!dds_emit_ref_value(aTHX_ ctx, f, &value)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dds_emit_ref_value(aTHX_ ctx, f, &value)) |
5339 |
262 |
5601 |
|
| 1594 |
5339 |
| return FALSE; |
| 1595 |
5339 |
▶ | } else if (f->stage == DDS_STAGE_SCALAR_REF && f->result.deferred) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (f->stage == DDS_STAGE_SCALAR_REF && f->result.deferred) { |
575 |
4764 |
5339 |
| } else if (f->stage == DDS_STAGE_SCALAR_REF && f->result.deferred) { |
111 |
464 |
575 |
|
| 1596 |
111 |
| f->role->done = f->result.deferred; |
| 1597 |
|
| } |
| 1598 |
|
| |
| 1599 |
5601 |
| dds_finish_ref(aTHX_ ctx, f); |
| 1600 |
5601 |
| return TRUE; |
| 1601 |
|
| } |
| 1602 |
|
| |
| 1603 |
|
| /* |
| 1604 |
|
| * Emission driver and output |
| 1605 |
|
| * |
| 1606 |
|
| * The driver drains heap continuations for one value. The output coordinator |
| 1607 |
|
| * constructs roots, resolves remaining dependencies and runs original-object |
| 1608 |
|
| * postdump hooks. |
| 1609 |
|
| */ |
| 1610 |
|
| |
| 1611 |
|
| /* Drive heap continuations until one requested value is emitted, returning its |
| 1612 |
|
| * alias or deferred-completion result to the caller. |
| 1613 |
|
| */ |
| 1614 |
2029 |
| dds_result dds_emit_sv(pTHX_ dds_ctx *ctx, SV *sv, UV depth, dds_mark *mark, SV *name, IV indent, |
| 1615 |
|
| bool is_ref) |
| 1616 |
|
| { |
| 1617 |
2029 |
| struct dds_frame *base = ctx->frames; |
| 1618 |
2029 |
| dds_result result = {NULL, NULL}; |
| 1619 |
|
| |
| 1620 |
2029 |
| dds_push_frame(aTHX_ ctx, DDS_FRAME_SV, sv, depth, mark, name, indent, is_ref); |
| 1621 |
83575 |
▶ | while (ctx->frames != base) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (ctx->frames != base) { |
81547 |
2028 |
83575 |
|
| 1622 |
81547 |
| struct dds_frame *frame = ctx->frames; |
| 1623 |
81547 |
| bool done = FALSE; |
| 1624 |
|
| |
| 1625 |
|
| /* Scratch values expire after this step. Frames own every string |
| 1626 |
|
| * or fetched temporary needed when child traversal returns. */ |
| 1627 |
81547 |
| ENTER; |
| 1628 |
81547 |
| SAVETMPS; |
| 1629 |
|
| |
| 1630 |
81547 |
| switch (frame->kind) { |
| 1631 |
37024 |
| case DDS_FRAME_SV: |
| 1632 |
37024 |
| done = dds_step_sv(aTHX_ ctx, frame); |
| 1633 |
37023 |
| break; |
| 1634 |
15445 |
| case DDS_FRAME_REF: |
| 1635 |
15445 |
| done = dds_step_ref(aTHX_ ctx, frame); |
| 1636 |
15445 |
| break; |
| 1637 |
10699 |
| case DDS_FRAME_ARRAY: |
| 1638 |
10699 |
| done = dds_step_array(aTHX_ ctx, frame); |
| 1639 |
10699 |
| break; |
| 1640 |
18379 |
| case DDS_FRAME_HASH: |
| 1641 |
18379 |
| done = dds_step_hash(aTHX_ ctx, frame); |
| 1642 |
18379 |
| break; |
| 1643 |
|
| } |
| 1644 |
|
| |
| 1645 |
81546 |
▶ | if (done) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (done) { |
41787 |
39759 |
81546 |
|
| 1646 |
41787 |
| result = frame->result; |
| 1647 |
41787 |
| ctx->frames = frame->parent; |
| 1648 |
41787 |
| ctx->active = frame->active.parent; |
| 1649 |
41787 |
▶ | if (ctx->frames != base) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->frames != base) |
39759 |
2028 |
41787 |
|
| 1650 |
39759 |
| ctx->frames->result = result; |
| 1651 |
41787 |
| frame->parent = ctx->free_frames; |
| 1652 |
41787 |
| ctx->free_frames = frame; |
| 1653 |
41787 |
| dds_release_frame(aTHX_ frame); |
| 1654 |
|
| } |
| 1655 |
|
| |
| 1656 |
81546 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
76302 |
5244 |
81546 |
|
| 1657 |
81546 |
| LEAVE; |
| 1658 |
|
| } |
| 1659 |
|
| |
| 1660 |
2028 |
| return result; |
| 1661 |
|
| } |
| 1662 |
|
| |
| 1663 |
|
| /* Emit or defer enabled glob-slot assignments according to canonical names, |
| 1664 |
|
| * fetching each live slot immediately before use. |
| 1665 |
|
| */ |
| 1666 |
141 |
| void dds_emit_glob(pTHX_ dds_ctx *ctx, GV *gv, SV *name, UV depth) |
| 1667 |
|
| { |
| 1668 |
141 |
▶ | UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 4 : 3; |
Branch: 2 branches
| Branch | True | False | Total |
| UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 4 : 3; |
141 |
0 |
141 |
| UV i, limit = ctx->style.deparse && ctx->style.deparseglob ? 4 : 3; |
141 |
0 |
141 |
|
| 1669 |
|
| static const char *slots[] = {"SCALAR", "HASH", "ARRAY", "CODE"}; |
| 1670 |
|
| |
| 1671 |
701 |
▶ | for (i = 0; i < limit; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < limit; i++) { |
561 |
140 |
701 |
|
| 1672 |
|
| SV *value, *target, *rv; |
| 1673 |
|
| dds_node *node; |
| 1674 |
|
| dds_mark *mark; |
| 1675 |
|
| dds_result result; |
| 1676 |
|
| SV *path; |
| 1677 |
561 |
| UV replacements = 0; |
| 1678 |
|
| |
| 1679 |
|
| /* Fetch each slot from the owned glob immediately before use; |
| 1680 |
|
| * earlier slot callbacks may have replaced later slots. */ |
| 1681 |
561 |
| switch (i) { |
| 1682 |
141 |
| case 0: |
| 1683 |
141 |
| value = GvSV(gv); |
| 1684 |
141 |
| break; |
| 1685 |
140 |
| case 1: |
| 1686 |
140 |
| value = (SV *)GvHV(gv); |
| 1687 |
140 |
| break; |
| 1688 |
140 |
| case 2: |
| 1689 |
140 |
| value = (SV *)GvAV(gv); |
| 1690 |
140 |
| break; |
| 1691 |
140 |
| default: |
| 1692 |
140 |
| value = (SV *)GvCV(gv); |
| 1693 |
140 |
| break; |
| 1694 |
|
| } |
| 1695 |
561 |
▶ | if (!value || (i == 0 && !SvOK(value))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!value || (i == 0 && !SvOK(value))) |
157 |
404 |
561 |
| if (!value || (i == 0 && !SvOK(value))) |
24 |
133 |
157 |
| if (!value || (i == 0 && !SvOK(value))) |
0 |
24 |
24 |
|
| 1696 |
468 |
| continue; |
| 1697 |
|
| |
| 1698 |
157 |
| target = value; |
| 1699 |
157 |
| node = dds_find(aTHX_ ctx, target, FALSE); |
| 1700 |
157 |
▶ | if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
Branch: 5 branches
| Branch | True | False | Total |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
157 |
0 |
157 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
43 |
114 |
157 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
43 |
0 |
43 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
20 |
137 |
157 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && !node->postop_queued) |
11 |
9 |
20 |
|
| 1701 |
11 |
| dds_queue_postdump(aTHX_ ctx, node, target); |
| 1702 |
201 |
▶ | while (node && node->proxy && SvROK(node->proxy)) { |
Branch: 3 branches
| Branch | True | False | Total |
| while (node && node->proxy && SvROK(node->proxy)) { |
201 |
0 |
201 |
| while (node && node->proxy && SvROK(node->proxy)) { |
44 |
157 |
201 |
| while (node && node->proxy && SvROK(node->proxy)) { |
44 |
0 |
44 |
|
| 1703 |
44 |
| target = SvRV(node->proxy); |
| 1704 |
44 |
| node = dds_find(aTHX_ ctx, target, FALSE); |
| 1705 |
44 |
▶ | if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && |
Branch: 4 branches
| Branch | True | False | Total |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && |
44 |
0 |
44 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && |
1 |
43 |
44 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && |
1 |
0 |
1 |
| if (node && (!node->proxy || SvROK(node->proxy)) && node->postop && |
1 |
43 |
44 |
|
| 1706 |
1 |
▶ | !node->postop_queued) |
Branch: 1 branch
| Branch | True | False | Total |
| !node->postop_queued) |
1 |
0 |
1 |
|
| 1707 |
1 |
| dds_queue_postdump(aTHX_ ctx, node, target); |
| 1708 |
44 |
▶ | if (++replacements > 100) |
Branch: 1 branch
| Branch | True | False | Total |
| if (++replacements > 100) |
0 |
44 |
44 |
|
| 1709 |
0 |
| croak("Cyclic freezer replacement"); |
| 1710 |
|
| } |
| 1711 |
157 |
▶ | if (!node || !node->ref.present) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!node || !node->ref.present) |
157 |
0 |
157 |
| if (!node || !node->ref.present) |
1 |
156 |
157 |
|
| 1712 |
1 |
| continue; |
| 1713 |
|
| |
| 1714 |
156 |
| path = DDS_TEMP(newSVsv(name)); |
| 1715 |
156 |
| sv_catpvf(path, "{%s}", slots[i]); |
| 1716 |
156 |
▶ | if (sv_cmp(node->ref.name, path)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_cmp(node->ref.name, path)) { |
63 |
93 |
156 |
|
| 1717 |
63 |
| dds_fix *fix = dds_new_fix(aTHX_ DDS_FIX_REF, name, node); |
| 1718 |
63 |
| SV *class_name = dds_class(aTHX_ target); |
| 1719 |
|
| |
| 1720 |
63 |
▶ | if (SvOK(class_name)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(class_name)) |
0 |
63 |
63 |
|
| 1721 |
0 |
| fix->class_name = newSVsv(class_name); |
| 1722 |
63 |
| dds_add_fix(aTHX_ ctx, fix); |
| 1723 |
63 |
| continue; |
| 1724 |
|
| } |
| 1725 |
|
| |
| 1726 |
93 |
| rv = DDS_TEMP(newRV_inc(value)); |
| 1727 |
93 |
| mark = dds_new_mark(aTHX_ ctx); |
| 1728 |
93 |
▶ | if (!ctx->style.terse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->style.terse) { |
93 |
0 |
93 |
|
| 1729 |
93 |
| dds_write(aTHX_ ctx, name); |
| 1730 |
92 |
| dds_put(aTHX_ ctx, " = "); |
| 1731 |
|
| } |
| 1732 |
|
| |
| 1733 |
|
| /* Only the actual canonical slot may construct the value. Other |
| 1734 |
|
| * slots defer their assignment until that construction is ready. */ |
| 1735 |
92 |
| result = dds_emit_sv(aTHX_ ctx, rv, depth, mark, path, sv_len_utf8(name) + 3, FALSE); |
| 1736 |
92 |
▶ | if (result.alias) |
Branch: 1 branch
| Branch | True | False | Total |
| if (result.alias) |
0 |
92 |
92 |
|
| 1737 |
0 |
| croak("Unexpected alias for glob slot"); |
| 1738 |
92 |
| dds_put(aTHX_ ctx, ";\n"); |
| 1739 |
92 |
| mark->ready = TRUE; |
| 1740 |
|
| } |
| 1741 |
|
| |
| 1742 |
140 |
▶ | if (ctx->style.deparse && ctx->style.deparseglob && GvFORM(gv)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ctx->style.deparse && ctx->style.deparseglob && GvFORM(gv)) { |
140 |
0 |
140 |
| if (ctx->style.deparse && ctx->style.deparseglob && GvFORM(gv)) { |
140 |
0 |
140 |
| if (ctx->style.deparse && ctx->style.deparseglob && GvFORM(gv)) { |
1 |
139 |
140 |
|
| 1743 |
|
| SV *args[2], *text; |
| 1744 |
|
| |
| 1745 |
1 |
| args[0] = DDS_TEMP(newRV_inc((SV *)gv)); |
| 1746 |
1 |
| args[1] = name; |
| 1747 |
1 |
| text = dds_call(aTHX_ ctx, "_xs_glob_format_text", ctx->owner, G_SCALAR, 2, args); |
| 1748 |
1 |
▶ | if (SvOK(text)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(text)) |
1 |
0 |
1 |
|
| 1749 |
1 |
| dds_write(aTHX_ ctx, text); |
| 1750 |
|
| } |
| 1751 |
140 |
| } |
| 1752 |
|
| |
| 1753 |
|
| /* Emit private named class-field snapshots and release fixups made ready by |
| 1754 |
|
| * each snapshot assignment. |
| 1755 |
|
| */ |
| 1756 |
0 |
| static void dds_emit_class_fields(pTHX_ dds_ctx *ctx) |
| 1757 |
|
| { |
| 1758 |
|
| dds_node *node; |
| 1759 |
|
| |
| 1760 |
0 |
▶ | for (node = ctx->class_head; node; node = node->class_next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (node = ctx->class_head; node; node = node->class_next) { |
0 |
0 |
0 |
|
| 1761 |
0 |
| dds_mark *mark = dds_new_mark(aTHX_ ctx); |
| 1762 |
|
| |
| 1763 |
0 |
| dds_put(aTHX_ ctx, "my "); |
| 1764 |
0 |
| dds_write(aTHX_ ctx, node->class_fields_name); |
| 1765 |
0 |
| dds_put(aTHX_ ctx, " = "); |
| 1766 |
0 |
| (void)dds_emit_sv(aTHX_ ctx, node->class_fields, node->ref.depth + 1, mark, |
| 1767 |
|
| node->class_fields_name, 0, FALSE); |
| 1768 |
0 |
| dds_put(aTHX_ ctx, ";\n"); |
| 1769 |
0 |
| mark->ready = TRUE; |
| 1770 |
0 |
| dds_apply_fixes(aTHX_ ctx, FALSE); |
| 1771 |
|
| } |
| 1772 |
0 |
| } |
| 1773 |
|
| |
| 1774 |
|
| /* Prepare output context, construct roots and class snapshots, drain fixups in |
| 1775 |
|
| * dependency order, then run postdump hooks and deliver void-context output. |
| 1776 |
|
| */ |
| 1777 |
1513 |
| SV *dds_output(pTHX_ dds_ctx *ctx, I32 gimme) |
| 1778 |
|
| { |
| 1779 |
|
| UV i; |
| 1780 |
|
| AV *names, *declared; |
| 1781 |
|
| SV *printer; |
| 1782 |
|
| bool class_terse, class_declare; |
| 1783 |
|
| |
| 1784 |
1513 |
| dds_clear_emission(aTHX_ ctx); |
| 1785 |
1513 |
| dds_load_style(aTHX_ ctx); |
| 1786 |
|
| |
| 1787 |
|
| /* Root replacement invalidates the saved catalogue. Structural edits |
| 1788 |
|
| * inside the graph still require the caller to run Data again. */ |
| 1789 |
2359 |
▶ | for (i = 0; ctx->cataloged && i < ctx->root_count; i++) |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; ctx->cataloged && i < ctx->root_count; i++) |
1276 |
1083 |
2359 |
| for (i = 0; ctx->cataloged && i < ctx->root_count; i++) |
846 |
430 |
1276 |
|
| 1790 |
846 |
▶ | if (ctx->roots[i].analyzed_ref != (SvROK(ctx->roots[i].sv) ? SvRV(ctx->roots[i].sv) : NULL)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->roots[i].analyzed_ref != (SvROK(ctx->roots[i].sv) ? SvRV(ctx->roots[i].sv) : NULL)) |
738 |
108 |
846 |
| if (ctx->roots[i].analyzed_ref != (SvROK(ctx->roots[i].sv) ? SvRV(ctx->roots[i].sv) : NULL)) |
2 |
844 |
846 |
|
| 1791 |
2 |
| ctx->cataloged = FALSE; |
| 1792 |
1513 |
▶ | if (!ctx->cataloged) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->cataloged) |
1083 |
430 |
1513 |
|
| 1793 |
1083 |
| dds_analyze(aTHX_ ctx); |
| 1794 |
|
| |
| 1795 |
|
| /* Class snapshots need named storage even for a terse expression. */ |
| 1796 |
1513 |
▶ | class_terse = ctx->class_head && ctx->style.terse; |
Branch: 2 branches
| Branch | True | False | Total |
| class_terse = ctx->class_head && ctx->style.terse; |
0 |
1513 |
1513 |
| class_terse = ctx->class_head && ctx->style.terse; |
0 |
0 |
0 |
|
| 1797 |
1513 |
▶ | class_declare = ctx->class_head && (ctx->style.declare || class_terse); |
Branch: 3 branches
| Branch | True | False | Total |
| class_declare = ctx->class_head && (ctx->style.declare || class_terse); |
0 |
1513 |
1513 |
| class_declare = ctx->class_head && (ctx->style.declare || class_terse); |
0 |
0 |
0 |
| class_declare = ctx->class_head && (ctx->style.declare || class_terse); |
0 |
0 |
0 |
|
| 1798 |
1513 |
▶ | if (class_terse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (class_terse) { |
0 |
1513 |
1513 |
|
| 1799 |
0 |
| ctx->style.terse = FALSE; |
| 1800 |
0 |
| ctx->style.declare = TRUE; |
| 1801 |
|
| } |
| 1802 |
|
| |
| 1803 |
1513 |
| ctx->out = newSVpvs(""); |
| 1804 |
1513 |
▶ | if (gimme == G_ARRAY) |
Branch: 1 branch
| Branch | True | False | Total |
| if (gimme == G_ARRAY) |
11 |
1502 |
1513 |
|
| 1805 |
11 |
| ctx->chunks = newAV(); |
| 1806 |
1513 |
| printer = dds_hget(aTHX_ ctx->object, "fh"); |
| 1807 |
1513 |
▶ | if (SvTRUE(printer)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(printer)) |
6 |
1507 |
1513 |
|
| 1808 |
6 |
| ctx->printer = newSVsv(printer); |
| 1809 |
|
| |
| 1810 |
1513 |
| names = newAV(); |
| 1811 |
1513 |
| declared = newAV(); |
| 1812 |
1513 |
| hv_stores(ctx->object, "out_names", newRV_noinc((SV *)names)); |
| 1813 |
1513 |
| hv_stores(ctx->object, "declare", newRV_noinc((SV *)declared)); |
| 1814 |
3450 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
1937 |
1513 |
3450 |
|
| 1815 |
1937 |
| av_push(names, newSVsv(ctx->roots[i].name)); |
| 1816 |
1937 |
| av_push(declared, newSVsv(ctx->roots[i].name)); |
| 1817 |
|
| } |
| 1818 |
|
| |
| 1819 |
1513 |
▶ | if (ctx->style.compress && SvTRUE(ctx->style.compressor)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx->style.compress && SvTRUE(ctx->style.compressor)) { |
9 |
1504 |
1513 |
| if (ctx->style.compress && SvTRUE(ctx->style.compressor)) { |
9 |
0 |
9 |
|
| 1820 |
9 |
| SV *prelude = dds_invoke(aTHX_ ctx, ctx->style.compressor, FALSE, G_SCALAR, 0, NULL); |
| 1821 |
|
| |
| 1822 |
9 |
▶ | if (SvTRUE(prelude)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(prelude)) |
9 |
0 |
9 |
|
| 1823 |
9 |
| dds_write(aTHX_ ctx, prelude); |
| 1824 |
|
| } |
| 1825 |
1513 |
▶ | if (class_terse) |
Branch: 1 branch
| Branch | True | False | Total |
| if (class_terse) |
0 |
1513 |
1513 |
|
| 1826 |
0 |
| dds_put(aTHX_ ctx, "do {\n"); |
| 1827 |
|
| |
| 1828 |
1513 |
▶ | if (HvTOTALKEYS(ctx->lexical_added)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (HvTOTALKEYS(ctx->lexical_added)) { |
11 |
1502 |
1513 |
|
| 1829 |
11 |
| AV *keys = (AV *)DDS_TEMP((SV *)newAV()); |
| 1830 |
|
| HE *he; |
| 1831 |
|
| SSize_t k; |
| 1832 |
|
| |
| 1833 |
11 |
| hv_iterinit(ctx->lexical_added); |
| 1834 |
38 |
▶ | while ((he = hv_iternext(ctx->lexical_added))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(ctx->lexical_added))) |
27 |
11 |
38 |
|
| 1835 |
27 |
| av_push(keys, newSVsv(hv_iterkeysv(he))); |
| 1836 |
11 |
| sortsv(AvARRAY(keys), av_len(keys) + 1, Perl_sv_cmp); |
| 1837 |
11 |
| dds_put(aTHX_ ctx, "my ("); |
| 1838 |
38 |
▶ | for (k = 0; k <= av_len(keys); k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k <= av_len(keys); k++) { |
27 |
11 |
38 |
|
| 1839 |
27 |
▶ | if (k) |
Branch: 1 branch
| Branch | True | False | Total |
| if (k) |
16 |
11 |
27 |
|
| 1840 |
16 |
| dds_put(aTHX_ ctx, ","); |
| 1841 |
27 |
| dds_write(aTHX_ ctx, *av_fetch(keys, k, 0)); |
| 1842 |
|
| } |
| 1843 |
11 |
| dds_put(aTHX_ ctx, ");\n"); |
| 1844 |
|
| } |
| 1845 |
|
| |
| 1846 |
1513 |
▶ | if (ctx->class_head) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->class_head) { |
0 |
1513 |
1513 |
|
| 1847 |
0 |
▶ | if (class_declare) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (class_declare) { |
0 |
0 |
0 |
|
| 1848 |
0 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
0 |
0 |
0 |
|
| 1849 |
0 |
| SV *name = ctx->roots[i].name; |
| 1850 |
|
| |
| 1851 |
0 |
▶ | if (DDS_PV(name)[0] == '*' || DDS_PV(name)[0] == '&' || |
Branch: 1 branch
| Branch | True | False | Total |
| if (DDS_PV(name)[0] == '*' || DDS_PV(name)[0] == '&' || |
0 |
0 |
0 |
|
| 1852 |
0 |
| hv_exists_ent(ctx->lexical_added, name, 0)) |
| 1853 |
0 |
| continue; |
| 1854 |
0 |
| dds_put(aTHX_ ctx, "my "); |
| 1855 |
0 |
| dds_write(aTHX_ ctx, name); |
| 1856 |
0 |
| dds_put(aTHX_ ctx, ";\n"); |
| 1857 |
|
| } |
| 1858 |
|
| } |
| 1859 |
0 |
| dds_put(aTHX_ ctx, "{\n"); |
| 1860 |
|
| } |
| 1861 |
|
| |
| 1862 |
|
| /* Construct roots first. Ready fixups can follow each assignment. */ |
| 1863 |
3448 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
1937 |
1511 |
3448 |
|
| 1864 |
1937 |
| dds_mark *mark = dds_new_mark(aTHX_ ctx); |
| 1865 |
|
| dds_result result = |
| 1866 |
1937 |
| dds_emit_sv(aTHX_ ctx, ctx->roots[i].sv, 1, mark, ctx->roots[i].name, 0, FALSE); |
| 1867 |
|
| |
| 1868 |
1936 |
▶ | if (result.alias) |
Branch: 1 branch
| Branch | True | False | Total |
| if (result.alias) |
0 |
1936 |
1936 |
|
| 1869 |
0 |
| croak("Unexpected root alias"); |
| 1870 |
1936 |
| dds_put(aTHX_ ctx, ";\n"); |
| 1871 |
1936 |
| mark->ready = TRUE; |
| 1872 |
1936 |
| dds_apply_fixes(aTHX_ ctx, FALSE); |
| 1873 |
|
| } |
| 1874 |
|
| |
| 1875 |
|
| /* Hydration shares the reconstructed field slots, so it must wait |
| 1876 |
|
| * until assignments and aliases into those snapshots are complete. */ |
| 1877 |
1511 |
▶ | if (ctx->class_head) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->class_head) { |
0 |
1511 |
1511 |
|
| 1878 |
|
| dds_node *node; |
| 1879 |
|
| |
| 1880 |
0 |
| dds_emit_class_fields(aTHX_ ctx); |
| 1881 |
0 |
▶ | for (node = ctx->class_head; node; node = node->class_next) |
Branch: 1 branch
| Branch | True | False | Total |
| for (node = ctx->class_head; node; node = node->class_next) |
0 |
0 |
0 |
|
| 1882 |
0 |
| dds_add_fix(aTHX_ ctx, dds_new_fix(aTHX_ DDS_FIX_CLASS, NULL, node)); |
| 1883 |
|
| } |
| 1884 |
|
| |
| 1885 |
1511 |
| dds_apply_fixes(aTHX_ ctx, TRUE); |
| 1886 |
|
| |
| 1887 |
|
| /* Weakening comes last: temporary strong edges protect cyclic data |
| 1888 |
|
| * while thaws, class hydration and other fixups are still pending. */ |
| 1889 |
1511 |
| ctx->final_weakening = TRUE; |
| 1890 |
1511 |
| dds_apply_fixes(aTHX_ ctx, TRUE); |
| 1891 |
1511 |
▶ | if (ctx->fix_head) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->fix_head) |
0 |
1511 |
1511 |
|
| 1892 |
0 |
| croak("DDS cannot resolve graph fixups; call Data again if the graph changed"); |
| 1893 |
|
| |
| 1894 |
1511 |
▶ | if (ctx->class_head) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->class_head) |
0 |
1511 |
1511 |
|
| 1895 |
0 |
| dds_put(aTHX_ ctx, "}\n"); |
| 1896 |
1511 |
▶ | if (class_terse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (class_terse) { |
0 |
1511 |
1511 |
|
| 1897 |
0 |
▶ | for (i = 0; i < ctx->root_count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ctx->root_count; i++) { |
0 |
0 |
0 |
|
| 1898 |
0 |
▶ | if (i) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) |
0 |
0 |
0 |
|
| 1899 |
0 |
| dds_put(aTHX_ ctx, ", "); |
| 1900 |
0 |
| dds_write(aTHX_ ctx, dds_ref_expression(aTHX_ ctx, ctx->roots[i].name, &PL_sv_undef)); |
| 1901 |
|
| } |
| 1902 |
0 |
| dds_put(aTHX_ ctx, ";\n};\n"); |
| 1903 |
|
| } |
| 1904 |
|
| |
| 1905 |
1511 |
| dds_run_postdump(aTHX_ ctx); |
| 1906 |
|
| |
| 1907 |
1510 |
▶ | if (gimme == G_VOID && !ctx->printer) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (gimme == G_VOID && !ctx->printer) { |
9 |
1501 |
1510 |
| if (gimme == G_VOID && !ctx->printer) { |
5 |
4 |
9 |
|
| 1908 |
|
| SV *args[2]; |
| 1909 |
|
| |
| 1910 |
5 |
| args[0] = DDS_TEMP(newRV_inc((SV *)gv_fetchpvs("main::STDOUT", GV_ADD, SVt_PVIO))); |
| 1911 |
5 |
| args[1] = ctx->out; |
| 1912 |
|
| |
| 1913 |
|
| /* Dispatch through the actual glob: it may be localized or tied. |
| 1914 |
|
| * PRINT is user code and needs the same guard as a To callback. */ |
| 1915 |
5 |
| (void)dds_invoke(aTHX_ ctx, DDS_TEMP(newSVpvs("print")), TRUE, G_VOID | G_DISCARD, 2, args); |
| 1916 |
|
| } |
| 1917 |
|
| |
| 1918 |
1509 |
| return ctx->out; |
| 1919 |
|
| } |