Skip to content

Commit

Permalink
move PL_expect and PL_copline into the PL_parser structure
Browse files Browse the repository at this point in the history
p4raw-id: //depot/perl@31134
  • Loading branch information
Dave Mitchell committed May 4, 2007
1 parent d932dae commit 53a7735
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 91 deletions.
4 changes: 0 additions & 4 deletions embedvar.h
Expand Up @@ -171,7 +171,6 @@
#define PL_comppad_name_fill (vTHX->Icomppad_name_fill)
#define PL_comppad_name_floor (vTHX->Icomppad_name_floor)
#define PL_cop_seqmax (vTHX->Icop_seqmax)
#define PL_copline (vTHX->Icopline)
#define PL_cryptseen (vTHX->Icryptseen)
#define PL_cshlen (vTHX->Icshlen)
#define PL_cshname (vTHX->Icshname)
Expand Down Expand Up @@ -206,7 +205,6 @@
#define PL_exit_flags (vTHX->Iexit_flags)
#define PL_exitlist (vTHX->Iexitlist)
#define PL_exitlistlen (vTHX->Iexitlistlen)
#define PL_expect (vTHX->Iexpect)
#define PL_fdpid (vTHX->Ifdpid)
#define PL_filemode (vTHX->Ifilemode)
#define PL_forkprocess (vTHX->Iforkprocess)
Expand Down Expand Up @@ -436,7 +434,6 @@
#define PL_Icomppad_name_fill PL_comppad_name_fill
#define PL_Icomppad_name_floor PL_comppad_name_floor
#define PL_Icop_seqmax PL_cop_seqmax
#define PL_Icopline PL_copline
#define PL_Icryptseen PL_cryptseen
#define PL_Icshlen PL_cshlen
#define PL_Icshname PL_cshname
Expand Down Expand Up @@ -471,7 +468,6 @@
#define PL_Iexit_flags PL_exit_flags
#define PL_Iexitlist PL_exitlist
#define PL_Iexitlistlen PL_exitlistlen
#define PL_Iexpect PL_expect
#define PL_Ifdpid PL_fdpid
#define PL_Ifilemode PL_filemode
#define PL_Iforkprocess PL_forkprocess
Expand Down
10 changes: 10 additions & 0 deletions ext/Devel/PPPort/parts/inc/variables
Expand Up @@ -93,6 +93,12 @@ __NEED_VAR__ U32 PL_signals = D_PPP_PERL_SIGNALS_INIT;
/* Replace: 0 */
#endif

#if { VERSION >= 5.9.5 }
# define PL_PARSER_EXISTS
# define PL_expect (PL_parser ? PL_parser->expect : 0)
# define PL_copline (PL_parser ? PL_parser->copline : 0)
#endif

=xsinit

#define NEED_PL_signals
Expand Down Expand Up @@ -211,7 +217,11 @@ other_variables()
ppp_TESTVAR(PL_dirty);
ppp_TESTVAR(PL_dowarn);
ppp_TESTVAR(PL_errgv);
#ifdef PL_PARSER_EXISTS
ppp_TESTVAR(PL_parser); /* just any var that isn't PL_expect */
#else
ppp_TESTVAR(PL_expect);
#endif
ppp_TESTVAR(PL_laststatval);
ppp_TESTVAR(PL_no_modify);
ppp_TESTVAR(PL_perl_destruct_level);
Expand Down
8 changes: 4 additions & 4 deletions intrpvar.h
Expand Up @@ -178,7 +178,6 @@ PERLVAR(Ieval_start, OP *)

/* runtime control stuff */
PERLVARI(Icurcopdb, COP *, NULL)
PERLVARI(Icopline, line_t, NOLINE)

/* statics moved here for shared library purposes */
PERLVARI(Igensym, I32, 0) /* next symbol for getsym() to define */
Expand Down Expand Up @@ -305,10 +304,11 @@ PERLVAR(Ioldbufptr, char *)
PERLVAR(Ioldoldbufptr, char *)
PERLVAR(Ibufend, char *)

PERLVARI(Iexpect, U8, XSTATE) /* how to interpret ambiguous tokens */
PERLVAR(Ilex_state, U8) /* next token is determined */
PERLVAR(Ierror_count, U8) /* how many errors so far, max 10 */
PERLVARI(Icv_has_eval, bool, FALSE) /* PL_compcv includes an entereval or similar */
/* Space for one more U8 here without increasing the structure size */

PERLVAR(Imulti_end, I32) /* last line of multi-line string */

PERLVAR(Isubname, SV *) /* name of current subroutine */
Expand Down Expand Up @@ -537,8 +537,8 @@ PERLVARI(Islab_count, U32, 0) /* Size of the array */

PERLVARI(Iisarev, HV*, NULL) /* Reverse map of @ISA dependencies */

/* If you are adding a U16, see the comment above on where there are 2 bytes
of gap which currently will be structure padding. */
/* If you are adding a U8 or U16, see the 'Space' comments above on where
* there are gaps which currently will be structure padding. */

/* Within a stable branch, new variables must be added to the very end, before
* this comment, for binary compatibility (the offsets of the old members must
Expand Down
68 changes: 36 additions & 32 deletions op.c
Expand Up @@ -782,8 +782,8 @@ S_scalarboolean(pTHX_ OP *o)
if (ckWARN(WARN_SYNTAX)) {
const line_t oldline = CopLINE(PL_curcop);

if (PL_copline != NOLINE)
CopLINE_set(PL_curcop, PL_copline);
if (PL_parser && PL_parser->copline != NOLINE)
CopLINE_set(PL_curcop, PL_parser->copline);
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Found = in conditional, should be ==");
CopLINE_set(PL_curcop, oldline);
}
Expand Down Expand Up @@ -1818,7 +1818,6 @@ S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs, bool for_my)

/* fake up C<use attributes $pkg,$rv,@attrs> */
ENTER; /* need to protect against side-effects of 'use' */
SAVEI8(PL_expect);
stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no;

#define ATTRSMODULE "attributes"
Expand Down Expand Up @@ -3653,8 +3652,8 @@ Perl_package(pTHX_ OP *o)
sv_setsv(PL_curstname, sv);

PL_hints |= HINT_BLOCK_SCOPE;
PL_copline = NOLINE;
PL_expect = XSTATE;
PL_parser->copline = NOLINE;
PL_parser->expect = XSTATE;

#ifndef PERL_MAD
op_free(o);
Expand Down Expand Up @@ -3778,8 +3777,8 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
*/

PL_hints |= HINT_BLOCK_SCOPE;
PL_copline = NOLINE;
PL_expect = XSTATE;
PL_parser->copline = NOLINE;
PL_parser->expect = XSTATE;
PL_cop_seqmax++; /* Purely for B::*'s benefit */

#ifdef PERL_MAD
Expand Down Expand Up @@ -3857,17 +3856,19 @@ Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args)
sv = va_arg(*args, SV*);
}
}
{
const line_t ocopline = PL_copline;
COP * const ocurcop = PL_curcop;
const U8 oexpect = PL_expect;

utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
veop, modname, imop);
PL_expect = oexpect;
PL_copline = ocopline;
PL_curcop = ocurcop;
}
/* utilize() fakes up a BEGIN { require ..; import ... }, so make sure
* that it has a PL_parser to play with while doing that, and also
* that it doesn't mess with any existing parser, by creating a tmp
* new parser with lex_start(). This won't actually be used for much,
* since pp_require() will create another parser for the real work. */

ENTER;
SAVEVPTR(PL_curcop);
lex_start(NULL);
utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
veop, modname, imop);
LEAVE;
}

OP *
Expand Down Expand Up @@ -4176,11 +4177,12 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
HINTS_REFCNT_UNLOCK;
}

if (PL_copline == NOLINE)
if (PL_parser && PL_parser->copline == NOLINE)
CopLINE_set(cop, CopLINE(PL_curcop));
else {
CopLINE_set(cop, PL_copline);
PL_copline = NOLINE;
CopLINE_set(cop, PL_parser->copline);
if (PL_parser)
PL_parser->copline = NOLINE;
}
#ifdef USE_ITHREADS
CopFILE_set(cop, CopFILE(PL_curcop)); /* XXX share in a pvtable? */
Expand Down Expand Up @@ -4326,7 +4328,7 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
}
if (warnop) {
const line_t oldline = CopLINE(PL_curcop);
CopLINE_set(PL_curcop, PL_copline);
CopLINE_set(PL_curcop, PL_parser->copline);
Perl_warner(aTHX_ packWARN(WARN_MISC),
"Value of %s%s can be \"0\"; test with defined()",
PL_op_desc[warnop],
Expand Down Expand Up @@ -4595,7 +4597,7 @@ whileline, OP *expr, OP *block, OP *cont, I32 has_my)
redo = LINKLIST(listop);

if (expr) {
PL_copline = (line_t)whileline;
PL_parser->copline = (line_t)whileline;
scalar(listop);
o = new_logop(OP_AND, 0, &expr, &listop);
if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) {
Expand Down Expand Up @@ -4754,7 +4756,7 @@ Perl_newFOROP(pTHX_ I32 flags, char *label, line_t forline, OP *sv, OP *expr, OP
wop = newWHILEOP(flags, 1, loop, forline, newOP(OP_ITER, 0), block, cont, 0);
if (madsv)
op_getmad(madsv, (OP*)loop, 'v');
PL_copline = forline;
PL_parser->copline = forline;
return newSTATEOP(0, label, wop);
}

Expand Down Expand Up @@ -5318,8 +5320,8 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
&& (!const_sv || sv_cmp(cv_const_sv(cv), const_sv))))
{
const line_t oldline = CopLINE(PL_curcop);
if (PL_copline != NOLINE)
CopLINE_set(PL_curcop, PL_copline);
if (PL_parser && PL_parser->copline != NOLINE)
CopLINE_set(PL_curcop, PL_parser->copline);
Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
CvCONST(cv) ? "Constant subroutine %s redefined"
: "Subroutine %s redefined", name);
Expand Down Expand Up @@ -5539,7 +5541,8 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
}

done:
PL_copline = NOLINE;
if (PL_parser)
PL_parser->copline = NOLINE;
LEAVE_SCOPE(floor);
return cv;
}
Expand Down Expand Up @@ -5635,7 +5638,7 @@ Perl_newCONSTSUB(pTHX_ HV *stash, const char *name, SV *sv)
ENTER;

SAVECOPLINE(PL_curcop);
CopLINE_set(PL_curcop, PL_copline);
CopLINE_set(PL_curcop, PL_parser ? PL_parser->copline : NOLINE);

SAVEHINTS();
PL_hints &= ~HINT_BLOCK_SCOPE;
Expand Down Expand Up @@ -5748,8 +5751,8 @@ Perl_newXS(pTHX_ const char *name, XSUBADDR_t subaddr, const char *filename)
const char *redefined_name = HvNAME_get(stash);
if ( strEQ(redefined_name,"autouse") ) {
const line_t oldline = CopLINE(PL_curcop);
if (PL_copline != NOLINE)
CopLINE_set(PL_curcop, PL_copline);
if (PL_parser && PL_parser->copline != NOLINE)
CopLINE_set(PL_curcop, PL_parser->copline);
Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
CvCONST(cv) ? "Constant subroutine %s redefined"
: "Subroutine %s redefined"
Expand Down Expand Up @@ -5815,8 +5818,8 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
if ((cv = GvFORM(gv))) {
if (ckWARN(WARN_REDEFINE)) {
const line_t oldline = CopLINE(PL_curcop);
if (PL_copline != NOLINE)
CopLINE_set(PL_curcop, PL_copline);
if (PL_parser && PL_parser->copline != NOLINE)
CopLINE_set(PL_curcop, PL_parser->copline);
Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
o ? "Format %"SVf" redefined"
: "Format STDOUT redefined", SVfARG(cSVOPo->op_sv));
Expand All @@ -5843,7 +5846,8 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
#else
op_free(o);
#endif
PL_copline = NOLINE;
if (PL_parser)
PL_parser->copline = NOLINE;
LEAVE_SCOPE(floor);
#ifdef PERL_MAD
return pegop;
Expand Down
2 changes: 2 additions & 0 deletions parser.h
Expand Up @@ -45,6 +45,7 @@ typedef struct yy_parser {
U8 lex_defer; /* state after determined token */
bool lex_dojoin; /* doing an array interpolation */
U8 lex_expect; /* expect after determined token */
U8 expect; /* how to interpret ambiguous tokens */
I32 lex_formbrack; /* bracket count at outer format level */
OP *lex_inpat; /* in pattern $) and $| are special */
OP *lex_op; /* extra info to pass back on op */
Expand All @@ -59,6 +60,7 @@ typedef struct yy_parser {
bool preambled;
SUBLEXINFO sublex_info;
SV *linestr; /* current chunk of src text */
line_t copline; /* current line number */

#ifdef PERL_MAD
SV *endwhite;
Expand Down
4 changes: 0 additions & 4 deletions perlapi.h
Expand Up @@ -218,8 +218,6 @@ END_EXTERN_C
#define PL_comppad_name_floor (*Perl_Icomppad_name_floor_ptr(aTHX))
#undef PL_cop_seqmax
#define PL_cop_seqmax (*Perl_Icop_seqmax_ptr(aTHX))
#undef PL_copline
#define PL_copline (*Perl_Icopline_ptr(aTHX))
#undef PL_cryptseen
#define PL_cryptseen (*Perl_Icryptseen_ptr(aTHX))
#undef PL_cshlen
Expand Down Expand Up @@ -288,8 +286,6 @@ END_EXTERN_C
#define PL_exitlist (*Perl_Iexitlist_ptr(aTHX))
#undef PL_exitlistlen
#define PL_exitlistlen (*Perl_Iexitlistlen_ptr(aTHX))
#undef PL_expect
#define PL_expect (*Perl_Iexpect_ptr(aTHX))
#undef PL_fdpid
#define PL_fdpid (*Perl_Ifdpid_ptr(aTHX))
#undef PL_filemode
Expand Down

0 comments on commit 53a7735

Please sign in to comment.