From: Matt S Trout Date: Tue, 30 Sep 2008 11:17:32 +0000 (+0000) Subject: clean up lexing checks X-Git-Tag: 0.005000~88 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-Declare.git;a=commitdiff_plain;h=96f1272669073ca92e17777ca1c93406081d7355 clean up lexing checks --- diff --git a/Changes b/Changes index a811102..619e00e 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Changes for Devel-Declare + - clean up checks for whether we're lexing and whether lex_stuff exists + to handle the PL_parser factor-out in 5.10 + 0.002000 - rewrite guts into perl, add tests for new declaration style diff --git a/Declare.xs b/Declare.xs index 34652c9..76d70dd 100644 --- a/Declare.xs +++ b/Declare.xs @@ -29,6 +29,22 @@ static int in_declare = 0; +/* in 5.10, PL_parser will be NULL if we aren't parsing, and PL_lex_stuff + is a lookup into it - so if anything else we can use to tell, so we + need to be a bit more careful if PL_parser exists */ + +#define DD_AM_LEXING_CHECK (PL_lex_state == LEX_NORMAL || PL_lex_state == LEX_INTERPNORMAL) + +#ifdef PL_parser +#define DD_HAVE_PARSER PL_parser +#define DD_HAVE_LEX_STUFF (PL_parser && PL_lex_stuff) +#define DD_AM_LEXING (PL_parser && DD_AM_LEXING_CHECK) +#else +#define DD_HAVE_PARSER 1 +#define DD_HAVE_LEX_STUFF PL_lex_stuff +#define DD_AM_LEXING DD_AM_LEXING_CHECK +#endif + /* thing that decides whether we're dealing with a declarator */ int dd_is_declarator(pTHX_ char* name) { @@ -117,11 +133,12 @@ void dd_set_linestr(pTHX_ char* new_value) { } char* dd_get_lex_stuff(pTHX) { - return (PL_lex_stuff ? SvPVX(PL_lex_stuff) : ""); + return (DD_HAVE_LEX_STUFF ? SvPVX(PL_lex_stuff) : ""); } char* dd_clear_lex_stuff(pTHX) { - PL_lex_stuff = Nullsv; + if (DD_HAVE_PARSER) + PL_lex_stuff = Nullsv; } char* dd_get_curstash_name(pTHX) { @@ -209,7 +226,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o) { if (kid->op_type != OP_GV) /* not a GV so ignore */ return o; - if (PL_lex_state != LEX_NORMAL && PL_lex_state != LEX_INTERPNORMAL) + if (!DD_AM_LEXING) return o; /* not lexing? */ #ifdef DD_DEBUG