diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-04 14:24:16 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-04 14:24:16 +0000 |
commit | af9b0da125871c6bfbc3b7893d199a79420e5833 (patch) | |
tree | e93349e2c178a202d3fb4688db0ed76358b3a97a /node.c | |
parent | 6d022ae147c8b226e9b41a446cd254871cb64719 (diff) |
Avoid usage of the magic number `(NODE*)-1`
This magic number has two meanings depending upon the context:
* "required keyword argument (no name)" on NODE_LASGN (`def foo(x:)`)
* "rest argument (no name)" on NODE_MASGN and NODE_POSTARG
('a, b, * = ary` or `a, b, *, z = ary`)
To show this intention explicitly, two macros are introduced:
NODE_SPECIAL_REQUIRED_KEYWORD and NODE_SPECIAL_NO_NAME_REST.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -366,12 +366,12 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("example: a, b = foo"); F_NODE(nd_value, "rhsn"); F_NODE(nd_head, "lhsn"); - if ((VALUE)node->nd_args != (VALUE)-1) { + if (node->nd_args != NODE_SPECIAL_NO_NAME_REST) { LAST_NODE; F_NODE(nd_args, "splatn"); } else { - F_MSG(nd_args, "splatn", "-1 (rest argument without name)"); + F_MSG(nd_args, "splatn", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)"); } return; @@ -402,8 +402,8 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) asgn: F_ID(nd_vid, "variable"); LAST_NODE; - if (node->nd_value == (NODE *)-1) { - F_MSG(nd_value, "rvalue", "(required keyword argument)"); + if (node->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD) { + F_MSG(nd_value, "rvalue", "NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)"); } else { F_NODE(nd_value, "rvalue"); @@ -983,11 +983,11 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("post arguments"); ANN("format: *[nd_1st], [nd_2nd..] = .."); ANN("example: a, *rest, z = foo"); - if ((VALUE)node->nd_1st != (VALUE)-1) { + if (node->nd_1st != NODE_SPECIAL_NO_NAME_REST) { F_NODE(nd_1st, "rest argument"); } else { - F_MSG(nd_1st, "rest argument", "-1 (rest argument without name)"); + F_MSG(nd_1st, "rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)"); } LAST_NODE; F_NODE(nd_2nd, "post arguments"); |