parse.y: concatenated literals
* parse.y (literal_concat_gen): merge fixed strings across concatenated literals, after an interpolation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e6c5b9f308
commit
e7576a777c
@ -1,3 +1,8 @@
|
|||||||
|
Fri Oct 26 13:24:20 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (literal_concat_gen): merge fixed strings across
|
||||||
|
concatenated literals, after an interpolation.
|
||||||
|
|
||||||
Thu Oct 25 17:48:54 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
Thu Oct 25 17:48:54 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* win32/win32.c (has_redirection): should use shell (cmd.exe) when
|
* win32/win32.c (has_redirection): should use shell (cmd.exe) when
|
||||||
|
22
parse.y
22
parse.y
@ -8246,6 +8246,8 @@ static NODE *
|
|||||||
literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
|
literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
|
||||||
{
|
{
|
||||||
enum node_type htype;
|
enum node_type htype;
|
||||||
|
NODE *headlast;
|
||||||
|
VALUE lit;
|
||||||
|
|
||||||
if (!head) return tail;
|
if (!head) return tail;
|
||||||
if (!tail) return head;
|
if (!tail) return head;
|
||||||
@ -8254,11 +8256,20 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
|
|||||||
if (htype == NODE_EVSTR) {
|
if (htype == NODE_EVSTR) {
|
||||||
NODE *node = NEW_DSTR(Qnil);
|
NODE *node = NEW_DSTR(Qnil);
|
||||||
head = list_append(node, head);
|
head = list_append(node, head);
|
||||||
|
htype = NODE_DSTR;
|
||||||
}
|
}
|
||||||
switch (nd_type(tail)) {
|
switch (nd_type(tail)) {
|
||||||
case NODE_STR:
|
case NODE_STR:
|
||||||
|
if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
|
||||||
|
nd_type(headlast) == NODE_STR) {
|
||||||
|
htype = NODE_STR;
|
||||||
|
lit = headlast->nd_lit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lit = head->nd_lit;
|
||||||
|
}
|
||||||
if (htype == NODE_STR) {
|
if (htype == NODE_STR) {
|
||||||
if (!literal_concat0(parser, head->nd_lit, tail->nd_lit)) {
|
if (!literal_concat0(parser, lit, tail->nd_lit)) {
|
||||||
error:
|
error:
|
||||||
rb_gc_force_recycle((VALUE)head);
|
rb_gc_force_recycle((VALUE)head);
|
||||||
rb_gc_force_recycle((VALUE)tail);
|
rb_gc_force_recycle((VALUE)tail);
|
||||||
@ -8280,11 +8291,20 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
|
|||||||
head = tail;
|
head = tail;
|
||||||
}
|
}
|
||||||
else if (NIL_P(tail->nd_lit)) {
|
else if (NIL_P(tail->nd_lit)) {
|
||||||
|
append:
|
||||||
head->nd_alen += tail->nd_alen - 1;
|
head->nd_alen += tail->nd_alen - 1;
|
||||||
head->nd_next->nd_end->nd_next = tail->nd_next;
|
head->nd_next->nd_end->nd_next = tail->nd_next;
|
||||||
head->nd_next->nd_end = tail->nd_next->nd_end;
|
head->nd_next->nd_end = tail->nd_next->nd_end;
|
||||||
rb_gc_force_recycle((VALUE)tail);
|
rb_gc_force_recycle((VALUE)tail);
|
||||||
}
|
}
|
||||||
|
else if (htype == NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
|
||||||
|
nd_type(headlast) == NODE_STR) {
|
||||||
|
lit = headlast->nd_lit;
|
||||||
|
if (!literal_concat0(parser, lit, tail->nd_lit))
|
||||||
|
goto error;
|
||||||
|
tail->nd_lit = Qnil;
|
||||||
|
goto append;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
nd_set_type(tail, NODE_ARRAY);
|
nd_set_type(tail, NODE_ARRAY);
|
||||||
tail->nd_head = NEW_STR(tail->nd_lit);
|
tail->nd_head = NEW_STR(tail->nd_lit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user