X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=op.c;h=8f8e796ea20ac27c659d07875509abc080f788b8;hb=664bb207f6bd57f05b66c9abec00898987f7060b;hp=91e996eac2cdf40fcb33326e19dda0ec587adeea;hpb=864dbfa3ca8032ef66f7aa86961933b19b962357;p=p5sagit%2Fp5-mst-13.2.git diff --git a/op.c b/op.c index 91e996e..8f8e796 100644 --- a/op.c +++ b/op.c @@ -18,12 +18,7 @@ #include "EXTERN.h" #define PERL_IN_OP_C #include "perl.h" - -#ifdef PERL_OBJECT -#define CHECKCALL this->*PL_check -#else -#define CHECKCALL *PL_check -#endif +#include "keywords.h" /* #define PL_OP_SLAB_ALLOC */ @@ -38,7 +33,7 @@ static int PL_OpSpace = 0; } while (0) STATIC void * -Slab_Alloc(pTHX_ int m, size_t sz) +S_Slab_Alloc(pTHX_ int m, size_t sz) { Newz(m,PL_OpPtr,SLAB_SIZE,char); PL_OpSpace = SLAB_SIZE - sz; @@ -55,14 +50,14 @@ Slab_Alloc(pTHX_ int m, size_t sz) #define CHECKOP(type,o) \ ((PL_op_mask && PL_op_mask[type]) \ ? ( op_free((OP*)o), \ - croak("%s trapped by operation mask", PL_op_desc[type]), \ + Perl_croak(aTHX_ "%s trapped by operation mask", PL_op_desc[type]), \ Nullop ) \ - : (CHECKCALL[type])((OP*)o)) + : CALL_FPTR(PL_check[type])(aTHX_ (OP*)o)) #define PAD_MAX 999999999 STATIC char* -gv_ename(pTHX_ GV *gv) +S_gv_ename(pTHX_ GV *gv) { STRLEN n_a; SV* tmpsv = sv_newmortal(); @@ -71,61 +66,40 @@ gv_ename(pTHX_ GV *gv) } STATIC OP * -no_fh_allowed(pTHX_ OP *o) +S_no_fh_allowed(pTHX_ OP *o) { - yyerror(form("Missing comma after first argument to %s function", + yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function", PL_op_desc[o->op_type])); return o; } STATIC OP * -too_few_arguments(pTHX_ OP *o, char *name) +S_too_few_arguments(pTHX_ OP *o, char *name) { - yyerror(form("Not enough arguments for %s", name)); + yyerror(Perl_form(aTHX_ "Not enough arguments for %s", name)); return o; } STATIC OP * -too_many_arguments(pTHX_ OP *o, char *name) +S_too_many_arguments(pTHX_ OP *o, char *name) { - yyerror(form("Too many arguments for %s", name)); + yyerror(Perl_form(aTHX_ "Too many arguments for %s", name)); return o; } STATIC void -bad_type(pTHX_ I32 n, char *t, char *name, OP *kid) +S_bad_type(pTHX_ I32 n, char *t, char *name, OP *kid) { - yyerror(form("Type of arg %d to %s must be %s (not %s)", + yyerror(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)", (int)n, name, t, PL_op_desc[kid->op_type])); } STATIC void -no_bareword_allowed(pTHX_ OP *o) +S_no_bareword_allowed(pTHX_ OP *o) { - warn("Bareword \"%s\" not allowed while \"strict subs\" in use", - SvPV_nolen(cSVOPo->op_sv)); - ++PL_error_count; -} - -void -Perl_assertref(pTHX_ OP *o) -{ - int type = o->op_type; - if (type != OP_AELEM && type != OP_HELEM && type != OP_GELEM) { - yyerror(form("Can't use subscript on %s", PL_op_desc[type])); - if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) { - dTHR; - SV *msg = sv_2mortal( - newSVpvf("(Did you mean $ or @ instead of %c?)\n", - type == OP_ENTERSUB ? '&' : '%')); - if (PL_in_eval & EVAL_WARNONLY) - warn("%_", msg); - else if (PL_in_eval) - sv_catsv(GvSV(PL_errgv), msg); - else - PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg)); - } - } + qerror(Perl_mess(aTHX_ + "Bareword \"%s\" not allowed while \"strict subs\" in use", + SvPV_nolen(cSVOPo->op_sv))); } /* "register" allocation */ @@ -138,11 +112,12 @@ Perl_pad_allocmy(pTHX_ char *name) SV *sv; if (!( + PL_in_my == KEY_our || isALPHA(name[1]) || (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) || - name[1] == '_' && (int)strlen(name) > 2)) + name[1] == '_' && (int)strlen(name) > 2 )) { - if (!isPRINT(name[1])) { + if (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1])) { /* 1999-02-27 mjd@plover.com */ char *p; p = strchr(name, '\0'); @@ -161,7 +136,7 @@ Perl_pad_allocmy(pTHX_ char *name) name[2] = toCTRL(name[1]); name[1] = '^'; } - yyerror(form("Can't use global %s in \"my\"",name)); + yyerror(Perl_form(aTHX_ "Can't use global %s in \"my\"",name)); } if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) { SV **svp = AvARRAY(PL_comppad_name); @@ -171,9 +146,11 @@ Perl_pad_allocmy(pTHX_ char *name) && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) && strEQ(name, SvPVX(sv))) { - warner(WARN_UNSAFE, - "\"my\" variable %s masks earlier declaration in same %s", - name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement")); + Perl_warner(aTHX_ WARN_UNSAFE, + "\"%s\" variable %s masks earlier declaration in same %s", + (PL_in_my == KEY_our ? "our" : "my"), + name, + (SvIVX(sv) == PAD_MAX ? "scope" : "statement")); break; } } @@ -184,15 +161,17 @@ Perl_pad_allocmy(pTHX_ char *name) sv_setpv(sv, name); if (PL_in_my_stash) { if (*name != '$') - yyerror(form("Can't declare class for non-scalar %s in \"my\"", + yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"", name)); SvOBJECT_on(sv); (void)SvUPGRADE(sv, SVt_PVMG); SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash); PL_sv_objcount++; } + if (PL_in_my == KEY_our) + SvFLAGS(sv) |= SVpad_OUR; av_store(PL_comppad_name, off, sv); - SvNVX(sv) = (double)PAD_MAX; + SvNVX(sv) = (NV)PAD_MAX; SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */ if (!PL_min_intro_pending) PL_min_intro_pending = off; @@ -208,7 +187,7 @@ Perl_pad_allocmy(pTHX_ char *name) #define FINDLEX_NOSEARCH 1 /* don't search outer contexts */ STATIC PADOFFSET -pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv, +S_pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval, U32 flags) { dTHR; @@ -255,9 +234,11 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv, sv_upgrade(namesv, SVt_PVNV); sv_setpv(namesv, name); av_store(PL_comppad_name, newoff, namesv); - SvNVX(namesv) = (double)PL_curcop->cop_seq; + SvNVX(namesv) = (NV)PL_curcop->cop_seq; SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */ SvFAKE_on(namesv); /* A ref, not a real var */ + if (SvFLAGS(sv) & SVpad_OUR)/* An "our" variable */ + SvFLAGS(namesv) |= SVpad_OUR; if (SvOBJECT(sv)) { /* A typed var */ SvOBJECT_on(namesv); (void)SvUPGRADE(namesv, SVt_PVMG); @@ -283,7 +264,7 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv, if (ckWARN(WARN_CLOSURE) && !CvUNIQUE(bcv) && !CvUNIQUE(cv)) { - warner(WARN_CLOSURE, + Perl_warner(aTHX_ WARN_CLOSURE, "Variable \"%s\" may be unavailable", name); } @@ -294,7 +275,7 @@ pad_findlex(pTHX_ char *name, PADOFFSET newoff, U32 seq, CV* startcv, } else if (!CvUNIQUE(PL_compcv)) { if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv)) - warner(WARN_CLOSURE, + Perl_warner(aTHX_ WARN_CLOSURE, "Variable \"%s\" will not stay shared", name); } } @@ -382,7 +363,7 @@ Perl_pad_findmy(pTHX_ char *name) seq > I_32(SvNVX(sv)))) && strEQ(SvPVX(sv), name)) { - if (SvIVX(sv)) + if (SvIVX(sv) || SvFLAGS(sv) & SVpad_OUR) return (PADOFFSET)off; pendoff = off; /* this pending def. will override import */ } @@ -414,13 +395,14 @@ Perl_pad_findmy(pTHX_ char *name) void Perl_pad_leavemy(pTHX_ I32 fill) { + dTHR; I32 off; SV **svp = AvARRAY(PL_comppad_name); SV *sv; if (PL_min_intro_pending && fill < PL_min_intro_pending) { for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) { - if ((sv = svp[off]) && sv != &PL_sv_undef) - warn("%s never introduced", SvPVX(sv)); + if ((sv = svp[off]) && sv != &PL_sv_undef && ckWARN_d(WARN_INTERNAL)) + Perl_warner(aTHX_ WARN_INTERNAL, "%s never introduced", SvPVX(sv)); } } /* "Deintroduce" my variables that are leaving with this scope. */ @@ -438,7 +420,7 @@ Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype) I32 retval; if (AvARRAY(PL_comppad) != PL_curpad) - croak("panic: pad_alloc"); + Perl_croak(aTHX_ "panic: pad_alloc"); if (PL_pad_reset_pending) pad_reset(); if (tmptype & SVs_PADMY) { @@ -488,7 +470,7 @@ Perl_pad_sv(pTHX_ PADOFFSET po) (unsigned long) thr, (unsigned long) PL_curpad, po)); #else if (!po) - croak("panic: pad_sv po"); + Perl_croak(aTHX_ "panic: pad_sv po"); DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx sv %d\n", (unsigned long) PL_curpad, po)); #endif /* USE_THREADS */ @@ -502,9 +484,9 @@ Perl_pad_free(pTHX_ PADOFFSET po) if (!PL_curpad) return; if (AvARRAY(PL_comppad) != PL_curpad) - croak("panic: pad_free curpad"); + Perl_croak(aTHX_ "panic: pad_free curpad"); if (!po) - croak("panic: pad_free po"); + Perl_croak(aTHX_ "panic: pad_free po"); #ifdef USE_THREADS DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx free %d\n", (unsigned long) thr, (unsigned long) PL_curpad, po)); @@ -523,9 +505,9 @@ Perl_pad_swipe(pTHX_ PADOFFSET po) { dTHR; if (AvARRAY(PL_comppad) != PL_curpad) - croak("panic: pad_swipe curpad"); + Perl_croak(aTHX_ "panic: pad_swipe curpad"); if (!po) - croak("panic: pad_swipe po"); + Perl_croak(aTHX_ "panic: pad_swipe po"); #ifdef USE_THREADS DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx swipe %d\n", (unsigned long) thr, (unsigned long) PL_curpad, po)); @@ -554,7 +536,7 @@ Perl_pad_reset(pTHX) register I32 po; if (AvARRAY(PL_comppad) != PL_curpad) - croak("panic: pad_reset curpad"); + Perl_croak(aTHX_ "panic: pad_reset curpad"); #ifdef USE_THREADS DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx reset\n", (unsigned long) thr, (unsigned long) PL_curpad)); @@ -647,6 +629,7 @@ void Perl_op_free(pTHX_ OP *o) { register OP *kid, *nextkid; + OPCODE type; if (!o || o->op_seq == (U16)-1) return; @@ -657,42 +640,57 @@ Perl_op_free(pTHX_ OP *o) op_free(kid); } } + type = o->op_type; + if (type == OP_NULL) + type = o->op_targ; + + /* COP* is not cleared by op_clear() so that we may track line + * numbers etc even after null() */ + if (type == OP_NEXTSTATE || type == OP_SETSTATE || type == OP_DBSTATE) + cop_free((COP*)o); + + op_clear(o); +#ifdef PL_OP_SLAB_ALLOC + if ((char *) o == PL_OpPtr) + { + } +#else + Safefree(o); +#endif +} + +STATIC void +S_op_clear(pTHX_ OP *o) +{ switch (o->op_type) { - case OP_NULL: - o->op_targ = 0; /* Was holding old type, if any. */ - break; - case OP_ENTEREVAL: - o->op_targ = 0; /* Was holding hints. */ + case OP_NULL: /* Was holding old type, if any. */ + case OP_ENTEREVAL: /* Was holding hints. */ +#ifdef USE_THREADS + case OP_THREADSV: /* Was holding index into thr->threadsv AV. */ +#endif + o->op_targ = 0; break; #ifdef USE_THREADS case OP_ENTERITER: if (!(o->op_flags & OPf_SPECIAL)) break; /* FALL THROUGH */ - case OP_THREADSV: - o->op_targ = 0; /* Was holding index into thr->threadsv AV. */ - break; #endif /* USE_THREADS */ default: if (!(o->op_flags & OPf_REF) - || (PL_check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst))) + || (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst))) break; /* FALL THROUGH */ case OP_GVSV: case OP_GV: case OP_AELEMFAST: SvREFCNT_dec(cGVOPo->op_gv); - break; - case OP_NEXTSTATE: - case OP_DBSTATE: - Safefree(cCOPo->cop_label); - SvREFCNT_dec(cCOPo->cop_filegv); - if (cCOPo->cop_warnings != WARN_NONE && cCOPo->cop_warnings != WARN_ALL) - SvREFCNT_dec(cCOPo->cop_warnings); + cGVOPo->op_gv = Nullgv; break; case OP_CONST: SvREFCNT_dec(cSVOPo->op_sv); + cSVOPo->op_sv = Nullsv; break; case OP_GOTO: case OP_NEXT: @@ -702,38 +700,46 @@ Perl_op_free(pTHX_ OP *o) break; /* FALL THROUGH */ case OP_TRANS: - if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) + if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) { SvREFCNT_dec(cSVOPo->op_sv); - else + cSVOPo->op_sv = Nullsv; + } + else { Safefree(cPVOPo->op_pv); + cPVOPo->op_pv = Nullch; + } break; case OP_SUBST: op_free(cPMOPo->op_pmreplroot); + cPMOPo->op_pmreplroot = Nullop; /* FALL THROUGH */ case OP_PUSHRE: case OP_MATCH: case OP_QR: ReREFCNT_dec(cPMOPo->op_pmregexp); + cPMOPo->op_pmregexp = (REGEXP*)NULL; break; } if (o->op_targ > 0) pad_free(o->op_targ); +} -#ifdef PL_OP_SLAB_ALLOC - if ((char *) o == PL_OpPtr) - { - } -#else - Safefree(o); -#endif +STATIC void +S_cop_free(pTHX_ COP* cop) +{ + Safefree(cop->cop_label); + SvREFCNT_dec(cop->cop_filegv); + if (! specialWARN(cop->cop_warnings)) + SvREFCNT_dec(cop->cop_warnings); } STATIC void -null(pTHX_ OP *o) +S_null(pTHX_ OP *o) { - if (o->op_type != OP_NULL && o->op_type != OP_THREADSV && o->op_targ > 0) - pad_free(o->op_targ); + if (o->op_type == OP_NULL) + return; + op_clear(o); o->op_targ = o->op_type; o->op_type = OP_NULL; o->op_ppaddr = PL_ppaddr[OP_NULL]; @@ -779,7 +785,7 @@ Perl_scalarkids(pTHX_ OP *o) } STATIC OP * -scalarboolean(pTHX_ OP *o) +S_scalarboolean(pTHX_ OP *o) { if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) { dTHR; @@ -788,7 +794,7 @@ scalarboolean(pTHX_ OP *o) if (PL_copline != NOLINE) PL_curcop->cop_line = PL_copline; - warner(WARN_SYNTAX, "Found = in conditional, should be =="); + Perl_warner(aTHX_ WARN_SYNTAX, "Found = in conditional, should be =="); PL_curcop->cop_line = oldline; } } @@ -805,6 +811,10 @@ Perl_scalar(pTHX_ OP *o) || o->op_type == OP_RETURN) return o; + if ((o->op_private & OPpTARGET_MY) + && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */ + return scalar(o); /* As if inside SASSIGN */ + o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR; switch (o->op_type) { @@ -870,9 +880,12 @@ Perl_scalarvoid(pTHX_ OP *o) SV* sv; U8 want; - if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE || - (o->op_type == OP_NULL && - (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE))) + if (o->op_type == OP_NEXTSTATE + || o->op_type == OP_SETSTATE + || o->op_type == OP_DBSTATE + || (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE + || o->op_targ == OP_SETSTATE + || o->op_targ == OP_DBSTATE))) { dTHR; PL_curcop = (COP*)o; /* for warning below */ @@ -884,6 +897,10 @@ Perl_scalarvoid(pTHX_ OP *o) || o->op_type == OP_RETURN) return o; + if ((o->op_private & OPpTARGET_MY) + && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */ + return scalar(o); /* As if inside SASSIGN */ + o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID; switch (o->op_type) { @@ -998,8 +1015,7 @@ Perl_scalarvoid(pTHX_ OP *o) } } } - null(o); /* don't execute a constant */ - SvREFCNT_dec(sv); /* don't even remember it */ + null(o); /* don't execute or even remember it */ break; case OP_POSTINC: @@ -1057,7 +1073,7 @@ Perl_scalarvoid(pTHX_ OP *o) if (useless) { dTHR; if (ckWARN(WARN_VOID)) - warner(WARN_VOID, "Useless use of %s in void context", useless); + Perl_warner(aTHX_ WARN_VOID, "Useless use of %s in void context", useless); } return o; } @@ -1083,6 +1099,10 @@ Perl_list(pTHX_ OP *o) || o->op_type == OP_RETURN) return o; + if ((o->op_private & OPpTARGET_MY) + && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */ + return o; /* As if inside SASSIGN */ + o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST; switch (o->op_type) { @@ -1169,7 +1189,7 @@ Perl_scalarseq(pTHX_ OP *o) } STATIC OP * -modkids(pTHX_ OP *o, I32 type) +S_modkids(pTHX_ OP *o, I32 type) { OP *kid; if (o && o->op_flags & OPf_KIDS) { @@ -1190,6 +1210,10 @@ Perl_mod(pTHX_ OP *o, I32 type) if (!o || PL_error_count) return o; + if ((o->op_private & OPpTARGET_MY) + && (PL_opargs[o->op_type] & OA_TARGLEX)) /* OPp share the meaning */ + return o; + switch (o->op_type) { case OP_UNDEF: PL_modcount++; @@ -1208,7 +1232,7 @@ Perl_mod(pTHX_ OP *o, I32 type) else if (type == OP_REFGEN) goto nomod; else - croak("That use of $[ is unsupported"); + Perl_croak(aTHX_ "That use of $[ is unsupported"); break; case OP_STUB: if (o->op_flags & OPf_PARENS) @@ -1223,15 +1247,103 @@ Perl_mod(pTHX_ OP *o, I32 type) null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */ break; } + else { /* lvalue subroutine call */ + o->op_private |= OPpLVAL_INTRO; + if (type == OP_GREPSTART || type == OP_ENTERSUB) { + /* Backward compatibility mode: */ + o->op_private |= OPpENTERSUB_INARGS; + break; + } + else { /* Compile-time error message: */ + OP *kid = cUNOPo->op_first; + CV *cv; + OP *okid; + + if (kid->op_type == OP_PUSHMARK) + goto skip_kids; + if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST) + Perl_croak(aTHX_ + "panic: unexpected lvalue entersub " + "args: type/targ %ld:%ld", + (long)kid->op_type,kid->op_targ); + kid = kLISTOP->op_first; + skip_kids: + while (kid->op_sibling) + kid = kid->op_sibling; + if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) { + /* Indirect call */ + if (kid->op_type == OP_METHOD_NAMED + || kid->op_type == OP_METHOD) + { + OP *newop; + + if (kid->op_sibling || kid->op_next != kid) { + yyerror("panic: unexpected optree near method call"); + break; + } + + NewOp(1101, newop, 1, OP); + newop->op_type = OP_RV2CV; + newop->op_ppaddr = PL_ppaddr[OP_RV2CV]; + newop->op_next = newop; + kid->op_sibling = newop; + newop->op_private |= OPpLVAL_INTRO; + break; + } + + if (kid->op_type != OP_RV2CV) + Perl_croak(aTHX_ + "panic: unexpected lvalue entersub " + "entry via type/targ %ld:%ld", + (long)kid->op_type,kid->op_targ); + kid->op_private |= OPpLVAL_INTRO; + break; /* Postpone until runtime */ + } + + okid = kid; + kid = kUNOP->op_first; + if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV) + kid = kUNOP->op_first; + if (kid->op_type == OP_NULL) + Perl_croak(aTHX_ + "Unexpected constant lvalue entersub " + "entry via type/targ %ld:%ld", + (long)kid->op_type,kid->op_targ); + if (kid->op_type != OP_GV) { + /* Restore RV2CV to check lvalueness */ + restore_2cv: + if (kid->op_next && kid->op_next != kid) { /* Happens? */ + okid->op_next = kid->op_next; + kid->op_next = okid; + } + else + okid->op_next = Nullop; + okid->op_type = OP_RV2CV; + okid->op_targ = 0; + okid->op_ppaddr = PL_ppaddr[OP_RV2CV]; + okid->op_private |= OPpLVAL_INTRO; + break; + } + + cv = GvCV(kGVOP->op_gv); + if (!cv) + goto restore_2cv; + if (CvLVALUE(cv)) + break; + } + } /* FALL THROUGH */ default: nomod: /* grep, foreach, subcalls, refgen */ if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) break; - yyerror(form("Can't modify %s in %s", + yyerror(Perl_form(aTHX_ "Can't modify %s in %s", (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL) - ? "do block" : PL_op_desc[o->op_type]), + ? "do block" + : (o->op_type == OP_ENTERSUB + ? "non-lvalue subroutine call" + : PL_op_desc[o->op_type])), type ? PL_op_desc[type] : "local")); return o; @@ -1268,7 +1380,7 @@ Perl_mod(pTHX_ OP *o, I32 type) case OP_RV2AV: case OP_RV2HV: if (!type && cUNOPo->op_first->op_type != OP_GV) - croak("Can't localize through a reference"); + Perl_croak(aTHX_ "Can't localize through a reference"); if (type == OP_REFGEN && o->op_flags & OPf_PARENS) { PL_modcount = 10000; return o; /* Treat \(@foo) like ordinary list. */ @@ -1290,7 +1402,7 @@ Perl_mod(pTHX_ OP *o, I32 type) break; case OP_RV2SV: if (!type && cUNOPo->op_first->op_type != OP_GV) - croak("Can't localize through a reference"); + Perl_croak(aTHX_ "Can't localize through a reference"); ref(cUNOPo->op_first, o->op_type); /* FALL THROUGH */ case OP_GV: @@ -1314,7 +1426,7 @@ Perl_mod(pTHX_ OP *o, I32 type) case OP_PADSV: PL_modcount++; if (!type) - croak("Can't localize lexical variable %s", + Perl_croak(aTHX_ "Can't localize lexical variable %s", SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a)); break; @@ -1391,7 +1503,7 @@ Perl_mod(pTHX_ OP *o, I32 type) } STATIC bool -scalar_mod_type(pTHX_ OP *o, I32 type) +S_scalar_mod_type(pTHX_ OP *o, I32 type) { switch (type) { case OP_SASSIGN: @@ -1438,7 +1550,7 @@ scalar_mod_type(pTHX_ OP *o, I32 type) } STATIC bool -is_handle_constructor(pTHX_ OP *o, I32 argnum) +S_is_handle_constructor(pTHX_ OP *o, I32 argnum) { switch (o->op_type) { case OP_PIPE_OP: @@ -1560,8 +1672,60 @@ Perl_ref(pTHX_ OP *o, I32 type) } -OP * -Perl_my(pTHX_ OP *o) +STATIC OP * +S_dup_attrlist(pTHX_ OP *o) +{ + OP *rop = Nullop; + + /* An attrlist is either a simple OP_CONST or an OP_LIST with kids, + * where the first kid is OP_PUSHMARK and the remaining ones + * are OP_CONST. We need to push the OP_CONST values. + */ + if (o->op_type == OP_CONST) + rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc(cSVOPo->op_sv)); + else { + assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS)); + for (o = cLISTOPo->op_first; o; o=o->op_sibling) { + if (o->op_type == OP_CONST) + rop = append_elem(OP_LIST, rop, + newSVOP(OP_CONST, o->op_flags, + SvREFCNT_inc(cSVOPo->op_sv))); + } + } + return rop; +} + +STATIC void +S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs) +{ + OP *modname; /* for 'use' */ + SV *stashsv; + + /* fake up C */ + ENTER; /* need to protect against side-effects of 'use' */ + SAVEINT(PL_expect); + if (stash && HvNAME(stash)) + stashsv = newSVpv(HvNAME(stash), 0); + else + stashsv = &PL_sv_no; +#define ATTRSMODULE "attributes" + modname = newSVOP(OP_CONST, 0, + newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1)); + modname->op_private |= OPpCONST_BARE; + /* that flag is required to make 'use' work right */ + utilize(1, start_subparse(FALSE, 0), + Nullop, /* version */ + modname, + prepend_elem(OP_LIST, + newSVOP(OP_CONST, 0, stashsv), + prepend_elem(OP_LIST, + newSVOP(OP_CONST, 0, newRV(target)), + dup_attrlist(attrs)))); + LEAVE; +} + +STATIC OP * +S_my_kid(pTHX_ OP *o, OP *attrs) { OP *kid; I32 type; @@ -1572,23 +1736,59 @@ Perl_my(pTHX_ OP *o) type = o->op_type; if (type == OP_LIST) { for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) - my(kid); + my_kid(kid, attrs); } else if (type == OP_UNDEF) { return o; + } else if (type == OP_RV2SV || /* "our" declaration */ + type == OP_RV2AV || + type == OP_RV2HV) { /* XXX does this let anything illegal in? */ + return o; } else if (type != OP_PADSV && type != OP_PADAV && type != OP_PADHV && type != OP_PUSHMARK) { - yyerror(form("Can't declare %s in my", PL_op_desc[o->op_type])); + yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type])); return o; } + else if (attrs && type != OP_PUSHMARK) { + HV *stash; + SV *padsv; + SV **namesvp; + + /* check for C when deciding package */ + namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE); + if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp))) + stash = SvSTASH(*namesvp); + else + stash = PL_curstash; + padsv = PAD_SV(o->op_targ); + apply_attrs(stash, padsv, attrs); + } o->op_flags |= OPf_MOD; o->op_private |= OPpLVAL_INTRO; return o; } OP * +Perl_my_attrs(pTHX_ OP *o, OP *attrs) +{ + if (o->op_flags & OPf_PARENS) + list(o); + PL_in_my = FALSE; + PL_in_my_stash = Nullhv; + if (attrs) + SAVEFREEOP(attrs); + return my_kid(o, attrs); +} + +OP * +Perl_my(pTHX_ OP *o) +{ + return my_kid(o, Nullop); +} + +OP * Perl_sawparens(pTHX_ OP *o) { if (o) @@ -1613,7 +1813,7 @@ Perl_bind_match(pTHX_ I32 type, OP *left, OP *right) char *sample = ((left->op_type == OP_RV2AV || left->op_type == OP_PADAV) ? "@array" : "%hash"); - warner(WARN_UNSAFE, + Perl_warner(aTHX_ WARN_UNSAFE, "Applying %s to %s will act on scalar(%s)", desc, sample, sample); } @@ -1662,8 +1862,8 @@ Perl_scope(pTHX_ OP *o) o->op_ppaddr = PL_ppaddr[OP_SCOPE]; kid = ((LISTOP*)o)->op_first; if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){ - SvREFCNT_dec(((COP*)kid)->cop_filegv); - null(kid); + kid->op_type = OP_SETSTATE; + kid->op_ppaddr = PL_ppaddr[OP_SETSTATE]; } } else @@ -1705,8 +1905,7 @@ Perl_block_start(pTHX_ int full) SAVEHINTS(); PL_hints &= ~HINT_BLOCK_SCOPE; SAVEPPTR(PL_compiling.cop_warnings); - if (PL_compiling.cop_warnings != WARN_ALL && - PL_compiling.cop_warnings != WARN_NONE) { + if (! specialWARN(PL_compiling.cop_warnings)) { PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ; SAVEFREESV(PL_compiling.cop_warnings) ; } @@ -1732,7 +1931,7 @@ Perl_block_end(pTHX_ I32 floor, OP *seq) } STATIC OP * -newDEFSVOP(pTHX) +S_newDEFSVOP(pTHX) { #ifdef USE_THREADS OP *o = newOP(OP_THREADSV, 0); @@ -1792,7 +1991,7 @@ Perl_localize(pTHX_ OP *o, I32 lex) char *s; for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ; if (*s == ';' || *s == '=') - warner(WARN_PARENTHESIS, "Parentheses missing around \"%s\" list", + Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list", lex ? "my" : "local"); } } @@ -1830,11 +2029,17 @@ Perl_fold_constants(pTHX_ register OP *o) if (PL_opargs[type] & OA_RETSCALAR) scalar(o); - if (PL_opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET && !o->op_targ) o->op_targ = pad_alloc(type, SVs_PADTMP); - if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)) + /* integerize op, unless it happens to be C<-foo>. + * XXX should pp_i_negate() do magic string negation instead? */ + if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER) + && !(type == OP_NEGATE && cUNOPo->op_first->op_type == OP_CONST + && (cUNOPo->op_first->op_private & OPpCONST_BARE))) + { o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)]; + } if (!(PL_opargs[type] & OA_FOLDCONST)) goto nope; @@ -1863,7 +2068,8 @@ Perl_fold_constants(pTHX_ register OP *o) goto nope; /* Don't try to run w/ errors */ for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) { - if (curop->op_type != OP_CONST && + if ((curop->op_type != OP_CONST || + (curop->op_private & OPpCONST_BARE)) && curop->op_type != OP_LIST && curop->op_type != OP_SCALAR && curop->op_type != OP_NULL && @@ -1876,7 +2082,7 @@ Perl_fold_constants(pTHX_ register OP *o) curop = LINKLIST(o); o->op_next = 0; PL_op = curop; - CALLRUNOPS(); + CALLRUNOPS(aTHX); sv = *(PL_stack_sp--); if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */ pad_swipe(o->op_targ); @@ -1893,7 +2099,7 @@ Perl_fold_constants(pTHX_ register OP *o) type != OP_NEGATE) { IV iv = SvIV(sv); - if ((double)iv == SvNV(sv)) { + if ((NV)iv == SvNV(sv)) { SvREFCNT_dec(sv); sv = newSViv(iv); } @@ -1940,10 +2146,10 @@ Perl_gen_constant_list(pTHX_ register OP *o) PL_op = curop = LINKLIST(o); o->op_next = 0; - pp_pushmark(ARGS); - CALLRUNOPS(); + pp_pushmark(); + CALLRUNOPS(aTHX); PL_op = curop; - pp_anonlist(ARGS); + pp_anonlist(); PL_tmps_floor = oldtmps_floor; o->op_type = OP_RV2AV; @@ -2185,7 +2391,7 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last) } binop = (BINOP*)CHECKOP(type, binop); - if (binop->op_next) + if (binop->op_next || binop->op_type != type) return (OP*)binop; binop->op_last = binop->op_first->op_sibling; @@ -2352,15 +2558,15 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) if (rfirst == 0xffffffff) { diff = tdiff; /* oops, pretend rdiff is infinite */ if (diff > 0) - sv_catpvf(listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast); + Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast); else - sv_catpvf(listsv, "%04x\t\tXXXX\n", tfirst); + Perl_sv_catpvf(aTHX_ listsv, "%04x\t\tXXXX\n", tfirst); } else { if (diff > 0) - sv_catpvf(listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst); + Perl_sv_catpvf(aTHX_ listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst); else - sv_catpvf(listsv, "%04x\t\t%04x\n", tfirst, rfirst); + Perl_sv_catpvf(aTHX_ listsv, "%04x\t\t%04x\n", tfirst, rfirst); if (rfirst + diff > max) max = rfirst + diff; @@ -2507,7 +2713,7 @@ Perl_pmruntime(pTHX_ OP *o, OP *expr, OP *repl) p = SvPV(pat, plen); pm->op_pmflags |= PMf_SKIPWHITE; } - pm->op_pmregexp = CALLREGCOMP(p, p + plen, pm); + pm->op_pmregexp = CALLREGCOMP(aTHX_ p, p + plen, pm); if (strEQ("\\s+", pm->op_pmregexp->precomp)) pm->op_pmflags |= PMf_WHITE; op_free(expr); @@ -2723,7 +2929,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg) GV *gv; if (id->op_type != OP_CONST) - croak("Module name must be constant"); + Perl_croak(aTHX_ "Module name must be constant"); veop = Nullop; @@ -2735,20 +2941,19 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg) } else { OP *pack; - OP *meth; if (version->op_type != OP_CONST || !SvNIOK(vesv)) - croak("Version number must be constant number"); + Perl_croak(aTHX_ "Version number must be constant number"); /* Make copy of id so we don't free it twice */ pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv)); /* Fake up a method call to VERSION */ - meth = newSVOP(OP_CONST, 0, newSVpvn("VERSION", 7)); veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, append_elem(OP_LIST, prepend_elem(OP_LIST, pack, list(version)), - newUNOP(OP_METHOD, 0, meth))); + newSVOP(OP_METHOD_NAMED, 0, + newSVpvn("VERSION", 7)))); } } @@ -2761,15 +2966,12 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg) else { /* Make copy of id so we don't free it twice */ pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)id)->op_sv)); - meth = newSVOP(OP_CONST, 0, - aver - ? newSVpvn("import", 6) - : newSVpvn("unimport", 8) - ); imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, append_elem(OP_LIST, prepend_elem(OP_LIST, pack, list(arg)), - newUNOP(OP_METHOD, 0, meth))); + newSVOP(OP_METHOD_NAMED, 0, + aver ? newSVpvn("import", 6) + : newSVpvn("unimport", 8)))); } /* Fake up a require, handle override, if any */ @@ -2789,9 +2991,10 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg) } /* Fake up the BEGIN {}, which does its thing immediately. */ - newSUB(floor, + newATTRSUB(floor, newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)), Nullop, + Nullop, append_elem(OP_LINESEQ, append_elem(OP_LINESEQ, newSTATEOP(0, Nullch, rqop), @@ -2834,7 +3037,7 @@ Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval) } STATIC I32 -list_assignment(pTHX_ register OP *o) +S_list_assignment(pTHX_ register OP *o) { if (!o) return TRUE; @@ -2843,8 +3046,8 @@ list_assignment(pTHX_ register OP *o) o = cUNOPo->op_first; if (o->op_type == OP_COND_EXPR) { - I32 t = list_assignment(cCONDOPo->op_first->op_sibling); - I32 f = list_assignment(cCONDOPo->op_first->op_sibling->op_sibling); + I32 t = list_assignment(cLOGOPo->op_first->op_sibling); + I32 f = list_assignment(cLOGOPo->op_first->op_sibling->op_sibling); if (t && f) return TRUE; @@ -3034,8 +3237,7 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o) } cop->cop_seq = seq; cop->cop_arybase = PL_curcop->cop_arybase; - if (PL_curcop->cop_warnings == WARN_NONE - || PL_curcop->cop_warnings == WARN_ALL) + if (specialWARN(PL_curcop->cop_warnings)) cop->cop_warnings = PL_curcop->cop_warnings ; else cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ; @@ -3077,7 +3279,7 @@ Perl_intro_my(pTHX) for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) { if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) { SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */ - SvNVX(sv) = (double)PL_cop_seqmax; + SvNVX(sv) = (NV)PL_cop_seqmax; } } PL_min_intro_pending = 0; @@ -3092,7 +3294,7 @@ Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other) } STATIC OP * -new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) +S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) { dTHR; LOGOP *logop; @@ -3121,7 +3323,7 @@ new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) } if (first->op_type == OP_CONST) { if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE)) - warner(WARN_PRECEDENCE, "Probable precedence problem on %s", + Perl_warner(aTHX_ WARN_PRECEDENCE, "Probable precedence problem on %s", PL_op_desc[type]); if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) { op_free(first); @@ -3163,7 +3365,7 @@ new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) if (warnop) { line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warner(WARN_UNSAFE, + Perl_warner(aTHX_ WARN_UNSAFE, "Value of %s%s can be \"0\"; test with defined()", PL_op_desc[warnop], ((warnop == OP_READLINE || warnop == OP_GLOB) @@ -3202,7 +3404,8 @@ OP * Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop) { dTHR; - CONDOP *condop; + LOGOP *logop; + OP *start; OP *o; if (!falseop) @@ -3227,27 +3430,27 @@ Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop) list(trueop); scalar(falseop); } - NewOp(1101, condop, 1, CONDOP); + NewOp(1101, logop, 1, LOGOP); + logop->op_type = OP_COND_EXPR; + logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR]; + logop->op_first = first; + logop->op_flags = flags | OPf_KIDS; + logop->op_private = 1 | (flags >> 8); + logop->op_other = LINKLIST(trueop); + logop->op_next = LINKLIST(falseop); - condop->op_type = OP_COND_EXPR; - condop->op_ppaddr = PL_ppaddr[OP_COND_EXPR]; - condop->op_first = first; - condop->op_flags = flags | OPf_KIDS; - condop->op_true = LINKLIST(trueop); - condop->op_false = LINKLIST(falseop); - condop->op_private = 1 | (flags >> 8); /* establish postfix order */ - condop->op_next = LINKLIST(first); - first->op_next = (OP*)condop; + start = LINKLIST(first); + first->op_next = (OP*)logop; first->op_sibling = trueop; trueop->op_sibling = falseop; - o = newUNOP(OP_NULL, 0, (OP*)condop); + o = newUNOP(OP_NULL, 0, (OP*)logop); - trueop->op_next = o; - falseop->op_next = o; + trueop->op_next = falseop->op_next = o; + o->op_next = start; return o; } @@ -3255,34 +3458,36 @@ OP * Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right) { dTHR; - CONDOP *condop; + LOGOP *range; OP *flip; OP *flop; + OP *leftstart; OP *o; - NewOp(1101, condop, 1, CONDOP); + NewOp(1101, range, 1, LOGOP); - condop->op_type = OP_RANGE; - condop->op_ppaddr = PL_ppaddr[OP_RANGE]; - condop->op_first = left; - condop->op_flags = OPf_KIDS; - condop->op_true = LINKLIST(left); - condop->op_false = LINKLIST(right); - condop->op_private = 1 | (flags >> 8); + range->op_type = OP_RANGE; + range->op_ppaddr = PL_ppaddr[OP_RANGE]; + range->op_first = left; + range->op_flags = OPf_KIDS; + leftstart = LINKLIST(left); + range->op_other = LINKLIST(right); + range->op_private = 1 | (flags >> 8); left->op_sibling = right; - condop->op_next = (OP*)condop; - flip = newUNOP(OP_FLIP, flags, (OP*)condop); + range->op_next = (OP*)range; + flip = newUNOP(OP_FLIP, flags, (OP*)range); flop = newUNOP(OP_FLOP, 0, flip); o = newUNOP(OP_NULL, 0, flop); linklist(flop); + range->op_next = leftstart; left->op_next = flip; right->op_next = flop; - condop->op_targ = pad_alloc(OP_RANGE, SVs_PADMY); - sv_upgrade(PAD_SV(condop->op_targ), SVt_PVNV); + range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY); + sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV); flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY); sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV); @@ -3469,7 +3674,7 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo sv = Nullop; } else - croak("Can't use %s for loop variable", PL_op_desc[sv->op_type]); + Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]); } else { #ifdef USE_THREADS @@ -3492,7 +3697,7 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo * treated as min/max values by 'pp_iterinit'. */ UNOP* flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first; - CONDOP* range = (CONDOP*) flip->op_first; + LOGOP* range = (LOGOP*) flip->op_first; OP* left = range->op_first; OP* right = left->op_sibling; LISTOP* listop; @@ -3501,8 +3706,8 @@ Perl_newFOROP(pTHX_ I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *blo range->op_first = Nullop; listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right); - listop->op_first->op_next = range->op_true; - left->op_next = range->op_false; + listop->op_first->op_next = range->op_next; + left->op_next = range->op_other; right->op_next = (OP*)listop; listop->op_next = listop->op_first; @@ -3574,10 +3779,10 @@ Perl_cv_undef(pTHX_ CV *cv) if (!CvXSUB(cv) && CvROOT(cv)) { #ifdef USE_THREADS if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr)) - croak("Can't undef active subroutine"); + Perl_croak(aTHX_ "Can't undef active subroutine"); #else if (CvDEPTH(cv)) - croak("Can't undef active subroutine"); + Perl_croak(aTHX_ "Can't undef active subroutine"); #endif /* USE_THREADS */ ENTER; @@ -3664,7 +3869,7 @@ cv_dump(CV *cv) #endif /* DEBUG_CLOSURES */ STATIC CV * -cv_clone2(pTHX_ CV *proto, CV *outside) +S_cv_clone2(pTHX_ CV *proto, CV *outside) { dTHR; AV* av; @@ -3738,7 +3943,7 @@ cv_clone2(pTHX_ CV *proto, CV *outside) if (!off) PL_curpad[ix] = SvREFCNT_inc(ppad[ix]); else if (off != ix) - croak("panic: cv_clone: %s", name); + Perl_croak(aTHX_ "panic: cv_clone: %s", name); } else { /* our own lexical */ SV* sv; @@ -3808,7 +4013,9 @@ Perl_cv_clone(pTHX_ CV *proto) void Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p) { - if ((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) { + dTHR; + + if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_UNSAFE)) { SV* msg = sv_newmortal(); SV* name = Nullsv; @@ -3816,15 +4023,15 @@ Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p) gv_efullname3(name = sv_newmortal(), gv, Nullch); sv_setpv(msg, "Prototype mismatch:"); if (name) - sv_catpvf(msg, " sub %_", name); + Perl_sv_catpvf(aTHX_ msg, " sub %_", name); if (SvPOK(cv)) - sv_catpvf(msg, " (%s)", SvPVX(cv)); + Perl_sv_catpvf(aTHX_ msg, " (%s)", SvPVX(cv)); sv_catpv(msg, " vs "); if (p) - sv_catpvf(msg, "(%s)", p); + Perl_sv_catpvf(aTHX_ msg, "(%s)", p); else sv_catpv(msg, "none"); - warn("%_", msg); + Perl_warner(aTHX_ WARN_UNSAFE, "%_", msg); } } @@ -3850,7 +4057,7 @@ Perl_op_const_sv(pTHX_ OP *o, CV *cv) for (; o; o = o->op_next) { OPCODE type = o->op_type; - if(sv && o->op_next == o) + if (sv && o->op_next == o) return sv; if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK) continue; @@ -3874,14 +4081,35 @@ Perl_op_const_sv(pTHX_ OP *o, CV *cv) return sv; } +void +Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) +{ + if (o) + SAVEFREEOP(o); + if (proto) + SAVEFREEOP(proto); + if (attrs) + SAVEFREEOP(attrs); + if (block) + SAVEFREEOP(block); + Perl_croak(aTHX_ "\"my sub\" not yet implemented"); +} + CV * Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) { + return Perl_newATTRSUB(aTHX_ floor, o, proto, Nullop, block); +} + +CV * +Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) +{ dTHR; STRLEN n_a; char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch; GV *gv = gv_fetchpv(name ? name : "__ANON__", - GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV); + GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT), + SVt_PVCV); char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch; register CV *cv=0; I32 ix; @@ -3890,12 +4118,17 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) SAVEFREEOP(o); if (proto) SAVEFREEOP(proto); + if (attrs) + SAVEFREEOP(attrs); - if (SvTYPE(gv) != SVt_PVGV) { /* Prototype now, and had + if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at maximum a prototype before. */ if (SvTYPE(gv) > SVt_NULL) { - if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1)) - warn("Runaway prototype"); + if (!SvPOK((SV*)gv) && !(SvIOK((SV*)gv) && SvIVX((SV*)gv) == -1) + && ckWARN_d(WARN_UNSAFE)) + { + Perl_warner(aTHX_ WARN_UNSAFE, "Runaway prototype"); + } cv_ckproto((CV*)gv, NULL, ps); } if (ps) @@ -3916,14 +4149,16 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) { SV* const_sv; bool const_changed = TRUE; - if (!block) { + if (!block && !attrs) { /* just a "sub foo;" when &foo is already defined */ SAVEFREESV(PL_compcv); goto done; } /* ahem, death to those who redefine active sort subs */ if (PL_curstackinfo->si_type == PERLSI_SORT && PL_sortcop == CvSTART(cv)) - croak("Can't redefine active sort subroutine %s", name); + Perl_croak(aTHX_ "Can't redefine active sort subroutine %s", name); + if (!block) + goto withattrs; if(const_sv = cv_const_sv(cv)) const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv)); if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE) @@ -3933,16 +4168,48 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) "autouse"))) { line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warner(WARN_REDEFINE, + Perl_warner(aTHX_ WARN_REDEFINE, const_sv ? "Constant subroutine %s redefined" - : "Subroutine %s redefined", name); + : "Subroutine %s redefined", name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); cv = Nullcv; } } + withattrs: + if (attrs) { + HV *stash; + SV *rcv; + + /* Need to do a C + * before we clobber PL_compcv. + */ + if (cv && !block) { + rcv = (SV*)cv; + if (CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv)))) + stash = GvSTASH(CvGV(cv)); + else if (CvSTASH(cv) && HvNAME(CvSTASH(cv))) + stash = CvSTASH(cv); + else + stash = PL_curstash; + } + else { + /* possibly about to re-define existing subr -- ignore old cv */ + rcv = (SV*)PL_compcv; + if (name && GvSTASH(gv) && HvNAME(GvSTASH(gv))) + stash = GvSTASH(gv); + else + stash = PL_curstash; + } + apply_attrs(stash, rcv, attrs); + } if (cv) { /* must reuse cv if autoloaded */ + if (!block) { + /* got here with just attrs -- work done, so bug out */ + SAVEFREESV(PL_compcv); + goto done; + } cv_undef(cv); CvFLAGS(cv) = CvFLAGS(PL_compcv); CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv); @@ -3985,11 +4252,11 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) char *not_safe = "BEGIN not safe after errors--compilation aborted"; if (PL_in_eval & EVAL_KEEPERR) - croak(not_safe); + Perl_croak(aTHX_ not_safe); else { /* force display of errors found but not reported */ sv_catpv(ERRSV, not_safe); - croak("%s", SvPVx(ERRSV, n_a)); + Perl_croak(aTHX_ "%s", SvPVx(ERRSV, n_a)); } } } @@ -4040,7 +4307,12 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) } } - CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block)); + if(CvLVALUE(cv)) { + CvROOT(cv) = newUNOP(OP_LEAVESUBLV, 0, scalarseq(block)); + } + else { + CvROOT(cv) = newUNOP(OP_LEAVESUB, 0, scalarseq(block)); + } CvSTART(cv) = LINKLIST(CvROOT(cv)); CvROOT(cv)->op_next = 0; peep(CvSTART(cv)); @@ -4055,7 +4327,7 @@ Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block) CV *cv; HV *hv; - sv_setpvf(sv, "%_:%ld-%ld", + Perl_sv_setpvf(aTHX_ sv, "%_:%ld-%ld", GvSV(PL_curcop->cop_filegv), (long)PL_subline, (long)PL_curcop->cop_line); gv_efullname3(tmpstr, gv, Nullch); @@ -4130,10 +4402,11 @@ Perl_newCONSTSUB(pTHX_ HV *stash, char *name, SV *sv) if(stash) PL_curstash = PL_curcop->cop_stash = stash; - newSUB( + newATTRSUB( start_subparse(FALSE, 0), newSVOP(OP_CONST, 0, newSVpv(name,0)), newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ + Nullop, newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) ); @@ -4164,7 +4437,7 @@ Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename) line_t oldline = PL_curcop->cop_line; if (PL_copline != NOLINE) PL_curcop->cop_line = PL_copline; - warner(WARN_REDEFINE, "Subroutine %s redefined",name); + Perl_warner(aTHX_ WARN_REDEFINE, "Subroutine %s redefined",name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); @@ -4245,7 +4518,7 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block) line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warner(WARN_REDEFINE, "Format %s redefined",name); + Perl_warner(aTHX_ WARN_REDEFINE, "Format %s redefined",name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); @@ -4286,8 +4559,15 @@ Perl_newANONHASH(pTHX_ OP *o) OP * Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block) { + return newANONATTRSUB(floor, proto, Nullop, block); +} + +OP * +Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block) +{ return newUNOP(OP_REFGEN, 0, - newSVOP(OP_ANONCODE, 0, (SV*)newSUB(floor, 0, proto, block))); + newSVOP(OP_ANONCODE, 0, + (SV*)newATTRSUB(floor, 0, proto, attrs, block))); } OP * @@ -4306,7 +4586,8 @@ Perl_oopsAV(pTHX_ OP *o) break; default: - warn("oops: oopsAV"); + if (ckWARN_d(WARN_INTERNAL)) + Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsAV"); break; } return o; @@ -4315,6 +4596,8 @@ Perl_oopsAV(pTHX_ OP *o) OP * Perl_oopsHV(pTHX_ OP *o) { + dTHR; + switch (o->op_type) { case OP_PADSV: case OP_PADAV: @@ -4330,7 +4613,8 @@ Perl_oopsHV(pTHX_ OP *o) break; default: - warn("oops: oopsHV"); + if (ckWARN_d(WARN_INTERNAL)) + Perl_warner(aTHX_ WARN_INTERNAL, "oops: oopsHV"); break; } return o; @@ -4369,7 +4653,7 @@ Perl_newHVREF(pTHX_ OP *o) OP * Perl_oopsCV(pTHX_ OP *o) { - croak("NOT IMPL LINE %d",__LINE__); + Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__); /* STUB */ return o; } @@ -4398,7 +4682,7 @@ Perl_newSVREF(pTHX_ OP *o) /* Check routines. */ OP * -ck_anoncode(OP *o) +Perl_ck_anoncode(pTHX_ OP *o) { PADOFFSET ix; SV* name; @@ -4418,14 +4702,14 @@ ck_anoncode(OP *o) } OP * -ck_bitop(OP *o) +Perl_ck_bitop(pTHX_ OP *o) { o->op_private = PL_hints; return o; } OP * -ck_concat(OP *o) +Perl_ck_concat(pTHX_ OP *o) { if (cUNOPo->op_first->op_type == OP_CONCAT) o->op_flags |= OPf_STACKED; @@ -4433,7 +4717,7 @@ ck_concat(OP *o) } OP * -ck_spair(OP *o) +Perl_ck_spair(pTHX_ OP *o) { if (o->op_flags & OPf_KIDS) { OP* newop; @@ -4458,7 +4742,7 @@ ck_spair(OP *o) } OP * -ck_delete(OP *o) +Perl_ck_delete(pTHX_ OP *o) { o = ck_fun(o); o->op_private = 0; @@ -4467,7 +4751,7 @@ ck_delete(OP *o) if (kid->op_type == OP_HSLICE) o->op_private |= OPpSLICE; else if (kid->op_type != OP_HELEM) - croak("%s argument is not a HASH element or slice", + Perl_croak(aTHX_ "%s argument is not a HASH element or slice", PL_op_desc[o->op_type]); null(kid); } @@ -4475,7 +4759,7 @@ ck_delete(OP *o) } OP * -ck_eof(OP *o) +Perl_ck_eof(pTHX_ OP *o) { I32 type = o->op_type; @@ -4491,7 +4775,7 @@ ck_eof(OP *o) } OP * -ck_eval(OP *o) +Perl_ck_eval(pTHX_ OP *o) { PL_hints |= HINT_BLOCK_SCOPE; if (o->op_flags & OPf_KIDS) { @@ -4534,7 +4818,7 @@ ck_eval(OP *o) } OP * -ck_exec(OP *o) +Perl_ck_exec(pTHX_ OP *o) { OP *kid; if (o->op_flags & OPf_STACKED) { @@ -4549,13 +4833,13 @@ ck_exec(OP *o) } OP * -ck_exists(OP *o) +Perl_ck_exists(pTHX_ OP *o) { o = ck_fun(o); if (o->op_flags & OPf_KIDS) { OP *kid = cUNOPo->op_first; if (kid->op_type != OP_HELEM) - croak("%s argument is not a HASH element", PL_op_desc[o->op_type]); + Perl_croak(aTHX_ "%s argument is not a HASH element", PL_op_desc[o->op_type]); null(kid); } return o; @@ -4563,7 +4847,7 @@ ck_exists(OP *o) #if 0 OP * -ck_gvconst(register OP *o) +Perl_ck_gvconst(pTHX_ register OP *o) { o = fold_constants(o); if (o->op_type == OP_CONST) @@ -4573,7 +4857,7 @@ ck_gvconst(register OP *o) #endif OP * -ck_rvconst(register OP *o) +Perl_ck_rvconst(pTHX_ register OP *o) { dTHR; SVOP *kid = (SVOP*)cUNOPo->op_first; @@ -4620,7 +4904,7 @@ ck_rvconst(register OP *o) break; } if (badtype) - croak("Constant is not %s reference", badtype); + Perl_croak(aTHX_ "Constant is not %s reference", badtype); return o; } name = SvPV(kidsv, n_a); @@ -4638,7 +4922,7 @@ ck_rvconst(register OP *o) break; } if (badthing) - croak( + Perl_croak(aTHX_ "Can't use bareword (\"%s\") as %s ref while \"strict refs\" in use", name, badthing); } @@ -4668,13 +4952,14 @@ ck_rvconst(register OP *o) kid->op_type = OP_GV; SvREFCNT_dec(kid->op_sv); kid->op_sv = SvREFCNT_inc(gv); + kid->op_ppaddr = PL_ppaddr[OP_GV]; } } return o; } OP * -ck_ftst(OP *o) +Perl_ck_ftst(pTHX_ OP *o) { dTHR; I32 type = o->op_type; @@ -4705,7 +4990,7 @@ ck_ftst(OP *o) } OP * -ck_fun(OP *o) +Perl_ck_fun(pTHX_ OP *o) { dTHR; register OP *kid; @@ -4763,10 +5048,17 @@ ck_fun(OP *o) char *name = SvPVx(((SVOP*)kid)->op_sv, n_a); OP *newop = newAVREF(newGVOP(OP_GV, 0, gv_fetchpv(name, TRUE, SVt_PVAV) )); +#ifdef IV_IS_QUAD if (ckWARN(WARN_SYNTAX)) - warner(WARN_SYNTAX, + Perl_warner(aTHX_ WARN_SYNTAX, + "Array @%s missing the @ in argument %" PERL_PRId64 " of %s()", + name, (IV)numargs, PL_op_desc[type]); +#else + if (ckWARN(WARN_SYNTAX)) + Perl_warner(aTHX_ WARN_SYNTAX, "Array @%s missing the @ in argument %ld of %s()", name, (long)numargs, PL_op_desc[type]); +#endif op_free(kid); kid = newop; kid->op_sibling = sibl; @@ -4783,10 +5075,17 @@ ck_fun(OP *o) char *name = SvPVx(((SVOP*)kid)->op_sv, n_a); OP *newop = newHVREF(newGVOP(OP_GV, 0, gv_fetchpv(name, TRUE, SVt_PVHV) )); +#ifdef IV_IS_QUAD + if (ckWARN(WARN_SYNTAX)) + Perl_warner(aTHX_ WARN_SYNTAX, + "Hash %%%s missing the %% in argument %" PERL_PRId64 " of %s()", + name, (IV)numargs, PL_op_desc[type]); +#else if (ckWARN(WARN_SYNTAX)) - warner(WARN_SYNTAX, + Perl_warner(aTHX_ WARN_SYNTAX, "Hash %%%s missing the %% in argument %ld of %s()", name, (long)numargs, PL_op_desc[type]); +#endif op_free(kid); kid = newop; kid->op_sibling = sibl; @@ -4879,7 +5178,7 @@ ck_fun(OP *o) } OP * -ck_glob(OP *o) +Perl_ck_glob(pTHX_ OP *o) { GV *gv; @@ -4912,7 +5211,7 @@ ck_glob(OP *o) } OP * -ck_grep(OP *o) +Perl_ck_grep(pTHX_ OP *o) { LOGOP *gwop; OP *kid; @@ -4941,7 +5240,7 @@ ck_grep(OP *o) return o; kid = cLISTOPo->op_first->op_sibling; if (kid->op_type != OP_NULL) - croak("panic: ck_grep"); + Perl_croak(aTHX_ "panic: ck_grep"); kid = kUNOP->op_first; gwop->op_type = type; @@ -4963,7 +5262,7 @@ ck_grep(OP *o) } OP * -ck_index(OP *o) +Perl_ck_index(pTHX_ OP *o) { if (o->op_flags & OPf_KIDS) { OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ @@ -4976,53 +5275,59 @@ ck_index(OP *o) } OP * -ck_lengthconst(OP *o) +Perl_ck_lengthconst(pTHX_ OP *o) { /* XXX length optimization goes here */ return ck_fun(o); } OP * -ck_lfun(OP *o) +Perl_ck_lfun(pTHX_ OP *o) { OPCODE type = o->op_type; return modkids(ck_fun(o), type); } OP * -ck_defined(OP *o) /* 19990527 MJD */ +Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */ { dTHR; - if (ckWARN(WARN_DEPRECATED)) { - switch (cUNOPo->op_first->op_type) { - case OP_RV2AV: - case OP_PADAV: - case OP_AASSIGN: /* Is this a good idea? */ - warner(WARN_DEPRECATED, "defined(@array) is deprecated (and not really meaningful)"); - warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n"); - break; - case OP_RV2HV: - case OP_PADHV: - warner(WARN_DEPRECATED, "defined(%hash) is deprecated (and not really meaningful)"); - warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n"); - break; - default: - /* no warning */ + if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) { + switch (cUNOPo->op_first->op_type) { + case OP_RV2AV: + break; /* Globals via GV can be undef */ + case OP_PADAV: + case OP_AASSIGN: /* Is this a good idea? */ + Perl_warner(aTHX_ WARN_DEPRECATED, + "defined(@array) is deprecated"); + Perl_warner(aTHX_ WARN_DEPRECATED, + "(Maybe you should just omit the defined()?)\n"); break; - } + case OP_RV2HV: + break; /* Globals via GV can be undef */ + case OP_PADHV: + Perl_warner(aTHX_ WARN_DEPRECATED, + "defined(%hash) is deprecated"); + Perl_warner(aTHX_ WARN_DEPRECATED, + "(Maybe you should just omit the defined()?)\n"); + break; + default: + /* no warning */ + break; + } } return ck_rfun(o); } OP * -ck_rfun(OP *o) +Perl_ck_rfun(pTHX_ OP *o) { OPCODE type = o->op_type; return refkids(ck_fun(o), type); } OP * -ck_listiob(OP *o) +Perl_ck_listiob(pTHX_ OP *o) { register OP *kid; @@ -5060,7 +5365,7 @@ ck_listiob(OP *o) } OP * -ck_fun_locale(OP *o) +Perl_ck_fun_locale(pTHX_ OP *o) { o = ck_fun(o); @@ -5074,7 +5379,59 @@ ck_fun_locale(OP *o) } OP * -ck_scmp(OP *o) +Perl_ck_sassign(pTHX_ OP *o) +{ + OP *kid = cLISTOPo->op_first; + /* has a disposable target? */ + if ((PL_opargs[kid->op_type] & OA_TARGLEX) + && !(kid->op_flags & OPf_STACKED)) + { + OP *kkid = kid->op_sibling; + + /* Can just relocate the target. */ + if (kkid && kkid->op_type == OP_PADSV + && !(kkid->op_private & OPpLVAL_INTRO)) + { + /* Concat has problems if target is equal to right arg. */ + if (kid->op_type == OP_CONCAT) { + if (kLISTOP->op_first->op_sibling->op_type == OP_PADSV + && kLISTOP->op_first->op_sibling->op_targ == kkid->op_targ) + return o; + } + else if (kid->op_type == OP_JOIN) { + /* do_join has problems if the arguments coincide with target. + In fact the second argument *can* safely coincide, + but ignore=pessimize this rare occasion. */ + OP *arg = kLISTOP->op_first->op_sibling; /* Skip PUSHMARK */ + + while (arg) { + if (arg->op_type == OP_PADSV + && arg->op_targ == kkid->op_targ) + return o; + arg = arg->op_sibling; + } + } + else if (kid->op_type == OP_QUOTEMETA) { + /* quotemeta has problems if the argument coincides with target. */ + if (kLISTOP->op_first->op_type == OP_PADSV + && kLISTOP->op_first->op_targ == kkid->op_targ) + return o; + } + kid->op_targ = kkid->op_targ; + /* Now we do not need PADSV and SASSIGN. */ + kid->op_sibling = o->op_sibling; /* NULL */ + cLISTOPo->op_first = NULL; + op_free(o); + op_free(kkid); + kid->op_private |= OPpTARGET_MY; /* Used for context settings */ + return kid; + } + } + return o; +} + +OP * +Perl_ck_scmp(pTHX_ OP *o) { o->op_private = 0; #ifdef USE_LOCALE @@ -5086,20 +5443,40 @@ ck_scmp(OP *o) } OP * -ck_match(OP *o) +Perl_ck_match(pTHX_ OP *o) { o->op_private |= OPpRUNTIME; return o; } OP * -ck_null(OP *o) +Perl_ck_method(pTHX_ OP *o) { + OP *kid = cUNOPo->op_first; + if (kid->op_type == OP_CONST) { + SV* sv = kSVOP->op_sv; + if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) { + OP *cmop; + sv_upgrade(sv, SVt_PVIV); + SvIOK_on(sv); + PERL_HASH(SvUVX(sv), SvPVX(sv), SvCUR(sv)); + cmop = newSVOP(OP_METHOD_NAMED, 0, sv); + kSVOP->op_sv = Nullsv; + op_free(o); + return cmop; + } + } return o; } OP * -ck_repeat(OP *o) +Perl_ck_null(pTHX_ OP *o) +{ + return o; +} + +OP * +Perl_ck_repeat(pTHX_ OP *o) { if (cBINOPo->op_first->op_flags & OPf_PARENS) { o->op_private |= OPpREPEAT_DOLIST; @@ -5111,7 +5488,7 @@ ck_repeat(OP *o) } OP * -ck_require(OP *o) +Perl_ck_require(pTHX_ OP *o) { if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */ SVOP *kid = (SVOP*)cUNOPo->op_first; @@ -5133,16 +5510,16 @@ ck_require(OP *o) #if 0 OP * -ck_retarget(OP *o) +Perl_ck_retarget(pTHX_ OP *o) { - croak("NOT IMPL LINE %d",__LINE__); + Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__); /* STUB */ return o; } #endif OP * -ck_select(OP *o) +Perl_ck_select(pTHX_ OP *o) { OP* kid; if (o->op_flags & OPf_KIDS) { @@ -5162,7 +5539,7 @@ ck_select(OP *o) } OP * -ck_shift(OP *o) +Perl_ck_shift(pTHX_ OP *o) { I32 type = o->op_type; @@ -5191,7 +5568,7 @@ ck_shift(OP *o) } OP * -ck_sort(OP *o) +Perl_ck_sort(pTHX_ OP *o) { o->op_private = 0; #ifdef USE_LOCALE @@ -5243,7 +5620,7 @@ ck_sort(OP *o) } STATIC void -simplify_sort(pTHX_ OP *o) +S_simplify_sort(pTHX_ OP *o) { dTHR; register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ @@ -5299,13 +5676,14 @@ simplify_sort(pTHX_ OP *o) o->op_private |= OPpSORT_NUMERIC; if (k->op_type == OP_I_NCMP) o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER; - op_free(cLISTOPo->op_first->op_sibling); /* delete comparison block */ - cLISTOPo->op_first->op_sibling = cLISTOPo->op_last; - cLISTOPo->op_children = 1; + kid = cLISTOPo->op_first->op_sibling; + cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */ + op_free(kid); /* then delete it */ + cLISTOPo->op_children--; } OP * -ck_split(OP *o) +Perl_ck_split(pTHX_ OP *o) { register OP *kid; @@ -5314,7 +5692,7 @@ ck_split(OP *o) kid = cLISTOPo->op_first; if (kid->op_type != OP_NULL) - croak("panic: ck_split"); + Perl_croak(aTHX_ "panic: ck_split"); kid = kid->op_sibling; op_free(cLISTOPo->op_first); cLISTOPo->op_first = kid; @@ -5356,7 +5734,24 @@ ck_split(OP *o) } OP * -ck_subr(OP *o) +Perl_ck_join(pTHX_ OP *o) +{ + if (ckWARN(WARN_SYNTAX)) { + OP *kid = cLISTOPo->op_first->op_sibling; + if (kid && kid->op_type == OP_MATCH) { + char *pmstr = "STRING"; + if (kPMOP->op_pmregexp) + pmstr = kPMOP->op_pmregexp->precomp; + Perl_warner(aTHX_ WARN_SYNTAX, + "/%s/ should probably be written as \"%s\"", + pmstr, pmstr); + } + } + return ck_fun(o); +} + +OP * +Perl_ck_subr(pTHX_ OP *o) { dTHR; OP *prev = ((cUNOPo->op_first->op_sibling) @@ -5370,21 +5765,24 @@ ck_subr(OP *o) I32 arg = 0; STRLEN n_a; + o->op_private |= OPpENTERSUB_HASTARG; for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ; if (cvop->op_type == OP_RV2CV) { SVOP* tmpop; o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER); null(cvop); /* disable rv2cv */ tmpop = (SVOP*)((UNOP*)cvop)->op_first; - if (tmpop->op_type == OP_GV) { + if (tmpop->op_type == OP_GV && !(o->op_private & OPpENTERSUB_AMPER)) { cv = GvCVu(tmpop->op_sv); - if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) { + if (!cv) + tmpop->op_private |= OPpEARLY_CV; + else if (SvPOK(cv)) { namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv); proto = SvPV((SV*)cv, n_a); } } } - else if (cvop->op_type == OP_METHOD) { + else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) { if (o2->op_type == OP_CONST) o2->op_private &= ~OPpCONST_STRICT; else if (o2->op_type == OP_LIST) { @@ -5473,6 +5871,8 @@ ck_subr(OP *o) case '$': if (o2->op_type != OP_RV2SV && o2->op_type != OP_PADSV + && o2->op_type != OP_HELEM + && o2->op_type != OP_AELEM && o2->op_type != OP_THREADSV) { bad_type(arg, "scalar", gv_ename(namegv), o2); @@ -5503,7 +5903,7 @@ ck_subr(OP *o) continue; default: oops: - croak("Malformed prototype for %s: %s", + Perl_croak(aTHX_ "Malformed prototype for %s: %s", gv_ename(namegv), SvPV((SV*)cv, n_a)); } } @@ -5520,23 +5920,26 @@ ck_subr(OP *o) } OP * -ck_svconst(OP *o) +Perl_ck_svconst(pTHX_ OP *o) { SvREADONLY_on(cSVOPo->op_sv); return o; } OP * -ck_trunc(OP *o) +Perl_ck_trunc(pTHX_ OP *o) { if (o->op_flags & OPf_KIDS) { SVOP *kid = (SVOP*)cUNOPo->op_first; if (kid->op_type == OP_NULL) kid = (SVOP*)kid->op_sibling; - if (kid && - kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) + if (kid && kid->op_type == OP_CONST && + (kid->op_private & OPpCONST_BARE)) + { o->op_flags |= OPf_SPECIAL; + kid->op_private &= ~OPpCONST_STRICT; + } } return ck_fun(o); } @@ -5549,6 +5952,7 @@ Perl_peep(pTHX_ register OP *o) dTHR; register OP* oldop = 0; STRLEN n_a; + OP *last_composite = Nullop; if (!o || o->op_seq) return; @@ -5562,25 +5966,49 @@ Perl_peep(pTHX_ register OP *o) PL_op_seqmax++; PL_op = o; switch (o->op_type) { + case OP_SETSTATE: case OP_NEXTSTATE: case OP_DBSTATE: PL_curcop = ((COP*)o); /* for warnings */ o->op_seq = PL_op_seqmax++; + last_composite = Nullop; break; case OP_CONST: if (cSVOPo->op_private & OPpCONST_STRICT) no_bareword_allowed(o); /* FALL THROUGH */ - case OP_CONCAT: - case OP_JOIN: case OP_UC: case OP_UCFIRST: case OP_LC: case OP_LCFIRST: + if ( o->op_next && o->op_next->op_type == OP_STRINGIFY + && !(o->op_next->op_private & OPpTARGET_MY) ) + null(o->op_next); + o->op_seq = PL_op_seqmax++; + break; + case OP_CONCAT: + case OP_JOIN: case OP_QUOTEMETA: - if (o->op_next && o->op_next->op_type == OP_STRINGIFY) + if (o->op_next && o->op_next->op_type == OP_STRINGIFY) { + if (o->op_next->op_private & OPpTARGET_MY) { + if ((o->op_flags & OPf_STACKED) /* chained concats */ + || (o->op_type == OP_CONCAT + /* Concat has problems if target is equal to right arg. */ + && (((LISTOP*)o)->op_first->op_sibling->op_type + == OP_PADSV) + && (((LISTOP*)o)->op_first->op_sibling->op_targ + == o->op_next->op_targ))) { + goto ignore_optimization; + } + else { + o->op_targ = o->op_next->op_targ; + o->op_private |= OPpTARGET_MY; + } + } null(o->op_next); + } + ignore_optimization: o->op_seq = PL_op_seqmax++; break; case OP_STUB: @@ -5590,8 +6018,12 @@ Perl_peep(pTHX_ register OP *o) } goto nothin; case OP_NULL: - if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) + if (o->op_targ == OP_NEXTSTATE + || o->op_targ == OP_DBSTATE + || o->op_targ == OP_SETSTATE) + { PL_curcop = ((COP*)o); + } goto nothin; case OP_SCALAR: case OP_LINESEQ: @@ -5626,7 +6058,6 @@ Perl_peep(pTHX_ register OP *o) <= 255 && i >= 0) { - SvREFCNT_dec(((SVOP*)pop)->op_sv); null(o->op_next); null(pop->op_next); null(pop); @@ -5638,6 +6069,18 @@ Perl_peep(pTHX_ register OP *o) GvAVn(((GVOP*)o)->op_gv); } } + else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_UNSAFE)) { + GV *gv = cGVOPo->op_gv; + if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) { + /* XXX could check prototype here instead of just carping */ + SV *sv = sv_newmortal(); + gv_efullname3(sv, gv, Nullch); + Perl_warner(aTHX_ WARN_UNSAFE, + "%s() called too early to check prototype", + SvPV_nolen(sv)); + } + } + o->op_seq = PL_op_seqmax++; break; @@ -5645,18 +6088,16 @@ Perl_peep(pTHX_ register OP *o) case OP_GREPWHILE: case OP_AND: case OP_OR: + case OP_ANDASSIGN: + case OP_ORASSIGN: + case OP_COND_EXPR: + case OP_RANGE: o->op_seq = PL_op_seqmax++; while (cLOGOP->op_other->op_type == OP_NULL) cLOGOP->op_other = cLOGOP->op_other->op_next; peep(cLOGOP->op_other); break; - case OP_COND_EXPR: - o->op_seq = PL_op_seqmax++; - peep(cCONDOP->op_true); - peep(cCONDOP->op_false); - break; - case OP_ENTERLOOP: o->op_seq = PL_op_seqmax++; peep(cLOOP->op_redoop); @@ -5682,8 +6123,8 @@ Perl_peep(pTHX_ register OP *o) line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = ((COP*)o->op_next)->cop_line; - warner(WARN_SYNTAX, "Statement unlikely to be reached"); - warner(WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n"); + Perl_warner(aTHX_ WARN_SYNTAX, "Statement unlikely to be reached"); + Perl_warner(aTHX_ WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n"); PL_curcop->cop_line = oldline; } } @@ -5714,12 +6155,12 @@ Perl_peep(pTHX_ register OP *o) key = SvPV(*svp, keylen); indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE); if (!indsvp) { - croak("No such field \"%s\" in variable %s of type %s", + Perl_croak(aTHX_ "No such field \"%s\" in variable %s of type %s", key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname))); } ind = SvIV(*indsvp); if (ind < 1) - croak("Bad index while coercing array into hash"); + Perl_croak(aTHX_ "Bad index while coercing array into hash"); rop->op_type = OP_RV2AV; rop->op_ppaddr = PL_ppaddr[OP_RV2AV]; o->op_type = OP_AELEM; @@ -5729,6 +6170,40 @@ Perl_peep(pTHX_ register OP *o) break; } + case OP_RV2AV: + case OP_RV2HV: + if (!(o->op_flags & OPf_WANT) + || o->op_flags & OPf_WANT == OPf_WANT_LIST) + last_composite = o; + o->op_seq = PL_op_seqmax++; + break; + + case OP_RETURN: + if (o->op_next->op_type != OP_LEAVESUBLV) { + o->op_seq = PL_op_seqmax++; + break; + } + /* FALL THROUGH */ + + case OP_LEAVESUBLV: + if (last_composite) { + OP *r = last_composite; + + while (r->op_sibling) + r = r->op_sibling; + if (r->op_next == o + || (r->op_next->op_type == OP_LIST + && r->op_next->op_next == o)) + { + if (last_composite->op_type == OP_RV2AV) + yyerror("Lvalue subs returning arrays not implemented yet"); + else + yyerror("Lvalue subs returning hashes not implemented yet"); + ; + } + } + /* FALL THROUGH */ + default: o->op_seq = PL_op_seqmax++; break;