1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yui-knk 2017-10-20 16:22:22 +00:00
parent 43e320ba1b
commit 6d4b557811
3 changed files with 1025 additions and 524 deletions

2
node.c
View file

@ -23,7 +23,7 @@
#define A_LONG(val) rb_str_catf(buf, "%ld", (val)) #define A_LONG(val) rb_str_catf(buf, "%ld", (val))
#define A_LIT(lit) AR(rb_inspect(lit)) #define A_LIT(lit) AR(rb_inspect(lit))
#define A_NODE_HEADER(node, term) \ #define A_NODE_HEADER(node, term) \
rb_str_catf(buf, "@ %s (line: %d)"term, ruby_node_name(nd_type(node)), nd_line(node)) rb_str_catf(buf, "@ %s (line: %d, column: %d)"term, ruby_node_name(nd_type(node)), nd_line(node), nd_column(node))
#define A_FIELD_HEADER(len, name, term) \ #define A_FIELD_HEADER(len, name, term) \
rb_str_catf(buf, "+- %.*s:"term, (len), (name)) rb_str_catf(buf, "+- %.*s:"term, (len), (name))
#define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term)) #define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term))

2
node.h
View file

@ -284,6 +284,8 @@ typedef struct RNode {
#define nd_line(n) (int)(((SIGNED_VALUE)RNODE(n)->flags)>>NODE_LSHIFT) #define nd_line(n) (int)(((SIGNED_VALUE)RNODE(n)->flags)>>NODE_LSHIFT)
#define nd_set_line(n,l) \ #define nd_set_line(n,l) \
RNODE(n)->flags=((RNODE(n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT)) RNODE(n)->flags=((RNODE(n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT))
#define nd_column(n) (int)(RNODE(n)->nd_reserved)
#define nd_set_column(n, v) (RNODE(n)->nd_reserved=v)
#define nd_head u1.node #define nd_head u1.node
#define nd_alen u2.argc #define nd_alen u2.argc

1545
parse.y

File diff suppressed because it is too large Load diff