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

ruby-changes:36073

From: nobu <ko1@a...>
Date: Mon, 27 Oct 2014 15:26:11 +0900 (JST)
Subject: [ruby-changes:36073] nobu:r48154 (trunk): id.h.tmpl: ANDOP and OROP

nobu	2014-10-27 15:25:59 +0900 (Mon, 27 Oct 2014)

  New Revision: 48154

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

  Log:
    id.h.tmpl: ANDOP and OROP
    
    * template/id.h.tmpl (token_op_ids): define && and || for ripper.

  Modified files:
    trunk/parse.y
    trunk/symbol.c
    trunk/template/id.h.tmpl
Index: symbol.c
===================================================================
--- symbol.c	(revision 48153)
+++ symbol.c	(revision 48154)
@@ -51,6 +51,8 @@ static ID register_static_symid_str(ID, https://github.com/ruby/ruby/blob/trunk/symbol.c#L51
 #define tLSHFT  RUBY_TOKEN(LSHFT)
 #define tRSHFT  RUBY_TOKEN(RSHFT)
 #define tCOLON2 RUBY_TOKEN(COLON2)
+#define tANDOP  RUBY_TOKEN(ANDOP)
+#define tOROP   RUBY_TOKEN(OROP)
 
 static const struct {
     unsigned short token;
@@ -74,6 +76,8 @@ static const struct { https://github.com/ruby/ruby/blob/trunk/symbol.c#L76
     {tLSHFT,	"<<"},
     {tRSHFT,	">>"},
     {tCOLON2,   "::"},
+    {tANDOP,    "&&"},
+    {tOROP,     "||"},
 };
 
 #define op_tbl_count numberof(op_tbl)
Index: parse.y
===================================================================
--- parse.y	(revision 48153)
+++ parse.y	(revision 48154)
@@ -801,8 +801,8 @@ static void token_info_pop(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L801
 %token tNEQ		RUBY_TOKEN(NEQ)    "!="
 %token tGEQ		RUBY_TOKEN(GEQ)    ">="
 %token tLEQ		RUBY_TOKEN(LEQ)    "<="
-%token tANDOP		"&&"
-%token tOROP		"||"
+%token tANDOP		RUBY_TOKEN(ANDOP)  "&&"
+%token tOROP		RUBY_TOKEN(OROP)   "||"
 %token tMATCH		RUBY_TOKEN(MATCH)  "=~"
 %token tNMATCH		RUBY_TOKEN(NMATCH) "!~"
 %token tDOT2		RUBY_TOKEN(DOT2)   ".."
@@ -2298,7 +2298,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2298
 		    /*%%%*/
 			$$ = logop(NODE_AND, $1, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("&&"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idANDOP), $3);
 		    %*/
 		    }
 		| arg tOROP arg
@@ -2306,7 +2306,7 @@ arg		: lhs '=' arg https://github.com/ruby/ruby/blob/trunk/parse.y#L2306
 		    /*%%%*/
 			$$ = logop(NODE_OR, $1, $3);
 		    /*%
-			$$ = dispatch3(binary, $1, ripper_intern("||"), $3);
+			$$ = dispatch3(binary, $1, ID2SYM(idOROP), $3);
 		    %*/
 		    }
 		| keyword_defined opt_nl {in_defined = 1;} arg
@@ -10718,20 +10718,10 @@ ripper_id2sym(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L10718
     if ((name = keyword_id_to_str(id))) {
         return ID2SYM(rb_intern(name));
     }
-    switch (id) {
-      case tOROP:
-        name = "||";
-        break;
-      case tANDOP:
-        name = "&&";
-        break;
-      default:
-        if (!rb_id2str(id)) {
-            rb_bug("cannot convert ID to string: %ld", (unsigned long)id);
-        }
-        return ID2SYM(id);
+    if (!rb_id2str(id)) {
+	rb_bug("cannot convert ID to string: %ld", (unsigned long)id);
     }
-    return ID2SYM(rb_intern(name));
+    return ID2SYM(id);
 }
 
 static ID
Index: template/id.h.tmpl
===================================================================
--- template/id.h.tmpl	(revision 48153)
+++ template/id.h.tmpl	(revision 48154)
@@ -18,7 +18,7 @@ op_id_offset = 128 https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L18
 token_op_ids = %w[
   tDOT2 tDOT3 tUPLUS tUMINUS tPOW tDSTAR tCMP tLSHFT tRSHFT
   tLEQ tGEQ tEQ tEQQ tNEQ tMATCH tNMATCH tAREF tASET
-  tCOLON2 tCOLON3
+  tCOLON2 tCOLON3 tANDOP tOROP
 ]
 
 defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
@@ -92,6 +92,8 @@ enum ruby_method_ids { https://github.com/ruby/ruby/blob/trunk/template/id.h.tmpl#L92
     idAREF = RUBY_TOKEN(AREF),
     idASET = RUBY_TOKEN(ASET),
     idCOLON2 = RUBY_TOKEN(COLON2),
+    idANDOP = RUBY_TOKEN(ANDOP),
+    idOROP = RUBY_TOKEN(OROP),
     tPRESERVED_ID_BEGIN = <%=op_id_offset + token_op_ids.size - 1%>,
 % ids[:preserved].each do |token|
     id<%=token%>,

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

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