ruby-changes:46132
From: nobu <ko1@a...>
Date: Tue, 4 Apr 2017 23:13:51 +0900 (JST)
Subject: [ruby-changes:46132] nobu:r58246 (trunk): parse.y: flush debug buffer
nobu 2017-04-04 23:13:46 +0900 (Tue, 04 Apr 2017) New Revision: 58246 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58246 Log: parse.y: flush debug buffer * parse.y (rb_parser_trace_lex_state, rb_parser_show_bitstack): flush debug buffer before traces of lex_state and bitstack. Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 58245) +++ parse.y (revision 58246) @@ -103,14 +103,14 @@ enum lex_state_e { https://github.com/ruby/ruby/blob/trunk/parse.y#L103 #define IS_lex_state_all(ls) IS_lex_state_all_for(lex_state, (ls)) # define SET_LEX_STATE(ls) \ - (lex_state = (yydebug ? trace_lex_state(lex_state, (ls), __LINE__) : \ - (enum lex_state_e)(ls))) -static enum lex_state_e trace_lex_state(enum lex_state_e from, enum lex_state_e to, int line); + (lex_state = \ + (yydebug ? \ + rb_parser_trace_lex_state(parser, lex_state, (ls), __LINE__) : \ + (enum lex_state_e)(ls))) typedef VALUE stack_type; -static void show_bitstack(stack_type, const char *, int); -# define SHOW_BITSTACK(stack, name) (yydebug ? show_bitstack(stack, name, __LINE__) : (void)0) +# define SHOW_BITSTACK(stack, name) (yydebug ? rb_parser_show_bitstack(parser, stack, name, __LINE__) : (void)0) # define BITSTACK_PUSH(stack, n) (((stack) = ((stack)<<1)|((n)&1)), SHOW_BITSTACK(stack, #stack"(push)")) # define BITSTACK_POP(stack) (((stack) = (stack) >> 1), SHOW_BITSTACK(stack, #stack"(pop)")) # define BITSTACK_LEXPOP(stack) (((stack) = ((stack) >> 1) | ((stack) & 1)), SHOW_BITSTACK(stack, #stack"(lexpop)")) @@ -627,6 +627,8 @@ static VALUE parser_reg_compile(struct p https://github.com/ruby/ruby/blob/trunk/parse.y#L627 RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options); RUBY_FUNC_EXPORTED int rb_reg_fragment_setenc(struct parser_params*, VALUE, int); +static enum lex_state_e rb_parser_trace_lex_state(struct parser_params *, enum lex_state_e, enum lex_state_e, int); +static void rb_parser_show_bitstack(struct parser_params *, stack_type, const char *, int); static ID formal_argument_gen(struct parser_params*, ID); #define formal_argument(id) formal_argument_gen(parser, (id)) @@ -9048,8 +9050,20 @@ append_lex_state_name(enum lex_state_e s https://github.com/ruby/ruby/blob/trunk/parse.y#L9050 return buf; } +static void +flush_debug_buffer(struct parser_params *parser, VALUE out) +{ + VALUE mesg = parser->debug_buffer; + + if (!NIL_P(mesg) && RSTRING_LEN(mesg)) { + parser->debug_buffer = Qnil; + rb_io_puts(1, &mesg, out); + } +} + static enum lex_state_e -trace_lex_state(enum lex_state_e from, enum lex_state_e to, int line) +rb_parser_trace_lex_state(struct parser_params *parser, enum lex_state_e from, + enum lex_state_e to, int line) { VALUE mesg; mesg = rb_str_new_cstr("lex_state: "); @@ -9057,12 +9071,14 @@ trace_lex_state(enum lex_state_e from, e https://github.com/ruby/ruby/blob/trunk/parse.y#L9071 rb_str_cat_cstr(mesg, " -> "); append_lex_state_name(to, mesg); rb_str_catf(mesg, " at line %d\n", line); + flush_debug_buffer(parser, rb_stdout); rb_io_write(rb_stdout, mesg); return to; } static void -show_bitstack(stack_type stack, const char *name, int line) +rb_parser_show_bitstack(struct parser_params *parser, stack_type stack, + const char *name, int line) { VALUE mesg = rb_sprintf("%s: ", name); if (stack == 0) { @@ -9074,6 +9090,7 @@ show_bitstack(stack_type stack, const ch https://github.com/ruby/ruby/blob/trunk/parse.y#L9090 for (; mask; mask >>= 1) rb_str_cat(mesg, stack & mask ? "1" : "0", 1); } rb_str_catf(mesg, " at line %d\n", line); + flush_debug_buffer(parser, rb_stdout); rb_io_write(rb_stdout, mesg); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/