parse.y: token length
* parse.y (token_info_push, token_info_push): add token length parameter instead of strlen. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e1c189bef3
commit
aad3a8679f
30
parse.y
30
parse.y
@ -729,10 +729,10 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
static void token_info_push(struct parser_params*, const char *token);
|
static void token_info_push(struct parser_params*, const char *token, size_t len);
|
||||||
static void token_info_pop(struct parser_params*, const char *token);
|
static void token_info_pop(struct parser_params*, const char *token, size_t len);
|
||||||
#define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
|
#define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token), rb_strlen_lit(token)) : (void)0)
|
||||||
#define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
|
#define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token), rb_strlen_lit(token)) : (void)0)
|
||||||
#else
|
#else
|
||||||
#define token_info_push(token) /* nothing */
|
#define token_info_push(token) /* nothing */
|
||||||
#define token_info_pop(token) /* nothing */
|
#define token_info_pop(token) /* nothing */
|
||||||
@ -5282,10 +5282,10 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t)
|
|||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
static int
|
static int
|
||||||
token_info_get_column(struct parser_params *parser, const char *token)
|
token_info_get_column(struct parser_params *parser, const char *pend)
|
||||||
{
|
{
|
||||||
int column = 1;
|
int column = 1;
|
||||||
const char *p, *pend = lex_p - strlen(token);
|
const char *p;
|
||||||
for (p = lex_pbeg; p < pend; p++) {
|
for (p = lex_pbeg; p < pend; p++) {
|
||||||
if (*p == '\t') {
|
if (*p == '\t') {
|
||||||
column = (((column - 1) / 8) + 1) * 8;
|
column = (((column - 1) / 8) + 1) * 8;
|
||||||
@ -5296,9 +5296,9 @@ token_info_get_column(struct parser_params *parser, const char *token)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
token_info_has_nonspaces(struct parser_params *parser, const char *token)
|
token_info_has_nonspaces(struct parser_params *parser, const char *pend)
|
||||||
{
|
{
|
||||||
const char *p, *pend = lex_p - strlen(token);
|
const char *p;
|
||||||
for (p = lex_pbeg; p < pend; p++) {
|
for (p = lex_pbeg; p < pend; p++) {
|
||||||
if (*p != ' ' && *p != '\t') {
|
if (*p != ' ' && *p != '\t') {
|
||||||
return 1;
|
return 1;
|
||||||
@ -5309,16 +5309,17 @@ token_info_has_nonspaces(struct parser_params *parser, const char *token)
|
|||||||
|
|
||||||
#undef token_info_push
|
#undef token_info_push
|
||||||
static void
|
static void
|
||||||
token_info_push(struct parser_params *parser, const char *token)
|
token_info_push(struct parser_params *parser, const char *token, size_t len)
|
||||||
{
|
{
|
||||||
token_info *ptinfo;
|
token_info *ptinfo;
|
||||||
|
const char *t = lex_p - len;
|
||||||
|
|
||||||
if (!parser->token_info_enabled) return;
|
if (!parser->token_info_enabled) return;
|
||||||
ptinfo = ALLOC(token_info);
|
ptinfo = ALLOC(token_info);
|
||||||
ptinfo->token = token;
|
ptinfo->token = token;
|
||||||
ptinfo->linenum = ruby_sourceline;
|
ptinfo->linenum = ruby_sourceline;
|
||||||
ptinfo->column = token_info_get_column(parser, token);
|
ptinfo->column = token_info_get_column(parser, t);
|
||||||
ptinfo->nonspc = token_info_has_nonspaces(parser, token);
|
ptinfo->nonspc = token_info_has_nonspaces(parser, t);
|
||||||
ptinfo->next = parser->token_info;
|
ptinfo->next = parser->token_info;
|
||||||
|
|
||||||
parser->token_info = ptinfo;
|
parser->token_info = ptinfo;
|
||||||
@ -5326,21 +5327,22 @@ token_info_push(struct parser_params *parser, const char *token)
|
|||||||
|
|
||||||
#undef token_info_pop
|
#undef token_info_pop
|
||||||
static void
|
static void
|
||||||
token_info_pop(struct parser_params *parser, const char *token)
|
token_info_pop(struct parser_params *parser, const char *token, size_t len)
|
||||||
{
|
{
|
||||||
int linenum;
|
int linenum;
|
||||||
token_info *ptinfo = parser->token_info;
|
token_info *ptinfo = parser->token_info;
|
||||||
|
const char *t = lex_p - len;
|
||||||
|
|
||||||
if (!ptinfo) return;
|
if (!ptinfo) return;
|
||||||
parser->token_info = ptinfo->next;
|
parser->token_info = ptinfo->next;
|
||||||
if (token_info_get_column(parser, token) == ptinfo->column) { /* OK */
|
if (token_info_get_column(parser, t) == ptinfo->column) { /* OK */
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
linenum = ruby_sourceline;
|
linenum = ruby_sourceline;
|
||||||
if (linenum == ptinfo->linenum) { /* SKIP */
|
if (linenum == ptinfo->linenum) { /* SKIP */
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
if (token_info_has_nonspaces(parser, token) || ptinfo->nonspc) { /* SKIP */
|
if (token_info_has_nonspaces(parser, t) || ptinfo->nonspc) { /* SKIP */
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
if (parser->token_info_enabled) {
|
if (parser->token_info_enabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user