@@ -4281,6 +4281,7 @@ pm_interpolated_regular_expression_node_create(pm_parser_t *parser, const pm_tok
4281
4281
*node = (pm_interpolated_regular_expression_node_t) {
4282
4282
{
4283
4283
.type = PM_INTERPOLATED_REGULAR_EXPRESSION_NODE,
4284
+ .flags = PM_NODE_FLAG_STATIC_LITERAL,
4284
4285
.location = {
4285
4286
.start = opening->start,
4286
4287
.end = NULL,
@@ -4302,6 +4303,15 @@ pm_interpolated_regular_expression_node_append(pm_interpolated_regular_expressio
4302
4303
if (node->base.location.end < part->location.end) {
4303
4304
node->base.location.end = part->location.end;
4304
4305
}
4306
+
4307
+ if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
4308
+ pm_node_flag_set(part, PM_NODE_FLAG_STATIC_LITERAL | PM_STRING_FLAGS_FROZEN);
4309
+ }
4310
+
4311
+ if (!PM_NODE_FLAG_P(part, PM_NODE_FLAG_STATIC_LITERAL)) {
4312
+ pm_node_flag_unset((pm_node_t *) node, PM_NODE_FLAG_STATIC_LITERAL);
4313
+ }
4314
+
4305
4315
pm_node_list_append(&node->parts, part);
4306
4316
}
4307
4317
@@ -4312,6 +4322,38 @@ pm_interpolated_regular_expression_node_closing_set(pm_parser_t *parser, pm_inte
4312
4322
pm_node_flag_set((pm_node_t *)node, pm_regular_expression_flags_create(parser, closing));
4313
4323
}
4314
4324
4325
+ /**
4326
+ * Append a part to an InterpolatedStringNode node.
4327
+ */
4328
+ static inline void
4329
+ pm_interpolated_string_node_append(pm_parser_t *parser, pm_interpolated_string_node_t *node, pm_node_t *part) {
4330
+ if (node->parts.size == 0 && node->opening_loc.start == NULL) {
4331
+ node->base.location.start = part->location.start;
4332
+ }
4333
+
4334
+ if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
4335
+ pm_node_flag_set(part, PM_NODE_FLAG_STATIC_LITERAL | PM_STRING_FLAGS_FROZEN);
4336
+ }
4337
+
4338
+ if (!PM_NODE_FLAG_P(part, PM_NODE_FLAG_STATIC_LITERAL)) {
4339
+ pm_node_flag_unset((pm_node_t *) node, PM_NODE_FLAG_STATIC_LITERAL | PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN | PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE);
4340
+ }
4341
+
4342
+ pm_node_list_append(&node->parts, part);
4343
+ node->base.location.end = MAX(node->base.location.end, part->location.end);
4344
+
4345
+ if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
4346
+ switch (parser->frozen_string_literal) {
4347
+ case PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED:
4348
+ pm_node_flag_set((pm_node_t *) node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN);
4349
+ break;
4350
+ case PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED:
4351
+ pm_node_flag_set((pm_node_t *) node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE);
4352
+ break;
4353
+ }
4354
+ }
4355
+ }
4356
+
4315
4357
/**
4316
4358
* Allocate and initialize a new InterpolatedStringNode node.
4317
4359
*/
@@ -4322,6 +4364,7 @@ pm_interpolated_string_node_create(pm_parser_t *parser, const pm_token_t *openin
4322
4364
*node = (pm_interpolated_string_node_t) {
4323
4365
{
4324
4366
.type = PM_INTERPOLATED_STRING_NODE,
4367
+ .flags = PM_NODE_FLAG_STATIC_LITERAL,
4325
4368
.location = {
4326
4369
.start = opening->start,
4327
4370
.end = closing->end,
@@ -4333,25 +4376,14 @@ pm_interpolated_string_node_create(pm_parser_t *parser, const pm_token_t *openin
4333
4376
};
4334
4377
4335
4378
if (parts != NULL) {
4336
- node->parts = *parts;
4379
+ for (size_t index = 0; index < parts->size; index++) {
4380
+ pm_interpolated_string_node_append(parser, node, parts->nodes[index]);
4381
+ }
4337
4382
}
4338
4383
4339
4384
return node;
4340
4385
}
4341
4386
4342
- /**
4343
- * Append a part to an InterpolatedStringNode node.
4344
- */
4345
- static inline void
4346
- pm_interpolated_string_node_append(pm_interpolated_string_node_t *node, pm_node_t *part) {
4347
- if (node->parts.size == 0 && node->opening_loc.start == NULL) {
4348
- node->base.location.start = part->location.start;
4349
- }
4350
-
4351
- pm_node_list_append(&node->parts, part);
4352
- node->base.location.end = part->location.end;
4353
- }
4354
-
4355
4387
/**
4356
4388
* Set the closing token of the given InterpolatedStringNode node.
4357
4389
*/
@@ -4361,6 +4393,24 @@ pm_interpolated_string_node_closing_set(pm_interpolated_string_node_t *node, con
4361
4393
node->base.location.end = closing->end;
4362
4394
}
4363
4395
4396
+ static void
4397
+ pm_interpolated_symbol_node_append(pm_interpolated_symbol_node_t *node, pm_node_t *part) {
4398
+ if (node->parts.size == 0 && node->opening_loc.start == NULL) {
4399
+ node->base.location.start = part->location.start;
4400
+ }
4401
+
4402
+ if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
4403
+ pm_node_flag_set(part, PM_NODE_FLAG_STATIC_LITERAL | PM_STRING_FLAGS_FROZEN);
4404
+ }
4405
+
4406
+ if (!PM_NODE_FLAG_P(part, PM_NODE_FLAG_STATIC_LITERAL)) {
4407
+ pm_node_flag_unset((pm_node_t *) node, PM_NODE_FLAG_STATIC_LITERAL);
4408
+ }
4409
+
4410
+ pm_node_list_append(&node->parts, part);
4411
+ node->base.location.end = MAX(node->base.location.end, part->location.end);
4412
+ }
4413
+
4364
4414
/**
4365
4415
* Allocate and initialize a new InterpolatedSymbolNode node.
4366
4416
*/
@@ -4371,6 +4421,7 @@ pm_interpolated_symbol_node_create(pm_parser_t *parser, const pm_token_t *openin
4371
4421
*node = (pm_interpolated_symbol_node_t) {
4372
4422
{
4373
4423
.type = PM_INTERPOLATED_SYMBOL_NODE,
4424
+ .flags = PM_NODE_FLAG_STATIC_LITERAL,
4374
4425
.location = {
4375
4426
.start = opening->start,
4376
4427
.end = closing->end,
@@ -4382,22 +4433,14 @@ pm_interpolated_symbol_node_create(pm_parser_t *parser, const pm_token_t *openin
4382
4433
};
4383
4434
4384
4435
if (parts != NULL) {
4385
- node->parts = *parts;
4436
+ for (size_t index = 0; index < parts->size; index++) {
4437
+ pm_interpolated_symbol_node_append(node, parts->nodes[index]);
4438
+ }
4386
4439
}
4387
4440
4388
4441
return node;
4389
4442
}
4390
4443
4391
- static inline void
4392
- pm_interpolated_symbol_node_append(pm_interpolated_symbol_node_t *node, pm_node_t *part) {
4393
- if (node->parts.size == 0 && node->opening_loc.start == NULL) {
4394
- node->base.location.start = part->location.start;
4395
- }
4396
-
4397
- pm_node_list_append(&node->parts, part);
4398
- node->base.location.end = part->location.end;
4399
- }
4400
-
4401
4444
/**
4402
4445
* Allocate a new InterpolatedXStringNode node.
4403
4446
*/
@@ -4423,6 +4466,10 @@ pm_interpolated_xstring_node_create(pm_parser_t *parser, const pm_token_t *openi
4423
4466
4424
4467
static inline void
4425
4468
pm_interpolated_xstring_node_append(pm_interpolated_x_string_node_t *node, pm_node_t *part) {
4469
+ if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
4470
+ pm_node_flag_set(part, PM_NODE_FLAG_STATIC_LITERAL | PM_STRING_FLAGS_FROZEN);
4471
+ }
4472
+
4426
4473
pm_node_list_append(&node->parts, part);
4427
4474
node->base.location.end = part->location.end;
4428
4475
}
@@ -15427,11 +15474,11 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
15427
15474
pm_token_t bounds = not_provided(parser);
15428
15475
15429
15476
pm_interpolated_string_node_t *container = pm_interpolated_string_node_create(parser, &bounds, NULL, &bounds);
15430
- pm_interpolated_string_node_append(container, current);
15477
+ pm_interpolated_string_node_append(parser, container, current);
15431
15478
current = (pm_node_t *) container;
15432
15479
}
15433
15480
15434
- pm_interpolated_string_node_append((pm_interpolated_string_node_t *) current, node);
15481
+ pm_interpolated_string_node_append(parser, (pm_interpolated_string_node_t *) current, node);
15435
15482
}
15436
15483
}
15437
15484
@@ -17365,15 +17412,15 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17365
17412
// If we hit string content and the current node is
17366
17413
// an interpolated string, then we need to append
17367
17414
// the string content to the list of child nodes.
17368
- pm_interpolated_string_node_append((pm_interpolated_string_node_t *) current, string);
17415
+ pm_interpolated_string_node_append(parser, (pm_interpolated_string_node_t *) current, string);
17369
17416
} else if (PM_NODE_TYPE_P(current, PM_STRING_NODE)) {
17370
17417
// If we hit string content and the current node is
17371
17418
// a string node, then we need to convert the
17372
17419
// current node into an interpolated string and add
17373
17420
// the string content to the list of child nodes.
17374
17421
pm_interpolated_string_node_t *interpolated = pm_interpolated_string_node_create(parser, &opening, NULL, &closing);
17375
- pm_interpolated_string_node_append(interpolated, current);
17376
- pm_interpolated_string_node_append(interpolated, string);
17422
+ pm_interpolated_string_node_append(parser, interpolated, current);
17423
+ pm_interpolated_string_node_append(parser, interpolated, string);
17377
17424
current = (pm_node_t *) interpolated;
17378
17425
} else {
17379
17426
assert(false && "unreachable");
@@ -17398,7 +17445,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17398
17445
pm_token_t opening = not_provided(parser);
17399
17446
pm_token_t closing = not_provided(parser);
17400
17447
pm_interpolated_string_node_t *interpolated = pm_interpolated_string_node_create(parser, &opening, NULL, &closing);
17401
- pm_interpolated_string_node_append(interpolated, current);
17448
+ pm_interpolated_string_node_append(parser, interpolated, current);
17402
17449
current = (pm_node_t *) interpolated;
17403
17450
} else {
17404
17451
// If we hit an embedded variable and the current
@@ -17407,7 +17454,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17407
17454
}
17408
17455
17409
17456
pm_node_t *part = parse_string_part(parser);
17410
- pm_interpolated_string_node_append((pm_interpolated_string_node_t *) current, part);
17457
+ pm_interpolated_string_node_append(parser, (pm_interpolated_string_node_t *) current, part);
17411
17458
break;
17412
17459
}
17413
17460
case PM_TOKEN_EMBEXPR_BEGIN: {
@@ -17427,7 +17474,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17427
17474
pm_token_t opening = not_provided(parser);
17428
17475
pm_token_t closing = not_provided(parser);
17429
17476
pm_interpolated_string_node_t *interpolated = pm_interpolated_string_node_create(parser, &opening, NULL, &closing);
17430
- pm_interpolated_string_node_append(interpolated, current);
17477
+ pm_interpolated_string_node_append(parser, interpolated, current);
17431
17478
current = (pm_node_t *) interpolated;
17432
17479
} else if (PM_NODE_TYPE_P(current, PM_INTERPOLATED_STRING_NODE)) {
17433
17480
// If we hit an embedded expression and the current
@@ -17438,7 +17485,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
17438
17485
}
17439
17486
17440
17487
pm_node_t *part = parse_string_part(parser);
17441
- pm_interpolated_string_node_append((pm_interpolated_string_node_t *) current, part);
17488
+ pm_interpolated_string_node_append(parser, (pm_interpolated_string_node_t *) current, part);
17442
17489
break;
17443
17490
}
17444
17491
default:
0 commit comments