ruby-changes:49891
From: nobu <ko1@a...>
Date: Tue, 23 Jan 2018 11:23:25 +0900 (JST)
Subject: [ruby-changes:49891] nobu:r62009 (trunk): parse.y: removed implicit parser_params macros
nobu 2018-01-23 11:23:18 +0900 (Tue, 23 Jan 2018) New Revision: 62009 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62009 Log: parse.y: removed implicit parser_params macros Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 62008) +++ parse.y (revision 62009) @@ -4343,32 +4343,11 @@ none : /* none */ https://github.com/ruby/ruby/blob/trunk/parse.y#L4343 # undef yylval # define yylval (*p->lval) -static int parser_regx_options(struct parser_params*); -static int parser_tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**); -static void parser_tokaddmbc(struct parser_params *p, int c, rb_encoding *enc); -static enum yytokentype parser_parse_string(struct parser_params*,rb_strterm_literal_t*); -static enum yytokentype parser_here_document(struct parser_params*,rb_strterm_heredoc_t*); - - -# define nextc() parser_nextc(p) -# define pushback(c) parser_pushback(p, (c)) -# define newtok() parser_newtok(p) -# define tokspace(n) parser_tokspace(p, (n)) -# define tokadd(c) parser_tokadd(p, (c)) -# define tok_hex(numlen) parser_tok_hex(p, (numlen)) -# define read_escape(flags,e) parser_read_escape(p, (flags), (e)) -# define tokadd_escape(e) parser_tokadd_escape(p, (e)) -# define regx_options() parser_regx_options(p) -# define tokadd_string(func,term,paren,nest,enc) parser_tokadd_string(p,(func),(term),(paren),(nest),(enc)) -# define parse_string(n) parser_parse_string(p,(n)) -# define tokaddmbc(c, enc) parser_tokaddmbc(p, (c), (enc)) -# define here_document(n) parser_here_document(p,(n)) -# define heredoc_identifier() parser_heredoc_identifier(p) -# define heredoc_restore(n) parser_heredoc_restore(p,(n)) -# define whole_match_p(e,l,i) parser_whole_match_p(p,(e),(l),(i)) -# define number_literal_suffix(f) parser_number_literal_suffix(p, (f)) -# define set_number_literal(v, t, f) parser_set_number_literal(p, (v), (t), (f)) -# define set_integer_literal(v, f) parser_set_integer_literal(p, (v), (f)) +static int regx_options(struct parser_params*); +static int tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**); +static void tokaddmbc(struct parser_params *p, int c, rb_encoding *enc); +static enum yytokentype parse_string(struct parser_params*,rb_strterm_literal_t*); +static enum yytokentype here_document(struct parser_params*,rb_strterm_heredoc_t*); #ifndef RIPPER # define set_yylval_node(x) { \ @@ -4399,12 +4378,12 @@ ripper_yylval_id(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L4378 #endif #ifndef RIPPER -#define literal_flush(ptr) (p->lex.ptok = (ptr)) -#define dispatch_scan_event(t) ((void)0) -#define dispatch_delayed_token(t) ((void)0) -#define has_delayed_token() (0) +#define literal_flush(p, ptr) ((p)->lex.ptok = (ptr)) +#define dispatch_scan_event(p, t) ((void)0) +#define dispatch_delayed_token(p, t) ((void)0) +#define has_delayed_token(p) (0) #else -#define literal_flush(ptr) ((void)0) +#define literal_flush(p, ptr) ((void)(ptr)) #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val)) @@ -4437,7 +4416,7 @@ ripper_dispatch_scan_event(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L4416 if (!ripper_has_scan_event(p)) return; add_mark_object(p, yylval_rval = ripper_scan_event_val(p, t)); } -#define dispatch_scan_event(t) ripper_dispatch_scan_event(p, t) +#define dispatch_scan_event(p, t) ripper_dispatch_scan_event(p, t) static void ripper_dispatch_delayed_token(struct parser_params *p, int t) @@ -4452,19 +4431,30 @@ ripper_dispatch_delayed_token(struct par https://github.com/ruby/ruby/blob/trunk/parse.y#L4431 p->ruby_sourceline = saved_line; p->lex.ptok = saved_tokp; } -#define dispatch_delayed_token(t) ripper_dispatch_delayed_token(p, t) -#define has_delayed_token() (!NIL_P(p->delayed)) +#define dispatch_delayed_token(p, t) ripper_dispatch_delayed_token(p, t) +#define has_delayed_token(p) (!NIL_P(p->delayed)) #endif /* RIPPER */ #include "ruby/regex.h" #include "ruby/util.h" -#define parser_encoding_name() (p->enc->name) -#define parser_mbclen() mbclen((p->lex.pcur-1),p->lex.pend,p->enc) -#define is_identchar(ptr,ptr_end/*unused*/,enc) (rb_enc_isalnum((unsigned char)(*(ptr)),(enc)) || (*(ptr)) == '_' || !ISASCII(*(ptr))) -#define parser_is_identchar() (!p->eofp && is_identchar((p->lex.pcur-1),p->lex.pend,p->enc)) +static inline int +is_identchar(const char *ptr, const char *MAYBE_UNUSED(ptr_end), rb_encoding *enc) +{ + return rb_enc_isalnum((unsigned char)*ptr, enc) || *ptr == '_' || !ISASCII(*ptr); +} + +static inline int +parser_is_identchar(struct parser_params *p) +{ + return !(p)->eofp && is_identchar(p->lex.pcur-1, p->lex.pend, p->enc); +} -#define parser_isascii() ISASCII(*(p->lex.pcur-1)) +static inline int +parser_isascii(struct parser_params *p) +{ + return ISASCII(*(p->lex.pcur-1)); +} static void setup_token_info(token_info *ptinfo, const char *ptr, const rb_code_location_t *loc) @@ -4525,7 +4515,7 @@ parser_precise_mbclen(struct parser_para https://github.com/ruby/ruby/blob/trunk/parse.y#L4515 { int len = rb_enc_precise_mbclen(ptr, p->lex.pend, p->enc); if (!MBCLEN_CHARFOUND_P(len)) { - compile_error(p, "invalid multibyte char (%s)", parser_encoding_name()); + compile_error(p, "invalid multibyte char (%s)", rb_enc_name(p->enc)); return -1; } return len; @@ -5050,10 +5040,10 @@ parser_str_new(const char *ptr, long len https://github.com/ruby/ruby/blob/trunk/parse.y#L5040 #ifdef RIPPER static void -parser_add_delayed_token(struct parser_params *p, const char *tok, const char *end) +add_delayed_token(struct parser_params *p, const char *tok, const char *end) { if (tok < end) { - if (!has_delayed_token()) { + if (!has_delayed_token(p)) { p->delayed = rb_str_buf_new(1024); rb_enc_associate(p->delayed, p->enc); p->delayed_line = p->ruby_sourceline; @@ -5063,13 +5053,12 @@ parser_add_delayed_token(struct parser_p https://github.com/ruby/ruby/blob/trunk/parse.y#L5053 p->lex.ptok = end; } } -#define add_delayed_token(tok, end) parser_add_delayed_token(p, (tok), (end)) #else -#define add_delayed_token(tok, end) ((void)(tok), (void)(end)) +#define add_delayed_token(p, tok, end) ((void)(tok), (void)(end)) #endif static int -parser_nextline(struct parser_params *p) +nextline(struct parser_params *p) { VALUE v = p->lex.nextline; p->lex.nextline = 0; @@ -5084,7 +5073,7 @@ parser_nextline(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L5073 } p->cr_seen = FALSE; } - add_delayed_token(p->lex.ptok, p->lex.pend); + add_delayed_token(p, p->lex.ptok, p->lex.pend); if (p->heredoc_end > 0) { p->ruby_sourceline = p->heredoc_end; p->heredoc_end = 0; @@ -5115,12 +5104,12 @@ parser_cr(struct parser_params *p, int c https://github.com/ruby/ruby/blob/trunk/parse.y#L5104 } static inline int -parser_nextc(struct parser_params *p) +nextc(struct parser_params *p) { int c; if (UNLIKELY((p->lex.pcur == p->lex.pend) || p->eofp || p->lex.nextline)) { - if (parser_nextline(p)) return -1; + if (nextline(p)) return -1; } c = (unsigned char)*p->lex.pcur++; if (UNLIKELY(c == '\r')) { @@ -5131,7 +5120,7 @@ parser_nextc(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L5120 } static void -parser_pushback(struct parser_params *p, int c) +pushback(struct parser_params *p, int c) { if (c == -1) return; p->lex.pcur--; @@ -5148,7 +5137,7 @@ parser_pushback(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L5137 #define toklast() (p->tokidx>0?p->tokenbuf[p->tokidx-1]:0) static char* -parser_newtok(struct parser_params *p) +newtok(struct parser_params *p) { p->tokidx = 0; p->tokline = p->ruby_sourceline; @@ -5164,7 +5153,7 @@ parser_newtok(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L5153 } static char * -parser_tokspace(struct parser_params *p, int n) +tokspace(struct parser_params *p, int n) { p->tokidx += n; @@ -5176,7 +5165,7 @@ parser_tokspace(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L5165 } static void -parser_tokadd(struct parser_params *p, int c) +tokadd(struct parser_params *p, int c) { p->tokenbuf[p->tokidx++] = (char)c; if (p->tokidx >= p->toksiz) { @@ -5186,7 +5175,7 @@ parser_tokadd(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L5175 } static int -parser_tok_hex(struct parser_params *p, size_t *numlen) +tok_hex(struct parser_params *p, size_t *numlen) { int c; @@ -5200,15 +5189,15 @@ parser_tok_hex(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L5189 return c; } -#define tokcopy(n) memcpy(tokspace(n), p->lex.pcur - (n), (n)) +#define tokcopy(p, n) memcpy(tokspace(p, n), (p)->lex.pcur - (n), (n)) static int -parser_tokadd_codepoint(struct parser_params *p, rb_encoding **encp, - int regexp_literal, int wide) +tokadd_codepoint(struct parser_params *p, rb_encoding **encp, + int regexp_literal, int wide) { size_t numlen; int codepoint = scan_hex(p->lex.pcur, wide ? p->lex.pend - p->lex.pcur : 4, &numlen); - literal_flush(p->lex.pcur); + literal_flush(p, p->lex.pcur); p->lex.pcur += numlen; if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) { yyerror0("invalid Unicode escape"); @@ -5223,7 +5212,7 @@ parser_tokadd_codepoint(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L5212 return wide; } if (regexp_literal) { - tokcopy((int)numlen); + tokcopy(p, (int)numlen); } else if (codepoint >= 0x80) { rb_encoding *utf8 = rb_utf8_encoding(); @@ -5236,10 +5225,10 @@ parser_tokadd_codepoint(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L5225 return wide; } *encp = utf8; - tokaddmbc(codepoint, *encp); + tokaddmbc(p, codepoint, *encp); } else { - tokadd(codepoint); + tokadd(p, codepoint); } return TRUE; } @@ -5258,15 +5247,15 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5247 const int open_brace = '{', close_brace = '}'; - if (regexp_literal) { tokadd('\\'); tokadd('u'); } + if (regexp_literal) { tokadd(p, '\\'); tokadd(p, 'u'); } if (peek(open_brace)) { /* handle \u{...} form */ - int c, last = nextc(); + int c, last = nextc(p); if (p->lex.pcur >= p->lex.pend) goto unterminated; while (ISSPACE(c = *p->lex.pcur) && ++p->lex.pcur < p->lex.pend); while (c != close_brace) { - if (regexp_literal) tokadd(last); - if (!parser_tokadd_codepoint(p, encp, regexp_literal, TRUE)) { + if (regexp_literal) tokadd(p, last); + if (!tokadd_codepoint(p, encp, regexp_literal, TRUE)) { break; } while (ISSPACE(c = *p->lex.pcur)) { @@ -5277,16 +5266,16 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5266 if (c != close_brace) { unterminated: - literal_flush(p->lex.pcur); + literal_flush(p, p->lex.pcur); yyerror0("unterminated Unicode escape"); return 0; } - if (regexp_literal) tokadd(close_brace); - nextc(); + if (regexp_literal) tokadd(p, close_brace); + nextc(p); } else { /* handle \uxxxx form */ - if (!parser_tokadd_codepoint(p, encp, regexp_literal, FALSE)) { + if (!tokadd_codepoint(p, encp, regexp_literal, FALSE)) { return 0; } } @@ -5298,13 +5287,12 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5287 #define ESCAPE_META 2 static int -parser_read_escape(struct parser_params *p, int flags, - rb_encoding **encp) +read_escape(struct parser_params *p, int flags, rb_encoding **encp) { int c; size_t numlen; - switch (c = nextc()) { + switch (c = nextc(p)) { case '\\': /* Backslash */ return c; @@ -5331,13 +5319,13 @@ parser_read_escape(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5319 case '0': case '1': case '2': case '3': /* octal constant */ case '4': case '5': case '6': case '7': - pushback(c); + pushback(p, c); c = scan_oct(p->lex.pcur, 3, &numlen); p->lex.pcur += numlen; return c; case 'x': /* hex constant */ - c = tok_hex(&numlen); + c = tok_hex(p, &numlen); if (numlen == 0) return 0; return c; @@ -5349,12 +5337,12 @@ parser_read_escape(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5337 case 'M': if (flags & ESCAPE_META) goto eof; - if ((c = nextc()) != '-') { + if ((c = nextc(p)) != '-') { goto eof; } - if ((c = nextc()) == '\\') { + if ((c = nextc(p)) == '\\') { if (peek('u')) goto eof; - return read_escape(flags|ESCAPE_META, encp) | 0x80; + return read_escape(p, flags|ESCAPE_META, encp) | 0x80; } else if (c == -1 || !ISASCII(c)) goto eof; else { @@ -5362,14 +5350,14 @@ parser_read_escape(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5350 } case 'C': - if ((c = nextc()) != '-') { + if ((c = nextc(p)) != '-') { goto eof; } case 'c': if (flags & ESCAPE_CONTROL) goto eof; - if ((c = nextc())== '\\') { + if ((c = nextc(p))== '\\') { if (peek('u')) goto eof; - c = read_escape(flags|ESCAPE_CONTROL, encp); + c = read_escape(p, flags|ESCAPE_CONTROL, encp); } else if (c == '?') return 0177; @@ -5379,7 +5367,7 @@ parser_read_escape(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5367 eof: case -1: yyerror0("Invalid escape character syntax"); - pushback(c); + pushback(p, c); return '\0'; default: @@ -5388,21 +5376,21 @@ parser_read_escape(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5376 } static void -parser_tokaddmbc(struct parser_params *p, int c, rb_encoding *enc) +tokaddmbc(struct parser_params *p, int c, rb_encoding *enc) { int len = rb_enc_codelen(c, enc); - rb_enc_mbcput(c, tokspace(len), enc); + rb_enc_mbcput(c, tokspace(p, len), enc); } static int -parser_tokadd_escape(struct parser_params *p, rb_encoding **encp) +tokadd_escape(struct parser_params *p, rb_encoding **encp) { int c; int flags = 0; size_t numlen; first: - switch (c = nextc()) { + switch (c = nextc(p)) { case '\n': return 0; /* just ignore */ @@ -5412,47 +5400,47 @@ parser_tokadd_escape(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5400 ruby_scan_oct(--p->lex.pcur, 3, &numlen); if (numlen == 0) goto eof; p->lex.pcur += numlen; - tokcopy((int)numlen + 1); + tokcopy(p, (int)numlen + 1); } return 0; case 'x': /* hex constant */ { - tok_hex(&numlen); + tok_hex(p, &numlen); if (numlen == 0) return -1; - tokcopy((int)numlen + 2); + tokcopy(p, (int)numlen + 2); } return 0; case 'M': if (flags & ESCAPE_META) goto eof; - if ((c = nextc()) != '-') { - pushback(c); + if ((c = nextc(p)) != '-') { + pushback(p, c); goto eof; } - tokcopy(3); + tokcopy(p, 3); flags |= ESCAPE_META; goto escaped; case 'C': if (flags & ESCAPE_CONTROL) goto eof; - if ((c = nextc()) != '-') { - pushback(c); + if ((c = nextc(p)) != '-') { + pushback(p, c); goto eof; } - tokcopy(3); + tokcopy(p, 3); goto escaped; case 'c': if (flags & ESCAPE_CONTROL) goto eof; - tokcopy(2); + tokcopy(p, 2); flags |= ESCAPE_CONTROL; escaped: - if ((c = nextc()) == '\\') { + if ((c = nextc(p)) == '\\') { goto first; } else if (c == -1) goto eof; - tokadd(c); + tokadd(p, c); return 0; eof: @@ -5461,22 +5449,22 @@ parser_tokadd_escape(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5449 return -1; default: - tokadd('\\'); - tokadd(c); + tokadd(p, '\\'); + tokadd(p, c); } return 0; } static int -parser_regx_options(struct parser_params *p) +regx_options(struct parser_params *p) { int kcode = 0; int kopt = 0; int options = 0; int c, opt, kc; - newtok(); - while (c = nextc(), ISALPHA(c)) { + newtok(p); + while (c = nextc(p), ISALPHA(c)) { if (c == 'o') { options |= RE_OPTION_ONCE; } @@ -5490,11 +5478,11 @@ parser_regx_options(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5478 } } else { - tokadd(c); + tokadd(p, c); } } options |= kopt; - pushback(c); + pushback(p, c); if (toklen()) { tokfix(); compile_error(p, "unknown regexp option%s - %s", @@ -5508,9 +5496,9 @@ tokadd_mbchar(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L5496 { int len = parser_precise_mbclen(p, p->lex.pcur-1); if (len < 0) return -1; - tokadd(c); + tokadd(p, c); p->lex.pcur += --len; - if (len > 0) tokcopy(len); + if (len > 0) tokcopy(p, len); return c; } @@ -5554,9 +5542,9 @@ parser_update_heredoc_indent(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L5542 } static int -parser_tokadd_string(struct parser_params *p, - int func, int term, int paren, long *nest, - rb_encoding **encp) +tokadd_string(struct parser_params *p, + int func, int term, int paren, long *nest, + rb_encoding **encp) { int c; rb_encoding *enc = 0; @@ -5580,7 +5568,7 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5568 p->lex.pcur = pos; \ } while (0) - while ((c = nextc()) != -1) { + while ((c = nextc(p)) != -1) { if (p->heredoc_indent > 0) { parser_update_heredoc_indent(p, c); } @@ -5590,7 +5578,7 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5578 } else if (c == term) { if (!nest || !*nest) { - pushback(c); + pushback(p, c); break; } --*nest; @@ -5598,27 +5586,27 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5586 else if ((func & STR_FUNC_EXPAND) && c == '#' && p->lex.pcur < p->lex.pend) { int c2 = *p->lex.pcur; if (c2 == '$' || c2 == '@' || c2 == '{') { - pushback(c); + pushback(p, c); break; } } else if (c == '\\') { - literal_flush(p->lex.pcur - 1); - c = nextc(); + literal_flush(p, p->lex.pcur - 1); + c = nextc(p); switch (c) { case '\n': if (func & STR_FUNC_QWORDS) break; if (func & STR_FUNC_EXPAND) continue; - tokadd('\\'); + tokadd(p, '\\'); break; case '\\': - if (func & STR_FUNC_ESCAPE) tokadd(c); + if (func & STR_FUNC_ESCAPE) tokadd(p, c); break; case 'u': if ((func & STR_FUNC_EXPAND) == 0) { - tokadd('\\'); + tokadd(p, '\\'); break; } if (!parser_tokadd_utf8(p, &enc, term, @@ -5631,16 +5619,16 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5619 default: if (c == -1) return -1; if (!ISASCII(c)) { - if ((func & STR_FUNC_EXPAND) == 0) tokadd('\\'); + if ((func & STR_FUNC_EXPAND) == 0) tokadd(p, '\\'); goto non_ascii; } if (func & STR_FUNC_REGEXP) { if (c == term && !simple_re_meta(c)) { - tokadd(c); + tokadd(p, c); continue; } - pushback(c); - if ((c = tokadd_escape(&enc)) < 0) + pushback(p, c); + if ((c = tokadd_escape(p, &enc)) < 0) return -1; if (enc && enc != *encp) { mixed_escape(p->lex.ptok+2, enc, *encp); @@ -5648,21 +5636,21 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L5636 continue; } else if (func & STR_FUNC_EXPAND) { - pushback(c); - if (func & STR_FUNC_ESCAPE) tokadd('\\'); - c (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/