mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Store last location of a node on RNode
* node.c (rb_node_init): Initialize last location with 0. * node.h (struct rb_code_range_struct): Define a structure which contains first location and last location of a node. * node.h (struct RNode): Use rb_code_range_t to store last location of a node. * node.h (nd_column, nd_set_column, nd_lineno, nd_set_lineno): Follow-up the change of struct RNode. * node.h (nd_last_column, nd_set_last_column, nd_last_lineno, nd_set_last_lineno): Define getter/setter macros for last location of RNode. * parse.y : Set last location of tokens. Thanks to Yusuke Endoh (mame) for design of data structures. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a82aaea719
commit
1ef7b0cd5a
3 changed files with 415 additions and 538 deletions
6
node.c
6
node.c
|
@ -1069,8 +1069,10 @@ rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
|||
n->u1.value = a0;
|
||||
n->u2.value = a1;
|
||||
n->u3.value = a2;
|
||||
n->nd_first_loc.lineno = 0;
|
||||
n->nd_first_loc.column = 0;
|
||||
n->nd_loc.first_loc.lineno = 0;
|
||||
n->nd_loc.first_loc.column = 0;
|
||||
n->nd_loc.last_loc.lineno = 0;
|
||||
n->nd_loc.last_loc.column = 0;
|
||||
}
|
||||
|
||||
typedef struct node_buffer_elem_struct {
|
||||
|
|
20
node.h
20
node.h
|
@ -227,6 +227,11 @@ typedef struct rb_code_location_struct {
|
|||
int column;
|
||||
} rb_code_location_t;
|
||||
|
||||
typedef struct rb_code_range_struct {
|
||||
rb_code_location_t first_loc;
|
||||
rb_code_location_t last_loc;
|
||||
} rb_code_range_t;
|
||||
|
||||
typedef struct RNode {
|
||||
VALUE flags;
|
||||
union {
|
||||
|
@ -251,7 +256,7 @@ typedef struct RNode {
|
|||
long cnt;
|
||||
VALUE value;
|
||||
} u3;
|
||||
rb_code_location_t nd_first_loc;
|
||||
rb_code_range_t nd_loc;
|
||||
} NODE;
|
||||
|
||||
#define RNODE(obj) (R_CAST(RNode)(obj))
|
||||
|
@ -276,10 +281,15 @@ typedef struct RNode {
|
|||
#define nd_set_line(n,l) \
|
||||
(n)->flags=(((n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT))
|
||||
|
||||
#define nd_column(n) ((int)((n)->nd_first_loc.column))
|
||||
#define nd_set_column(n, v) ((n)->nd_first_loc.column = (v))
|
||||
#define nd_lineno(n) ((int)((n)->nd_first_loc.lineno))
|
||||
#define nd_set_lineno(n, v) ((n)->nd_first_loc.lineno = (v))
|
||||
#define nd_column(n) ((int)((n)->nd_loc.first_loc.column))
|
||||
#define nd_set_column(n, v) ((n)->nd_loc.first_loc.column = (v))
|
||||
#define nd_lineno(n) ((int)((n)->nd_loc.first_loc.lineno))
|
||||
#define nd_set_lineno(n, v) ((n)->nd_loc.first_loc.lineno = (v))
|
||||
|
||||
#define nd_last_column(n) ((int)((n)->nd_loc.last_loc.column))
|
||||
#define nd_set_last_column(n, v) ((n)->nd_loc.last_loc.column = (v))
|
||||
#define nd_last_lineno(n) ((int)((n)->nd_loc.last_loc.lineno))
|
||||
#define nd_set_last_lineno(n, v) ((n)->nd_loc.last_loc.lineno = (v))
|
||||
|
||||
#define nd_head u1.node
|
||||
#define nd_alen u2.argc
|
||||
|
|
Loading…
Reference in a new issue