зеркало из https://github.com/github/ruby.git
parse.y: set bison's first_loc.lineno to nd_line by default
This change initializes nd_line, lineno of each node, by default, by using the first line number of code range that bison tracks, instead of extracting from lexer state. The lexer state basically provides only the last line number of code range, so many hacks are used to approximate the first line number. The hacks have been introduced on demand, or very ad-hocly. I think this change will make it possible to remove most of the hacks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
413d862f23
Коммит
4db3b9ebe0
258
parse.y
258
parse.y
|
@ -380,6 +380,8 @@ add_mark_object_gen(struct parser_params *parser, VALUE obj)
|
||||||
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE, const rb_code_range_t*);
|
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE, const rb_code_range_t*);
|
||||||
#define rb_node_newnode(type, a1, a2, a3, loc) node_newnode(parser, (type), (a1), (a2), (a3), (loc))
|
#define rb_node_newnode(type, a1, a2, a3, loc) node_newnode(parser, (type), (a1), (a2), (a3), (loc))
|
||||||
|
|
||||||
|
static NODE *nd_set_loc(NODE *nd, const YYLTYPE *location);
|
||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
static inline void
|
static inline void
|
||||||
set_line_body(NODE *body, int line)
|
set_line_body(NODE *body, int line)
|
||||||
|
@ -557,7 +559,6 @@ static NODE *new_rescue_gen(struct parser_params *parser, NODE *b, NODE *res, NO
|
||||||
static NODE *new_undef_gen(struct parser_params *parser, NODE *i, const YYLTYPE *location);
|
static NODE *new_undef_gen(struct parser_params *parser, NODE *i, const YYLTYPE *location);
|
||||||
#define new_undef(i, location) new_undef_gen(parser, i, location)
|
#define new_undef(i, location) new_undef_gen(parser, i, location)
|
||||||
|
|
||||||
static NODE *nd_set_loc(NODE *nd, const YYLTYPE *location);
|
|
||||||
static NODE *new_zarray_gen(struct parser_params *parser, const YYLTYPE *location);
|
static NODE *new_zarray_gen(struct parser_params *parser, const YYLTYPE *location);
|
||||||
#define new_zarray(location) new_zarray_gen(parser, location)
|
#define new_zarray(location) new_zarray_gen(parser, location)
|
||||||
#define make_array(ary, location) ((ary) ? (nd_set_loc(ary, location), ary) : new_zarray(location))
|
#define make_array(ary, location) ((ary) ? (nd_set_loc(ary, location), ary) : new_zarray(location))
|
||||||
|
@ -2949,7 +2950,7 @@ primary : literal
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_CLASS($2, $5, $3, &@$);
|
$$ = NEW_CLASS($2, $5, $3, &@$);
|
||||||
$$->nd_body->nd_loc = @$;
|
nd_set_line($$->nd_body, ruby_sourceline);
|
||||||
set_line_body($5, $<num>4);
|
set_line_body($5, $<num>4);
|
||||||
nd_set_line($$, $<num>4);
|
nd_set_line($$, $<num>4);
|
||||||
/*%
|
/*%
|
||||||
|
@ -2971,7 +2972,7 @@ primary : literal
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_SCLASS($3, $6, &@$);
|
$$ = NEW_SCLASS($3, $6, &@$);
|
||||||
$$->nd_body->nd_loc = @$;
|
nd_set_line($$->nd_body, ruby_sourceline);
|
||||||
set_line_body($6, nd_line($3));
|
set_line_body($6, nd_line($3));
|
||||||
fixpos($$, $3);
|
fixpos($$, $3);
|
||||||
/*%
|
/*%
|
||||||
|
@ -3002,7 +3003,7 @@ primary : literal
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_MODULE($2, $4, &@$);
|
$$ = NEW_MODULE($2, $4, &@$);
|
||||||
$$->nd_body->nd_loc = @$;
|
nd_set_line($$->nd_body, ruby_sourceline);
|
||||||
set_line_body($4, $<num>3);
|
set_line_body($4, $<num>3);
|
||||||
nd_set_line($$, $<num>3);
|
nd_set_line($$, $<num>3);
|
||||||
/*%
|
/*%
|
||||||
|
@ -3029,7 +3030,7 @@ primary : literal
|
||||||
NODE *body = remove_begin($6);
|
NODE *body = remove_begin($6);
|
||||||
reduce_nodes(&body);
|
reduce_nodes(&body);
|
||||||
$$ = NEW_DEFN($2, $5, body, &@$);
|
$$ = NEW_DEFN($2, $5, body, &@$);
|
||||||
$$->nd_defn->nd_loc = @$;
|
nd_set_line($$->nd_defn, ruby_sourceline);
|
||||||
set_line_body(body, $<num>1);
|
set_line_body(body, $<num>1);
|
||||||
nd_set_line($$, $<num>1);
|
nd_set_line($$, $<num>1);
|
||||||
/*%
|
/*%
|
||||||
|
@ -3056,7 +3057,7 @@ primary : literal
|
||||||
NODE *body = remove_begin($8);
|
NODE *body = remove_begin($8);
|
||||||
reduce_nodes(&body);
|
reduce_nodes(&body);
|
||||||
$$ = NEW_DEFS($2, $5, $7, body, &@$);
|
$$ = NEW_DEFS($2, $5, $7, body, &@$);
|
||||||
$$->nd_defn->nd_loc = @$;
|
nd_set_line($$->nd_defn, ruby_sourceline);
|
||||||
set_line_body(body, $<num>1);
|
set_line_body(body, $<num>1);
|
||||||
nd_set_line($$, $<num>1);
|
nd_set_line($$, $<num>1);
|
||||||
/*%
|
/*%
|
||||||
|
@ -3559,8 +3560,8 @@ lambda : {
|
||||||
CMDARG_LEXPOP();
|
CMDARG_LEXPOP();
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_LAMBDA($3, $6, &@$);
|
$$ = NEW_LAMBDA($3, $6, &@$);
|
||||||
|
nd_set_line($$->nd_body, ruby_sourceline);
|
||||||
nd_set_line($$, $<num>4);
|
nd_set_line($$, $<num>4);
|
||||||
$$->nd_body->nd_loc = @$;
|
|
||||||
/*%
|
/*%
|
||||||
$$ = dispatch2(lambda, $3, $6);
|
$$ = dispatch2(lambda, $3, $6);
|
||||||
%*/
|
%*/
|
||||||
|
@ -4192,6 +4193,7 @@ string_content : tSTRING_CONTENT
|
||||||
lex_strterm = $<strterm>2;
|
lex_strterm = $<strterm>2;
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_EVSTR($3, &@$);
|
$$ = NEW_EVSTR($3, &@$);
|
||||||
|
nd_set_line($$, ruby_sourceline);
|
||||||
/*%
|
/*%
|
||||||
$$ = dispatch1(string_dvar, $3);
|
$$ = dispatch1(string_dvar, $3);
|
||||||
%*/
|
%*/
|
||||||
|
@ -4308,28 +4310,28 @@ numeric : simple_numeric
|
||||||
simple_numeric : tINTEGER
|
simple_numeric : tINTEGER
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| tFLOAT
|
| tFLOAT
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| tRATIONAL
|
| tRATIONAL
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| tIMAGINARY
|
| tIMAGINARY
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
|
@ -4387,14 +4389,14 @@ var_lhs : user_variable
|
||||||
backref : tNTH_REF
|
backref : tNTH_REF
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| tBACK_REF
|
| tBACK_REF
|
||||||
{
|
{
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$->nd_loc = @$;
|
nd_set_loc($$, &@$);
|
||||||
/*%
|
/*%
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
|
@ -8920,11 +8922,18 @@ node_newnode(struct parser_params *parser, enum node_type type, VALUE a0, VALUE
|
||||||
|
|
||||||
rb_node_init(n, type, a0, a1, a2);
|
rb_node_init(n, type, a0, a1, a2);
|
||||||
|
|
||||||
nd_set_line(n, ruby_sourceline);
|
nd_set_loc(n, loc);
|
||||||
n->nd_loc = *loc;
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NODE *
|
||||||
|
nd_set_loc(NODE *nd, const YYLTYPE *location)
|
||||||
|
{
|
||||||
|
nd->nd_loc = *location;
|
||||||
|
nd_set_line(nd, location->first_loc.lineno);
|
||||||
|
return nd;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef RIPPER
|
#ifndef RIPPER
|
||||||
static enum node_type
|
static enum node_type
|
||||||
nodetype(NODE *node) /* for debug */
|
nodetype(NODE *node) /* for debug */
|
||||||
|
@ -8970,14 +8979,6 @@ parser_warn(struct parser_params *parser, NODE *node, const char *mesg)
|
||||||
}
|
}
|
||||||
#define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
|
#define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
|
||||||
|
|
||||||
static NODE *
|
|
||||||
nd_set_loc(NODE *nd, const YYLTYPE *location)
|
|
||||||
{
|
|
||||||
nd->nd_loc = *location;
|
|
||||||
nd_set_line(nd, location->first_loc.lineno);
|
|
||||||
return nd;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NODE*
|
static NODE*
|
||||||
block_append_gen(struct parser_params *parser, NODE *head, NODE *tail, const YYLTYPE *location)
|
block_append_gen(struct parser_params *parser, NODE *head, NODE *tail, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
|
@ -8998,7 +8999,6 @@ block_append_gen(struct parser_params *parser, NODE *head, NODE *tail, const YYL
|
||||||
default:
|
default:
|
||||||
h = end = NEW_BLOCK(head, location);
|
h = end = NEW_BLOCK(head, location);
|
||||||
end->nd_end = end;
|
end->nd_end = end;
|
||||||
nd_set_line(end, location->first_loc.lineno);
|
|
||||||
head = end;
|
head = end;
|
||||||
break;
|
break;
|
||||||
case NODE_BLOCK:
|
case NODE_BLOCK:
|
||||||
|
@ -9024,7 +9024,6 @@ block_append_gen(struct parser_params *parser, NODE *head, NODE *tail, const YYL
|
||||||
|
|
||||||
if (nd_type(tail) != NODE_BLOCK) {
|
if (nd_type(tail) != NODE_BLOCK) {
|
||||||
tail = NEW_BLOCK(tail, location);
|
tail = NEW_BLOCK(tail, location);
|
||||||
nd_set_line(tail, location->first_loc.lineno);
|
|
||||||
tail->nd_end = tail;
|
tail->nd_end = tail;
|
||||||
}
|
}
|
||||||
end->nd_next = tail;
|
end->nd_next = tail;
|
||||||
|
@ -9204,7 +9203,6 @@ static NODE *
|
||||||
new_evstr_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
new_evstr_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *head = node;
|
NODE *head = node;
|
||||||
NODE *evstr;
|
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
switch (nd_type(node)) {
|
switch (nd_type(node)) {
|
||||||
|
@ -9212,9 +9210,7 @@ new_evstr_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
evstr = NEW_EVSTR(head, location);
|
return NEW_EVSTR(head, location);
|
||||||
nd_set_line(evstr, location->first_loc.lineno);
|
|
||||||
return evstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
@ -9285,7 +9281,6 @@ match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTY
|
||||||
/* fallthru */
|
/* fallthru */
|
||||||
case NODE_DREGX:
|
case NODE_DREGX:
|
||||||
match3 = NEW_MATCH3(node2, node1, location);
|
match3 = NEW_MATCH3(node2, node1, location);
|
||||||
nd_set_line(match3, line);
|
|
||||||
return match3;
|
return match3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9322,21 +9317,13 @@ gettable_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
NODE *node;
|
NODE *node;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case keyword_self:
|
case keyword_self:
|
||||||
node = NEW_SELF(location);
|
return NEW_SELF(location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case keyword_nil:
|
case keyword_nil:
|
||||||
node = NEW_NIL(location);
|
return NEW_NIL(location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case keyword_true:
|
case keyword_true:
|
||||||
node = NEW_TRUE(location);
|
return NEW_TRUE(location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case keyword_false:
|
case keyword_false:
|
||||||
node = NEW_FALSE(location);
|
return NEW_FALSE(location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case keyword__FILE__:
|
case keyword__FILE__:
|
||||||
WARN_LOCATION("__FILE__");
|
WARN_LOCATION("__FILE__");
|
||||||
node = new_str(rb_str_dup(ruby_sourcefile_string), location);
|
node = new_str(rb_str_dup(ruby_sourcefile_string), location);
|
||||||
|
@ -9371,23 +9358,15 @@ gettable_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
/* method call without arguments */
|
/* method call without arguments */
|
||||||
node = NEW_VCALL(id, location);
|
return NEW_VCALL(id, location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case ID_GLOBAL:
|
case ID_GLOBAL:
|
||||||
node = new_gvar(id, location);
|
return new_gvar(id, location);
|
||||||
return node;
|
|
||||||
case ID_INSTANCE:
|
case ID_INSTANCE:
|
||||||
node = new_ivar(id, location);
|
return new_ivar(id, location);
|
||||||
return node;
|
|
||||||
case ID_CONST:
|
case ID_CONST:
|
||||||
node = NEW_CONST(id, location);
|
return NEW_CONST(id, location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
case ID_CLASS:
|
case ID_CLASS:
|
||||||
node = NEW_CVAR(id, location);
|
return NEW_CVAR(id, location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
compile_error(PARSER_ARG "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
|
compile_error(PARSER_ARG "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -9426,9 +9405,7 @@ kwd_append(NODE *kwlist, NODE *kw)
|
||||||
static NODE *
|
static NODE *
|
||||||
new_defined_gen(struct parser_params *parser, NODE *expr, const YYLTYPE *location)
|
new_defined_gen(struct parser_params *parser, NODE *expr, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *defined = NEW_DEFINED(remove_begin_all(expr),location);
|
return NEW_DEFINED(remove_begin_all(expr),location);
|
||||||
nd_set_line(defined, location->first_loc.lineno);
|
|
||||||
return defined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
@ -9487,7 +9464,6 @@ new_regexp_gen(struct parser_params *parser, NODE *node, int options, const YYLT
|
||||||
}
|
}
|
||||||
if (options & RE_OPTION_ONCE) {
|
if (options & RE_OPTION_ONCE) {
|
||||||
node = NEW_NODE(NODE_ONCE, 0, node, 0, location);
|
node = NEW_NODE(NODE_ONCE, 0, node, 0, location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -9497,183 +9473,138 @@ new_regexp_gen(struct parser_params *parser, NODE *node, int options, const YYLT
|
||||||
static NODE *
|
static NODE *
|
||||||
new_lit_gen(struct parser_params *parser, VALUE sym, const YYLTYPE *location)
|
new_lit_gen(struct parser_params *parser, VALUE sym, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *lit = NEW_LIT(sym, location);
|
|
||||||
add_mark_object(sym);
|
add_mark_object(sym);
|
||||||
nd_set_line(lit, location->first_loc.lineno);
|
return NEW_LIT(sym, location);
|
||||||
return lit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_list_gen(struct parser_params *parser, NODE *item, const YYLTYPE *location)
|
new_list_gen(struct parser_params *parser, NODE *item, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *list = NEW_LIST(item, location);
|
return NEW_LIST(item, location);
|
||||||
nd_set_line(list, location->first_loc.lineno);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_str_gen(struct parser_params *parser, VALUE str, const YYLTYPE *location)
|
new_str_gen(struct parser_params *parser, VALUE str, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *nd_str = NEW_STR(str, location);
|
|
||||||
add_mark_object(str);
|
add_mark_object(str);
|
||||||
nd_set_line(nd_str, location->first_loc.lineno);
|
return NEW_STR(str, location);
|
||||||
return nd_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_dvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
new_dvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *dvar = NEW_DVAR(id, location);
|
return NEW_DVAR(id, location);
|
||||||
nd_set_line(dvar, location->first_loc.lineno);
|
|
||||||
return dvar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_resbody_gen(struct parser_params *parser, NODE *exc_list, NODE *stmt, NODE *rescue, const YYLTYPE *location)
|
new_resbody_gen(struct parser_params *parser, NODE *exc_list, NODE *stmt, NODE *rescue, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *resbody = NEW_RESBODY(exc_list, stmt, rescue, location);
|
return NEW_RESBODY(exc_list, stmt, rescue, location);
|
||||||
nd_set_line(resbody, location->first_loc.lineno);
|
|
||||||
return resbody;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_errinfo_gen(struct parser_params *parser, const YYLTYPE *location)
|
new_errinfo_gen(struct parser_params *parser, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *errinfo = NEW_ERRINFO(location);
|
return NEW_ERRINFO(location);
|
||||||
nd_set_line(errinfo, location->first_loc.lineno);
|
|
||||||
return errinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_call_gen(struct parser_params *parser, NODE *recv, ID mid, NODE *args, const YYLTYPE *location)
|
new_call_gen(struct parser_params *parser, NODE *recv, ID mid, NODE *args, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *call = NEW_CALL(recv, mid, args, location);
|
return NEW_CALL(recv, mid, args, location);
|
||||||
nd_set_line(call, location->first_loc.lineno);
|
|
||||||
return call;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_fcall_gen(struct parser_params *parser, ID mid, NODE *args, const YYLTYPE *location)
|
new_fcall_gen(struct parser_params *parser, ID mid, NODE *args, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *fcall = NEW_FCALL(mid, args, location);
|
return NEW_FCALL(mid, args, location);
|
||||||
nd_set_line(fcall, location->first_loc.lineno);
|
|
||||||
return fcall;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_for_gen(struct parser_params *parser, NODE *var, NODE *iter, NODE *body, const YYLTYPE *location)
|
new_for_gen(struct parser_params *parser, NODE *var, NODE *iter, NODE *body, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *nd_for = NEW_FOR(var, iter, body, location);
|
return NEW_FOR(var, iter, body, location);
|
||||||
nd_set_line(nd_for, location->first_loc.lineno);
|
|
||||||
return nd_for;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_gvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
new_gvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *gvar = NEW_GVAR(id, location);
|
return NEW_GVAR(id, location);
|
||||||
nd_set_line(gvar, location->first_loc.lineno);
|
|
||||||
return gvar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_lvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
new_lvar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *lvar = NEW_LVAR(id, location);
|
return NEW_LVAR(id, location);
|
||||||
nd_set_line(lvar, location->first_loc.lineno);
|
|
||||||
return lvar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_dstr_gen(struct parser_params *parser, VALUE str, const YYLTYPE *location)
|
new_dstr_gen(struct parser_params *parser, VALUE str, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *dstr = NEW_DSTR(str, location);
|
|
||||||
add_mark_object(str);
|
add_mark_object(str);
|
||||||
nd_set_line(dstr, location->first_loc.lineno);
|
return NEW_DSTR(str, location);
|
||||||
return dstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_rescue_gen(struct parser_params *parser, NODE *b, NODE *res, NODE *e, const YYLTYPE *location)
|
new_rescue_gen(struct parser_params *parser, NODE *b, NODE *res, NODE *e, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *rescue = NEW_RESCUE(b, res, e, location);
|
return NEW_RESCUE(b, res, e, location);
|
||||||
nd_set_line(rescue, location->first_loc.lineno);
|
|
||||||
return rescue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_undef_gen(struct parser_params *parser, NODE *i, const YYLTYPE *location)
|
new_undef_gen(struct parser_params *parser, NODE *i, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *undef = NEW_UNDEF(i, location);
|
return NEW_UNDEF(i, location);
|
||||||
nd_set_line(undef, location->first_loc.lineno);
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_zarray_gen(struct parser_params *parser, const YYLTYPE *location)
|
new_zarray_gen(struct parser_params *parser, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *zarray = NEW_ZARRAY(location);
|
return NEW_ZARRAY(location);
|
||||||
nd_set_line(zarray, location->first_loc.lineno);
|
|
||||||
return zarray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_ivar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
new_ivar_gen(struct parser_params *parser, ID id, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *ivar = NEW_IVAR(id, location);
|
return NEW_IVAR(id, location);
|
||||||
nd_set_line(ivar, location->first_loc.lineno);
|
|
||||||
return ivar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_postarg_gen(struct parser_params *parser, NODE *i, NODE *v, const YYLTYPE *location)
|
new_postarg_gen(struct parser_params *parser, NODE *i, NODE *v, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *postarg = NEW_POSTARG(i, v, location);
|
return NEW_POSTARG(i, v, location);
|
||||||
nd_set_line(postarg, location->first_loc.lineno);
|
|
||||||
return postarg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_cdecl_gen(struct parser_params *parser, ID v, NODE *val, NODE *path, const YYLTYPE *location)
|
new_cdecl_gen(struct parser_params *parser, ID v, NODE *val, NODE *path, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *nd_cdecl = NEW_CDECL(v, val, path, location);
|
return NEW_CDECL(v, val, path, location);
|
||||||
nd_set_line(nd_cdecl, location->first_loc.lineno);
|
|
||||||
return nd_cdecl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_scope_gen(struct parser_params *parser, NODE *a, NODE *b, const YYLTYPE *location)
|
new_scope_gen(struct parser_params *parser, NODE *a, NODE *b, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *scope = NEW_SCOPE(a, b, location);
|
return NEW_SCOPE(a, b, location);
|
||||||
nd_set_line(scope, location->first_loc.lineno);
|
|
||||||
return scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_begin_gen(struct parser_params *parser, NODE *b, const YYLTYPE *location)
|
new_begin_gen(struct parser_params *parser, NODE *b, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *begin = NEW_BEGIN(b, location);
|
return NEW_BEGIN(b, location);
|
||||||
nd_set_line(begin, location->first_loc.lineno);
|
|
||||||
return begin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_masgn_gen(struct parser_params *parser, NODE *l, NODE *r, const YYLTYPE *location)
|
new_masgn_gen(struct parser_params *parser, NODE *l, NODE *r, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *masgn = NEW_MASGN(l, r, location);
|
return NEW_MASGN(l, r, location);
|
||||||
nd_set_line(masgn, location->first_loc.lineno);
|
|
||||||
return masgn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
new_kw_arg_gen(struct parser_params *parser, NODE *k, const YYLTYPE *location)
|
new_kw_arg_gen(struct parser_params *parser, NODE *k, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *kw_arg;
|
|
||||||
if (!k) return 0;
|
if (!k) return 0;
|
||||||
kw_arg = NEW_KW_ARG(0, (k), location);
|
return NEW_KW_ARG(0, (k), location);
|
||||||
nd_set_line(kw_arg, location->first_loc.lineno);
|
|
||||||
return kw_arg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
@ -9696,7 +9627,6 @@ new_xstring_gen(struct parser_params *parser, NODE *node, const YYLTYPE *locatio
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
node = NEW_NODE(NODE_DXSTR, Qnil, 1, new_list(node, location), location);
|
node = NEW_NODE(NODE_DXSTR, Qnil, 1, new_list(node, location), location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -9705,10 +9635,7 @@ new_xstring_gen(struct parser_params *parser, NODE *node, const YYLTYPE *locatio
|
||||||
static NODE *
|
static NODE *
|
||||||
new_body_gen(struct parser_params *parser, NODE *param, NODE *stmt, const YYLTYPE *location)
|
new_body_gen(struct parser_params *parser, NODE *param, NODE *stmt, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *iter = NEW_ITER(param, stmt, location);
|
return NEW_ITER(param, stmt, location);
|
||||||
nd_set_line(iter->nd_body, location->first_loc.lineno);
|
|
||||||
nd_set_line(iter, location->first_loc.lineno);
|
|
||||||
return iter;
|
|
||||||
}
|
}
|
||||||
#else /* !RIPPER */
|
#else /* !RIPPER */
|
||||||
static int
|
static int
|
||||||
|
@ -9903,17 +9830,6 @@ rb_parser_set_location(struct parser_params *parser, YYLTYPE *yylloc)
|
||||||
}
|
}
|
||||||
#endif /* !RIPPER */
|
#endif /* !RIPPER */
|
||||||
|
|
||||||
#ifndef RIPPER
|
|
||||||
static NODE*
|
|
||||||
assignable_result0(NODE *node, const YYLTYPE *location)
|
|
||||||
{
|
|
||||||
if (node) {
|
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
#endif /* !RIPPER */
|
|
||||||
|
|
||||||
#ifdef RIPPER
|
#ifdef RIPPER
|
||||||
static VALUE
|
static VALUE
|
||||||
assignable_gen(struct parser_params *parser, VALUE lhs)
|
assignable_gen(struct parser_params *parser, VALUE lhs)
|
||||||
|
@ -9928,7 +9844,7 @@ assignable_gen(struct parser_params *parser, ID id, NODE *val, const YYLTYPE *lo
|
||||||
# define assignable_error() (lhs)
|
# define assignable_error() (lhs)
|
||||||
# define parser_yyerror(parser, loc, x) (lhs = assign_error_gen(parser, lhs))
|
# define parser_yyerror(parser, loc, x) (lhs = assign_error_gen(parser, lhs))
|
||||||
#else
|
#else
|
||||||
# define assignable_result(x) assignable_result0(x, location)
|
# define assignable_result(x) (x)
|
||||||
# define assignable_error() new_begin(0, location)
|
# define assignable_error() new_begin(0, location)
|
||||||
#endif
|
#endif
|
||||||
if (!id) return assignable_error();
|
if (!id) return assignable_error();
|
||||||
|
@ -10059,9 +9975,7 @@ new_bv_gen(struct parser_params *parser, ID name)
|
||||||
static NODE *
|
static NODE *
|
||||||
aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx, const YYLTYPE *location)
|
aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *attrasgn = NEW_ATTRASGN(recv, tASET, idx, location);
|
return NEW_ATTRASGN(recv, tASET, idx, location);
|
||||||
nd_set_line(attrasgn, location->first_loc.lineno);
|
|
||||||
return attrasgn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -10095,8 +10009,6 @@ rb_backref_error_gen(struct parser_params *parser, NODE *node)
|
||||||
static NODE *
|
static NODE *
|
||||||
arg_concat_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *location)
|
arg_concat_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *argscat;
|
|
||||||
|
|
||||||
if (!node2) return node1;
|
if (!node2) return node1;
|
||||||
switch (nd_type(node1)) {
|
switch (nd_type(node1)) {
|
||||||
case NODE_BLOCK_PASS:
|
case NODE_BLOCK_PASS:
|
||||||
|
@ -10116,16 +10028,12 @@ arg_concat_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYL
|
||||||
node1->nd_body = list_concat(node1->nd_body, node2);
|
node1->nd_body = list_concat(node1->nd_body, node2);
|
||||||
return node1;
|
return node1;
|
||||||
}
|
}
|
||||||
argscat = NEW_ARGSCAT(node1, node2, location);
|
return NEW_ARGSCAT(node1, node2, location);
|
||||||
nd_set_line(argscat, location->first_loc.lineno);
|
|
||||||
return argscat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
arg_append_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *location)
|
arg_append_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *argspush;
|
|
||||||
|
|
||||||
if (!node1) return new_list(node2, &node2->nd_loc);
|
if (!node1) return new_list(node2, &node2->nd_loc);
|
||||||
switch (nd_type(node1)) {
|
switch (nd_type(node1)) {
|
||||||
case NODE_ARRAY:
|
case NODE_ARRAY:
|
||||||
|
@ -10140,9 +10048,7 @@ arg_append_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYL
|
||||||
nd_set_type(node1, NODE_ARGSCAT);
|
nd_set_type(node1, NODE_ARGSCAT);
|
||||||
return node1;
|
return node1;
|
||||||
}
|
}
|
||||||
argspush = NEW_ARGSPUSH(node1, node2, location);
|
return NEW_ARGSPUSH(node1, node2, location);
|
||||||
nd_set_line(argspush, location->first_loc.lineno);
|
|
||||||
return argspush;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
@ -10571,13 +10477,10 @@ cond0(struct parser_params *parser, NODE *node, int method_op, const YYLTYPE *lo
|
||||||
|
|
||||||
case NODE_DREGX:
|
case NODE_DREGX:
|
||||||
{
|
{
|
||||||
NODE *match;
|
|
||||||
if (!method_op)
|
if (!method_op)
|
||||||
warning_unless_e_option(parser, node, "regex literal in condition");
|
warning_unless_e_option(parser, node, "regex literal in condition");
|
||||||
|
|
||||||
match = NEW_MATCH2(node, new_gvar(idLASTLINE, location), location);
|
return NEW_MATCH2(node, new_gvar(idLASTLINE, location), location);
|
||||||
nd_set_line(match, location->first_loc.lineno);
|
|
||||||
return match;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case NODE_AND:
|
case NODE_AND:
|
||||||
|
@ -10631,33 +10534,23 @@ cond_gen(struct parser_params *parser, NODE *node, int method_op, const YYLTYPE
|
||||||
static NODE*
|
static NODE*
|
||||||
new_nil_gen(struct parser_params *parser, const YYLTYPE *location)
|
new_nil_gen(struct parser_params *parser, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *node_nil = NEW_NIL(location);
|
return NEW_NIL(location);
|
||||||
nd_set_line(node_nil, location->first_loc.lineno);
|
|
||||||
return node_nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE*
|
static NODE*
|
||||||
new_if_gen(struct parser_params *parser, NODE *cc, NODE *left, NODE *right, const YYLTYPE *location)
|
new_if_gen(struct parser_params *parser, NODE *cc, NODE *left, NODE *right, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *node_if;
|
|
||||||
|
|
||||||
if (!cc) return right;
|
if (!cc) return right;
|
||||||
cc = cond0(parser, cc, FALSE, location);
|
cc = cond0(parser, cc, FALSE, location);
|
||||||
node_if = NEW_IF(cc, left, right, location);
|
return newline_node(NEW_IF(cc, left, right, location));
|
||||||
nd_set_line(node_if, location->first_loc.lineno);
|
|
||||||
return newline_node(node_if);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE*
|
static NODE*
|
||||||
new_unless_gen(struct parser_params *parser, NODE *cc, NODE *left, NODE *right, const YYLTYPE *location)
|
new_unless_gen(struct parser_params *parser, NODE *cc, NODE *left, NODE *right, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *node_unless;
|
|
||||||
|
|
||||||
if (!cc) return right;
|
if (!cc) return right;
|
||||||
cc = cond0(parser, cc, FALSE, location);
|
cc = cond0(parser, cc, FALSE, location);
|
||||||
node_unless = NEW_UNLESS(cc, left, right, location);
|
return newline_node(NEW_UNLESS(cc, left, right, location));
|
||||||
nd_set_line(node_unless, location->first_loc.lineno);
|
|
||||||
return newline_node(node_unless);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE*
|
static NODE*
|
||||||
|
@ -10709,12 +10602,9 @@ ret_args_gen(struct parser_params *parser, NODE *node)
|
||||||
static NODE *
|
static NODE *
|
||||||
new_yield_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
new_yield_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *yield;
|
|
||||||
if (node) no_blockarg(parser, node);
|
if (node) no_blockarg(parser, node);
|
||||||
|
|
||||||
yield = NEW_YIELD(node, location);
|
return NEW_YIELD(node, location);
|
||||||
nd_set_line(yield, location->first_loc.lineno);
|
|
||||||
return yield;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -10879,7 +10769,6 @@ dsym_node_gen(struct parser_params *parser, NODE *node, const YYLTYPE *location)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
node = NEW_NODE(NODE_DSYM, Qnil, 1, new_list(node, location), location);
|
node = NEW_NODE(NODE_DSYM, Qnil, 1, new_list(node, location), location);
|
||||||
nd_set_line(node, location->first_loc.lineno);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -10936,11 +10825,8 @@ remove_duplicate_keys(struct parser_params *parser, NODE *hash, const YYLTYPE *l
|
||||||
static NODE *
|
static NODE *
|
||||||
new_hash_gen(struct parser_params *parser, NODE *hash, const YYLTYPE *location)
|
new_hash_gen(struct parser_params *parser, NODE *hash, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *nd_hash;
|
|
||||||
if (hash) hash = remove_duplicate_keys(parser, hash, location);
|
if (hash) hash = remove_duplicate_keys(parser, hash, location);
|
||||||
nd_hash = NEW_HASH(hash, location);
|
return NEW_HASH(hash, location);
|
||||||
nd_set_line(nd_hash, location->first_loc.lineno);
|
|
||||||
return nd_hash;
|
|
||||||
}
|
}
|
||||||
#endif /* !RIPPER */
|
#endif /* !RIPPER */
|
||||||
|
|
||||||
|
@ -10957,7 +10843,6 @@ new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, con
|
||||||
lhs->nd_value = rhs;
|
lhs->nd_value = rhs;
|
||||||
nd_set_loc(lhs, location);
|
nd_set_loc(lhs, location);
|
||||||
asgn = NEW_OP_ASGN_OR(gettable(vid, &lhs_location), lhs, location);
|
asgn = NEW_OP_ASGN_OR(gettable(vid, &lhs_location), lhs, location);
|
||||||
nd_set_line(asgn, location->first_loc.lineno);
|
|
||||||
if (is_notop_id(vid)) {
|
if (is_notop_id(vid)) {
|
||||||
switch (id_type(vid)) {
|
switch (id_type(vid)) {
|
||||||
case ID_GLOBAL:
|
case ID_GLOBAL:
|
||||||
|
@ -10971,7 +10856,6 @@ new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, con
|
||||||
lhs->nd_value = rhs;
|
lhs->nd_value = rhs;
|
||||||
nd_set_loc(lhs, location);
|
nd_set_loc(lhs, location);
|
||||||
asgn = NEW_OP_ASGN_AND(gettable(vid, &lhs_location), lhs, location);
|
asgn = NEW_OP_ASGN_AND(gettable(vid, &lhs_location), lhs, location);
|
||||||
nd_set_line(asgn, location->first_loc.lineno);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
asgn = lhs;
|
asgn = lhs;
|
||||||
|
@ -10998,7 +10882,6 @@ new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs,
|
||||||
op = 1;
|
op = 1;
|
||||||
}
|
}
|
||||||
asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, location);
|
asgn = NEW_OP_ASGN2(lhs, CALL_Q_P(atype), attr, op, rhs, location);
|
||||||
nd_set_line(asgn, location->first_loc.lineno);
|
|
||||||
fixpos(asgn, lhs);
|
fixpos(asgn, lhs);
|
||||||
return asgn;
|
return asgn;
|
||||||
}
|
}
|
||||||
|
@ -11021,16 +10904,13 @@ new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rh
|
||||||
asgn = new_begin(0, location);
|
asgn = new_begin(0, location);
|
||||||
}
|
}
|
||||||
fixpos(asgn, lhs);
|
fixpos(asgn, lhs);
|
||||||
nd_set_line(lhs, location->first_loc.lineno);
|
|
||||||
return asgn;
|
return asgn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
const_path_field_gen(struct parser_params *parser, NODE *head, ID mid, const YYLTYPE *location)
|
const_path_field_gen(struct parser_params *parser, NODE *head, ID mid, const YYLTYPE *location)
|
||||||
{
|
{
|
||||||
NODE *colon2 = NEW_COLON2(head, mid, location);
|
return NEW_COLON2(head, mid, location);
|
||||||
nd_set_line(colon2, location->first_loc.lineno);
|
|
||||||
return colon2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
|
|
Загрузка…
Ссылка в новой задаче