only use -fno-strict-aliasing when needed by compiler
[python/dscho.git] / Modules / sre.h
blob518c11db309ab26fc17c19a4ca5e143c070112d6
1 /*
2 * Secret Labs' Regular Expression Engine
4 * regular expression matching engine
6 * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
8 * See the _sre.c file for information on usage and redistribution.
9 */
11 #ifndef SRE_INCLUDED
12 #define SRE_INCLUDED
14 #include "sre_constants.h"
16 /* size of a code word (must be unsigned short or larger, and
17 large enough to hold a Py_UNICODE character) */
18 #ifdef Py_UNICODE_WIDE
19 #define SRE_CODE Py_UCS4
20 #else
21 #define SRE_CODE unsigned short
22 #endif
24 typedef struct {
25 PyObject_VAR_HEAD
26 Py_ssize_t groups; /* must be first! */
27 PyObject* groupindex;
28 PyObject* indexgroup;
29 /* compatibility */
30 PyObject* pattern; /* pattern source (or None) */
31 int flags; /* flags used when compiling pattern source */
32 PyObject *weakreflist; /* List of weak references */
33 int charsize; /* pattern charsize (or -1) */
34 /* pattern code */
35 Py_ssize_t codesize;
36 SRE_CODE code[1];
37 } PatternObject;
39 #define PatternObject_GetCode(o) (((PatternObject*)(o))->code)
41 typedef struct {
42 PyObject_VAR_HEAD
43 PyObject* string; /* link to the target string (must be first) */
44 PyObject* regs; /* cached list of matching spans */
45 PatternObject* pattern; /* link to the regex (pattern) object */
46 Py_ssize_t pos, endpos; /* current target slice */
47 Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */
48 Py_ssize_t groups; /* number of groups (start/end marks) */
49 Py_ssize_t mark[1];
50 } MatchObject;
52 typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
54 /* FIXME: <fl> shouldn't be a constant, really... */
55 #define SRE_MARK_SIZE 200
57 typedef struct SRE_REPEAT_T {
58 Py_ssize_t count;
59 SRE_CODE* pattern; /* points to REPEAT operator arguments */
60 void* last_ptr; /* helper to check for infinite loops */
61 struct SRE_REPEAT_T *prev; /* points to previous repeat context */
62 } SRE_REPEAT;
64 typedef struct {
65 /* string pointers */
66 void* ptr; /* current position (also end of current slice) */
67 void* beginning; /* start of original string */
68 void* start; /* start of current slice */
69 void* end; /* end of original string */
70 /* attributes for the match object */
71 PyObject* string;
72 Py_ssize_t pos, endpos;
73 /* character size */
74 int charsize;
75 /* registers */
76 Py_ssize_t lastindex;
77 Py_ssize_t lastmark;
78 void* mark[SRE_MARK_SIZE];
79 /* dynamically allocated stuff */
80 char* data_stack;
81 size_t data_stack_size;
82 size_t data_stack_base;
83 /* current repeat context */
84 SRE_REPEAT *repeat;
85 /* hooks */
86 SRE_TOLOWER_HOOK lower;
87 } SRE_STATE;
89 typedef struct {
90 PyObject_HEAD
91 PyObject* pattern;
92 SRE_STATE state;
93 } ScannerObject;
95 #endif