diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-10-09 23:55:22 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-12-14 19:19:16 +0900 |
commit | 60f0c376f762aafadaba38e761d2dc9b0c1c0c82 (patch) | |
tree | e4ff5010c2a211be5430bb2d9b89163edb264cf5 /parse.y | |
parent | 65450e8f7daf59ca64a12ff1da0efdc0f4280dc1 (diff) | |
download | ruby-60f0c376f762aafadaba38e761d2dc9b0c1c0c82.tar.gz |
Implemented shareable_constant_value op_asgn
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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 { |