This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Rework LOOPX macro
authorFather Chrysostomos <sprout@cpan.org>
Fri, 22 Aug 2014 01:19:31 +0000 (18:19 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 25 Aug 2014 02:02:56 +0000 (19:02 -0700)
All its callers have the same two lines preceding it, so fold them
into the macro.  Only assign to PL_expect after the force_word call if
force_word did not find a word.  (If it did find one, then force_next
would have recorded the previous PL_expect value, which will clobber
the one we have just assigned.)

toke.c

diff --git a/toke.c b/toke.c
index b5efb7a..8ac5b0b 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -217,7 +217,11 @@ static const char* const lex_state_names[] = {
 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
 #define POSTDEREF(f) return (PL_bufptr = s, S_postderef(aTHX_ REPORT(f),s[1]))
-#define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
+#define LOOPX(f) return (PL_expect = XOPERATOR, \
+                        PL_bufptr = force_word(s,WORD,TRUE,FALSE), \
+                        pl_yylval.ival=f, \
+                        (void)(PL_nexttoke || (PL_expect = XTERM)), \
+                        REPORT((int)LOOPEX))
 #define FTST(f)  return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
 #define FUN0(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
 #define FUN0OP(f)  return (pl_yylval.opval=f, CLINE, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0OP))
@@ -7084,8 +7088,6 @@ Perl_yylex(pTHX)
            UNI(OP_DBMCLOSE);
 
        case KEY_dump:
-           PL_expect = XOPERATOR;
-           s = force_word(s,WORD,TRUE,FALSE);
            LOOPX(OP_DUMP);
 
        case KEY_else:
@@ -7209,8 +7211,6 @@ Perl_yylex(pTHX)
            LOP(OP_GREPSTART, XREF);
 
        case KEY_goto:
-           PL_expect = XOPERATOR;
-           s = force_word(s,WORD,TRUE,FALSE);
            LOOPX(OP_GOTO);
 
        case KEY_gmtime:
@@ -7335,8 +7335,6 @@ Perl_yylex(pTHX)
            LOP(OP_KILL,XTERM);
 
        case KEY_last:
-           PL_expect = XOPERATOR;
-           s = force_word(s,WORD,TRUE,FALSE);
            LOOPX(OP_LAST);
        
        case KEY_lc:
@@ -7435,8 +7433,6 @@ Perl_yylex(pTHX)
            OPERATOR(MY);
 
        case KEY_next:
-           PL_expect = XOPERATOR;
-           s = force_word(s,WORD,TRUE,FALSE);
            LOOPX(OP_NEXT);
 
        case KEY_ne:
@@ -7647,8 +7643,6 @@ Perl_yylex(pTHX)
            UNI(OP_RESET);
 
        case KEY_redo:
-           PL_expect = XOPERATOR;
-           s = force_word(s,WORD,TRUE,FALSE);
            LOOPX(OP_REDO);
 
        case KEY_rename: