[前][次][番号順一覧][スレッド一覧]

ruby-changes:31555

From: nobu <ko1@a...>
Date: Sun, 10 Nov 2013 15:13:11 +0900 (JST)
Subject: [ruby-changes:31555] nobu:r43634 (trunk): parse.y: remove "f" suffix [Feature #9042]

nobu	2013-11-10 15:13:02 +0900 (Sun, 10 Nov 2013)

  New Revision: 43634

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43634

  Log:
    parse.y: remove "f" suffix [ruby-core:57966] [Feature #9042]
    
    revert r42847 "test_string.rb: add test string encoding"
    
    revert r42846 "parse.y: freeze in advance to reduce objects"
    
    revert r42843 "parse.y: deduplicate frozen string literals"
    
    revert r42780 "test_string.rb: yet another test"
    
    revert r42779 "parse.y: valid suffix word only"
    
    revert r42778 "test_string.rb: remove duplicated code"
    
    revert r42775 "parse.y: force_encoding"
    
    This reverts commit 93ea04ecec7639ca8d0e58948e78461434782ecc.
    
    revert r42773 "Add frozen string literals"

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/compile.c
    trunk/ext/ripper/eventids2.c
    trunk/parse.y
    trunk/test/ripper/test_scanner_events.rb
    trunk/test/ruby/test_string.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43633)
+++ ChangeLog	(revision 43634)
@@ -2865,8 +2865,6 @@ Thu Sep  5 17:25:49 2013  Nobuyoshi Naka https://github.com/ruby/ruby/blob/trunk/ChangeLog#L2865
 
 	* string.c (rb_fstring): get rid of duplicating already frozen object.
 
-	* parse.y (str_suffix_gen): freeze in advance to reduce objects.
-
 Thu Sep  5 14:01:22 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/optparse.rb:  The Integer acceptable now allows binary and
@@ -2884,8 +2882,6 @@ Thu Sep  5 13:49:00 2013  Charlie Somerv https://github.com/ruby/ruby/blob/trunk/ChangeLog#L2882
 
 	* internal.h: add rb_fstring() prototype
 
-	* parse.y (str_suffix_gen): deduplicate frozen string literals
-
 	* string.c (rb_fstring): deduplicate frozen string literals
 
 	* string.c (rb_str_free): delete fstrings from frozen_strings table when
@@ -2893,8 +2889,6 @@ Thu Sep  5 13:49:00 2013  Charlie Somerv https://github.com/ruby/ruby/blob/trunk/ChangeLog#L2889
 
 	* string.c (Init_String): initialize frozen_strings table
 
-	* test/ruby/test_string.rb: test frozen strings are deduplicated
-
 Thu Sep  5 12:48:00 2013  Kenta Murata  <mrkn@c...>
 
 	* configure.in (with_gmp): set with_gmp no if it is empty.
@@ -3178,11 +3172,6 @@ Mon Sep  2 23:46:29 2013  Akinori MUSHA https://github.com/ruby/ruby/blob/trunk/ChangeLog#L3172
 
 	* numeric.c (num_step): Optimize for infinite loop.
 
-Mon Sep  2 23:46:10 2013  Nobuyoshi Nakada  <nobu@r...>
-
-	* parse.y (parser_str_options): use valid suffix word only, as well as
-	  numeric literal, for the backward compatibility.
-
 Mon Sep  2 22:55:59 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (ISDIGIT): Unused macro removed.
@@ -3193,28 +3182,6 @@ Mon Sep  2 22:49:15 2013  Tanaka Akira https://github.com/ruby/ruby/blob/trunk/ChangeLog#L3182
 	  (str2big_normal): Ditto.
 	  (str2big_karatsuba): Ditto.
 
-Mon Sep  2 17:53:33 2013  Nobuyoshi Nakada  <nobu@r...>
-
-	* parse.y (str_suffix_gen): String#b creates new string object, use
-	  force_encoding instead.
-
-Mon Sep  2 16:06:00 2013  Charlie Somerville  <charliesome@r...>
-
-	* NEWS: Add note about frozen string literals
-
-	* compile.c (case_when_optimizable_literal): optimize NODE_LIT strings
-	  in when clauses of case statements
-
-	* ext/ripper/eventids2.c: add tSTRING_SUFFIX
-
-	* parse.y: add 'f' suffix on string literals for frozen strings
-
-	* test/ripper/test_scanner_events.rb: add scanner tests
-
-	* test/ruby/test_string.rb: add frozen string tests
-
-	[Feature #8579] [ruby-core:55699]
-
 Mon Sep  2 14:39:29 2013  Akinori MUSHA  <knu@i...>
 
 	* ruby.c (Process#setproctitle): [DOC] Fix and improve rdoc.
Index: compile.c
===================================================================
--- compile.c	(revision 43633)
+++ compile.c	(revision 43634)
@@ -2508,8 +2508,7 @@ case_when_optimizable_literal(NODE * nod https://github.com/ruby/ruby/blob/trunk/compile.c#L2508
 	    modf(RFLOAT_VALUE(v), &ival) == 0.0) {
 	    return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
 	}
-	if (SYMBOL_P(v) || RB_TYPE_P(v, T_STRING) ||
-	    rb_obj_is_kind_of(v, rb_cNumeric)) {
+	if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
 	    return v;
 	}
 	break;
Index: parse.y
===================================================================
--- parse.y	(revision 43633)
+++ parse.y	(revision 43634)
@@ -400,8 +400,6 @@ static NODE *new_evstr_gen(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L400
 #define new_evstr(n) new_evstr_gen(parser,(n))
 static NODE *evstr2dstr_gen(struct parser_params*,NODE*);
 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
-static NODE *str_suffix_gen(struct parser_params*, NODE*, long);
-#define str_suffix(n,o) str_suffix_gen(parser,(n),(o))
 static NODE *splat_array(NODE*);
 
 static NODE *call_bin_op_gen(struct parser_params*,NODE*,ID,NODE*);
@@ -533,9 +531,6 @@ static int lvar_defined_gen(struct parse https://github.com/ruby/ruby/blob/trunk/parse.y#L531
 #define RE_OPTION_MASK  0xff
 #define RE_OPTION_ARG_ENCODING_NONE 32
 
-#define STR_OPTION_FROZEN 1
-#define STR_OPTION_BINARY 0	/* disabled */
-
 #define NODE_STRTERM NODE_ZARRAY	/* nothing to gc */
 #define NODE_HEREDOC NODE_ARRAY 	/* 1, 3 to gc */
 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
@@ -763,7 +758,7 @@ static void token_info_pop(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L758
 %token <id>   tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
 %token <node> tINTEGER tFLOAT tRATIONAL tIMAGINARY tSTRING_CONTENT tCHAR
 %token <node> tNTH_REF tBACK_REF
-%token <num>  tREGEXP_END tSTRING_SUFFIX
+%token <num>  tREGEXP_END
 
 %type <node> singleton strings string string1 xstring regexp
 %type <node> string_contents xstring_contents regexp_contents string_content
@@ -789,7 +784,6 @@ static void token_info_pop(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L784
 %type <id>   fsym keyword_variable user_variable sym symbol operation operation2 operation3
 %type <id>   cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
 %type <id>   f_kwrest f_label
-%type <num>  opt_string_sfx
 /*%%%*/
 /*%
 %type <val> program reswords then do dot_or_colon
@@ -3812,7 +3806,7 @@ literal		: numeric https://github.com/ruby/ruby/blob/trunk/parse.y#L3806
 		| dsym
 		;
 
-strings 	: string opt_string_sfx
+strings		: string
 		    {
 		    /*%%%*/
 			NODE *node = $1;
@@ -3822,7 +3816,6 @@ strings 	: string opt_string_sfx https://github.com/ruby/ruby/blob/trunk/parse.y#L3816
 			else {
 			    node = evstr2dstr(node);
 			}
-			node = str_suffix(node, $2);
 			$$ = node;
 		    /*%
 			$$ = $1;
@@ -3852,10 +3845,6 @@ string1		: tSTRING_BEG string_contents t https://github.com/ruby/ruby/blob/trunk/parse.y#L3845
 		    }
 		;
 
-opt_string_sfx	: tSTRING_SUFFIX
-		| /* none */ {$$ = 0;}
-		;
-
 xstring		: tXSTRING_BEG xstring_contents tSTRING_END
 		    {
 		    /*%%%*/
@@ -5019,7 +5008,6 @@ none		: /* none */ https://github.com/ruby/ruby/blob/trunk/parse.y#L5008
 # define yylval  (*((YYSTYPE*)(parser->parser_yylval)))
 
 static int parser_regx_options(struct parser_params*);
-static int parser_str_options(struct parser_params*);
 static int parser_tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**);
 static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc);
 static int parser_parse_string(struct parser_params*,NODE*);
@@ -5035,7 +5023,6 @@ static int parser_here_document(struct p https://github.com/ruby/ruby/blob/trunk/parse.y#L5023
 # define read_escape(flags,e)         parser_read_escape(parser, (flags), (e))
 # define tokadd_escape(e)             parser_tokadd_escape(parser, (e))
 # define regx_options()               parser_regx_options(parser)
-# define str_options()                parser_str_options(parser)
 # define tokadd_string(f,t,p,n,e)     parser_tokadd_string(parser,(f),(t),(p),(n),(e))
 # define parse_string(n)              parser_parse_string(parser,(n))
 # define tokaddmbc(c, enc)            parser_tokaddmbc(parser, (c), (enc))
@@ -5545,11 +5532,10 @@ rb_parser_compile_file_path(volatile VAL https://github.com/ruby/ruby/blob/trunk/parse.y#L5532
 #define STR_FUNC_QWORDS 0x08
 #define STR_FUNC_SYMBOL 0x10
 #define STR_FUNC_INDENT 0x20
-#define STR_FUNC_OPTION 0x40
 
 enum string_type {
-    str_squote = (STR_FUNC_OPTION),
-    str_dquote = (STR_FUNC_EXPAND|STR_FUNC_OPTION),
+    str_squote = (0),
+    str_dquote = (STR_FUNC_EXPAND),
     str_xquote = (STR_FUNC_EXPAND),
     str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
     str_sword  = (STR_FUNC_QWORDS),
@@ -5996,33 +5982,6 @@ parser_regx_options(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5982
     return options | RE_OPTION_ENCODING(kcode);
 }
 
-static int
-parser_str_options(struct parser_params *parser)
-{
-    int c, options = 0;
-    const char *save_p = lex_p;
-
-    while (c = nextc(), ISALPHA(c)) {
-	switch (c) {
-#if STR_OPTION_FROZEN
-	  case 'f':
-	    options |= STR_OPTION_FROZEN;
-	    break;
-#endif
-#if STR_OPTION_BINARY
-	  case 'b':
-	    options |= STR_OPTION_BINARY;
-	    break;
-#endif
-	  default:
-	    lex_p = save_p;
-	    return 0;
-        }
-    }
-    pushback(c);
-    return options;
-}
-
 static void
 dispose_string(VALUE str)
 {
@@ -6289,10 +6248,6 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6248
     rb_encoding *enc = current_enc;
 
     if (func == -1) return tSTRING_END;
-    if (func == 0) {
-	set_yylval_num(term);
-	return tSTRING_SUFFIX;
-    }
     c = nextc();
     if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
 	do {c = nextc();} while (ISSPACE(c));
@@ -6301,18 +6256,11 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6256
     if (c == term && !quote->nd_nest) {
 	if (func & STR_FUNC_QWORDS) {
 	    quote->nd_func = -1;
-	    quote->u2.id = 0;
 	    return ' ';
 	}
-	if (func & STR_FUNC_REGEXP) {
-	    set_yylval_num(regx_options());
-	    return tREGEXP_END;
-	}
-	if ((func & STR_FUNC_OPTION) && (func = str_options()) != 0) {
-	    quote->nd_func = 0;
-	    quote->u2.id = func;
-	}
-	return tSTRING_END;
+	if (!(func & STR_FUNC_REGEXP)) return tSTRING_END;
+        set_yylval_num(regx_options());
+	return tREGEXP_END;
     }
     if (space) {
 	pushback(c);
@@ -7000,8 +6948,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L6948
 	}
 	else {
 	    token = parse_string(lex_strterm);
-	    if ((token == tSTRING_END && lex_strterm->nd_func) ||
-		token == tSTRING_SUFFIX || token == tREGEXP_END) {
+	    if (token == tSTRING_END || token == tREGEXP_END) {
 		rb_gc_force_recycle((VALUE)lex_strterm);
 		lex_strterm = 0;
 		lex_state = EXPR_END;
@@ -8549,40 +8496,6 @@ evstr2dstr_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L8496
     }
     return node;
 }
-
-static NODE *
-str_suffix_gen(struct parser_params *parser, NODE *node, long opt)
-{
-    if (nd_type(node) == NODE_STR) {
-#if STR_OPTION_BINARY
-	if (opt & STR_OPTION_BINARY) {
-	    rb_enc_associate_index(node->nd_lit, ENCINDEX_ASCII);
-	}
-#endif
-#if STR_OPTION_FROZEN
-	if (opt & STR_OPTION_FROZEN) {
-	    OBJ_FREEZE(node->nd_lit);
-	    node->nd_lit = rb_fstring(node->nd_lit);
-	    nd_set_type(node, NODE_LIT);
-	}
-#endif
-    }
-    else {
-#if STR_OPTION_BINARY
-	if (opt & STR_OPTION_BINARY) {
-	    VALUE ascii8bit = rb_enc_from_encoding(rb_ascii8bit_encoding());
-	    NODE *args = NEW_LIST(NEW_LIT(ascii8bit));
-	    node = NEW_CALL(node, rb_intern("force_encoding"), args);
-	}
-#endif
-#if STR_OPTION_FROZEN
-	if (opt & STR_OPTION_FROZEN) {
-	    node = NEW_CALL(node, rb_intern("freeze"), 0);
-	}
-#endif
-    }
-    return node;
-}
 
 static NODE *
 new_evstr_gen(struct parser_params *parser, NODE *node)
Index: ext/ripper/eventids2.c
===================================================================
--- ext/ripper/eventids2.c	(revision 43633)
+++ ext/ripper/eventids2.c	(revision 43634)
@@ -37,7 +37,6 @@ static ID ripper_id_symbeg; https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L37
 static ID ripper_id_tstring_beg;
 static ID ripper_id_tstring_content;
 static ID ripper_id_tstring_end;
-static ID ripper_id_tstring_suffix;
 static ID ripper_id_words_beg;
 static ID ripper_id_qwords_beg;
 static ID ripper_id_qsymbols_beg;
@@ -95,7 +94,6 @@ ripper_init_eventids2(void) https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L94
     ripper_id_tstring_beg = rb_intern_const("on_tstring_beg");
     ripper_id_tstring_content = rb_intern_const("on_tstring_content");
     ripper_id_tstring_end = rb_intern_const("on_tstring_end");
-    ripper_id_tstring_suffix = rb_intern_const("on_tstring_suffix");
     ripper_id_words_beg = rb_intern_const("on_words_beg");
     ripper_id_qwords_beg = rb_intern_const("on_qwords_beg");
     ripper_id_qsymbols_beg = rb_intern_const("on_qsymbols_beg");
@@ -254,7 +252,6 @@ static const struct token_assoc { https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L252
     {tSTRING_DEND,	&ripper_id_embexpr_end},
     {tSTRING_DVAR,	&ripper_id_embvar},
     {tSTRING_END,	&ripper_id_tstring_end},
-    {tSTRING_SUFFIX,	&ripper_id_tstring_suffix},
     {tSYMBEG,		&ripper_id_symbeg},
     {tUMINUS,		&ripper_id_op},
     {tUMINUS_NUM,	&ripper_id_op},
Index: NEWS
===================================================================
--- NEWS	(revision 43633)
+++ NEWS	(revision 43634)
@@ -27,8 +27,6 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L27
 
 * def-expr now returns the symbol of its name instead of nil.
 
-* Added 'f' suffix for string literals that returns a frozen String object.
-
 === Core classes updates (outstanding ones only)
 
 * Array
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 43633)
+++ test/ruby/test_string.rb	(revision 43634)
@@ -2201,60 +2201,6 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2201
       })
     end
     assert_equal "hello", str
-    assert_not_predicate str, :frozen?
-  end
-
-  def test_frozen_string
-    assert_equal "hello", "hello"f
-
-    assert_predicate "hello"f, :frozen?
-
-    f = -> { "hello"f }
-
-    assert_equal f.call.object_id, f.call.object_id
-  end
-
-  def test_frozen_dstring
-    assert_equal "hello123", "hello#{123}"f
-
-    assert_predicate "hello#{123}"f, :frozen?
-
-    i = 0
-    f = -> { "#{i += 1}"f }
-    assert_equal "1", f.call
-    assert_equal "2", f.call
-  end
-
-  def test_frozen_string_adjacent
-    str = nil
-    assert_nothing_raised(SyntaxError) do
-      eval(%{
-        str = "hello" "world"f
-      })
-    end
-    assert_equal "helloworld", str
-    assert_predicate str, :frozen?
-  end
-
-  def test_frozen_string_cannot_be_adjacent
-    assert_raise(SyntaxError) do
-      eval(%{
-        "hello"f "world"
-      })
-    end
-  end
-
-  def test_frozen_strings_are_deduplicated
-    a = "hello"f
-    b = "hello"f
-    assert_equal a.object_id, b.object_id
-  end
-
-  def test_frozen_strings_are_deduplicated_with_encoding
-    a = eval("# coding: utf-8\n'hello'f")
-    b = eval("# coding: ascii\n'hello'f")
-    assert_equal Encoding::UTF_8, a.encoding
-    assert_equal Encoding::US_ASCII, b.encoding
   end
 
   def test_eq_tilde_can_be_overridden
Index: test/ripper/test_scanner_events.rb
===================================================================
--- test/ripper/test_scanner_events.rb	(revision 43633)
+++ test/ripper/test_scanner_events.rb	(revision 43634)
@@ -591,15 +591,6 @@ class TestRipper::ScannerEvents < Test:: https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L591
                  scan('tstring_end', '%Q[abcdef]')
   end
 
-  def test_tstring_suffix
-    assert_equal ['"f'],
-                 scan('tstring_end', '"abcdef"f')
-    assert_equal [']f'],
-                 scan('tstring_end', '%q[abcdef]f')
-    assert_equal [']f'],
-                 scan('tstring_end', '%Q[abcdef]f')
-  end
-
   def test_regexp_beg
     assert_equal [],
                  scan('regexp_beg', '')

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]