X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Declare.xs;h=7e968350d4b4969976f580dec0aca07225c045d7;hb=8d96afb78ab58b0cd511077d97286175ff52692f;hp=99124d0211b7f693d83c78d671b63c5433fd54fa;hpb=f11d21b25ceebe4df4bbc27f189302a952d2acc6;p=p5sagit%2FDevel-Declare.git diff --git a/Declare.xs b/Declare.xs index 99124d0..7e96835 100644 --- a/Declare.xs +++ b/Declare.xs @@ -36,6 +36,8 @@ static int in_declare = 0; #define DD_AM_LEXING DD_AM_LEXING_CHECK #endif +static OP *previous_op = NULL; + /* thing that decides whether we're dealing with a declarator */ int dd_is_declarator(pTHX_ char* name) { @@ -114,7 +116,7 @@ char* dd_get_linestr(pTHX) { } void dd_set_linestr(pTHX_ char* new_value) { - int new_len = strlen(new_value); + unsigned int new_len = strlen(new_value); if (SvLEN(PL_linestr) < new_len) { croak("forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr)); @@ -182,7 +184,6 @@ int dd_toke_scan_word(pTHX_ int offset, int handle_package) { int dd_toke_scan_ident(pTHX_ int offset) { char tmpbuf[sizeof PL_tokenbuf]; char* base_s = SvPVX(PL_linestr) + offset; - STRLEN len; char* s = scan_ident(base_s, PL_bufend, tmpbuf, sizeof tmpbuf, 0); return s - base_s; } @@ -206,6 +207,8 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { OP* kid; int dd_flags; + PERL_UNUSED_VAR(user_data); + if (in_declare) { if (dd_debug) { printf("Deconstructing declare\n"); @@ -299,6 +302,8 @@ OP* dd_pp_entereval(pTHX) { } STATIC OP *dd_ck_entereval(pTHX_ OP *o, void *user_data) { + PERL_UNUSED_VAR(user_data); + if (o->op_ppaddr == PL_ppaddr[OP_ENTEREVAL]) o->op_ppaddr = dd_pp_entereval; return o; @@ -316,6 +321,8 @@ STATIC OP *dd_ck_const(pTHX_ OP *o, void *user_data) { int dd_flags; char* name; + PERL_UNUSED_VAR(user_data); + /* if this is set, we just grabbed a delimited string or something, not a bareword, so NO TOUCHY */ @@ -333,9 +340,29 @@ STATIC OP *dd_ck_const(pTHX_ OP *o, void *user_data) { if (dd_flags == -1) return o; + if (previous_op != NULL) { + switch (previous_op->op_type) { + case OP_QR: + case OP_MATCH: + case OP_SUBST: + case OP_TRANS: + return o; + break; + default: + break; + } + } dd_linestr_callback(aTHX_ "const", name); - return o; + return o; +} + +STATIC OP * +remember_previous_op (pTHX_ OP *o, void *user_data) +{ + PERL_UNUSED_VAR (user_data); + previous_op = o; + return o; } static int initialized = 0; @@ -346,12 +373,17 @@ PROTOTYPES: DISABLE void setup() + PREINIT: + I32 i; CODE: if (!initialized++) { hook_op_check(OP_RV2CV, dd_ck_rv2cv, NULL); hook_op_check(OP_ENTEREVAL, dd_ck_entereval, NULL); hook_op_check(OP_CONST, dd_ck_const, NULL); } + for (i = 0; i < OP_max; i++) { + (void)hook_op_check(i, remember_previous_op, NULL); + } filter_add(dd_filter_realloc, NULL); char*