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

ruby-changes:40684

From: nobu <ko1@a...>
Date: Fri, 27 Nov 2015 11:23:31 +0900 (JST)
Subject: [ruby-changes:40684] nobu:r52763 (trunk): parse.y: reduce ifdefs

nobu	2015-11-27 11:22:57 +0900 (Fri, 27 Nov 2015)

  New Revision: 52763

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

  Log:
    parse.y: reduce ifdefs
    
    * parse.y (dispatch_ignored_scan_event, has_delayed_token): more
      macros to reduce ifdefs.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 52762)
+++ parse.y	(revision 52763)
@@ -5223,7 +5223,9 @@ ripper_yylval_id(ID x) https://github.com/ruby/ruby/blob/trunk/parse.y#L5223
 #ifndef RIPPER
 #define ripper_flush(p) (void)(p)
 #define dispatch_scan_event(t) ((void)0)
+#define dispatch_ignored_scan_event(t) ((void)0)
 #define dispatch_delayed_token(t) ((void)0)
+#define has_delayed_token() (0)
 #else
 #define ripper_flush(p) ((p)->tokp = (p)->lex.pcur)
 
@@ -5267,6 +5269,7 @@ ripper_dispatch_ignored_scan_event(struc https://github.com/ruby/ruby/blob/trunk/parse.y#L5269
     if (!ripper_has_scan_event(parser)) return;
     (void)ripper_scan_event_val(parser, t);
 }
+#define dispatch_ignored_scan_event(t) ripper_dispatch_ignored_scan_event(parser, t)
 
 static void
 ripper_dispatch_delayed_token(struct parser_params *parser, int t)
@@ -5282,6 +5285,7 @@ ripper_dispatch_delayed_token(struct par https://github.com/ruby/ruby/blob/trunk/parse.y#L5285
     parser->tokp = saved_tokp;
 }
 #define dispatch_delayed_token(t) ripper_dispatch_delayed_token(parser, t)
+#define has_delayed_token() (!NIL_P(parser->delayed))
 #endif /* RIPPER */
 
 #include "ruby/regex.h"
@@ -5747,7 +5751,7 @@ parser_nextc(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L5751
 	{
 #ifdef RIPPER
 	    if (parser->tokp < lex_pend) {
-		if (NIL_P(parser->delayed)) {
+		if (!has_delayed_token()) {
 		    parser->delayed = rb_str_buf_new(1024);
 		    rb_enc_associate(parser->delayed, current_enc);
 		    rb_str_buf_cat(parser->delayed,
@@ -6322,12 +6326,12 @@ ripper_flush_string_content(struct parse https://github.com/ruby/ruby/blob/trunk/parse.y#L6326
     VALUE content = yylval.val;
     if (!ripper_is_node_yylval(content))
 	content = ripper_new_yylval(0, 0, content);
-    if (!NIL_P(parser->delayed)) {
+    if (has_delayed_token()) {
 	ptrdiff_t len = lex_p - parser->tokp;
 	if (len > 0) {
 	    rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
 	}
-	ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
+	dispatch_delayed_token(tSTRING_CONTENT);
 	parser->tokp = lex_p;
 	RNODE(content)->nd_rval = yylval.val;
     }
@@ -6623,10 +6627,10 @@ parser_set_integer_literal(struct parser https://github.com/ruby/ruby/blob/trunk/parse.y#L6627
 static void
 ripper_dispatch_heredoc_end(struct parser_params *parser)
 {
-    if (!NIL_P(parser->delayed))
-	ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
+    if (has_delayed_token())
+	dispatch_delayed_token(tSTRING_CONTENT);
     lex_goto_eol(parser);
-    ripper_dispatch_ignored_scan_event(parser, tHEREDOC_END);
+    dispatch_ignored_scan_event(tHEREDOC_END);
 }
 
 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
@@ -6651,7 +6655,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6655
       error:
 	compile_error(PARSER_ARG "can't find string \"%s\" anywhere before EOF", eos);
 #ifdef RIPPER
-	if (NIL_P(parser->delayed)) {
+	if (!has_delayed_token()) {
 	    dispatch_scan_event(tSTRING_CONTENT);
 	}
 	else {
@@ -6670,7 +6674,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6674
 		}
 		rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
 	    }
-	    ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
+	    dispatch_delayed_token(tSTRING_CONTENT);
 	}
 	lex_goto_eol(parser);
 #endif
@@ -8569,14 +8573,10 @@ yylex(YYSTYPE *lval, struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L8573
     parser->lval = lval;
     lval->val = Qundef;
     t = parser_yylex(parser);
-#ifdef RIPPER
-    if (!NIL_P(parser->delayed)) {
-	ripper_dispatch_delayed_token(parser, t);
-	return t;
-    }
-    if (t != 0)
-	ripper_dispatch_scan_event(parser, t);
-#endif
+    if (has_delayed_token())
+	dispatch_delayed_token(t);
+    else if (t != 0)
+	dispatch_scan_event(t);
 
     return t;
 }

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

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