summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-10-09 23:55:22 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-14 19:19:16 +0900
commit60f0c376f762aafadaba38e761d2dc9b0c1c0c82 (patch)
treee4ff5010c2a211be5430bb2d9b89163edb264cf5 /parse.y
parent65450e8f7daf59ca64a12ff1da0efdc0f4280dc1 (diff)
Implemented shareable_constant_value op_asgn
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3681
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y23
1 files changed, 22 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index de3a8a8183..986c67c594 100644
--- a/parse.y
+++ b/parse.y
@@ -11876,7 +11876,20 @@ new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYP
if (lhs) {
ID vid = lhs->nd_vid;
YYLTYPE lhs_loc = lhs->nd_loc;
+ bool shareable = false;
+ switch (nd_type(lhs)) {
+ case NODE_CDECL:
+ case NODE_COLON2:
+ case NODE_COLON3:
+ shareable = true;
+ break;
+ default:
+ break;
+ }
if (op == tOROP) {
+ if (shareable) {
+ rhs = shareable_constant_value(p, rhs, &rhs->nd_loc);
+ }
lhs->nd_value = rhs;
nd_set_loc(lhs, loc);
asgn = NEW_OP_ASGN_OR(gettable(p, vid, &lhs_loc), lhs, loc);
@@ -11890,13 +11903,20 @@ new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const YYLTYP
}
}
else if (op == tANDOP) {
+ if (shareable) {
+ rhs = shareable_constant_value(p, rhs, &rhs->nd_loc);
+ }
lhs->nd_value = rhs;
nd_set_loc(lhs, loc);
asgn = NEW_OP_ASGN_AND(gettable(p, vid, &lhs_loc), lhs, loc);
}
else {
asgn = lhs;
- asgn->nd_value = NEW_CALL(gettable(p, vid, &lhs_loc), op, NEW_LIST(rhs, &rhs->nd_loc), loc);
+ rhs = NEW_CALL(gettable(p, vid, &lhs_loc), op, NEW_LIST(rhs, &rhs->nd_loc), loc);
+ if (shareable) {
+ rhs = shareable_constant_value(p, rhs, &rhs->nd_loc);
+ }
+ asgn->nd_value = rhs;
nd_set_loc(asgn, loc);
}
}
@@ -11941,6 +11961,7 @@ new_const_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, const
NODE *asgn;
if (lhs) {
+ rhs = shareable_constant_value(p, rhs, loc);
asgn = NEW_OP_CDECL(lhs, op, rhs, loc);
}
else {