clean up lexing checks
Matt S Trout [Tue, 30 Sep 2008 11:17:32 +0000 (11:17 +0000)]
Changes
Declare.xs

diff --git a/Changes b/Changes
index a811102..619e00e 100644 (file)
--- 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
 
index 34652c9..76d70dd 100644 (file)
 
 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