@@ -907,7 +907,7 @@ pm_array_node_elements_append(pm_array_node_t *node, pm_node_t *element) {
907
907
908
908
// If the element is not a static literal, then the array is not a static
909
909
// literal. Turn that flag off.
910
- 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) {
910
+ if (PM_NODE_TYPE_P(element, PM_ARRAY_NODE) || PM_NODE_TYPE_P(element, PM_HASH_NODE) || PM_NODE_TYPE_P(element, PM_RANGE_NODE) || (element->flags & PM_NODE_FLAG_STATIC_LITERAL) == 0) {
911
911
node->base.flags &= (pm_node_flags_t) ~PM_NODE_FLAG_STATIC_LITERAL;
912
912
}
913
913
}
@@ -1051,8 +1051,10 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper
1051
1051
end = key->location.end;
1052
1052
}
1053
1053
1054
+ // If the key and value of this assoc node are both static literals, then
1055
+ // we can mark this node as a static literal.
1054
1056
pm_node_flags_t flags = 0;
1055
- if (value && !PM_NODE_TYPE_P(value, PM_ARRAY_NODE) && !PM_NODE_TYPE_P(value, PM_HASH_NODE)) {
1057
+ if (value && !PM_NODE_TYPE_P(value, PM_ARRAY_NODE) && !PM_NODE_TYPE_P(value, PM_HASH_NODE) && !PM_NODE_TYPE_P(value, PM_RANGE_NODE) ) {
1056
1058
flags = key->flags & value->flags & PM_NODE_FLAG_STATIC_LITERAL;
1057
1059
}
1058
1060
@@ -3870,10 +3872,27 @@ pm_pre_execution_node_create(pm_parser_t *parser, const pm_token_t *keyword, con
3870
3872
static pm_range_node_t *
3871
3873
pm_range_node_create(pm_parser_t *parser, pm_node_t *left, const pm_token_t *operator, pm_node_t *right) {
3872
3874
pm_range_node_t *node = PM_ALLOC_NODE(parser, pm_range_node_t);
3875
+ pm_node_flags_t flags = 0;
3876
+
3877
+ // Indicate that this node an exclusive range if the operator is `...`.
3878
+ if (operator->type == PM_TOKEN_DOT_DOT_DOT || operator->type == PM_TOKEN_UDOT_DOT_DOT) {
3879
+ flags |= PM_RANGE_FLAGS_EXCLUDE_END;
3880
+ }
3881
+
3882
+ // Indicate that this node is a static literal (i.e., can be compiled with
3883
+ // a putobject in CRuby) if the left and right are implicit nil, explicit
3884
+ // nil, or integers.
3885
+ if (
3886
+ (left == NULL || PM_NODE_TYPE_P(left, PM_NIL_NODE) || PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) &&
3887
+ (right == NULL || PM_NODE_TYPE_P(right, PM_NIL_NODE) || PM_NODE_TYPE_P(right, PM_INTEGER_NODE))
3888
+ ) {
3889
+ flags |= PM_NODE_FLAG_STATIC_LITERAL;
3890
+ }
3873
3891
3874
3892
*node = (pm_range_node_t) {
3875
3893
{
3876
3894
.type = PM_RANGE_NODE,
3895
+ .flags = flags,
3877
3896
.location = {
3878
3897
.start = (left == NULL ? operator->start : left->location.start),
3879
3898
.end = (right == NULL ? operator->end : right->location.end)
@@ -3884,15 +3903,6 @@ pm_range_node_create(pm_parser_t *parser, pm_node_t *left, const pm_token_t *ope
3884
3903
.operator_loc = PM_LOCATION_TOKEN_VALUE(operator)
3885
3904
};
3886
3905
3887
- switch (operator->type) {
3888
- case PM_TOKEN_DOT_DOT_DOT:
3889
- case PM_TOKEN_UDOT_DOT_DOT:
3890
- node->base.flags |= PM_RANGE_FLAGS_EXCLUDE_END;
3891
- break;
3892
- default:
3893
- break;
3894
- }
3895
-
3896
3906
return node;
3897
3907
}
3898
3908
0 commit comments