Project

General

Profile

Feature #17768 ยป 2021-aprilfool.patch

mame (Yusuke Endoh), 04/01/2021 12:02 AM

View differences:

parse.y
268 268
	VALUE prevline;
269 269
	VALUE lastline;
270 270
	VALUE nextline;
271
        st_table *new_nodes;
271 272
	const char *pbeg;
272 273
	const char *pcur;
273 274
	const char *pend;
......
450 451
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE, const rb_code_location_t*);
451 452
#define rb_node_newnode(type, a1, a2, a3, loc) node_newnode(p, (type), (a1), (a2), (a3), (loc))
452 453

  
453
static NODE *nd_set_loc(NODE *nd, const YYLTYPE *loc);
454
static NODE *nd_set_loc(struct parser_params *, NODE *nd, const YYLTYPE *loc);
454 455

  
455 456
static int
456 457
parser_get_node_id(struct parser_params *p)
......
560 561

  
561 562
static NODE *new_regexp(struct parser_params *, NODE *, int, const YYLTYPE *);
562 563

  
563
#define make_list(list, loc) ((list) ? (nd_set_loc(list, loc), list) : NEW_ZLIST(loc))
564
#define make_list(list, loc) ((list) ? (nd_set_loc(p, list, loc), list) : NEW_ZLIST(loc))
564 565

  
565 566
static NODE *new_xstring(struct parser_params *, NODE *, const YYLTYPE *loc);
566 567

  
......
4580 4581
		    {
4581 4582
		    /*%%%*/
4582 4583
			$$ = heredoc_dedent(p, $2);
4583
			if ($$) nd_set_loc($$, &@$);
4584
			if ($$) nd_set_loc(p, $$, &@$);
4584 4585
		    /*% %*/
4585 4586
		    /*% ripper: string_literal!(heredoc_dedent(p, $2)) %*/
4586 4587
		    }
......
9206 9207
		}
9207 9208
#endif
9208 9209
		goto normal_newline;
9210
              case '^': {
9211
                const char *down = RSTRING_PTR(p->lex.lastline);
9212
		if (p->lex.prevline && !p->eofp) p->lex.lastline = p->lex.prevline;
9213

  
9214
                int i = 0;
9215
                while (1) {
9216
                    while (ISSPACE(down[i]) && down[i] != '\n') i++;
9217
                    if (down[i] == '\n') break;
9218
                    if (down[i] != '^') {
9219
                        yyerror0("invalid syntax in down assignment line");
9220
                        break;
9221
                    }
9222

  
9223
                    int j = i;
9224
                    while (down[j] == '^') j++;
9225

  
9226
                    int k = j;
9227
                    while (down[k] != '^' && !ISSPACE(down[k]) && down[k] != '\n' && ISASCII(down[k])) k++;
9228

  
9229
                    rb_code_location_t loc = { { p->ruby_sourceline - 1, i }, { p->ruby_sourceline - 1, j } };
9230
                    NODE *node;
9231
                    if (p->lex.new_nodes && st_lookup(p->lex.new_nodes, (st_data_t)&loc, (st_data_t*)&node)) {
9232
                        NODE *n = rb_ast_newnode(p->ast, nd_type(node));
9233
                        rb_node_init(n, nd_type(node), node->u1.value, node->u2.value, node->u3.value);
9234
                        nd_set_loc(p, n, &node->nd_loc);
9235
                        n->node_id = node->node_id;
9236
                        ID id = intern_cstr(down + j, k - j, p->enc);
9237
                        NODE *tmp = assignable(p, id, n, &loc);
9238
                        *node = *tmp;
9239
                        node->node_id = -1;
9240
                    }
9241
                    else {
9242
                        yyerror0("cannot identify node");
9243
                        break;
9244
                    }
9245

  
9246
                    i = k;
9247
                }
9248
                p->lex.pbeg = RSTRING_PTR(p->lex.lastline);
9249
                p->lex.pend = p->lex.pcur = p->lex.pbeg + RSTRING_LEN(p->lex.lastline);
9250
                pushback(p, 1); /* always pushback */
9251
                p->lex.ptok = p->lex.pcur;
9252
                goto normal_newline;
9253
              }
9209 9254
	    }
9210 9255
	}
9211 9256
      normal_newline:
9257
        if (p->lex.new_nodes) st_clear(p->lex.new_nodes);
9212 9258
	p->command_start = TRUE;
9213 9259
	SET_LEX_STATE(EXPR_BEG);
9214 9260
	return '\n';
......
9815 9861

  
9816 9862
#define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
9817 9863

  
9864
int
9865
st_loc_cmp(st_data_t x, st_data_t y)
9866
{
9867
    const YYLTYPE *loc1 = (const YYLTYPE *)x;
9868
    const YYLTYPE *loc2 = (const YYLTYPE *)y;
9869
    return !(
9870
        loc1->beg_pos.lineno == loc2->beg_pos.lineno &&
9871
        loc1->beg_pos.column == loc2->beg_pos.column &&
9872
        loc1->end_pos.lineno == loc2->end_pos.lineno &&
9873
        loc1->end_pos.column == loc2->end_pos.column
9874
    );
9875
}
9876

  
9877
st_index_t
9878
st_loc_hash(st_data_t x)
9879
{
9880
    const YYLTYPE *loc = (const YYLTYPE *)x;
9881
    return loc->beg_pos.lineno ^ loc->beg_pos.column ^ loc->end_pos.lineno ^ loc->end_pos.column;
9882
}
9883

  
9884
static const struct st_hash_type st_hashtype_loc = {
9885
    st_loc_cmp,
9886
    st_loc_hash,
9887
};
9888

  
9818 9889
static NODE*
9819 9890
node_newnode(struct parser_params *p, enum node_type type, VALUE a0, VALUE a1, VALUE a2, const rb_code_location_t *loc)
9820 9891
{
......
9822 9893

  
9823 9894
    rb_node_init(n, type, a0, a1, a2);
9824 9895

  
9825
    nd_set_loc(n, loc);
9896
    nd_set_loc(p, n, loc);
9826 9897
    nd_set_node_id(n, parser_get_node_id(p));
9827 9898
    return n;
9828 9899
}
9829 9900

  
9830 9901
static NODE *
9831
nd_set_loc(NODE *nd, const YYLTYPE *loc)
9902
nd_set_loc(struct parser_params *p, NODE *nd, const YYLTYPE *loc)
9832 9903
{
9904
    if (!p->lex.new_nodes) p->lex.new_nodes = st_init_table(&st_hashtype_loc);
9833 9905
    nd->nd_loc = *loc;
9906
    if (!st_lookup(p->lex.new_nodes, (st_data_t)&nd->nd_loc, NULL)) {
9907
        st_insert(p->lex.new_nodes, (st_data_t)&nd->nd_loc, (st_data_t)nd);
9908
    }
9834 9909
    nd_set_line(nd, loc->beg_pos.lineno);
9835 9910
    return nd;
9836 9911
}
......
10404 10479
	{
10405 10480
	    VALUE src = node->nd_lit;
10406 10481
	    nd_set_type(node, NODE_LIT);
10407
	    nd_set_loc(node, loc);
10482
	    nd_set_loc(p, node, loc);
10408 10483
	    RB_OBJ_WRITTEN(p->ast, Qnil, node->nd_lit = reg_compile(p, src, options));
10409 10484
	}
10410 10485
	break;
......
10415 10490
	/* fall through */
10416 10491
      case NODE_DSTR:
10417 10492
	nd_set_type(node, NODE_DREGX);
10418
	nd_set_loc(node, loc);
10493
	nd_set_loc(p, node, loc);
10419 10494
	node->nd_cflag = options & RE_OPTION_MASK;
10420 10495
	if (!NIL_P(node->nd_lit)) reg_fragment_check(p, node->nd_lit, options);
10421 10496
	for (list = (prev = node)->nd_next; list; list = list->nd_next) {
......
10474 10549
    switch (nd_type(node)) {
10475 10550
      case NODE_STR:
10476 10551
	nd_set_type(node, NODE_XSTR);
10477
	nd_set_loc(node, loc);
10552
	nd_set_loc(p, node, loc);
10478 10553
	break;
10479 10554
      case NODE_DSTR:
10480 10555
	nd_set_type(node, NODE_DXSTR);
10481
	nd_set_loc(node, loc);
10556
	nd_set_loc(p, node, loc);
10482 10557
	break;
10483 10558
      default:
10484 10559
	node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node, loc), loc);
......
11300 11375
      case NODE_MASGN:
11301 11376
      case NODE_CVASGN:
11302 11377
	lhs->nd_value = rhs;
11303
	nd_set_loc(lhs, loc);
11378
	nd_set_loc(p, lhs, loc);
11304 11379
	break;
11305 11380

  
11306 11381
      case NODE_ATTRASGN:
11307 11382
	lhs->nd_args = arg_append(p, lhs->nd_args, rhs, loc);
11308
	nd_set_loc(lhs, loc);
11383
	nd_set_loc(p, lhs, loc);
11309 11384
	break;
11310 11385

  
11311 11386
      default:
......
11892 11967
    args->ruby2_keywords = rest_arg == idFWD_REST;
11893 11968

  
11894 11969
    p->ruby_sourceline = saved_line;
11895
    nd_set_loc(tail, loc);
11970
    nd_set_loc(p, tail, loc);
11896 11971

  
11897 11972
    return tail;
11898 11973
}
......
11968 12043
	if (!args) {
11969 12044
	    YYLTYPE loc = RUBY_INIT_YYLLOC();
11970 12045
	    args = new_args_tail(p, 0, 0, 0, 0);
11971
	    nd_set_loc(args, &loc);
12046
	    nd_set_loc(p, args, &loc);
11972 12047
	}
11973 12048
	args->nd_ainfo->pre_args_num = max_numparam;
11974 12049
    }
......
12104 12179
    switch (nd_type(node)) {
12105 12180
      case NODE_DSTR:
12106 12181
	nd_set_type(node, NODE_DSYM);
12107
	nd_set_loc(node, loc);
12182
	nd_set_loc(p, node, loc);
12108 12183
	break;
12109 12184
      case NODE_STR:
12110 12185
	lit = node->nd_lit;
12111 12186
	RB_OBJ_WRITTEN(p->ast, Qnil, node->nd_lit = ID2SYM(rb_intern_str(lit)));
12112 12187
	nd_set_type(node, NODE_LIT);
12113
	nd_set_loc(node, loc);
12188
	nd_set_loc(p, node, loc);
12114 12189
	break;
12115 12190
      default:
12116 12191
	node = NEW_NODE(NODE_DSYM, Qnil, 1, NEW_LIST(node, loc), loc);
......
12236 12311
	if (op == tOROP) {
12237 12312
	    rhs = shareable_constant_value(p, shareable, lhs, rhs, &rhs->nd_loc);
12238 12313
	    lhs->nd_value = rhs;
12239
	    nd_set_loc(lhs, loc);
12314
	    nd_set_loc(p, lhs, loc);
12240 12315
	    asgn = NEW_OP_ASGN_OR(gettable(p, vid, &lhs_loc), lhs, loc);
12241 12316
	    if (is_notop_id(vid)) {
12242 12317
		switch (id_type(vid)) {
......
12252 12327
		rhs = shareable_constant_value(p, shareable, lhs, rhs, &rhs->nd_loc);
12253 12328
	    }
12254 12329
	    lhs->nd_value = rhs;
12255
	    nd_set_loc(lhs, loc);
12330
	    nd_set_loc(p, lhs, loc);
12256 12331
	    asgn = NEW_OP_ASGN_AND(gettable(p, vid, &lhs_loc), lhs, loc);
12257 12332
	}
12258 12333
	else {
......
12262 12337
		rhs = shareable_constant_value(p, shareable, lhs, rhs, &rhs->nd_loc);
12263 12338
	    }
12264 12339
	    asgn->nd_value = rhs;
12265
	    nd_set_loc(asgn, loc);
12340
	    nd_set_loc(p, asgn, loc);
12266 12341
	}
12267 12342
    }
12268 12343
    else {