aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-09-28 13:48:46 -0400
committergit <svn-admin@ruby-lang.org>2023-09-28 18:15:35 +0000
commit56cf1633a2509170d83e5fac64a77d933106adc5 (patch)
tree3769306085b3d6afc0e57e37cc8f7e8b7f17f519 /prism
parenteaa0fbf9b956fa25e73c3d55e2eba8887324e233 (diff)
downloadruby-56cf1633a2509170d83e5fac64a77d933106adc5.tar.gz
[ruby/prism] Turn on static literal for assoc, hash, and array nodes
https://github.com/ruby/prism/commit/80c2c931b5
Diffstat (limited to 'prism')
-rw-r--r--prism/prism.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 464dc576fa..5e3e769775 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -878,6 +878,7 @@ pm_array_node_create(pm_parser_t *parser, const pm_token_t *opening) {
*node = (pm_array_node_t) {
{
.type = PM_ARRAY_NODE,
+ .flags = PM_NODE_FLAG_STATIC_LITERAL,
.location = PM_LOCATION_TOKEN_VALUE(opening)
},
.opening_loc = PM_OPTIONAL_LOCATION_TOKEN_VALUE(opening),
@@ -900,8 +901,15 @@ pm_array_node_elements_append(pm_array_node_t *node, pm_node_t *element) {
if (!node->elements.size && !node->opening_loc.start) {
node->base.location.start = element->location.start;
}
+
pm_node_list_append(&node->elements, element);
node->base.location.end = element->location.end;
+
+ // If the element is not a static literal, then the array is not a static
+ // literal. Turn that flag off.
+ if (PM_NODE_TYPE_P(element, PM_ARRAY_NODE) || PM_NODE_TYPE_P(element, PM_HASH_NODE) || (element->flags & PM_NODE_FLAG_STATIC_LITERAL) == 0) {
+ node->base.flags &= (pm_node_flags_t) ~PM_NODE_FLAG_STATIC_LITERAL;
+ }
}
// Set the closing token and end location of an array node.
@@ -1043,9 +1051,15 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper
end = key->location.end;
}
+ pm_node_flags_t flags = 0;
+ if (value && !PM_NODE_TYPE_P(value, PM_ARRAY_NODE) && !PM_NODE_TYPE_P(value, PM_HASH_NODE)) {
+ flags = key->flags & value->flags & PM_NODE_FLAG_STATIC_LITERAL;
+ }
+
*node = (pm_assoc_node_t) {
{
.type = PM_ASSOC_NODE,
+ .flags = flags,
.location = {
.start = key->location.start,
.end = end
@@ -2620,6 +2634,7 @@ pm_hash_node_create(pm_parser_t *parser, const pm_token_t *opening) {
*node = (pm_hash_node_t) {
{
.type = PM_HASH_NODE,
+ .flags = PM_NODE_FLAG_STATIC_LITERAL,
.location = PM_LOCATION_TOKEN_VALUE(opening)
},
.opening_loc = PM_LOCATION_TOKEN_VALUE(opening),
@@ -2630,9 +2645,16 @@ pm_hash_node_create(pm_parser_t *parser, const pm_token_t *opening) {
return node;
}
+// Append a new element to a hash node.
static inline void
pm_hash_node_elements_append(pm_hash_node_t *hash, pm_node_t *element) {
pm_node_list_append(&hash->elements, element);
+
+ // If the element is not a static literal, then the hash is not a static
+ // literal. Turn that flag off.
+ if ((element->flags & PM_NODE_FLAG_STATIC_LITERAL) == 0) {
+ hash->base.flags &= (pm_node_flags_t) ~PM_NODE_FLAG_STATIC_LITERAL;
+ }
}
static inline void
@@ -3892,7 +3914,7 @@ pm_regular_expression_node_create(pm_parser_t *parser, const pm_token_t *opening
*node = (pm_regular_expression_node_t) {
{
.type = PM_REGULAR_EXPRESSION_NODE,
- .flags = pm_regular_expression_flags_create(closing),
+ .flags = pm_regular_expression_flags_create(closing) | PM_NODE_FLAG_STATIC_LITERAL,
.location = {
.start = MIN(opening->start, closing->start),
.end = MAX(opening->end, closing->end)