@@ -157,23 +157,6 @@ static NODE *reg_named_capture_assign(struct parser_params* p, VALUE regexp, con
157157VALUE rb_io_gets_internal (VALUE io);
158158
159159VALUE 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- }
177160#endif /* !UNIVERSAL_PARSER */
178161
179162static inline int
@@ -7625,6 +7608,30 @@ parser_str_new(struct parser_params *p, const char *ptr, long len, rb_encoding *
76257608 return str;
76267609}
76277610
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+
76287635#define peek(p,c) peek_n(p, (c), 0)
76297636#define peek_n(p,c,n) (!lex_eol_n_p(p, n) && (c) == (unsigned char)(p)->lex.pcur[n])
76307637#define peekc(p) peekc_n(p, 0)
@@ -7851,7 +7858,7 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
78517858 int codepoint = (int)ruby_scan_hex(p->lex.pcur, wide ? p->lex.pend - p->lex.pcur : 4, &numlen);
78527859 p->lex.pcur += numlen;
78537860 if (p->lex.strterm == NULL ||
7854- ( strterm_is_heredoc((VALUE) p->lex.strterm) ) ||
7861+ strterm_is_heredoc(p->lex.strterm) ||
78557862 (p->lex.strterm->u.literal.func != str_regexp)) {
78567863 if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) {
78577864 literal_flush(p, p->lex.pcur);
@@ -8435,9 +8442,7 @@ tokadd_string(struct parser_params *p,
84358442 return c;
84368443}
84378444
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)
84418446
84428447#ifdef RIPPER
84438448static void
@@ -8548,6 +8553,7 @@ parser_peek_variable_name(struct parser_params *p)
85488553static inline enum yytokentype
85498554parser_string_term(struct parser_params *p, int func)
85508555{
8556+ xfree(p->lex.strterm);
85518557 p->lex.strterm = 0;
85528558 if (func & STR_FUNC_REGEXP) {
85538559 set_yylval_num(regx_options(p));
@@ -8578,6 +8584,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
85788584 if (func & STR_FUNC_TERM) {
85798585 if (func & STR_FUNC_QWORDS) nextc(p); /* delayed term */
85808586 SET_LEX_STATE(EXPR_END);
8587+ xfree(p->lex.strterm);
85818588 p->lex.strterm = 0;
85828589 return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END;
85838590 }
@@ -8624,6 +8631,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
86248631 if (func & STR_FUNC_QWORDS) {
86258632 /* no content to add, bailing out here */
86268633 unterminated_literal("unterminated list meets end of file");
8634+ xfree(p->lex.strterm);
86278635 p->lex.strterm = 0;
86288636 return tSTRING_END;
86298637 }
@@ -8714,13 +8722,15 @@ heredoc_identifier(struct parser_params *p)
87148722 dispatch_scan_event(p, tHEREDOC_BEG);
87158723 lex_goto_eol(p);
87168724
8717- p->lex.strterm = (rb_strterm_t *)new_strterm(0, 0, 0, p->lex.lastline, 1 );
8725+ p->lex.strterm = new_heredoc(p );
87188726 rb_strterm_heredoc_t *here = &p->lex.strterm->u.heredoc;
87198727 here->offset = offset;
87208728 here->sourceline = p->ruby_sourceline;
8721- here->length = (int )len;
8729+ here->length = (unsigned )len;
87228730 here->quote = quote;
87238731 here->func = func;
8732+ here->lastline = p->lex.lastline;
8733+ rb_ast_add_mark_object(p->ast, p->lex.lastline);
87248734
87258735 token_flush(p);
87268736 p->heredoc_indent = indent;
@@ -8732,6 +8742,7 @@ static void
87328742heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
87338743{
87348744 VALUE line;
8745+ rb_strterm_t *term = p->lex.strterm;
87358746
87368747 p->lex.strterm = 0;
87378748 line = here->lastline;
@@ -8744,6 +8755,7 @@ heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
87448755 p->ruby_sourceline = (int)here->sourceline;
87458756 if (p->eofp) p->lex.nextline = Qnil;
87468757 p->eofp = 0;
8758+ xfree(term);
87478759}
87488760
87498761static int
@@ -9007,7 +9019,6 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
90079019 compile_error(p, "can't find string \"%.*s\" anywhere before EOF",
90089020 (int)len, eos);
90099021 token_flush(p);
9010- p->lex.strterm = 0;
90119022 SET_LEX_STATE(EXPR_END);
90129023 return tSTRING_END;
90139024 }
@@ -9027,7 +9038,6 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
90279038 restore :
90289039 heredoc_restore (p , &p- >lex.strterm- >u.heredoc );
90299040 token_flush(p);
9030- p->lex.strterm = 0;
90319041 SET_LEX_STATE(EXPR_END);
90329042 return tSTRING_END;
90339043 }
@@ -10417,7 +10427,7 @@ parser_yylex(struct parser_params *p)
1041710427 int token_seen = p->token_seen;
1041810428
1041910429 if (p->lex.strterm) {
10420- if (strterm_is_heredoc((VALUE) p->lex.strterm)) {
10430+ if (strterm_is_heredoc(p->lex.strterm)) {
1042110431 token_flush(p);
1042210432 return here_document(p, &p->lex.strterm->u.heredoc);
1042310433 }
@@ -15417,7 +15427,6 @@ rb_ruby_parser_mark(void *ptr)
1541715427 rb_gc_mark(p->lex.lastline);
1541815428 rb_gc_mark(p->lex.nextline);
1541915429 rb_gc_mark(p->ruby_sourcefile_string);
15420- rb_gc_mark((VALUE)p->lex.strterm);
1542115430 rb_gc_mark((VALUE)p->ast);
1542215431 rb_gc_mark(p->case_labels);
1542315432 rb_gc_mark(p->delayed.token);
@@ -15710,16 +15719,6 @@ rb_parser_set_yydebug(VALUE self, VALUE flag)
1571015719 rb_ruby_parser_set_yydebug(p, RTEST(flag));
1571115720 return flag;
1571215721}
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- }
1572315722#endif /* !UNIVERSAL_PARSER */
1572415723
1572515724VALUE
0 commit comments