@@ -157,23 +157,6 @@ static NODE *reg_named_capture_assign(struct parser_params* p, VALUE regexp, con
157
157
VALUE rb_io_gets_internal (VALUE io);
158
158
159
159
VALUE rb_node_case_when_optimizable_literal (const NODE *const node);
160
-
161
- static int
162
- strterm_is_heredoc (VALUE strterm)
163
- {
164
- return ((rb_strterm_t *)strterm)->flags & STRTERM_HEREDOC;
165
- }
166
-
167
- static VALUE
168
- new_strterm (VALUE v1, VALUE v2, VALUE v3, VALUE v0, int heredoc)
169
- {
170
- rb_strterm_t *imemo = (rb_strterm_t *)rb_imemo_new (imemo_parser_strterm, v1, v2, v3, v0);
171
- if (heredoc) {
172
- imemo->flags |= STRTERM_HEREDOC;
173
- }
174
-
175
- return (VALUE)imemo;
176
- }
177
160
#endif /* !UNIVERSAL_PARSER */
178
161
179
162
static inline int
@@ -7625,6 +7608,30 @@ parser_str_new(struct parser_params *p, const char *ptr, long len, rb_encoding *
7625
7608
return str;
7626
7609
}
7627
7610
7611
+ static int
7612
+ strterm_is_heredoc(rb_strterm_t *strterm)
7613
+ {
7614
+ return strterm->flags & STRTERM_HEREDOC;
7615
+ }
7616
+
7617
+ static rb_strterm_t *
7618
+ new_strterm(struct parser_params *p, int func, int term, int paren)
7619
+ {
7620
+ rb_strterm_t *strterm = ZALLOC(rb_strterm_t);
7621
+ strterm->u.literal.func = func;
7622
+ strterm->u.literal.term = term;
7623
+ strterm->u.literal.paren = paren;
7624
+ return strterm;
7625
+ }
7626
+
7627
+ static rb_strterm_t *
7628
+ new_heredoc(struct parser_params *p)
7629
+ {
7630
+ rb_strterm_t *strterm = ZALLOC(rb_strterm_t);
7631
+ strterm->flags |= STRTERM_HEREDOC;
7632
+ return strterm;
7633
+ }
7634
+
7628
7635
#define peek(p,c) peek_n(p, (c), 0)
7629
7636
#define peek_n(p,c,n) (!lex_eol_n_p(p, n) && (c) == (unsigned char)(p)->lex.pcur[n])
7630
7637
#define peekc(p) peekc_n(p, 0)
@@ -7851,7 +7858,7 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
7851
7858
int codepoint = (int)ruby_scan_hex(p->lex.pcur, wide ? p->lex.pend - p->lex.pcur : 4, &numlen);
7852
7859
p->lex.pcur += numlen;
7853
7860
if (p->lex.strterm == NULL ||
7854
- ( strterm_is_heredoc((VALUE) p->lex.strterm) ) ||
7861
+ strterm_is_heredoc(p->lex.strterm) ||
7855
7862
(p->lex.strterm->u.literal.func != str_regexp)) {
7856
7863
if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) {
7857
7864
literal_flush(p, p->lex.pcur);
@@ -8435,9 +8442,7 @@ tokadd_string(struct parser_params *p,
8435
8442
return c;
8436
8443
}
8437
8444
8438
- /* imemo_parser_strterm for literal */
8439
- #define NEW_STRTERM(func, term, paren) \
8440
- (rb_strterm_t *)new_strterm((VALUE)(func), (VALUE)(paren), (VALUE)(term), 0, 0)
8445
+ #define NEW_STRTERM(func, term, paren) new_strterm(p, func, term, paren)
8441
8446
8442
8447
#ifdef RIPPER
8443
8448
static void
@@ -8548,6 +8553,7 @@ parser_peek_variable_name(struct parser_params *p)
8548
8553
static inline enum yytokentype
8549
8554
parser_string_term(struct parser_params *p, int func)
8550
8555
{
8556
+ xfree(p->lex.strterm);
8551
8557
p->lex.strterm = 0;
8552
8558
if (func & STR_FUNC_REGEXP) {
8553
8559
set_yylval_num(regx_options(p));
@@ -8578,6 +8584,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
8578
8584
if (func & STR_FUNC_TERM) {
8579
8585
if (func & STR_FUNC_QWORDS) nextc(p); /* delayed term */
8580
8586
SET_LEX_STATE(EXPR_END);
8587
+ xfree(p->lex.strterm);
8581
8588
p->lex.strterm = 0;
8582
8589
return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END;
8583
8590
}
@@ -8624,6 +8631,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
8624
8631
if (func & STR_FUNC_QWORDS) {
8625
8632
/* no content to add, bailing out here */
8626
8633
unterminated_literal("unterminated list meets end of file");
8634
+ xfree(p->lex.strterm);
8627
8635
p->lex.strterm = 0;
8628
8636
return tSTRING_END;
8629
8637
}
@@ -8714,13 +8722,15 @@ heredoc_identifier(struct parser_params *p)
8714
8722
dispatch_scan_event(p, tHEREDOC_BEG);
8715
8723
lex_goto_eol(p);
8716
8724
8717
- p->lex.strterm = (rb_strterm_t *)new_strterm(0, 0, 0, p->lex.lastline, 1 );
8725
+ p->lex.strterm = new_heredoc(p );
8718
8726
rb_strterm_heredoc_t *here = &p->lex.strterm->u.heredoc;
8719
8727
here->offset = offset;
8720
8728
here->sourceline = p->ruby_sourceline;
8721
- here->length = (int )len;
8729
+ here->length = (unsigned )len;
8722
8730
here->quote = quote;
8723
8731
here->func = func;
8732
+ here->lastline = p->lex.lastline;
8733
+ rb_ast_add_mark_object(p->ast, p->lex.lastline);
8724
8734
8725
8735
token_flush(p);
8726
8736
p->heredoc_indent = indent;
@@ -8732,6 +8742,7 @@ static void
8732
8742
heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
8733
8743
{
8734
8744
VALUE line;
8745
+ rb_strterm_t *term = p->lex.strterm;
8735
8746
8736
8747
p->lex.strterm = 0;
8737
8748
line = here->lastline;
@@ -8744,6 +8755,7 @@ heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
8744
8755
p->ruby_sourceline = (int)here->sourceline;
8745
8756
if (p->eofp) p->lex.nextline = Qnil;
8746
8757
p->eofp = 0;
8758
+ xfree(term);
8747
8759
}
8748
8760
8749
8761
static int
@@ -9007,7 +9019,6 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
9007
9019
compile_error(p, "can't find string \"%.*s\" anywhere before EOF",
9008
9020
(int)len, eos);
9009
9021
token_flush(p);
9010
- p->lex.strterm = 0;
9011
9022
SET_LEX_STATE(EXPR_END);
9012
9023
return tSTRING_END;
9013
9024
}
@@ -9027,7 +9038,6 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
9027
9038
restore :
9028
9039
heredoc_restore (p , &p- >lex.strterm- >u.heredoc );
9029
9040
token_flush(p);
9030
- p->lex.strterm = 0;
9031
9041
SET_LEX_STATE(EXPR_END);
9032
9042
return tSTRING_END;
9033
9043
}
@@ -10417,7 +10427,7 @@ parser_yylex(struct parser_params *p)
10417
10427
int token_seen = p->token_seen;
10418
10428
10419
10429
if (p->lex.strterm) {
10420
- if (strterm_is_heredoc((VALUE) p->lex.strterm)) {
10430
+ if (strterm_is_heredoc(p->lex.strterm)) {
10421
10431
token_flush(p);
10422
10432
return here_document(p, &p->lex.strterm->u.heredoc);
10423
10433
}
@@ -15417,7 +15427,6 @@ rb_ruby_parser_mark(void *ptr)
15417
15427
rb_gc_mark(p->lex.lastline);
15418
15428
rb_gc_mark(p->lex.nextline);
15419
15429
rb_gc_mark(p->ruby_sourcefile_string);
15420
- rb_gc_mark((VALUE)p->lex.strterm);
15421
15430
rb_gc_mark((VALUE)p->ast);
15422
15431
rb_gc_mark(p->case_labels);
15423
15432
rb_gc_mark(p->delayed.token);
@@ -15710,16 +15719,6 @@ rb_parser_set_yydebug(VALUE self, VALUE flag)
15710
15719
rb_ruby_parser_set_yydebug(p, RTEST(flag));
15711
15720
return flag;
15712
15721
}
15713
-
15714
- void
15715
- rb_strterm_mark(VALUE obj)
15716
- {
15717
- rb_strterm_t *strterm = (rb_strterm_t*)obj;
15718
- if (RBASIC(obj)->flags & STRTERM_HEREDOC) {
15719
- rb_strterm_heredoc_t *heredoc = &strterm->u.heredoc;
15720
- rb_gc_mark(heredoc->lastline);
15721
- }
15722
- }
15723
15722
#endif /* !UNIVERSAL_PARSER */
15724
15723
15725
15724
VALUE
0 commit comments