зеркало из https://github.com/github/ruby.git
Change numeric node value functions argument to `NODE *`
Change the argument to align with other node value functions like `rb_node_line_lineno_val`.
This commit is contained in:
Родитель
d9bad91c34
Коммит
7ffff3e043
8
ast.c
8
ast.c
|
@ -559,13 +559,13 @@ node_children(rb_ast_t *ast, const NODE *node)
|
|||
case NODE_XSTR:
|
||||
return rb_ary_new_from_args(1, RNODE_LIT(node)->nd_lit);
|
||||
case NODE_INTEGER:
|
||||
return rb_ary_new_from_args(1, rb_node_integer_literal_val(RNODE_INTEGER(node)));
|
||||
return rb_ary_new_from_args(1, rb_node_integer_literal_val(node));
|
||||
case NODE_FLOAT:
|
||||
return rb_ary_new_from_args(1, rb_node_float_literal_val(RNODE_FLOAT(node)));
|
||||
return rb_ary_new_from_args(1, rb_node_float_literal_val(node));
|
||||
case NODE_RATIONAL:
|
||||
return rb_ary_new_from_args(1, rb_node_rational_literal_val(RNODE_RATIONAL(node)));
|
||||
return rb_ary_new_from_args(1, rb_node_rational_literal_val(node));
|
||||
case NODE_IMAGINARY:
|
||||
return rb_ary_new_from_args(1, rb_node_imaginary_literal_val(RNODE_IMAGINARY(node)));
|
||||
return rb_ary_new_from_args(1, rb_node_imaginary_literal_val(node));
|
||||
case NODE_ONCE:
|
||||
return rb_ary_new_from_node_args(ast, 1, RNODE_ONCE(node)->nd_body);
|
||||
case NODE_DSTR:
|
||||
|
|
36
compile.c
36
compile.c
|
@ -1945,16 +1945,16 @@ iseq_set_arguments_keywords(rb_iseq_t *iseq, LINK_ANCHOR *const optargs,
|
|||
case NODE_LINE:
|
||||
dv = rb_node_line_lineno_val(val_node);;
|
||||
case NODE_INTEGER:
|
||||
dv = rb_node_integer_literal_val(RNODE_INTEGER(val_node));
|
||||
dv = rb_node_integer_literal_val(val_node);
|
||||
break;
|
||||
case NODE_FLOAT:
|
||||
dv = rb_node_float_literal_val(RNODE_FLOAT(val_node));
|
||||
dv = rb_node_float_literal_val(val_node);
|
||||
break;
|
||||
case NODE_RATIONAL:
|
||||
dv = rb_node_rational_literal_val(RNODE_RATIONAL(val_node));
|
||||
dv = rb_node_rational_literal_val(val_node);
|
||||
break;
|
||||
case NODE_IMAGINARY:
|
||||
dv = rb_node_imaginary_literal_val(RNODE_IMAGINARY(val_node));
|
||||
dv = rb_node_imaginary_literal_val(val_node);
|
||||
break;
|
||||
case NODE_NIL:
|
||||
dv = Qnil;
|
||||
|
@ -4732,13 +4732,13 @@ static_literal_value(const NODE *node, rb_iseq_t *iseq)
|
|||
{
|
||||
switch (nd_type(node)) {
|
||||
case NODE_INTEGER:
|
||||
return rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
return rb_node_integer_literal_val(node);
|
||||
case NODE_FLOAT:
|
||||
return rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
return rb_node_float_literal_val(node);
|
||||
case NODE_RATIONAL:
|
||||
return rb_node_rational_literal_val(RNODE_RATIONAL(node));
|
||||
return rb_node_rational_literal_val(node);
|
||||
case NODE_IMAGINARY:
|
||||
return rb_node_imaginary_literal_val(RNODE_IMAGINARY(node));
|
||||
return rb_node_imaginary_literal_val(node);
|
||||
case NODE_NIL:
|
||||
return Qnil;
|
||||
case NODE_TRUE:
|
||||
|
@ -5122,9 +5122,9 @@ rb_node_case_when_optimizable_literal(const NODE *const node)
|
|||
break;
|
||||
}
|
||||
case NODE_INTEGER:
|
||||
return rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
return rb_node_integer_literal_val(node);
|
||||
case NODE_FLOAT: {
|
||||
VALUE v = rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
VALUE v = rb_node_float_literal_val(node);
|
||||
double ival;
|
||||
|
||||
if (modf(RFLOAT_VALUE(v), &ival) == 0.0) {
|
||||
|
@ -6371,13 +6371,13 @@ optimized_range_item(const NODE *n)
|
|||
case NODE_LINE:
|
||||
return rb_node_line_lineno_val(n);
|
||||
case NODE_INTEGER:
|
||||
return rb_node_integer_literal_val(RNODE_INTEGER(n));
|
||||
return rb_node_integer_literal_val(n);
|
||||
case NODE_FLOAT:
|
||||
return rb_node_float_literal_val(RNODE_FLOAT(n));
|
||||
return rb_node_float_literal_val(n);
|
||||
case NODE_RATIONAL:
|
||||
return rb_node_rational_literal_val(RNODE_RATIONAL(n));
|
||||
return rb_node_rational_literal_val(n);
|
||||
case NODE_IMAGINARY:
|
||||
return rb_node_imaginary_literal_val(RNODE_IMAGINARY(n));
|
||||
return rb_node_imaginary_literal_val(n);
|
||||
case NODE_NIL:
|
||||
return Qnil;
|
||||
default:
|
||||
|
@ -10240,7 +10240,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
|
|||
break;
|
||||
}
|
||||
case NODE_INTEGER:{
|
||||
VALUE lit = rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
VALUE lit = rb_node_integer_literal_val(node);
|
||||
debugp_param("integer", lit);
|
||||
if (!popped) {
|
||||
ADD_INSN1(ret, node, putobject, lit);
|
||||
|
@ -10249,7 +10249,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
|
|||
break;
|
||||
}
|
||||
case NODE_FLOAT:{
|
||||
VALUE lit = rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
VALUE lit = rb_node_float_literal_val(node);
|
||||
debugp_param("float", lit);
|
||||
if (!popped) {
|
||||
ADD_INSN1(ret, node, putobject, lit);
|
||||
|
@ -10258,7 +10258,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
|
|||
break;
|
||||
}
|
||||
case NODE_RATIONAL:{
|
||||
VALUE lit = rb_node_rational_literal_val(RNODE_RATIONAL(node));
|
||||
VALUE lit = rb_node_rational_literal_val(node);
|
||||
debugp_param("rational", lit);
|
||||
if (!popped) {
|
||||
ADD_INSN1(ret, node, putobject, lit);
|
||||
|
@ -10267,7 +10267,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
|
|||
break;
|
||||
}
|
||||
case NODE_IMAGINARY:{
|
||||
VALUE lit = rb_node_imaginary_literal_val(RNODE_IMAGINARY(node));
|
||||
VALUE lit = rb_node_imaginary_literal_val(node);
|
||||
debugp_param("imaginary", lit);
|
||||
if (!popped) {
|
||||
ADD_INSN1(ret, node, putobject, lit);
|
||||
|
|
|
@ -74,9 +74,9 @@ enum lex_state_e {
|
|||
VALUE rb_node_line_lineno_val(const NODE *);
|
||||
VALUE rb_node_file_path_val(const NODE *);
|
||||
|
||||
VALUE rb_node_integer_literal_val(rb_node_integer_t* node);
|
||||
VALUE rb_node_float_literal_val(rb_node_float_t* node);
|
||||
VALUE rb_node_rational_literal_val(rb_node_rational_t* node);
|
||||
VALUE rb_node_imaginary_literal_val(rb_node_imaginary_t* node);
|
||||
VALUE rb_node_integer_literal_val(const NODE *);
|
||||
VALUE rb_node_float_literal_val(const NODE *);
|
||||
VALUE rb_node_rational_literal_val(const NODE *);
|
||||
VALUE rb_node_imaginary_literal_val(const NODE *);
|
||||
|
||||
#endif /* INTERNAL_RUBY_PARSE_H */
|
||||
|
|
|
@ -725,28 +725,28 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
|||
ANN("integer literal");
|
||||
ANN("format: [val]");
|
||||
ANN("example: 1");
|
||||
F_VALUE(val, rb_node_integer_literal_val(RNODE_INTEGER(node)), "val");
|
||||
F_VALUE(val, rb_node_integer_literal_val(node), "val");
|
||||
return;
|
||||
|
||||
case NODE_FLOAT:
|
||||
ANN("float literal");
|
||||
ANN("format: [val]");
|
||||
ANN("example: 1.2");
|
||||
F_VALUE(val, rb_node_float_literal_val(RNODE_FLOAT(node)), "val");
|
||||
F_VALUE(val, rb_node_float_literal_val(node), "val");
|
||||
return;
|
||||
|
||||
case NODE_RATIONAL:
|
||||
ANN("rational number literal");
|
||||
ANN("format: [val]");
|
||||
ANN("example: 1r");
|
||||
F_VALUE(val, rb_node_rational_literal_val(RNODE_RATIONAL(node)), "val");
|
||||
F_VALUE(val, rb_node_rational_literal_val(node), "val");
|
||||
return;
|
||||
|
||||
case NODE_IMAGINARY:
|
||||
ANN("complex number literal");
|
||||
ANN("format: [val]");
|
||||
ANN("example: 1i");
|
||||
F_VALUE(val, rb_node_imaginary_literal_val(RNODE_IMAGINARY(node)), "val");
|
||||
F_VALUE(val, rb_node_imaginary_literal_val(node), "val");
|
||||
return;
|
||||
|
||||
case NODE_ONCE:
|
||||
|
|
42
parse.y
42
parse.y
|
@ -144,11 +144,11 @@ node_imaginary_cmp(rb_node_imaginary_t *n1, rb_node_imaginary_t *n2)
|
|||
}
|
||||
|
||||
static int
|
||||
node_integer_line_cmp(rb_node_integer_t *i, rb_node_line_t *line)
|
||||
node_integer_line_cmp(const NODE *node_i, const NODE *line)
|
||||
{
|
||||
VALUE num = rb_node_integer_literal_val(i);
|
||||
VALUE num = rb_node_integer_literal_val(node_i);
|
||||
|
||||
return !(FIXNUM_P(num) && RNODE(line)->nd_loc.beg_pos.lineno == FIX2INT(num));
|
||||
return !(FIXNUM_P(num) && line->nd_loc.beg_pos.lineno == FIX2INT(num));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -174,10 +174,10 @@ node_cdhash_cmp(VALUE val, VALUE lit)
|
|||
|
||||
/* Special case for Integer and __LINE__ */
|
||||
if (type_val == NODE_INTEGER && type_lit == NODE_LINE) {
|
||||
return node_integer_line_cmp(RNODE_INTEGER(node_val), RNODE_LINE(node_lit));
|
||||
return node_integer_line_cmp(node_val, node_lit);
|
||||
}
|
||||
if (type_lit == NODE_INTEGER && type_val == NODE_LINE) {
|
||||
return node_integer_line_cmp(RNODE_INTEGER(node_lit), RNODE_LINE(node_val));
|
||||
return node_integer_line_cmp(node_lit, node_val);
|
||||
}
|
||||
|
||||
if (type_val != type_lit) {
|
||||
|
@ -223,16 +223,16 @@ node_cdhash_hash(VALUE a)
|
|||
enum node_type type = nd_type(node);
|
||||
switch (type) {
|
||||
case NODE_INTEGER:
|
||||
val = rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
val = rb_node_integer_literal_val(node);
|
||||
return (FIXNUM_P(val) ? val : FIX2LONG(rb_big_hash(val)));
|
||||
case NODE_FLOAT:
|
||||
val = rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
val = rb_node_float_literal_val(node);
|
||||
return rb_dbl_long_hash(RFLOAT_VALUE(val));
|
||||
case NODE_RATIONAL:
|
||||
val = rb_node_rational_literal_val(RNODE_RATIONAL(node));
|
||||
val = rb_node_rational_literal_val(node);
|
||||
return rb_rational_hash(val);
|
||||
case NODE_IMAGINARY:
|
||||
val = rb_node_imaginary_literal_val(RNODE_IMAGINARY(node));
|
||||
val = rb_node_imaginary_literal_val(node);
|
||||
return rb_complex_hash(val);
|
||||
case NODE_LINE:
|
||||
/* Same with NODE_INTEGER FIXNUM case */
|
||||
|
@ -2141,16 +2141,16 @@ rb_str_to_parser_encoding_string(rb_parser_t *p, VALUE str)
|
|||
#ifndef RIPPER
|
||||
switch (nd_type(RNODE($$))) {
|
||||
case NODE_INTEGER:
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_integer_literal_val(RNODE_INTEGER($$)));
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_integer_literal_val($$));
|
||||
break;
|
||||
case NODE_FLOAT:
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_float_literal_val(RNODE_FLOAT($$)));
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_float_literal_val($$));
|
||||
break;
|
||||
case NODE_RATIONAL:
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_rational_literal_val(RNODE_RATIONAL($$)));
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_rational_literal_val($$));
|
||||
break;
|
||||
case NODE_IMAGINARY:
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_imaginary_literal_val(RNODE_IMAGINARY($$)));
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, rb_node_imaginary_literal_val($$));
|
||||
break;
|
||||
case NODE_LIT:
|
||||
rb_parser_printf(p, "%+"PRIsVALUE, RNODE_LIT($$)->nd_lit);
|
||||
|
@ -13929,13 +13929,13 @@ shareable_literal_value(struct parser_params *p, NODE *node)
|
|||
case NODE_LINE:
|
||||
return rb_node_line_lineno_val(node);
|
||||
case NODE_INTEGER:
|
||||
return rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
return rb_node_integer_literal_val(node);
|
||||
case NODE_FLOAT:
|
||||
return rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
return rb_node_float_literal_val(node);
|
||||
case NODE_RATIONAL:
|
||||
return rb_node_rational_literal_val(RNODE_RATIONAL(node));
|
||||
return rb_node_rational_literal_val(node);
|
||||
case NODE_IMAGINARY:
|
||||
return rb_node_imaginary_literal_val(RNODE_IMAGINARY(node));
|
||||
return rb_node_imaginary_literal_val(node);
|
||||
case NODE_LIT:
|
||||
return RNODE_LIT(node)->nd_lit;
|
||||
default:
|
||||
|
@ -14975,13 +14975,13 @@ nd_st_key_val(struct parser_params *p, NODE *node)
|
|||
case NODE_LIT:
|
||||
return RNODE_LIT(node)->nd_lit;
|
||||
case NODE_INTEGER:
|
||||
return rb_node_integer_literal_val(RNODE_INTEGER(node));
|
||||
return rb_node_integer_literal_val(node);
|
||||
case NODE_FLOAT:
|
||||
return rb_node_float_literal_val(RNODE_FLOAT(node));
|
||||
return rb_node_float_literal_val(node);
|
||||
case NODE_RATIONAL:
|
||||
return rb_node_rational_literal_val(RNODE_RATIONAL(node));
|
||||
return rb_node_rational_literal_val(node);
|
||||
case NODE_IMAGINARY:
|
||||
return rb_node_imaginary_literal_val(RNODE_IMAGINARY(node));
|
||||
return rb_node_imaginary_literal_val(node);
|
||||
case NODE_LINE:
|
||||
return rb_node_line_lineno_val(node);
|
||||
case NODE_FILE:
|
||||
|
|
|
@ -46,8 +46,9 @@ compile_numeric_literal(char* val, int base)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_node_integer_literal_val(rb_node_integer_t* node)
|
||||
rb_node_integer_literal_val(const NODE *n)
|
||||
{
|
||||
rb_node_integer_t *node = RNODE_INTEGER(n);
|
||||
VALUE val = compile_numeric_literal(node->val, node->base);
|
||||
if (node->minus) {
|
||||
val = compile_negative_numeric(val);
|
||||
|
@ -56,8 +57,9 @@ rb_node_integer_literal_val(rb_node_integer_t* node)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_node_float_literal_val(rb_node_float_t* node)
|
||||
rb_node_float_literal_val(const NODE *n)
|
||||
{
|
||||
rb_node_float_t *node = RNODE_FLOAT(n);
|
||||
double d = strtod(node->val, 0);
|
||||
if (node->minus) {
|
||||
d = -d;
|
||||
|
@ -89,9 +91,10 @@ compile_rational_literal(char* node_val, int base, int seen_point)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_node_rational_literal_val(rb_node_rational_t* node)
|
||||
rb_node_rational_literal_val(const NODE *n)
|
||||
{
|
||||
VALUE lit;
|
||||
rb_node_rational_t *node = RNODE_RATIONAL(n);
|
||||
|
||||
lit = compile_rational_literal(node->val, node->base, node->seen_point);
|
||||
|
||||
|
@ -103,9 +106,10 @@ rb_node_rational_literal_val(rb_node_rational_t* node)
|
|||
}
|
||||
|
||||
VALUE
|
||||
rb_node_imaginary_literal_val(rb_node_imaginary_t* node)
|
||||
rb_node_imaginary_literal_val(const NODE *n)
|
||||
{
|
||||
VALUE lit;
|
||||
rb_node_imaginary_t *node = RNODE_IMAGINARY(n);
|
||||
|
||||
enum rb_numeric_type type = node->type;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче