Project

General

Profile

Misc #10287 ยป colon2head-20141103a.patch

arimay (yasuhiro arima), 11/02/2014 05:12 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
2669 2669
	debugi("compile_colon2 - colon", node->nd_vid);
2670 2670
	ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_vid));
2671 2671
	break;
2672
      case NODE_COLON3:
2673
	debugi("compile_colon2 - colon3", node->nd_mid);
2672
      case NODE_COLON2_HEAD:
2673
	debugi("compile_colon2 - colon2_head", node->nd_mid);
2674 2674
	ADD_INSN(body, nd_line(node), pop);
2675 2675
	ADD_INSN1(body, nd_line(node), putobject, rb_cObject);
2676 2676
	ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
......
2690 2690
static VALUE
2691 2691
compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath)
2692 2692
{
2693
    if (nd_type(cpath) == NODE_COLON3) {
2693
    if (nd_type(cpath) == NODE_COLON2_HEAD) {
2694 2694
	/* toplevel class ::Foo */
2695 2695
	ADD_INSN1(ret, nd_line(cpath), putobject, rb_cObject);
2696 2696
	return Qfalse;
......
2802 2802
		      ID2SYM(node->nd_mid), needstr);
2803 2803
	}
2804 2804
	return 1;
2805
      case NODE_COLON3:
2805
      case NODE_COLON2_HEAD:
2806 2806
	ADD_INSN1(ret, nd_line(node), putobject, rb_cObject);
2807 2807
	ADD_INSN3(ret, nd_line(node), defined,
2808 2808
		  INT2FIX(DEFINED_CONST), ID2SYM(node->nd_mid), needstr);
......
4134 4134
	ID mid;
4135 4135

  
4136 4136
	switch (nd_type(node->nd_head)) {
4137
	  case NODE_COLON3:
4137
	  case NODE_COLON2_HEAD:
4138 4138
	    ADD_INSN1(ret, line, putobject, rb_cObject);
4139 4139
	    break;
4140 4140
	  case NODE_COLON2:
......
5020 5020
	}
5021 5021
	break;
5022 5022
      }
5023
      case NODE_COLON3:{
5023
      case NODE_COLON2_HEAD:{
5024 5024
	LABEL *lend = NEW_LABEL(line);
5025 5025
	int ic_index = iseq->is_size++;
5026 5026

  
5027
	debugi("colon3#nd_mid", node->nd_mid);
5027
	debugi("colon2_head#nd_mid", node->nd_mid);
5028 5028

  
5029 5029
	/* add cache insn */
5030 5030
	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
212 212
    {tCHAR,			O(CHAR)},
213 213
    {tCMP,			O(op)},
214 214
    {tCOLON2,			O(op)},
215
    {tCOLON3,			O(op)},
215
    {tCOLON2_HEAD,		O(op)},
216 216
    {tCONSTANT,			O(const)},
217 217
    {tCVAR,			O(cvar)},
218 218
    {tDOT2,			O(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
816 816
%token tLSHFT		RUBY_TOKEN(LSHFT)  "<<"
817 817
%token tRSHFT		RUBY_TOKEN(RSHFT)  ">>"
818 818
%token tCOLON2		"::"
819
%token tCOLON3		":: at EXPR_BEG"
819
%token tCOLON2_HEAD	":: at EXPR_BEG"
820 820
%token <id> tOP_ASGN	/* +=, -=  etc. */
821 821
%token tASSOC		"=>"
822 822
%token tLPAREN		"("
......
1697 1697
			}
1698 1698
		    %*/
1699 1699
		    }
1700
		| tCOLON3 tCONSTANT
1700
		| tCOLON2_HEAD tCONSTANT
1701 1701
		    {
1702 1702
		    /*%%%*/
1703 1703
			if (in_def || in_single)
1704 1704
			    yyerror("dynamic constant assignment");
1705
			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1705
			$$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2));
1706 1706
		    /*%
1707 1707
			$$ = dispatch1(top_const_field, $2);
1708 1708
			if (in_def || in_single) {
......
1788 1788
			}
1789 1789
		    %*/
1790 1790
		    }
1791
		| tCOLON3 tCONSTANT
1791
		| tCOLON2_HEAD tCONSTANT
1792 1792
		    {
1793 1793
		    /*%%%*/
1794 1794
			if (in_def || in_single)
1795 1795
			    yyerror("dynamic constant assignment");
1796
			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1796
			$$ = NEW_CDECL(0, 0, NEW_COLON2_HEAD($2));
1797 1797
		    /*%
1798 1798
			$$ = dispatch1(top_const_field, $2);
1799 1799
			if (in_def || in_single) {
......
1826 1826
		| tCONSTANT
1827 1827
		;
1828 1828

  
1829
cpath		: tCOLON3 cname
1829
cpath		: tCOLON2_HEAD cname
1830 1830
		    {
1831 1831
		    /*%%%*/
1832
			$$ = NEW_COLON3($2);
1832
			$$ = NEW_COLON2_HEAD($2);
1833 1833
		    /*%
1834 1834
			$$ = dispatch1(top_const_ref, $2);
1835 1835
		    %*/
......
2035 2035
			$$ = dispatch3(opassign, $$, $4, $5);
2036 2036
		    %*/
2037 2037
		    }
2038
		| tCOLON3 tCONSTANT tOP_ASGN arg
2038
		| tCOLON2_HEAD tCONSTANT tOP_ASGN arg
2039 2039
		    {
2040 2040
		    /*%%%*/
2041
			$$ = NEW_COLON3($2);
2041
			$$ = NEW_COLON2_HEAD($2);
2042 2042
			$$ = new_const_op_assign($$, $3, $4);
2043 2043
		    /*%
2044 2044
			$$ = dispatch1(top_const_field, $2);
......
2671 2671
			$$ = dispatch2(const_path_ref, $1, $3);
2672 2672
		    %*/
2673 2673
		    }
2674
		| tCOLON3 tCONSTANT
2674
		| tCOLON2_HEAD tCONSTANT
2675 2675
		    {
2676 2676
		    /*%%%*/
2677
			$$ = NEW_COLON3($2);
2677
			$$ = NEW_COLON2_HEAD($2);
2678 2678
		    /*%
2679 2679
			$$ = dispatch1(top_const_ref, $2);
2680 2680
		    %*/
......
8189 8189
	if (c == ':') {
8190 8190
	    if (IS_BEG() || IS_lex_state(EXPR_CLASS) || IS_SPCARG(-1)) {
8191 8191
		lex_state = EXPR_BEG;
8192
		return tCOLON3;
8192
		return tCOLON2_HEAD;
8193 8193
	    }
8194 8194
	    lex_state = EXPR_DOT;
8195 8195
	    return tCOLON2;
......
9174 9174
	useless = "a literal";
9175 9175
	break;
9176 9176
      case NODE_COLON2:
9177
      case NODE_COLON3:
9177
      case NODE_COLON2_HEAD:
9178 9178
	useless = "::";
9179 9179
	break;
9180 9180
      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 tANDOP tOROP
21
  tCOLON2 tCOLON2_HEAD tANDOP tOROP
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