ruby-changes:48106
From: yui-knk <ko1@a...>
Date: Sat, 21 Oct 2017 01:22:29 +0900 (JST)
Subject: [ruby-changes:48106] yui-knk:r60220 (trunk): Store token first column number on RNode
yui-knk 2017-10-21 01:22:22 +0900 (Sat, 21 Oct 2017) New Revision: 60220 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60220 Log: Store token first column number on RNode * node.c (A_NODE_HEADER): Print column number. * node.h (nd_column, nd_set_column): Define getter/setter macros for column number of RNode. * parse.y: Set first column number of tokens. Notes: * Use `@n` to get the location of token in parse.y. * When we use `@n`, arguments of yyerror and yylex are changed. * Initialize column of nodes with -1 to make it easy to detect nodes which we forget to set a column number. Modified files: trunk/node.c trunk/node.h trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 60219) +++ parse.y (revision 60220) @@ -266,7 +266,8 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L266 #define TOK_INTERN() intern_cstr(tok(), toklen(), current_enc) static int parser_yyerror(struct parser_params*, const char*); -#define yyerror(msg) parser_yyerror(parser, (msg)) +#define yyerror0(msg) parser_yyerror(parser, (msg)) +#define yyerror(yylloc, parser, msg) yyerror0(msg) #define token_flush(p) ((p)->lex.ptok = (p)->lex.pcur) #define lex_strterm (parser->lex.strterm) @@ -315,13 +316,15 @@ static int parser_yyerror(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L316 #endif #define tokp lex.ptok +#define token_column ((int)(parser->tokp - lex_pbeg)) + #define CALL_Q_P(q) ((q) == TOKEN2VAL(tANDDOT)) #define NODE_CALL_Q(q) (CALL_Q_P(q) ? NODE_QCALL : NODE_CALL) #define NEW_QCALL(q,r,m,a) NEW_NODE(NODE_CALL_Q(q),r,m,a) #define lambda_beginning_p() (lpar_beg && lpar_beg == paren_nest) -static enum yytokentype yylex(YYSTYPE*, struct parser_params*); +static enum yytokentype yylex(YYSTYPE*, YYLTYPE*, struct parser_params*); static inline void parser_set_line(NODE *n, int l) @@ -346,18 +349,18 @@ set_line_body(NODE *body, int line) https://github.com/ruby/ruby/blob/trunk/parse.y#L349 static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE); #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3)) -static NODE *cond_gen(struct parser_params*,NODE*,int); -#define cond(node) cond_gen(parser, (node), FALSE) -#define method_cond(node) cond_gen(parser, (node), TRUE) +static NODE *cond_gen(struct parser_params*,NODE*,int,int); +#define cond(node,column) cond_gen(parser, (node), FALSE, column) +#define method_cond(node,column) cond_gen(parser, (node), TRUE, column) #define new_nil() NEW_NIL() -static NODE *new_if_gen(struct parser_params*,NODE*,NODE*,NODE*); -#define new_if(cc,left,right) new_if_gen(parser, (cc), (left), (right)) -static NODE *new_unless_gen(struct parser_params*,NODE*,NODE*,NODE*); -#define new_unless(cc,left,right) new_unless_gen(parser, (cc), (left), (right)) -static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*); -#define logop(id,node1,node2) \ +static NODE *new_if_gen(struct parser_params*,NODE*,NODE*,NODE*,int); +#define new_if(cc,left,right,column) new_if_gen(parser, (cc), (left), (right), (column)) +static NODE *new_unless_gen(struct parser_params*,NODE*,NODE*,NODE*,int); +#define new_unless(cc,left,right,column) new_unless_gen(parser, (cc), (left), (right), (column)) +static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*,int); +#define logop(id,node1,node2,column) \ logop_gen(parser, ((id)==idAND||(id)==idANDOP)?NODE_AND:NODE_OR, \ - (node1), (node2)) + (node1), (node2), (column)) static NODE *newline_node(NODE*); static void fixpos(NODE*,NODE*); @@ -376,30 +379,31 @@ static void reduce_nodes_gen(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L379 static void block_dup_check_gen(struct parser_params*,NODE*,NODE*); #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2)) -static NODE *block_append_gen(struct parser_params*,NODE*,NODE*); -#define block_append(h,t) block_append_gen(parser,(h),(t)) -static NODE *list_append_gen(struct parser_params*,NODE*,NODE*); -#define list_append(l,i) list_append_gen(parser,(l),(i)) +static NODE *block_append_gen(struct parser_params*,NODE*,NODE*,int); +#define block_append(h,t,column) block_append_gen(parser,(h),(t),(column)) +static NODE *list_append_gen(struct parser_params*,NODE*,NODE*,int); +#define list_append(l,i,column) list_append_gen(parser,(l),(i),(column)) static NODE *list_concat(NODE*,NODE*); -static NODE *arg_append_gen(struct parser_params*,NODE*,NODE*); -#define arg_append(h,t) arg_append_gen(parser,(h),(t)) -static NODE *arg_concat_gen(struct parser_params*,NODE*,NODE*); -#define arg_concat(h,t) arg_concat_gen(parser,(h),(t)) -static NODE *literal_concat_gen(struct parser_params*,NODE*,NODE*); -#define literal_concat(h,t) literal_concat_gen(parser,(h),(t)) +static NODE *arg_append_gen(struct parser_params*,NODE*,NODE*,int); +#define arg_append(h,t,column) arg_append_gen(parser,(h),(t),(column)) +static NODE *arg_concat_gen(struct parser_params*,NODE*,NODE*,int); +#define arg_concat(h,t,column) arg_concat_gen(parser,(h),(t),(column)) +static NODE *literal_concat_gen(struct parser_params*,NODE*,NODE*,int); +#define literal_concat(h,t,column) literal_concat_gen(parser,(h),(t),(column)) static int literal_concat0(struct parser_params *, VALUE, VALUE); -static NODE *new_evstr_gen(struct parser_params*,NODE*); -#define new_evstr(n) new_evstr_gen(parser,(n)) -static NODE *evstr2dstr_gen(struct parser_params*,NODE*); -#define evstr2dstr(n) evstr2dstr_gen(parser,(n)) +static NODE *new_evstr_gen(struct parser_params*,NODE*,int); +#define new_evstr(n, column) new_evstr_gen(parser,(n),(column)) +static NODE *evstr2dstr_gen(struct parser_params*,NODE*,int); +#define evstr2dstr(n,column) evstr2dstr_gen(parser,(n),(column)) static NODE *splat_array(NODE*); -static NODE *call_bin_op_gen(struct parser_params*,NODE*,ID,NODE*); -#define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1)) -static NODE *call_uni_op_gen(struct parser_params*,NODE*,ID); -#define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id)) -#define new_qcall(q,r,m,a) NEW_QCALL(q,r,m,a) -#define new_command_qcall(q,r,m,a) NEW_QCALL(q,r,m,a) +static NODE *call_bin_op_gen(struct parser_params*,NODE*,ID,NODE*,int); +#define call_bin_op(recv,id,arg1,column) call_bin_op_gen(parser, (recv),(id),(arg1),(column)) +static NODE *call_uni_op_gen(struct parser_params*,NODE*,ID,int); +#define call_uni_op(recv,id,column) call_uni_op_gen(parser, (recv),(id),(column)) +static NODE *new_qcall_gen(struct parser_params* parser, ID atype, NODE *recv, ID mid, NODE *args, int column); +#define new_qcall(q,r,m,a,column) new_qcall_gen(parser,q,r,m,a,column) +#define new_command_qcall(q,r,m,a,column) new_qcall_gen(parser,q,r,m,a,column) static NODE *new_command_gen(struct parser_params*parser, NODE *m, NODE *a) {m->nd_args = a; return m;} #define new_command(m,a) new_command_gen(parser, m, a) static NODE *method_add_block_gen(struct parser_params*parser, NODE *m, NODE *b) {b->nd_iter = m; return b;} @@ -407,68 +411,135 @@ static NODE *method_add_block_gen(struct https://github.com/ruby/ruby/blob/trunk/parse.y#L411 static NODE *new_args_gen(struct parser_params*,NODE*,NODE*,ID,NODE*,NODE*); #define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t)) -static NODE *new_args_tail_gen(struct parser_params*,NODE*,ID,ID); -#define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b)) -#define new_kw_arg(k) ((k) ? NEW_KW_ARG(0, (k)) : 0) +static NODE *new_args_tail_gen(struct parser_params*,NODE*,ID,ID,int); +#define new_args_tail(k,kr,b,column) new_args_tail_gen(parser, (k),(kr),(b),(column)) +static NODE *new_kw_arg_gen(struct parser_params *parser, NODE *k, int column); +#define new_kw_arg(k,column) new_kw_arg_gen(parser, k, column) static VALUE negate_lit_gen(struct parser_params*, VALUE); #define negate_lit(lit) negate_lit_gen(parser, lit) static NODE *ret_args_gen(struct parser_params*,NODE*); #define ret_args(node) ret_args_gen(parser, (node)) static NODE *arg_blk_pass(NODE*,NODE*); -static NODE *new_yield_gen(struct parser_params*,NODE*); -#define new_yield(node) new_yield_gen(parser, (node)) -static NODE *dsym_node_gen(struct parser_params*,NODE*); -#define dsym_node(node) dsym_node_gen(parser, (node)) - -static NODE *gettable_gen(struct parser_params*,ID); -#define gettable(id) gettable_gen(parser,(id)) -static NODE *assignable_gen(struct parser_params*,ID,NODE*); -#define assignable(id,node) assignable_gen(parser, (id), (node)) - -static NODE *aryset_gen(struct parser_params*,NODE*,NODE*); -#define aryset(node1,node2) aryset_gen(parser, (node1), (node2)) -static NODE *attrset_gen(struct parser_params*,NODE*,ID,ID); -#define attrset(node,q,id) attrset_gen(parser, (node), (q), (id)) +static NODE *new_yield_gen(struct parser_params*,NODE*,int); +#define new_yield(node,column) new_yield_gen(parser, (node), (column)) +static NODE *dsym_node_gen(struct parser_params*,NODE*,int); +#define dsym_node(node,column) dsym_node_gen(parser, (node), (column)) + +static NODE *gettable_gen(struct parser_params*,ID,int); +#define gettable(id,column) gettable_gen(parser,(id),(column)) +static NODE *assignable_gen(struct parser_params*,ID,NODE*,int); +#define assignable(id,node,column) assignable_gen(parser, (id), (node), (column)) + +static NODE *aryset_gen(struct parser_params*,NODE*,NODE*,int); +#define aryset(node1,node2,column) aryset_gen(parser, (node1), (node2), (column)) +static NODE *attrset_gen(struct parser_params*,NODE*,ID,ID,int); +#define attrset(node,q,id,column) attrset_gen(parser, (node), (q), (id), (column)) static void rb_backref_error_gen(struct parser_params*,NODE*); #define rb_backref_error(n) rb_backref_error_gen(parser,(n)) -static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*); -#define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2)) +static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*,int); +#define node_assign(node1, node2, column) node_assign_gen(parser, (node1), (node2), (column)) -static NODE *new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs); -static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs); -#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) -static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs); -#define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs)) +static NODE *new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, int column); +static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID atype, ID attr, ID op, NODE *rhs, int column); +#define new_attr_op_assign(lhs, type, attr, op, rhs, column) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs), (column)) +static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs, int column); +#define new_const_op_assign(lhs, op, rhs, column) new_const_op_assign_gen(parser, (lhs), (op), (rhs), (column)) -#define const_path_field(w, n) NEW_COLON2(w, n) +static NODE *const_path_field_gen(struct parser_params *parser, NODE *head, ID mid, int column); +#define const_path_field(w, n, column) const_path_field_gen(parser, w, n, column) #define top_const_field(n) NEW_COLON3(n) -static NODE *const_decl_gen(struct parser_params *parser, NODE* path); -#define const_decl(path) const_decl_gen(parser, path) +static NODE *const_decl_gen(struct parser_params *parser, NODE* path, int column); +#define const_decl(path, column) const_decl_gen(parser, path, column) #define var_field(n) (n) -#define backref_assign_error(n, a) (rb_backref_error(n), NEW_BEGIN(0)) +#define backref_assign_error(n, a, column) (rb_backref_error(n), new_begin(0, column)) static NODE *kwd_append(NODE*, NODE*); -static NODE *new_hash_gen(struct parser_params *parser, NODE *hash); -#define new_hash(hash) new_hash_gen(parser, (hash)) +static NODE *new_hash_gen(struct parser_params *parser, NODE *hash, int column); +#define new_hash(hash, column) new_hash_gen(parser, (hash), column) + +static NODE *new_defined_gen(struct parser_params *parser, NODE *expr, int column); +#define new_defined(expr, column) new_defined_gen(parser, expr, column) + +static NODE *new_regexp_gen(struct parser_params *, NODE *, int, int); +#define new_regexp(node, opt, column) new_regexp_gen(parser, node, opt, column) + +static NODE *new_lit_gen(struct parser_params *parser, VALUE sym, int column); +#define new_lit(sym, column) new_lit_gen(parser, sym, column) + +static NODE *new_list_gen(struct parser_params *parser, NODE *item, int column); +#define new_list(item, column) new_list_gen(parser, item, column) + +static NODE *new_str_gen(struct parser_params *parser, VALUE str, int column); +#define new_str(s,column) new_str_gen(parser, s, column) + +static NODE *new_dvar_gen(struct parser_params *parser, ID id, int column); +#define new_dvar(id, column) new_dvar_gen(parser, id, column) + +static NODE *new_resbody_gen(struct parser_params *parser, NODE *exc_list, NODE *stmt, NODE *rescue, int column); +#define new_resbody(e,s,r,column) new_resbody_gen(parser, (e),(s),(r),(column)) + +static NODE *new_errinfo_gen(struct parser_params *parser, int column); +#define new_errinfo(column) new_errinfo_gen(parser, column) + +static NODE *new_call_gen(struct parser_params *parser, NODE *recv, ID mid, NODE *args, int column); +#define new_call(recv,mid,args,column) new_call_gen(parser, recv,mid,args,column) + +static NODE *new_fcall_gen(struct parser_params *parser, ID mid, NODE *args, int column); +#define new_fcall(mid,args,column) new_fcall_gen(parser, mid, args, column) + +static NODE *new_for_gen(struct parser_params *parser, NODE *var, NODE *iter, NODE *body, int column); +#define new_for(var,iter,body,column) new_for_gen(parser, var, iter, body, column) + +static NODE *new_gvar_gen(struct parser_params *parser, ID id, int column); +#define new_gvar(id, column) new_gvar_gen(parser, id, column) -#define new_defined(expr) NEW_DEFINED(remove_begin_all(expr)) +static NODE *new_lvar_gen(struct parser_params *parser, ID id, int column); +#define new_lvar(id, column) new_lvar_gen(parser, id, column) -static NODE *new_regexp_gen(struct parser_params *, NODE *, int); -#define new_regexp(node, opt) new_regexp_gen(parser, node, opt) +static NODE *new_dstr_gen(struct parser_params *parser, VALUE str, int column); +#define new_dstr(s, column) new_dstr_gen(parser, s, column) -static NODE *new_xstring_gen(struct parser_params *, NODE *); -#define new_xstring(node) new_xstring_gen(parser, node) +static NODE *new_rescue_gen(struct parser_params *parser, NODE *b, NODE *res, NODE *e, int column); +#define new_rescue(b,res,e,column) new_rescue_gen(parser,b,res,e,column) + +static NODE *new_undef_gen(struct parser_params *parser, NODE *i, int column); +#define new_undef(i, column) new_undef_gen(parser, i, column) + +static NODE *new_zarray_gen(struct parser_params *parser, int column); +#define new_zarray(column) new_zarray_gen(parser, column) + +static NODE *new_ivar_gen(struct parser_params *parser, ID id, int column); +#define new_ivar(id, column) new_ivar_gen(parser,id,column) + +static NODE *new_postarg_gen(struct parser_params *parser, NODE *i, NODE *v, int column); +#define new_postarg(i,v,column) new_postarg_gen(parser,i,v,column) + +static NODE *new_cdecl_gen(struct parser_params *parser, ID v, NODE *val, NODE *path, int column); +#define new_cdecl(v,val,path,column) new_cdecl_gen(parser,v,val,path,column) + +static NODE *new_scope_gen(struct parser_params *parser, NODE *a, NODE *b, int column); +#define new_scope(a,b,column) new_scope_gen(parser,a,b,column) + +static NODE *new_begin_gen(struct parser_params *parser, NODE *b, int column); +#define new_begin(b,column) new_begin_gen(parser,b,column) + +static NODE *new_masgn_gen(struct parser_params *parser, NODE *l, NODE *r, int column); +#define new_masgn(l,r,column) new_masgn_gen(parser,l,r,column) + +static NODE *new_xstring_gen(struct parser_params *, NODE *, int column); +#define new_xstring(node, column) new_xstring_gen(parser, node, column) #define new_string1(str) (str) -#define new_brace_body(param, stmt) NEW_ITER(param, stmt) -#define new_do_body(param, stmt) NEW_ITER(param, stmt) +static NODE *new_body_gen(struct parser_params *parser, NODE *param, NODE *stmt, int column); +#define new_brace_body(param, stmt, column) new_body_gen(parser, param, stmt, column) +#define new_do_body(param, stmt, column) new_body_gen(parser, param, stmt, column) -static NODE *match_op_gen(struct parser_params*,NODE*,NODE*); -#define match_op(node1,node2) match_op_gen(parser, (node1), (node2)) +static NODE *match_op_gen(struct parser_params*,NODE*,NODE*,int); +#define match_op(node1,node2,column) match_op_gen(parser, (node1), (node2), (column)) static ID *local_tbl_gen(struct parser_params*); #define local_tbl() local_tbl_gen(parser) @@ -479,8 +550,8 @@ static void reg_fragment_setenc_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L550 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options)) static int reg_fragment_check_gen(struct parser_params*, VALUE, int); #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options)) -static NODE *reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp); -#define reg_named_capture_assign(regexp) reg_named_capture_assign_gen(parser,(regexp)) +static NODE *reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, int column); +#define reg_named_capture_assign(regexp,column) reg_named_capture_assign_gen(parser,(regexp),column) static NODE *parser_heredoc_dedent(struct parser_params*,NODE*); # define heredoc_dedent(str) parser_heredoc_dedent(parser, (str)) @@ -511,48 +582,48 @@ static ID ripper_get_id(VALUE); https://github.com/ruby/ruby/blob/trunk/parse.y#L582 static VALUE ripper_get_value(VALUE); #define get_value(val) ripper_get_value(val) static VALUE assignable_gen(struct parser_params*,VALUE); -#define assignable(lhs,node) assignable_gen(parser, (lhs)) +#define assignable(lhs,node,column) assignable_gen(parser, (lhs)) static int id_is_var_gen(struct parser_params *parser, ID id); #define id_is_var(id) id_is_var_gen(parser, (id)) -#define method_cond(node) (node) -#define call_bin_op(recv,id,arg1) dispatch3(binary, (recv), STATIC_ID2SYM(id), (arg1)) -#define match_op(node1,node2) call_bin_op((node1), idEqTilde, (node2)) -#define call_uni_op(recv,id) dispatch2(unary, STATIC_ID2SYM(id), (recv)) -#define logop(id,node1,node2) call_bin_op((node1), (id), (node2)) -#define node_assign(node1, node2) dispatch2(assign, (node1), (node2)) +#define method_cond(node,column) (node) +#define call_bin_op(recv,id,arg1,column) dispatch3(binary, (recv), STATIC_ID2SYM(id), (arg1)) +#define match_op(node1,node2,column) call_bin_op((node1), idEqTilde, (node2), -1) +#define call_uni_op(recv,id,column) dispatch2(unary, STATIC_ID2SYM(id), (recv)) +#define logop(id,node1,node2,column) call_bin_op((node1), (id), (node2), -1) +#define node_assign(node1, node2, column) dispatch2(assign, (node1), (node2)) static VALUE new_qcall_gen(struct parser_params *parser, VALUE q, VALUE r, VALUE m, VALUE a); -#define new_qcall(q,r,m,a) new_qcall_gen(parser, (r), (q), (m), (a)) -#define new_command_qcall(q,r,m,a) dispatch4(command_call, (r), (q), (m), (a)) +#define new_qcall(q,r,m,a,column) new_qcall_gen(parser, (r), (q), (m), (a)) +#define new_command_qcall(q,r,m,a,column) dispatch4(command_call, (r), (q), (m), (a)) #define new_command_call(q,r,m,a) dispatch4(command_call, (r), (q), (m), (a)) #define new_command(m,a) dispatch2(command, (m), (a)); #define new_nil() Qnil -static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs); +static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op, VALUE rhs, int column); static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs); -#define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) -#define new_const_op_assign(lhs, op, rhs) new_op_assign(lhs, op, rhs) +#define new_attr_op_assign(lhs, type, attr, op, rhs, column) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) +#define n (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/