perldoc pod update
[p5sagit/p5-mst-13.2.git] / op.c
diff --git a/op.c b/op.c
index 16f528d..6bfa1a1 100644 (file)
--- a/op.c
+++ b/op.c
@@ -35,6 +35,8 @@
         Nullop )                                               \
      : (CHECKCALL[type])((OP*)o))
 
+#define PAD_MAX 999999999
+
 static bool scalar_mod_type _((OP *o, I32 type));
 #ifndef PERL_OBJECT
 static I32 list_assignment _((OP *o));
@@ -46,7 +48,7 @@ static OP *too_few_arguments _((OP *o, char* name));
 static OP *too_many_arguments _((OP *o, char* name));
 static void null _((OP* o));
 static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq,
-       CV* startcv, I32 cx_ix));
+       CV* startcv, I32 cx_ix, I32 saweval));
 static OP *newDEFSVOP _((void));
 static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp));
 #endif
@@ -92,7 +94,7 @@ void
 assertref(OP *o)
 {
     int type = o->op_type;
-    if (type != OP_AELEM && type != OP_HELEM) {
+    if (type != OP_AELEM && type != OP_HELEM && type != OP_GELEM) {
        yyerror(form("Can't use subscript on %s", op_desc[type]));
        if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) {
            dTHR;
@@ -126,15 +128,17 @@ pad_allocmy(char *name)
        }
        croak("Can't use global %s in \"my\"",name);
     }
-    if (PL_dowarn && AvFILLp(PL_comppad_name) >= 0) {
+    if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) {
        SV **svp = AvARRAY(PL_comppad_name);
        for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) {
            if ((sv = svp[off])
                && sv != &PL_sv_undef
-               && SvIVX(sv) == 999999999       /* var is in open scope */
+               && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
                && strEQ(name, SvPVX(sv)))
            {
-               warn("\"my\" variable %s masks earlier declaration in same scope", name);
+               warner(WARN_UNSAFE,
+                       "\"my\" variable %s masks earlier declaration in same %s", 
+                       name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
                break;
            }
        }
@@ -152,7 +156,7 @@ pad_allocmy(char *name)
        PL_sv_objcount++;
     }
     av_store(PL_comppad_name, off, sv);
-    SvNVX(sv) = (double)999999999;
+    SvNVX(sv) = (double)PAD_MAX;
     SvIVX(sv) = 0;                     /* Not yet introduced--see newSTATEOP */
     if (!PL_min_intro_pending)
        PL_min_intro_pending = off;
@@ -166,7 +170,7 @@ pad_allocmy(char *name)
 }
 
 STATIC PADOFFSET
-pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
+pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval)
 {
     dTHR;
     CV *cv;
@@ -174,7 +178,6 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
     SV *sv;
     register I32 i;
     register PERL_CONTEXT *cx;
-    int saweval;
 
     for (cv = startcv; cv; cv = CvOUTSIDE(cv)) {
        AV *curlist = CvPADLIST(cv);
@@ -214,8 +217,14 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
                    sv_setpv(namesv, name);
                    av_store(PL_comppad_name, newoff, namesv);
                    SvNVX(namesv) = (double)PL_curcop->cop_seq;
-                   SvIVX(namesv) = 999999999;  /* A ref, intro immediately */
+                   SvIVX(namesv) = PAD_MAX;    /* A ref, intro immediately */
                    SvFAKE_on(namesv);          /* A ref, not a real var */
+                   if (SvOBJECT(sv)) {         /* A typed var */
+                       SvOBJECT_on(namesv);
+                       (void)SvUPGRADE(namesv, SVt_PVMG);
+                       SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv));
+                       PL_sv_objcount++;
+                   }
                    if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) {
                        /* "It's closures all the way down." */
                        CvCLONE_on(PL_compcv);
@@ -227,22 +236,27 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
                            CV *bcv;
                            for (bcv = startcv;
                                 bcv && bcv != cv && !CvCLONE(bcv);
-                                bcv = CvOUTSIDE(bcv)) {
+                                bcv = CvOUTSIDE(bcv))
+                           {
                                if (CvANON(bcv))
                                    CvCLONE_on(bcv);
                                else {
-                                   if (PL_dowarn && !CvUNIQUE(cv))
-                                       warn(
+                                   if (ckWARN(WARN_CLOSURE)
+                                       && !CvUNIQUE(bcv) && !CvUNIQUE(cv))
+                                   {
+                                       warner(WARN_CLOSURE,
                                          "Variable \"%s\" may be unavailable",
                                             name);
+                                   }
                                    break;
                                }
                            }
                        }
                    }
                    else if (!CvUNIQUE(PL_compcv)) {
-                       if (PL_dowarn && !SvFAKE(sv) && !CvUNIQUE(cv))
-                           warn("Variable \"%s\" will not stay shared", name);
+                       if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv))
+                           warner(WARN_CLOSURE,
+                               "Variable \"%s\" will not stay shared", name);
                    }
                }
                av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv));
@@ -256,20 +270,20 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
      * XXX This will also probably interact badly with eval tree caching.
      */
 
-    saweval = 0;
     for (i = cx_ix; i >= 0; i--) {
        cx = &cxstack[i];
-       switch (cx->cx_type) {
+       switch (CxTYPE(cx)) {
        default:
            if (i == 0 && saweval) {
                seq = cxstack[saweval].blk_oldcop->cop_seq;
-               return pad_findlex(name, newoff, seq, PL_main_cv, 0);
+               return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval);
            }
            break;
        case CXt_EVAL:
            switch (cx->blk_eval.old_op_type) {
            case OP_ENTEREVAL:
-               saweval = i;
+               if (CxREALEVAL(cx))
+                   saweval = i;
                break;
            case OP_REQUIRE:
                /* require must have its own scope */
@@ -285,7 +299,7 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
                continue;
            }
            seq = cxstack[saweval].blk_oldcop->cop_seq;
-           return pad_findlex(name, newoff, seq, cv, i-1);
+           return pad_findlex(name, newoff, seq, cv, i-1, saweval);
        }
     }
 
@@ -301,6 +315,8 @@ pad_findmy(char *name)
     SV *sv;
     SV **svp = AvARRAY(PL_comppad_name);
     U32 seq = PL_cop_seqmax;
+    PERL_CONTEXT *cx;
+    CV *outside;
 
 #ifdef USE_THREADS
     /*
@@ -330,8 +346,20 @@ pad_findmy(char *name)
        }
     }
 
+    outside = CvOUTSIDE(PL_compcv);
+
+    /* Check if if we're compiling an eval'', and adjust seq to be the
+     * eval's seq number.  This depends on eval'' having a non-null
+     * CvOUTSIDE() while it is being compiled.  The eval'' itself is
+     * identified by CvUNIQUE being set and CvGV being null. */
+    if (outside && CvUNIQUE(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) {
+       cx = &cxstack[cxstack_ix];
+       if (CxREALEVAL(cx))
+           seq = cx->blk_oldcop->cop_seq;
+    }
+
     /* See if it's in a nested scope */
-    off = pad_findlex(name, 0, seq, CvOUTSIDE(PL_compcv), cxstack_ix);
+    off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0);
     if (off) {
        /* If there is a pending local definition, this new alias must die */
        if (pendoff)
@@ -355,7 +383,7 @@ pad_leavemy(I32 fill)
     }
     /* "Deintroduce" my variables that are leaving with this scope. */
     for (off = AvFILLp(PL_comppad_name); off > fill; off--) {
-       if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == 999999999)
+       if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX)
            SvIVX(sv) = PL_cop_seqmax;
     }
 }
@@ -548,7 +576,7 @@ find_threadsv(char *name)
        default:
            sv_magic(sv, 0, 0, name, 1); 
        }
-       DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+       DEBUG_S(PerlIO_printf(PerlIO_stderr(),
                              "find_threadsv: new SV %p for $%s%c\n",
                              sv, (*name < 32) ? "^" : "",
                              (*name < 32) ? toCTRL(*name) : *name));
@@ -582,6 +610,10 @@ op_free(OP *o)
        o->op_targ = 0; /* Was holding hints. */
        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;
@@ -600,6 +632,8 @@ op_free(OP *o)
     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);
        break;
     case OP_CONST:
        SvREFCNT_dec(cSVOPo->op_sv);
@@ -612,7 +646,10 @@ op_free(OP *o)
            break;
        /* FALL THROUGH */
     case OP_TRANS:
-       Safefree(cPVOPo->op_pv);
+       if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
+           SvREFCNT_dec(cSVOPo->op_sv);
+       else
+           Safefree(cPVOPo->op_pv);
        break;
     case OP_SUBST:
        op_free(cPMOPo->op_pmreplroot);
@@ -682,15 +719,16 @@ scalarkids(OP *o)
 STATIC OP *
 scalarboolean(OP *o)
 {
-    if (PL_dowarn &&
-       o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
+    if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) {
        dTHR;
-       line_t oldline = PL_curcop->cop_line;
+       if (ckWARN(WARN_SYNTAX)) {
+           line_t oldline = PL_curcop->cop_line;
 
-       if (PL_copline != NOLINE)
-           PL_curcop->cop_line = PL_copline;
-       warn("Found = in conditional, should be ==");
-       PL_curcop->cop_line = oldline;
+           if (PL_copline != NOLINE)
+               PL_curcop->cop_line = PL_copline;
+           warner(WARN_SYNTAX, "Found = in conditional, should be ==");
+           PL_curcop->cop_line = oldline;
+       }
     }
     return scalar(o);
 }
@@ -877,15 +915,18 @@ scalarvoid(OP *o)
 
     case OP_CONST:
        sv = cSVOPo->op_sv;
-       if (PL_dowarn) {
-           useless = "a constant";
-           if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
-               useless = 0;
-           else if (SvPOK(sv)) {
-               if (strnEQ(SvPVX(sv), "di", 2) ||
-                   strnEQ(SvPVX(sv), "ds", 2) ||
-                   strnEQ(SvPVX(sv), "ig", 2))
-                       useless = 0;
+       {
+           dTHR;
+           if (ckWARN(WARN_VOID)) {
+               useless = "a constant";
+               if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
+                   useless = 0;
+               else if (SvPOK(sv)) {
+                   if (strnEQ(SvPVX(sv), "di", 2) ||
+                       strnEQ(SvPVX(sv), "ds", 2) ||
+                       strnEQ(SvPVX(sv), "ig", 2))
+                           useless = 0;
+               }
            }
        }
        null(o);                /* don't execute a constant */
@@ -944,8 +985,11 @@ scalarvoid(OP *o)
        }
        break;
     }
-    if (useless && PL_dowarn)
-       warn("Useless use of %s in void context", useless);
+    if (useless) {
+       dTHR;
+       if (ckWARN(WARN_VOID))
+           warner(WARN_VOID, "Useless use of %s in void context", useless);
+    }
     return o;
 }
 
@@ -1116,7 +1160,8 @@ mod(OP *o, I32 type)
        if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN)
            break;
        yyerror(form("Can't modify %s in %s",
-                    op_desc[o->op_type],
+                    (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)
+                     ? "do block" : op_desc[o->op_type]),
                     type ? op_desc[type] : "local"));
        return o;
 
@@ -1245,7 +1290,9 @@ mod(OP *o, I32 type)
        break;
 
     case OP_NULL:
-       if (!(o->op_flags & OPf_KIDS))
+       if (o->op_flags & OPf_SPECIAL)          /* do BLOCK */
+           goto nomod;
+       else if (!(o->op_flags & OPf_KIDS))
            break;
        if (o->op_targ != OP_LIST) {
            mod(cBINOPo->op_first, type);
@@ -1453,20 +1500,23 @@ sawparens(OP *o)
 OP *
 bind_match(I32 type, OP *left, OP *right)
 {
+    dTHR;
     OP *o;
 
-    if (PL_dowarn &&
-       (left->op_type == OP_RV2AV ||
-        left->op_type == OP_RV2HV ||
-        left->op_type == OP_PADAV ||
-        left->op_type == OP_PADHV)) {
-       char *desc = op_desc[(right->op_type == OP_SUBST ||
-                             right->op_type == OP_TRANS)
-                            ? right->op_type : OP_MATCH];
-       char *sample = ((left->op_type == OP_RV2AV ||
-                        left->op_type == OP_PADAV)
-                       ? "@array" : "%hash");
-       warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample);
+    if (ckWARN(WARN_UNSAFE) &&
+      (left->op_type == OP_RV2AV ||
+       left->op_type == OP_RV2HV ||
+       left->op_type == OP_PADAV ||
+       left->op_type == OP_PADHV)) {
+      char *desc = op_desc[(right->op_type == OP_SUBST ||
+                            right->op_type == OP_TRANS)
+                           ? right->op_type : OP_MATCH];
+      char *sample = ((left->op_type == OP_RV2AV ||
+                       left->op_type == OP_PADAV)
+                      ? "@array" : "%hash");
+      warner(WARN_UNSAFE,
+             "Applying %s to %s will act on scalar(%s)", 
+             desc, sample, sample);
     }
 
     if (right->op_type == OP_MATCH ||
@@ -1555,6 +1605,14 @@ block_start(int full)
     PL_pad_reset_pending = FALSE;
     SAVEHINTS();
     PL_hints &= ~HINT_BLOCK_SCOPE;
+    SAVEPPTR(PL_compiling.cop_warnings); 
+    if (PL_compiling.cop_warnings != WARN_ALL && 
+       PL_compiling.cop_warnings != WARN_NONE) {
+        PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
+        SAVEFREESV(PL_compiling.cop_warnings) ;
+    }
+
+
     return retval;
 }
 
@@ -1566,6 +1624,7 @@ block_end(I32 floor, OP *seq)
     OP* retval = scalarseq(seq);
     LEAVE_SCOPE(floor);
     PL_pad_reset_pending = FALSE;
+    PL_compiling.op_private = PL_hints;
     if (needblockscope)
        PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */
     pad_leavemy(PL_comppad_name_fill);
@@ -1625,11 +1684,13 @@ localize(OP *o, I32 lex)
     if (o->op_flags & OPf_PARENS)
        list(o);
     else {
-       if (PL_dowarn && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
+       dTHR;
+       if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') {
            char *s;
            for (s = PL_bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ;
            if (*s == ';' || *s == '=')
-               warn("Parens missing around \"%s\" list", lex ? "my" : "local");
+               warner(WARN_PARENTHESIS, "Parens missing around \"%s\" list",
+                               lex ? "my" : "local");
        }
     }
     PL_in_my = FALSE;
@@ -1862,7 +1923,7 @@ append_list(I32 type, LISTOP *first, LISTOP *last)
     first->op_last = last->op_last;
     first->op_children += last->op_children;
     if (first->op_children)
-       last->op_flags |= OPf_KIDS;
+       first->op_flags |= OPf_KIDS;
 
     Safefree(last);
     return (OP*)first;
@@ -2021,6 +2082,19 @@ newBINOP(I32 type, I32 flags, OP *first, OP *last)
     return fold_constants((OP *)binop);
 }
 
+static int
+utf8compare(const void *a, const void *b)
+{
+    int i;
+    for (i = 0; i < 10; i++) {
+       if ((*(U8**)a)[i] < (*(U8**)b)[i])
+           return -1;
+       if ((*(U8**)a)[i] > (*(U8**)b)[i])
+           return 1;
+    }
+    return 0;
+}
+
 OP *
 pmtrans(OP *o, OP *expr, OP *repl)
 {
@@ -2032,16 +2106,200 @@ pmtrans(OP *o, OP *expr, OP *repl)
     register U8 *r = (U8*)SvPV(rstr, rlen);
     register I32 i;
     register I32 j;
-    I32 Delete;
+    I32 del;
     I32 complement;
     I32 squash;
     register short *tbl;
 
-    tbl = (short*)cPVOPo->op_pv;
     complement = o->op_private & OPpTRANS_COMPLEMENT;
-    Delete     = o->op_private & OPpTRANS_DELETE;
+    del                = o->op_private & OPpTRANS_DELETE;
     squash     = o->op_private & OPpTRANS_SQUASH;
 
+    if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) {
+       SV* listsv = newSVpv("# comment\n",0);
+       SV* transv = 0;
+       U8* tend = t + tlen;
+       U8* rend = r + rlen;
+       I32 ulen;
+       U32 tfirst = 1;
+       U32 tlast = 0;
+       I32 tdiff;
+       U32 rfirst = 1;
+       U32 rlast = 0;
+       I32 rdiff;
+       I32 diff;
+       I32 none = 0;
+       U32 max = 0;
+       I32 bits;
+       I32 grows = 0;
+       I32 havefinal = 0;
+       U32 final;
+       HV *hv;
+       I32 from_utf    = o->op_private & OPpTRANS_FROM_UTF;
+       I32 to_utf      = o->op_private & OPpTRANS_TO_UTF;
+
+       if (complement) {
+           U8 tmpbuf[10];
+           U8** cp;
+           UV nextmin = 0;
+           New(1109, cp, tlen, U8*);
+           i = 0;
+           transv = newSVpv("",0);
+           while (t < tend) {
+               cp[i++] = t;
+               t += UTF8SKIP(t);
+               if (*t == 0xff) {
+                   t++;
+                   t += UTF8SKIP(t);
+               }
+           }
+           qsort(cp, i, sizeof(U8*), utf8compare);
+           for (j = 0; j < i; j++) {
+               U8 *s = cp[j];
+               UV val = utf8_to_uv(s, &ulen);
+               s += ulen;
+               diff = val - nextmin;
+               if (diff > 0) {
+                   t = uv_to_utf8(tmpbuf,nextmin);
+                   sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+                   if (diff > 1) {
+                       t = uv_to_utf8(tmpbuf, val - 1);
+                       sv_catpvn(transv, "\377", 1);
+                       sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+                   }
+               }
+               if (*s == 0xff)
+                   val = utf8_to_uv(s+1, &ulen);
+               if (val >= nextmin)
+                   nextmin = val + 1;
+           }
+           t = uv_to_utf8(tmpbuf,nextmin);
+           sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+           t = uv_to_utf8(tmpbuf, 0x7fffffff);
+           sv_catpvn(transv, "\377", 1);
+           sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
+           t = (U8*)SvPVX(transv);
+           tlen = SvCUR(transv);
+           tend = t + tlen;
+       }
+       else if (!rlen && !del) {
+           r = t; rlen = tlen; rend = tend;
+       }
+       if (!squash) {
+           if (to_utf && from_utf) {   /* only counting characters */
+               if (t == r || (tlen == rlen && memEQ(t, r, tlen)))
+                   o->op_private |= OPpTRANS_IDENTICAL;
+           }
+           else {      /* straight latin-1 translation */
+               if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) &&
+                   rlen == 4 && memEQ(r, "\0\377\303\277", 4))
+                   o->op_private |= OPpTRANS_IDENTICAL;
+           }
+       }
+
+       while (t < tend || tfirst <= tlast) {
+           /* see if we need more "t" chars */
+           if (tfirst > tlast) {
+               tfirst = (I32)utf8_to_uv(t, &ulen);
+               t += ulen;
+               if (t < tend && *t == 0xff) {   /* illegal utf8 val indicates range */
+                   tlast = (I32)utf8_to_uv(++t, &ulen);
+                   t += ulen;
+               }
+               else
+                   tlast = tfirst;
+           }
+
+           /* now see if we need more "r" chars */
+           if (rfirst > rlast) {
+               if (r < rend) {
+                   rfirst = (I32)utf8_to_uv(r, &ulen);
+                   r += ulen;
+                   if (r < rend && *r == 0xff) {       /* illegal utf8 val indicates range */
+                       rlast = (I32)utf8_to_uv(++r, &ulen);
+                       r += ulen;
+                   }
+                   else
+                       rlast = rfirst;
+               }
+               else {
+                   if (!havefinal++)
+                       final = rlast;
+                   rfirst = rlast = 0xffffffff;
+               }
+           }
+
+           /* now see which range will peter our first, if either. */
+           tdiff = tlast - tfirst;
+           rdiff = rlast - rfirst;
+
+           if (tdiff <= rdiff)
+               diff = tdiff;
+           else
+               diff = rdiff;
+
+           if (rfirst == 0xffffffff) {
+               diff = tdiff;   /* oops, pretend rdiff is infinite */
+               if (diff > 0)
+                   sv_catpvf(listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast);
+               else
+                   sv_catpvf(listsv, "%04x\t\tXXXX\n", tfirst);
+           }
+           else {
+               if (diff > 0)
+                   sv_catpvf(listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst);
+               else
+                   sv_catpvf(listsv, "%04x\t\t%04x\n", tfirst, rfirst);
+
+               if (rfirst + diff > max)
+                   max = rfirst + diff;
+               rfirst += diff + 1;
+               if (!grows) {
+                   if (rfirst <= 0x80)
+                       ;
+                   else if (rfirst <= 0x800)
+                       grows |= (tfirst < 0x80);
+                   else if (rfirst <= 0x10000)
+                       grows |= (tfirst < 0x800);
+                   else if (rfirst <= 0x200000)
+                       grows |= (tfirst < 0x10000);
+                   else if (rfirst <= 0x4000000)
+                       grows |= (tfirst < 0x200000);
+                   else if (rfirst <= 0x80000000)
+                       grows |= (tfirst < 0x4000000);
+               }
+           }
+           tfirst += diff + 1;
+       }
+
+       none = ++max;
+       if (del)
+           del = ++max;
+
+       if (max > 0xffff)
+           bits = 32;
+       else if (max > 0xff)
+           bits = 16;
+       else
+           bits = 8;
+
+       cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
+       SvREFCNT_dec(listsv);
+       if (transv)
+           SvREFCNT_dec(transv);
+
+       if (!del && havefinal)
+           (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0);
+
+       if (grows && to_utf)
+           o->op_private |= OPpTRANS_GROWS;
+
+       op_free(expr);
+       op_free(repl);
+       return o;
+    }
+
+    tbl = (short*)cPVOPo->op_pv;
     if (complement) {
        Zero(tbl, 256, short);
        for (i = 0; i < tlen; i++)
@@ -2049,7 +2307,7 @@ pmtrans(OP *o, OP *expr, OP *repl)
        for (i = 0, j = 0; i < 256; i++) {
            if (!tbl[i]) {
                if (j >= rlen) {
-                   if (Delete)
+                   if (del)
                        tbl[i] = -2;
                    else if (rlen)
                        tbl[i] = r[j-1];
@@ -2062,16 +2320,16 @@ pmtrans(OP *o, OP *expr, OP *repl)
        }
     }
     else {
-       if (!rlen && !Delete) {
+       if (!rlen && !del) {
            r = t; rlen = tlen;
            if (!squash)
-               o->op_private |= OPpTRANS_COUNTONLY;
+               o->op_private |= OPpTRANS_IDENTICAL;
        }
        for (i = 0; i < 256; i++)
            tbl[i] = -1;
        for (i = 0, j = 0; i < tlen; i++,j++) {
            if (j >= rlen) {
-               if (Delete) {
+               if (del) {
                    if (tbl[t[i]] == -1)
                        tbl[t[i]] = -2;
                    continue;
@@ -2347,6 +2605,7 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg)
     OP *rqop;
     OP *imop;
     OP *veop;
+    GV *gv;
 
     if (id->op_type != OP_CONST)
        croak("Module name must be constant");
@@ -2398,8 +2657,21 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg)
                        newUNOP(OP_METHOD, 0, meth)));
     }
 
-    /* Fake up a require */
-    rqop = newUNOP(OP_REQUIRE, 0, id);
+    /* Fake up a require, handle override, if any */
+    gv = gv_fetchpv("require", FALSE, SVt_PVCV);
+    if (!(gv && GvIMPORTED_CV(gv)))
+       gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV);
+
+    if (gv && GvIMPORTED_CV(gv)) {
+       rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
+                              append_elem(OP_LIST, id,
+                                          scalar(newUNOP(OP_RV2CV, 0,
+                                                         newGVOP(OP_GV, 0,
+                                                                 gv))))));
+    }
+    else {
+       rqop = newUNOP(OP_REQUIRE, 0, id);
+    }
 
     /* Fake up the BEGIN {}, which does its thing immediately. */
     newSUB(floor,
@@ -2416,6 +2688,29 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg)
 }
 
 OP *
+dofile(OP *term)
+{
+    OP *doop;
+    GV *gv;
+
+    gv = gv_fetchpv("do", FALSE, SVt_PVCV);
+    if (!(gv && GvIMPORTED_CV(gv)))
+       gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV);
+
+    if (gv && GvIMPORTED_CV(gv)) {
+       doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
+                              append_elem(OP_LIST, term,
+                                          scalar(newUNOP(OP_RV2CV, 0,
+                                                         newGVOP(OP_GV, 0,
+                                                                 gv))))));
+    }
+    else {
+       doop = newUNOP(OP_DOFILE, 0, scalar(term));
+    }
+    return doop;
+}
+
+OP *
 newSLICEOP(I32 flags, OP *subscript, OP *listval)
 {
     return newBINOP(OP_LSLICE, flags,
@@ -2611,10 +2906,11 @@ newSTATEOP(I32 flags, char *label, OP *o)
        cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ];
     }
     cop->op_flags = flags;
-    cop->op_private = 0 | (flags >> 8);
+    cop->op_private = (PL_hints & HINT_UTF8);
 #ifdef NATIVE_HINTS
     cop->op_private |= NATIVE_HINTS;
 #endif
+    PL_compiling.op_private = cop->op_private;
     cop->op_next = (OP*)cop;
 
     if (label) {
@@ -2623,6 +2919,12 @@ newSTATEOP(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)
+        cop->cop_warnings = PL_curcop->cop_warnings ;
+    else 
+        cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ;
+
 
     if (PL_copline == NOLINE)
         cop->cop_line = PL_curcop->cop_line;
@@ -2659,7 +2961,7 @@ intro_my(void)
     svp = AvARRAY(PL_comppad_name);
     for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
        if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) {
-           SvIVX(sv) = 999999999;      /* Don't know scope end yet. */
+           SvIVX(sv) = PAD_MAX;        /* Don't know scope end yet. */
            SvNVX(sv) = (double)PL_cop_seqmax;
        }
     }
@@ -2703,8 +3005,9 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp)
        }
     }
     if (first->op_type == OP_CONST) {
-       if (PL_dowarn && (first->op_private & OPpCONST_BARE))
-           warn("Probable precedence problem on %s", op_desc[type]);
+       if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE))
+           warner(WARN_PRECEDENCE, "Probable precedence problem on %s", 
+                       op_desc[type]);
        if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) {
            op_free(first);
            *firstp = Nullop;
@@ -2722,7 +3025,7 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp)
        else
            scalar(other);
     }
-    else if (PL_dowarn && (first->op_flags & OPf_KIDS)) {
+    else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) {
        OP *k1 = ((UNOP*)first)->op_first;
        OP *k2 = k1->op_sibling;
        OPCODE warnop = 0;
@@ -2745,7 +3048,8 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp)
        if (warnop) {
            line_t oldline = PL_curcop->cop_line;
            PL_curcop->cop_line = PL_copline;
-           warn("Value of %s%s can be \"0\"; test with defined()",
+           warner(WARN_UNSAFE,
+                "Value of %s%s can be \"0\"; test with defined()",
                 op_desc[warnop],
                 ((warnop == OP_READLINE || warnop == OP_GLOB)
                  ? " construct" : "() operator"));
@@ -3207,7 +3511,7 @@ CV* cv;
                  cv,
                  (CvANON(cv) ? "ANON"
                   : (cv == PL_main_cv) ? "MAIN"
-                  : CvUNIQUE(outside) ? "UNIQUE"
+                  : CvUNIQUE(cv) ? "UNIQUE"
                   : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
                  outside,
                  (!outside ? "null"
@@ -3307,7 +3611,7 @@ cv_clone2(CV *proto, CV *outside)
            char *name = SvPVX(namesv);    /* XXX */
            if (SvFLAGS(namesv) & SVf_FAKE) {   /* lexical from outside? */
                I32 off = pad_findlex(name, ix, SvIVX(namesv),
-                                     CvOUTSIDE(cv), cxstack_ix);
+                                     CvOUTSIDE(cv), cxstack_ix, 0);
                if (!off)
                    PL_curpad[ix] = SvREFCNT_inc(ppad[ix]);
                else if (off != ix)
@@ -3494,14 +3798,16 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block)
                croak("Can't redefine active sort subroutine %s", name);
            if(const_sv = cv_const_sv(cv))
                const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
-           if ((const_sv && const_changed) || PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
+           if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE) 
+                                       && !(CvGV(cv) && GvSTASH(CvGV(cv))
                                        && HvNAME(GvSTASH(CvGV(cv)))
                                        && strEQ(HvNAME(GvSTASH(CvGV(cv))),
                                                 "autouse"))) {
                line_t oldline = PL_curcop->cop_line;
                PL_curcop->cop_line = PL_copline;
-               warn(const_sv ? "Constant subroutine %s redefined"
-                    : "Subroutine %s redefined", name);
+               warner(WARN_REDEFINE,
+                       const_sv ? "Constant subroutine %s redefined"
+                                : "Subroutine %s redefined", name);
                PL_curcop->cop_line = oldline;
            }
            SvREFCNT_dec(cv);
@@ -3532,9 +3838,10 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block)
     CvSTASH(cv) = PL_curstash;
 #ifdef USE_THREADS
     CvOWNER(cv) = 0;
-    if (!CvMUTEXP(cv))
+    if (!CvMUTEXP(cv)) {
        New(666, CvMUTEXP(cv), 1, perl_mutex);
-    MUTEX_INIT(CvMUTEXP(cv));
+       MUTEX_INIT(CvMUTEXP(cv));
+    }
 #endif /* USE_THREADS */
 
     if (ps)
@@ -3656,6 +3963,7 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block)
            call_list(oldscope, PL_beginav);
 
            PL_curcop = &PL_compiling;
+           PL_compiling.op_private = PL_hints;
            LEAVE;
        }
        else if (strEQ(s, "END") && !PL_error_count) {
@@ -3721,12 +4029,12 @@ newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename)
        }
        else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
            /* already defined (or promised) */
-           if (PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv))
+           if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv))
                            && HvNAME(GvSTASH(CvGV(cv)))
                            && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) {
                line_t oldline = PL_curcop->cop_line;
                PL_curcop->cop_line = PL_copline;
-               warn("Subroutine %s redefined",name);
+               warner(WARN_REDEFINE, "Subroutine %s redefined",name);
                PL_curcop->cop_line = oldline;
            }
            SvREFCNT_dec(cv);
@@ -3777,6 +4085,7 @@ newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename)
            if (!PL_initav)
                PL_initav = newAV();
            av_push(PL_initav, (SV *)cv);
+           GvCV(gv) = 0;
        }
     }
     else
@@ -3801,11 +4110,11 @@ newFORM(I32 floor, OP *o, OP *block)
     gv = gv_fetchpv(name,TRUE, SVt_PVFM);
     GvMULTI_on(gv);
     if (cv = GvFORM(gv)) {
-       if (PL_dowarn) {
+       if (ckWARN(WARN_REDEFINE)) {
            line_t oldline = PL_curcop->cop_line;
 
            PL_curcop->cop_line = PL_copline;
-           warn("Format %s redefined",name);
+           warner(WARN_REDEFINE, "Format %s redefined",name);
            PL_curcop->cop_line = oldline;
        }
        SvREFCNT_dec(cv);
@@ -3857,7 +4166,7 @@ oopsAV(OP *o)
     case OP_PADSV:
        o->op_type = OP_PADAV;
        o->op_ppaddr = ppaddr[OP_PADAV];
-       return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV);
+       return ref(o, OP_RV2AV);
        
     case OP_RV2SV:
        o->op_type = OP_RV2AV;
@@ -3880,7 +4189,7 @@ oopsHV(OP *o)
     case OP_PADAV:
        o->op_type = OP_PADHV;
        o->op_ppaddr = ppaddr[OP_PADHV];
-       return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV);
+       return ref(o, OP_RV2HV);
 
     case OP_RV2SV:
     case OP_RV2AV:
@@ -4273,8 +4582,9 @@ ck_fun(OP *o)
                    char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
                    OP *newop = newAVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVAV) ));
-                   if (PL_dowarn)
-                       warn("Array @%s missing the @ in argument %ld of %s()",
+                   if (ckWARN(WARN_SYNTAX))
+                       warner(WARN_SYNTAX,
+                           "Array @%s missing the @ in argument %ld of %s()",
                            name, (long)numargs, op_desc[type]);
                    op_free(kid);
                    kid = newop;
@@ -4291,8 +4601,9 @@ ck_fun(OP *o)
                    char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na);
                    OP *newop = newHVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVHV) ));
-                   if (PL_dowarn)
-                       warn("Hash %%%s missing the %% in argument %ld of %s()",
+                   if (ckWARN(WARN_SYNTAX))
+                       warner(WARN_SYNTAX,
+                           "Hash %%%s missing the %% in argument %ld of %s()",
                            name, (long)numargs, op_desc[type]);
                    op_free(kid);
                    kid = newop;
@@ -4451,6 +4762,8 @@ ck_index(OP *o)
 {
     if (o->op_flags & OPf_KIDS) {
        OP *kid = cLISTOPo->op_first->op_sibling;       /* get past pushmark */
+       if (kid)
+           kid = kid->op_sibling;                      /* get past "big" */
        if (kid && kid->op_type == OP_CONST)
            fbm_compile(((SVOP*)kid)->op_sv, 0);
     }
@@ -4993,24 +5306,6 @@ peep(register OP *o)
            o->op_seq = PL_op_seqmax++;
            break;
 
-       case OP_PADAV:
-           if (o->op_next->op_type == OP_RV2AV
-               && (o->op_next->op_flags & OPf_REF))
-           {
-               null(o->op_next);
-               o->op_next = o->op_next->op_next;
-           }
-           break;
-       
-       case OP_PADHV:
-           if (o->op_next->op_type == OP_RV2HV
-               && (o->op_next->op_flags & OPf_REF))
-           {
-               null(o->op_next);
-               o->op_next = o->op_next->op_next;
-           }
-           break;
-
        case OP_MAPWHILE:
        case OP_GREPWHILE:
        case OP_AND:
@@ -5043,7 +5338,8 @@ peep(register OP *o)
 
        case OP_EXEC:
            o->op_seq = PL_op_seqmax++;
-           if (PL_dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) {
+           if (ckWARN(WARN_SYNTAX) && o->op_next 
+               && o->op_next->op_type == OP_NEXTSTATE) {
                if (o->op_next->op_sibling &&
                        o->op_next->op_sibling->op_type != OP_EXIT &&
                        o->op_next->op_sibling->op_type != OP_WARN &&
@@ -5051,8 +5347,8 @@ peep(register OP *o)
                    line_t oldline = PL_curcop->cop_line;
 
                    PL_curcop->cop_line = ((COP*)o->op_next)->cop_line;
-                   warn("Statement unlikely to be reached");
-                   warn("(Maybe you meant system() when you said exec()?)\n");
+                   warner(WARN_SYNTAX, "Statement unlikely to be reached");
+                   warner(WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n");
                    PL_curcop->cop_line = oldline;
                }
            }