The first three patches from:
[p5sagit/p5-mst-13.2.git] / regexp.h
index f2c9705..248090a 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -15,8 +15,8 @@
  * not the System V one.
  */
 #ifndef PLUGGABLE_RE_EXTENSION
-/* we don't want to include this stuff if we are inside Nicholas'
- * pluggable regex engine code */
+/* we don't want to include this stuff if we are inside of
+   an external regex engine based on the core one - like re 'debug'*/
 
 struct regnode {
     U8 flags;
@@ -32,83 +32,73 @@ struct reg_data;
 
 struct regexp_engine;
 
-typedef struct regexp_paren_ofs {
-    I32 *startp;
-    I32 *endp;
-} regexp_paren_ofs;
+struct reg_substr_datum {
+    I32 min_offset;
+    I32 max_offset;
+    SV *substr;                /* non-utf8 variant */
+    SV *utf8_substr;   /* utf8 variant */
+    I32 end_shift;
+};
+struct reg_substr_data {
+    struct reg_substr_datum data[3];   /* Actual array */
+};
 
 #ifdef PERL_OLD_COPY_ON_WRITE
 #define SV_SAVED_COPY   SV *saved_copy; /* If non-NULL, SV which is COW from original */
 #else
 #define SV_SAVED_COPY
 #endif
-
+/* this is ordered such that the most commonly used 
+   fields are at the start of the struct */
 typedef struct regexp {
-        /* Generic details */
-       const struct regexp_engine* engine; /* what created this regexp? */
-       I32 refcnt;             /* Refcount of this regexp */
-        
-        /* The original string as passed to the compilation routine */
-       char *precomp;          /* pre-compilation regular expression */
-       I32 prelen;             /* length of precomp */
-        
-       /* Used for generic optimisations by the perl core. 
-          All engines are expected to provide this information.  */
+        /* what engine created this regexp? */
+       const struct regexp_engine* engine; 
+       
+       /* Information about the match that the perl core uses to manage things */
        U32 extflags;           /* Flags used both externally and internally */
        I32 minlen;             /* mininum possible length of string to match */
        I32 minlenret;          /* mininum possible length of $& */
        U32 gofs;               /* chars left of pos that we search from */
-       U32 nparens;            /* number of capture buffers */
-       HV *paren_names;        /* Optional hash of paren names */
-        struct reg_substr_data *substrs; /* substring data about strings that must appear
+       struct reg_substr_data *substrs; /* substring data about strings that must appear
                                    in the final match, used for optimisations */
+       U32 nparens;            /* number of capture buffers */
 
-        /* Data about the last/current match. Used by the core and therefore
-           must be populated by all engines. */
+        /* private engine specific data */
+       U32 intflags;           /* Engine Specific Internal flags */
+       void *pprivate;         /* Data private to the regex engine which 
+                                   created this object. */
+        
+        /* Data about the last/current match. These are modified during matching*/
+        U32 lastparen;         /* last open paren matched */
+       U32 lastcloseparen;     /* last close paren matched */
+        I32 *startp;            /* Array of offsets from start of string (@-) */
+       I32 *endp;              /* Array of offsets from start of string (@+) */
        char *subbeg;           /* saved or original string 
                                   so \digit works forever. */
        I32 sublen;             /* Length of string pointed by subbeg */
-        I32 *startp;            /* Array of offsets from start of string (@-) */
-       I32 *endp;              /* Array of offsets from start of string (@+) */
-       
        SV_SAVED_COPY           /* If non-NULL, SV which is COW from original */
-        U32 lastparen;         /* last open paren matched */
-       U32 lastcloseparen;     /* last close paren matched */
-       
-        /* Perl Regex Engine specific data. Other engines shouldn't need 
-           to touch this. Should be refactored out into a different structure
-           and accessed via the *pprivate field. (except intflags) */
-       U32 intflags;           /* Internal flags */
-       void *pprivate;         /* Data private to the regex engine which 
-                                   created this object. Perl will never mess with
-                                   this member at all. */
+        
+        
+        /* Information about the match that isn't often used */
+       char *precomp;          /* pre-compilation regular expression */
+       I32 prelen;             /* length of precomp */
+       I32 seen_evals;         /* number of eval groups in the pattern - for security checks */ 
+        HV *paren_names;       /* Optional hash of paren names */
+        
+        /* Refcount of this regexp */
+       I32 refcnt;             /* Refcount of this regexp */
 } regexp;
 
-
-typedef struct regexp_internal {
-        regexp_paren_ofs *swap; /* Swap copy of *startp / *endp */
-       U32 *offsets;           /* offset annotations 20001228 MJD 
-                                   data about mapping the program to the 
-                                   string*/
-        regnode *regstclass;    /* Optional startclass as identified or constructed
-                                   by the optimiser */
-        struct reg_data *data; /* Additional miscellaneous data used by the program.
-                                   Used to make it easier to clone and free arbitrary
-                                   data that the regops need. Often the ARG field of
-                                   a regop is an index into this structure */
-       regnode program[1];     /* Unwarranted chumminess with compiler. */
-} regexp_internal;
-
-#define RXi_SET(x,y) (x)->pprivate = (void*)(y)   
-#define RXi_GET(x)   ((regexp_internal *)((x)->pprivate))
-#define RXi_GET_DECL(r,ri) regexp_internal *ri = RXi_GET(r)
-
+/* used for high speed searches */
 typedef struct re_scream_pos_data_s
 {
     char **scream_olds;                /* match pos */
     I32 *scream_pos;           /* Internal iterator of scream. */
 } re_scream_pos_data;
 
+/* regexp_engine structure. This is the dispatch table for regexes.
+ * Any regex engine implementation must be able to build one of these.
+ */
 typedef struct regexp_engine {
     regexp* (*comp) (pTHX_ char* exp, char* xend, PMOP* pm);
     I32            (*exec) (pTHX_ regexp* prog, char* stringarg, char* strend,
@@ -119,23 +109,11 @@ typedef struct regexp_engine {
                            struct re_scream_pos_data_s *data);
     SV*            (*checkstr) (pTHX_ regexp *prog);
     void    (*free) (pTHX_ struct regexp* r);
-    char*   (*as_str)   (pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags,  I32 *haseval);
 #ifdef USE_ITHREADS
-    regexp* (*dupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
+    void* (*dupe) (pTHX_ const regexp *r, CLONE_PARAMS *param);
 #endif    
 } regexp_engine;
 
-/* 
- * Flags stored in regexp->intflags 
- * These are used only internally to the regexp engine
- */
-#define PREGf_SKIP             0x00000001
-#define PREGf_IMPLICIT         0x00000002 /* Converted .* to ^.* */
-#define PREGf_NAUGHTY          0x00000004 /* how exponential is this pattern? */
-#define PREGf_VERBARG_SEEN      0x00000008
-#define PREGf_CUTGROUP_SEEN    0x00000010
-
-
 /* Flags stored in regexp->extflags 
  * These are used by code external to the regexp engine
  */