comparison src/regex.c @ 11656:a40849041718

(union fail_stack_elt): New union. (fail_stack_elt_t): Use that union. (PUSH_PATTERN_OP, PUSH_FAILURE_POINTER, PUSH_FAILURE_INT) (POP_FAILURE_POINTER, POP_FAILURE_INT): Corresponding changes. (re_compile_fastmap): Corresponding changes. (PUSH_FAILURE_ELT): New macro. (FAIL_STACK_TOP): Macro deleted. (WIDE_INT): Macro deleted. (PUSH_FAILURE_POINT): Use PUSH_FAILURE_ELT. (POP_FAILURE_ELT): New macro. (POP_FAILURE_POINT): Use POP_FAILURE_ELT.
author Richard M. Stallman <rms@gnu.org>
date Tue, 02 May 1995 16:27:24 +0000
parents eba5c25341ff
children bb59c20c60cb
comparison
equal deleted inserted replaced
11655:a9f93ce6e1b4 11656:a40849041718
47 47
48 #include "lisp.h" 48 #include "lisp.h"
49 #include "buffer.h" 49 #include "buffer.h"
50 #include "syntax.h" 50 #include "syntax.h"
51 51
52 #define WIDE_INT EMACS_INT
53
54 #else /* not emacs */ 52 #else /* not emacs */
55 53
56 #ifdef STDC_HEADERS 54 #ifdef STDC_HEADERS
57 #include <stdlib.h> 55 #include <stdlib.h>
58 #else 56 #else
59 char *malloc (); 57 char *malloc ();
60 char *realloc (); 58 char *realloc ();
61 #endif 59 #endif
62
63 /* This isn't right--it needs to check for machines with 64-bit pointers
64 and do something different. But I don't know what, and I don't
65 need to deal with it right now. -- rms. */
66 #define WIDE_INT int
67 60
68 /* We used to test for `BSTRING' here, but only GCC and Emacs define 61 /* We used to test for `BSTRING' here, but only GCC and Emacs define
69 `BSTRING', as far as I know, and neither of them use this code. */ 62 `BSTRING', as far as I know, and neither of them use this code. */
70 #ifndef INHIBIT_STRING_HEADER 63 #ifndef INHIBIT_STRING_HEADER
71 #if HAVE_STRING_H || STDC_HEADERS 64 #if HAVE_STRING_H || STDC_HEADERS
988 int re_max_failures = 20000000; 981 int re_max_failures = 20000000;
989 #else 982 #else
990 int re_max_failures = 2000; 983 int re_max_failures = 2000;
991 #endif 984 #endif
992 985
993 typedef unsigned char *fail_stack_elt_t; 986 union fail_stack_elt
987 {
988 unsigned char *pointer;
989 int integer;
990 };
991
992 typedef union fail_stack_elt fail_stack_elt_t;
994 993
995 typedef struct 994 typedef struct
996 { 995 {
997 fail_stack_elt_t *stack; 996 fail_stack_elt_t *stack;
998 unsigned size; 997 unsigned size;
1000 } fail_stack_type; 999 } fail_stack_type;
1001 1000
1002 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0) 1001 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
1003 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) 1002 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
1004 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) 1003 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
1005 #define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail])
1006 1004
1007 1005
1008 /* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ 1006 /* Initialize `fail_stack'. Do `return -2' if the alloc fails. */
1009 1007
1010 #ifdef MATCH_MAY_ALLOCATE 1008 #ifdef MATCH_MAY_ALLOCATE
1046 ? 0 \ 1044 ? 0 \
1047 : ((fail_stack).size <<= 1, \ 1045 : ((fail_stack).size <<= 1, \
1048 1))) 1046 1)))
1049 1047
1050 1048
1051 /* Push PATTERN_OP on FAIL_STACK. 1049 /* Push pointer POINTER on FAIL_STACK.
1052
1053 Return 1 if was able to do so and 0 if ran out of memory allocating 1050 Return 1 if was able to do so and 0 if ran out of memory allocating
1054 space to do so. */ 1051 space to do so. */
1055 #define PUSH_PATTERN_OP(pattern_op, fail_stack) \ 1052 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
1056 ((FAIL_STACK_FULL () \ 1053 ((FAIL_STACK_FULL () \
1057 && !DOUBLE_FAIL_STACK (fail_stack)) \ 1054 && !DOUBLE_FAIL_STACK (FAIL_STACK)) \
1058 ? 0 \ 1055 ? 0 \
1059 : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ 1056 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
1060 1)) 1057 1))
1061 1058
1062 /* Push a pointer value onto the failure stack. 1059 /* Push a pointer value onto the failure stack.
1063 Assumes the variable `fail_stack'. Probably should only 1060 Assumes the variable `fail_stack'. Probably should only
1064 be called from within `PUSH_FAILURE_POINT'. */ 1061 be called from within `PUSH_FAILURE_POINT'. */
1065 #define PUSH_FAILURE_POINTER(item) \ 1062 #define PUSH_FAILURE_POINTER(item) \
1066 fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) (item) 1063 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
1067 1064
1068 /* This pushes an integer-valued item onto the failure stack. 1065 /* This pushes an integer-valued item onto the failure stack.
1069 Assumes the variable `fail_stack'. Probably should only 1066 Assumes the variable `fail_stack'. Probably should only
1070 be called from within `PUSH_FAILURE_POINT'. */ 1067 be called from within `PUSH_FAILURE_POINT'. */
1071 #define PUSH_FAILURE_INT(item) \ 1068 #define PUSH_FAILURE_INT(item) \
1072 fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) (WIDE_INT) (item) 1069 fail_stack.stack[fail_stack.avail++].integer = (item)
1073 1070
1074 /* The complement operation. Assumes `fail_stack' is nonempty. */ 1071 /* Push a fail_stack_elt_t value onto the failure stack.
1075 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail] 1072 Assumes the variable `fail_stack'. Probably should only
1076 1073 be called from within `PUSH_FAILURE_POINT'. */
1077 /* The complement operation. Assumes `fail_stack' is nonempty. */ 1074 #define PUSH_FAILURE_ELT(item) \
1078 #define POP_FAILURE_INT() (WIDE_INT) fail_stack.stack[--fail_stack.avail] 1075 fail_stack.stack[fail_stack.avail++] = (item)
1076
1077 /* These three POP... operations complement the three PUSH... operations.
1078 All assume that `fail_stack' is nonempty. */
1079 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
1080 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
1081 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
1079 1082
1080 /* Used to omit pushing failure point id's when we're not debugging. */ 1083 /* Used to omit pushing failure point id's when we're not debugging. */
1081 #ifdef DEBUG 1084 #ifdef DEBUG
1082 #define DEBUG_PUSH PUSH_FAILURE_INT 1085 #define DEBUG_PUSH PUSH_FAILURE_INT
1083 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT () 1086 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
1145 DEBUG_PRINT2 (" matched_something=%d", \ 1148 DEBUG_PRINT2 (" matched_something=%d", \
1146 MATCHED_SOMETHING (reg_info[this_reg])); \ 1149 MATCHED_SOMETHING (reg_info[this_reg])); \
1147 DEBUG_PRINT2 (" ever_matched=%d", \ 1150 DEBUG_PRINT2 (" ever_matched=%d", \
1148 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ 1151 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
1149 DEBUG_PRINT1 ("\n"); \ 1152 DEBUG_PRINT1 ("\n"); \
1150 PUSH_FAILURE_POINTER (reg_info[this_reg].word); \ 1153 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
1151 } \ 1154 } \
1152 \ 1155 \
1153 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ 1156 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\
1154 PUSH_FAILURE_INT (lowest_active_reg); \ 1157 PUSH_FAILURE_INT (lowest_active_reg); \
1155 \ 1158 \
1247 \ 1250 \
1248 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ 1251 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
1249 { \ 1252 { \
1250 DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ 1253 DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \
1251 \ 1254 \
1252 reg_info[this_reg].word = POP_FAILURE_POINTER (); \ 1255 reg_info[this_reg].word = POP_FAILURE_ELT (); \
1253 DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ 1256 DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \
1254 \ 1257 \
1255 regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \ 1258 regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \
1256 DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ 1259 DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \
1257 \ 1260 \
1264 } /* POP_FAILURE_POINT */ 1267 } /* POP_FAILURE_POINT */
1265 1268
1266 1269
1267 1270
1268 /* Structure for per-register (a.k.a. per-group) information. 1271 /* Structure for per-register (a.k.a. per-group) information.
1269 This must not be longer than one word, because we push this value 1272 Other register information, such as the
1270 onto the failure stack. Other register information, such as the
1271 starting and ending positions (which are addresses), and the list of 1273 starting and ending positions (which are addresses), and the list of
1272 inner groups (which is a bits list) are maintained in separate 1274 inner groups (which is a bits list) are maintained in separate
1273 variables. 1275 variables.
1274 1276
1275 We are making a (strictly speaking) nonportable assumption here: that 1277 We are making a (strictly speaking) nonportable assumption here: that
1276 the compiler will pack our bit fields into something that fits into 1278 the compiler will pack our bit fields into something that fits into
1277 the type of `word', i.e., is something that fits into one item on the 1279 the type of `word', i.e., is something that fits into one item on the
1278 failure stack. */ 1280 failure stack. */
1281
1279 typedef union 1282 typedef union
1280 { 1283 {
1281 fail_stack_elt_t word; 1284 fail_stack_elt_t word;
1282 struct 1285 struct
1283 { 1286 {
2893 bufp->can_be_null |= path_can_be_null; 2896 bufp->can_be_null |= path_can_be_null;
2894 2897
2895 /* Reset for next path. */ 2898 /* Reset for next path. */
2896 path_can_be_null = true; 2899 path_can_be_null = true;
2897 2900
2898 p = fail_stack.stack[--fail_stack.avail]; 2901 p = fail_stack.stack[--fail_stack.avail].pointer;
2899 2902
2900 continue; 2903 continue;
2901 } 2904 }
2902 else 2905 else
2903 break; 2906 break;
3045 EXTRACT_NUMBER_AND_INCR (j, p); 3048 EXTRACT_NUMBER_AND_INCR (j, p);
3046 p += j; 3049 p += j;
3047 3050
3048 /* If what's on the stack is where we are now, pop it. */ 3051 /* If what's on the stack is where we are now, pop it. */
3049 if (!FAIL_STACK_EMPTY () 3052 if (!FAIL_STACK_EMPTY ()
3050 && fail_stack.stack[fail_stack.avail - 1] == p) 3053 && fail_stack.stack[fail_stack.avail - 1].pointer == p)
3051 fail_stack.avail--; 3054 fail_stack.avail--;
3052 3055
3053 continue; 3056 continue;
3054 3057
3055 3058