Project

General

Profile

Misc #10287 ยป colon3-colon2head.diff

git diff - arimay (yasuhiro arima), 09/23/2014 04:06 PM

View differences:

bootstraptest/test_class.rb
109 109
assert_equal '1',       %q( C = 1   # [yarv-dev:800]
110 110
                            begin module C; end; rescue TypeError; 1 end )
111 111

  
112
# colon2, colon3
112
# colon2, colon2_head
113 113
assert_equal '1',       %q( class A; end;  A::C = 1;  A::C )
114 114
assert_equal '1',       %q( A = 7;  begin A::C = 7; rescue TypeError; 1 end )
115 115
assert_equal '1',       %q( begin 7::C = 7; rescue TypeError; 1 end )
compile.c
2788 2788
	debugi("compile_colon2 - colon", node->nd_vid);
2789 2789
	ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_vid));
2790 2790
	break;
2791
      case NODE_COLON3:
2792
	debugi("compile_colon2 - colon3", node->nd_mid);
2791
      case NODE_COLON2_HEAD:
2792
	debugi("compile_colon2 - colon2_head", node->nd_mid);
2793 2793
	ADD_INSN(body, nd_line(node), pop);
2794 2794
	ADD_INSN1(body, nd_line(node), putobject, rb_cObject);
2795 2795
	ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
......
2809 2809
static VALUE
2810 2810
compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath)
2811 2811
{
2812
    if (nd_type(cpath) == NODE_COLON3) {
2812
    if (nd_type(cpath) == NODE_COLON2_HEAD) {
2813 2813
	/* toplevel class ::Foo */
2814 2814
	ADD_INSN1(ret, nd_line(cpath), putobject, rb_cObject);
2815 2815
	return Qfalse;
......
2921 2921
		      ID2SYM(node->nd_mid), needstr);
2922 2922
	}
2923 2923
	return 1;
2924
      case NODE_COLON3:
2924
      case NODE_COLON2_HEAD:
2925 2925
	ADD_INSN1(ret, nd_line(node), putobject, rb_cObject);
2926 2926
	ADD_INSN3(ret, nd_line(node), defined,
2927 2927
		  INT2FIX(DEFINED_CONST), ID2SYM(node->nd_mid), needstr);
......
4253 4253
	ID mid;
4254 4254

  
4255 4255
	switch (nd_type(node->nd_head)) {
4256
	  case NODE_COLON3:
4256
	  case NODE_COLON2_HEAD:
4257 4257
	    ADD_INSN1(ret, line, putobject, rb_cObject);
4258 4258
	    break;
4259 4259
	  case NODE_COLON2:
......
5139 5139
	}
5140 5140
	break;
5141 5141
      }
5142
      case NODE_COLON3:{
5142
      case NODE_COLON2_HEAD:{
5143 5143
	LABEL *lend = NEW_LABEL(line);
5144 5144
	int ic_index = iseq->is_size++;
5145 5145

  
5146
	debugi("colon3#nd_mid", node->nd_mid);
5146
	debugi("colon2_head#nd_mid", node->nd_mid);
5147 5147

  
5148 5148
	/* add cache insn */
5149 5149
	if (iseq->compile_data->option->inline_const_cache) {
ext/objspace/objspace.c
387 387
		COUNT_NODE(NODE_MODULE);
388 388
		COUNT_NODE(NODE_SCLASS);
389 389
		COUNT_NODE(NODE_COLON2);
390
		COUNT_NODE(NODE_COLON3);
390
		COUNT_NODE(NODE_COLON2_HEAD);
391 391
		COUNT_NODE(NODE_CREF);
392 392
		COUNT_NODE(NODE_DOT2);
393 393
		COUNT_NODE(NODE_DOT3);
ext/ripper/eventids2.c
203 203
    {tCHAR,		&ripper_id_CHAR},
204 204
    {tCMP,		&ripper_id_op},
205 205
    {tCOLON2,		&ripper_id_op},
206
    {tCOLON3,		&ripper_id_op},
206
    {tCOLON2_HEAD,	&ripper_id_op},
207 207
    {tCONSTANT,		&ripper_id_const},
208 208
    {tCVAR,		&ripper_id_cvar},
209 209
    {tDOT2,		&ripper_id_op},
lib/irb/ruby-lex.rb
547 547
       |op, io|
548 548
      if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen
549 549
        @lex_state = EXPR_BEG
550
        Token(TkCOLON3)
550
        Token(TkCOLON2_HEAD)
551 551
      else
552 552
        @lex_state = EXPR_DOT
553 553
        Token(TkCOLON2)
lib/irb/ruby-token.rb
185 185
    [:TkLSHFT,      TkOp,   "<<"],
186 186
    [:TkRSHFT,      TkOp,   ">>"],
187 187
    [:TkCOLON2,     TkOp],
188
    [:TkCOLON3,     TkOp],
188
    [:TkCOLON2_HEAD,TkOp],
189 189
    [:TkASSOC,      TkOp,   "=>"],
190 190
    [:TkQUESTION,   TkOp,   "?"],	 #?
191 191
    [:TkCOLON,      TkOp,   ":"],        #:
lib/rdoc/parser/ruby.rb
333 333

  
334 334
    # class ::A -> A is in the top level
335 335
    case name_t
336
    when TkCOLON2, TkCOLON3 then # bug
336
    when TkCOLON2, TkCOLON2_HEAD then # bug
337 337
      name_t = get_tk
338 338
      container = @top_level
339 339
      given_name << '::'
......
404 404
    skip_tkspace false
405 405
    tk = get_tk
406 406

  
407
    while TkCOLON2 === tk or TkCOLON3 === tk or TkCONSTANT === tk do
407
    while TkCOLON2 === tk or TkCOLON2_HEAD === tk or TkCONSTANT === tk do
408 408
      res += tk.name
409 409
      tk = get_tk
410 410
    end
......
933 933
          unget_tk tk
934 934
          break
935 935
        end
936
      when TkCOLON2, TkCOLON3 then
936
      when TkCOLON2, TkCOLON2_HEAD then
937 937
        rhs_name << '::'
938 938
      when nil then
939 939
        break
lib/rdoc/ruby_lex.rb
633 633
      #      p @lex_state.id2name, @space_seen
634 634
      if @lex_state == :EXPR_BEG or @lex_state == :EXPR_ARG && @space_seen
635 635
        @lex_state = :EXPR_BEG
636
        Token(TkCOLON3)
636
        Token(TkCOLON2_HEAD)
637 637
      else
638 638
        @lex_state = :EXPR_DOT
639 639
        Token(TkCOLON2)
lib/rdoc/ruby_token.rb
363 363
    [:TkLSHFT,      TkOp,   "<<"],
364 364
    [:TkRSHFT,      TkOp,   ">>"],
365 365
    [:TkCOLON2,     TkOp,   '::'],
366
    [:TkCOLON3,     TkOp,   '::'],
366
    [:TkCOLON2_HEAD,TkOp,   '::'],
367 367
    #[:OPASGN,       TkOp],               # +=, -=  etc. #
368 368
    [:TkASSOC,      TkOp,   "=>"],
369 369
    [:TkQUESTION,   TkOp,   "?"], #?
node.c
707 707
	F_NODE(nd_head, "receiver");
708 708
	break;
709 709

  
710
      case NODE_COLON3:
710
      case NODE_COLON2_HEAD:
711 711
	ANN("top-level constant reference");
712 712
	ANN("format: ::[nd_mid]");
713 713
	ANN("example: ::Object");
......
1002 1002
      case NODE_IASGN:
1003 1003
      case NODE_IASGN2:
1004 1004
      case NODE_CVASGN:
1005
      case NODE_COLON3:
1005
      case NODE_COLON2_HEAD:
1006 1006
      case NODE_OPT_N:
1007 1007
      case NODE_EVSTR:
1008 1008
      case NODE_UNDEF:
node.h
190 190
#define NODE_SCLASS      NODE_SCLASS
191 191
    NODE_COLON2,
192 192
#define NODE_COLON2      NODE_COLON2
193
    NODE_COLON3,
194
#define NODE_COLON3      NODE_COLON3
193
    NODE_COLON2_HEAD,
194
#define NODE_COLON2_HEAD NODE_COLON2_HEAD
195 195
    NODE_CREF,
196 196
#define NODE_CREF        NODE_CREF
197 197
    NODE_DOT2,
......
448 448
#define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(0,b),0)
449 449
#define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(0,b),0)
450 450
#define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
451
#define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
451
#define NEW_COLON2_HEAD(i) NEW_NODE(NODE_COLON2_HEAD,0,i,0)
452 452
#define NEW_CREF(a) NEW_NODE(NODE_CREF,a,0,0)
453 453
#define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0)
454 454
#define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0)
parse.y
807 807
%token tLSHFT		RUBY_TOKEN(LSHFT)  "<<"
808 808
%token tRSHFT		RUBY_TOKEN(RSHFT)  ">>"
809 809
%token tCOLON2		"::"
810
%token tCOLON3		":: at EXPR_BEG"
810
%token tCOLON2_HEAD	":: at EXPR_BEG"
811 811
%token <id> tOP_ASGN	/* +=, -=  etc. */
812 812
%token tASSOC		"=>"
813 813
%token tLPAREN		"("
......
1685 1685
			}
1686 1686
		    %*/
1687 1687
		    }
1688
		| tCOLON3 tCONSTANT
1688
		| tCOLON2_HEAD tCONSTANT
1689 1689
		    {
1690 1690
		    /*%%%*/
1691 1691
			if (in_def || in_single)
1692 1692
			    yyerror("dynamic constant assignment");
1693
			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1693
			$$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2));
1694 1694
		    /*%
1695 1695
			$$ = dispatch1(top_const_field, $2);
1696 1696
			if (in_def || in_single) {
......
1773 1773
			}
1774 1774
		    %*/
1775 1775
		    }
1776
		| tCOLON3 tCONSTANT
1776
		| tCOLON2_HEAD tCONSTANT
1777 1777
		    {
1778 1778
		    /*%%%*/
1779 1779
			if (in_def || in_single)
1780 1780
			    yyerror("dynamic constant assignment");
1781
			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1781
			$$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2));
1782 1782
		    /*%
1783 1783
			$$ = dispatch1(top_const_field, $2);
1784 1784
			if (in_def || in_single) {
......
1808 1808
		| tCONSTANT
1809 1809
		;
1810 1810

  
1811
cpath		: tCOLON3 cname
1811
cpath		: tCOLON2_HEAD cname
1812 1812
		    {
1813 1813
		    /*%%%*/
1814
			$$ = NEW_COLON3($2);
1814
			$$ = NEW_COLON2_HEAD($2);
1815 1815
		    /*%
1816 1816
			$$ = dispatch1(top_const_ref, $2);
1817 1817
		    %*/
......
2017 2017
			$$ = dispatch3(opassign, $$, $4, $5);
2018 2018
		    %*/
2019 2019
		    }
2020
		| tCOLON3 tCONSTANT tOP_ASGN arg
2020
		| tCOLON2_HEAD tCONSTANT tOP_ASGN arg
2021 2021
		    {
2022 2022
		    /*%%%*/
2023
			$$ = NEW_COLON3($2);
2023
			$$ = NEW_COLON2_HEAD($2);
2024 2024
			$$ = new_const_op_assign($$, $3, $4);
2025 2025
		    /*%
2026 2026
			$$ = dispatch1(top_const_field, $2);
......
2652 2652
			$$ = dispatch2(const_path_ref, $1, $3);
2653 2653
		    %*/
2654 2654
		    }
2655
		| tCOLON3 tCONSTANT
2655
		| tCOLON2_HEAD tCONSTANT
2656 2656
		    {
2657 2657
		    /*%%%*/
2658
			$$ = NEW_COLON3($2);
2658
			$$ = NEW_COLON2_HEAD($2);
2659 2659
		    /*%
2660 2660
			$$ = dispatch1(top_const_ref, $2);
2661 2661
		    %*/
......
8124 8124
	if (c == ':') {
8125 8125
	    if (IS_BEG() || IS_lex_state(EXPR_CLASS) || IS_SPCARG(-1)) {
8126 8126
		lex_state = EXPR_BEG;
8127
		return tCOLON3;
8127
		return tCOLON2_HEAD;
8128 8128
	    }
8129 8129
	    lex_state = EXPR_DOT;
8130 8130
	    return tCOLON2;
......
9099 9099
	useless = "a literal";
9100 9100
	break;
9101 9101
      case NODE_COLON2:
9102
      case NODE_COLON3:
9102
      case NODE_COLON2_HEAD:
9103 9103
	useless = "::";
9104 9104
	break;
9105 9105
      case NODE_DOT2:
template/id.h.tmpl
18 18
token_op_ids = %w[
19 19
  tDOT2 tDOT3 tUPLUS tUMINUS tPOW tDSTAR tCMP tLSHFT tRSHFT
20 20
  tLEQ tGEQ tEQ tEQQ tNEQ tMATCH tNMATCH tAREF tASET
21
  tCOLON2 tCOLON3
21
  tCOLON2 tCOLON2_HEAD
22 22
]
23 23

  
24 24
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
test/rdoc/test_rdoc_parser_ruby.rb
869 869
    assert_empty foo.comment
870 870
  end
871 871

  
872
  def test_parse_class_colon3
872
  def test_parse_class_colon2_head
873 873
    code = <<-CODE
874 874
class A
875 875
  class ::B
......
884 884
    assert_equal %w[A B], @store.all_classes.map { |c| c.full_name }.sort
885 885
  end
886 886

  
887
  def test_parse_class_colon3_self_reference
887
  def test_parse_class_colon2_head_self_reference
888 888
    code = <<-CODE
889 889
class A::B
890 890
  class ::A