Lines Matching +defs:ind +defs:stack

154 struct stack {
163 static void stack_check(struct stack *stack)
168 if (!stack)
171 SLJIT_ASSERT(stack->index >= 0 && stack->index < STACK_FRAGMENT_SIZE);
173 if (stack->first == NULL) {
174 SLJIT_ASSERT(stack->first == NULL && stack->last == NULL);
175 SLJIT_ASSERT(stack->index == STACK_FRAGMENT_SIZE - 1 && stack->count == 0);
180 if (stack->last == NULL) {
181 SLJIT_ASSERT(stack->index == STACK_FRAGMENT_SIZE - 1 && stack->count == 0);
185 SLJIT_ASSERT(stack->index >= 0 && stack->count >= 0);
187 SLJIT_ASSERT(stack->first->data.prev == NULL);
188 curr = stack->first;
190 if (curr == stack->last)
201 static void stack_init(struct stack *stack)
203 stack->first = NULL;
204 stack->last = NULL;
205 stack->index = STACK_FRAGMENT_SIZE - 1;
206 stack->count = 0;
209 static void stack_destroy(struct stack *stack)
211 struct stack_fragment *curr = stack->first;
215 stack_check(stack);
225 static SLJIT_INLINE struct stack_item* stack_top(struct stack *stack)
227 SLJIT_ASSERT(stack->last);
228 return stack->last->items + stack->index;
231 static int stack_push(struct stack *stack, int type, int value)
233 if (stack->last) {
234 stack->index++;
235 if (stack->index >= STACK_FRAGMENT_SIZE) {
236 stack->index = 0;
237 if (!stack->last->data.next) {
238 stack->last->data.next = (struct stack_fragment*)SLJIT_MALLOC(sizeof(struct stack_fragment), NULL);
239 if (!stack->last->data.next)
241 stack->last->data.next->data.next = NULL;
242 stack->last->data.next->data.prev = stack->last;
244 stack->last = stack->last->data.next;
247 else if (!stack->first) {
248 stack->last = (struct stack_fragment*)SLJIT_MALLOC(sizeof(struct stack_fragment), NULL);
249 if (!stack->last)
251 stack->last->data.prev = NULL;
252 stack->last->data.next = NULL;
253 stack->first = stack->last;
254 stack->index = 0;
257 stack->last = stack->first;
258 stack->index = 0;
260 stack->last->items[stack->index].type = type;
261 stack->last->items[stack->index].value = value;
262 stack->count++;
264 stack_check(stack);
269 static struct stack_item* stack_pop(struct stack *stack)
271 struct stack_item *ret = stack_top(stack);
273 if (stack->index > 0)
274 stack->index--;
276 stack->last = stack->last->data.prev;
277 stack->index = STACK_FRAGMENT_SIZE - 1;
280 stack->count--;
282 stack_check(stack);
287 static SLJIT_INLINE void stack_clone(struct stack *src, struct stack *dst)
292 static int stack_push_copy(struct stack *stack, int items, int length)
300 SLJIT_ASSERT(stack->count >= length && items <= length && items > 0);
304 frag1 = stack->last;
305 ind1 = stack->index;
307 if (stack->index + counter >= STACK_FRAGMENT_SIZE) {
308 counter -= STACK_FRAGMENT_SIZE - stack->index - 1 + 1;
309 stack->index = 0;
310 if (!stack->last->data.next) {
311 stack->last->data.next = (struct stack_fragment*)SLJIT_MALLOC(sizeof(struct stack_fragment), NULL);
312 if (!stack->last->data.next)
314 stack->last->data.next->data.next = NULL;
315 stack->last->data.next->data.prev = stack->last;
317 stack->last = stack->last->data.next;
320 stack->index += counter;
325 frag2 = stack->last;
326 ind2 = stack->index;
341 stack_check(stack);
343 stack->count += items;
379 struct stack stack;
380 struct stack depth;
425 static int iterate(struct stack *stack, int min, int max)
427 struct stack it;
433 stack_clone(stack, &it);
480 stack_clone(&it, stack);
482 if (stack_push(stack, type_open_br, 0))
484 if (stack_push(stack, type_close_br, 0))
489 count = stack->count - count;
492 if (stack_push_copy(stack, 1, count))
511 if (stack_push_copy(stack, count, count))
516 if (stack_push_copy(stack, count, count))
518 if (stack_push(stack, type_qestion_mark, 0))
528 if (stack_push(stack, type_qestion_mark, 0))
533 if (stack_push_copy(stack, count, count))
544 if (stack_push_copy(stack, count, count))
549 if (stack_push(stack, type_plus_sign, 0))
554 if (stack_push(stack, type_close_br, 0))
560 static int parse_iterator(const regex_char_t *regex_string, int length, struct stack *stack, sljit_sw *dfa_size, int begin)
595 if (stack_push(stack, type_id, val1))
632 val1 = iterate(stack, val1, val2);
638 if (stack_push(stack, type_asterisk, 0))
643 if (stack_push(stack, type_plus_sign, 0))
648 if (stack_push(stack, type_qestion_mark, 0))
653 val1 = iterate(stack, 0, 0);
668 struct stack* stack = &compiler_common->stack;
679 if (stack_push(stack, type_rng_start, 0))
689 if (stack_push(stack, type_rng_start, 1))
699 if (stack_push(stack, type_rng_char, ']'))
747 if (stack_push(stack, type_rng_left, left_char))
749 if (stack_push(stack, type_rng_right, right_char))
754 if (stack_push(stack, type_rng_char, left_char))
760 if (stack_push(stack, type_rng_end, 0))
771 /* Cache stack pointer. */
772 struct stack* stack = &compiler_common->stack;
777 stack_init(stack);
778 if (stack_push(stack, type_begin, 0))
792 if (stack_push(stack, type_newline, 0))
805 if (stack_push(stack, type_char, *regex_string))
812 if (stack_push(stack, type_rng_start, 1))
815 if (stack_push(stack, type_rng_char, '\n'))
817 if (stack_push(stack, type_rng_char, '\r'))
821 if (stack_push(stack, type_rng_end, 1))
829 if (stack_push(stack, type_open_br, 0))
838 if (stack_push(stack, type_close_br, 0))
844 if (stack_push(stack, type_select, 0))
853 if (stack_push(stack, type_asterisk, 0))
862 if (stack_push(stack, (*regex_string == '+') ? type_plus_sign : type_qestion_mark, 0))
868 tmp = parse_iterator(regex_string, length, stack, &compiler_common->dfa_size, begin);
879 if (stack_push(stack, type_char, '{'))
905 if (stack_push(stack, type_char, *regex_string))
923 if (stack_push(stack, type_newline, 1))
929 if (stack_push(stack, type_end, 0))
946 static struct stack_item* handle_iteratives(struct stack_item *transitions_ptr, struct stack_item *transitions, struct stack *depth)
978 struct stack *stack = &compiler_common->stack;
979 struct stack *depth = &compiler_common->depth;
988 /* Go through the items of the stack and generate the necessary branches and jumps (edges of DFA). */
990 while (stack->count > 0) {
991 item = stack_pop(stack);
1000 if (stack->count == 0)
1234 struct stack *stack = &compiler_common->stack;
1235 struct stack *depth = &compiler_common->depth;
1252 if (stack_push(stack, 0, from))
1316 struct stack *stack = &compiler_common->stack;
1330 while (stack->count > 0) {
1331 value = stack_pop(stack)->value;
1374 struct stack *stack = &compiler_common->stack;
1395 while (stack->count > 0) {
1396 value = stack_pop(stack)->value;
1635 struct stack *stack = &compiler_common->stack;
1638 int ind;
1642 while (stack->count > 0) {
1643 ind = stack_pop(stack)->value;
1644 search_states[ind].value = -1;
1645 if (search_states[ind].type >= 0) {
1646 if (dfa_transitions[ind].type == type_char) {
1647 EMIT_CMP(jump, SLJIT_EQUAL, R_CURR_CHAR, 0, SLJIT_IMM, dfa_transitions[ind].value);
1650 else if (dfa_transitions[ind].type == type_rng_start) {
1651 SLJIT_ASSERT(!dfa_transitions[ind].value);
1652 ind++;
1653 while (dfa_transitions[ind].type != type_rng_end) {
1654 if (dfa_transitions[ind].type == type_rng_char) {
1655 EMIT_CMP(jump, SLJIT_EQUAL, R_CURR_CHAR, 0, SLJIT_IMM, dfa_transitions[ind].value);
1659 SLJIT_ASSERT(dfa_transitions[ind].type == type_rng_left);
1664 if (dfa_transitions[ind].value != prev_value) {
1666 prev_value -= dfa_transitions[ind].value;
1673 prev_value = dfa_transitions[ind].value;
1675 EMIT_CMP(jump, SLJIT_LESS_EQUAL, R_TEMP, 0, SLJIT_IMM, dfa_transitions[ind + 1].value - dfa_transitions[ind].value);
1677 ind++;
1679 ind++;
1683 SLJIT_ASSERT(dfa_transitions[ind].type == type_newline);
1694 static int compile_newline_check(struct compiler_common *compiler_common, sljit_sw ind)
1708 offset = TERM_OFFSET_OF(compiler_common->search_states[ind].type, 1);
1733 static sljit_sw compile_range_check(struct compiler_common *compiler_common, sljit_sw ind)
1738 int invert = dfa_transitions[ind].value;
1744 ind++;
1746 while (dfa_transitions[ind].type != type_rng_end) {
1747 if (dfa_transitions[ind].type == type_rng_char) {
1748 EMIT_CMP(*range_jump_list, SLJIT_EQUAL, R_CURR_CHAR, 0, SLJIT_IMM, dfa_transitions[ind].value);
1752 SLJIT_ASSERT(dfa_transitions[ind].type == type_rng_left);
1757 if (dfa_transitions[ind].value != prev_value) {
1759 prev_value -= dfa_transitions[ind].value;
1766 prev_value = dfa_transitions[ind].value;
1768 EMIT_CMP(*range_jump_list, SLJIT_LESS_EQUAL, R_TEMP, 0, SLJIT_IMM, dfa_transitions[ind + 1].value - dfa_transitions[ind].value);
1770 ind++;
1772 ind++;
1779 offset = TERM_OFFSET_OF(compiler_common->search_states[ind].type, 1);
1789 return ind;
1804 #define TERM_OFFSET_OF(ind, offs) (((ind) * compiler_common.no_states + (offs)) * sizeof(sljit_sw))
1838 sljit_sw ind;
1868 stack_destroy(&compiler_common.stack);
1876 stack_destroy(&compiler_common.stack);
1901 stack_init(&compiler_common.stack);
1937 while (compiler_common.stack.count > 0) {
1938 ind = stack_pop(&compiler_common.stack)->value;
1939 if (compiler_common.search_states[ind].type == 0) {
1940 SLJIT_ASSERT(compiler_common.dfa_transitions[ind].type == type_end);
1942 empty_match_id = compiler_common.search_states[ind].value;
1944 else if (compiler_common.search_states[ind].type > 0) {
1945 SLJIT_ASSERT(compiler_common.dfa_transitions[ind].type != type_end);
1946 if (compiler_common.dfa_transitions[ind].type == type_rng_start && compiler_common.dfa_transitions[ind].value)
1949 compiler_common.search_states[ind].value = -1;
1955 while (compiler_common.stack.count > 0) {
1956 ind = stack_pop(&compiler_common.stack)->value;
1957 if (compiler_common.search_states[ind].type == 0) {
1958 SLJIT_ASSERT(compiler_common.dfa_transitions[ind].type == type_end);
1960 empty_match_id = compiler_common.search_states[ind].value;
1962 compiler_common.search_states[ind].value = -1;
2044 while (compiler_common.stack.count > 0) {
2045 ind = stack_pop(&compiler_common.stack)->value;
2046 if (compiler_common.search_states[ind].type >= 0)
2047 printf("-> (%3d:%3d) ", compiler_common.search_states[ind].type, compiler_common.search_states[ind].value);
2048 compiler_common.search_states[ind].value = -1;
2090 while (compiler_common.stack.count > 0) {
2091 ind = stack_pop(&compiler_common.stack)->value;
2092 if (compiler_common.search_states[ind].type >= 0) {
2093 EMIT_OP1(SLJIT_MOV, SLJIT_MEM1(R_CURR_STATE), TERM_OFFSET_OF(compiler_common.search_states[ind].type, 2), R_TEMP, 0);
2095 compiler_common.search_states[ind].value = -1;
2190 for (ind = 1; ind < compiler_common.dfa_size - 1; ind++) {
2191 if (compiler_common.search_states[ind].type >= 0) {
2192 SLJIT_ASSERT(compiler_common.search_states[ind].type < compiler_common.terms_size);
2194 compiler_common.machine->entry_addrs[compiler_common.search_states[ind].type] = (sljit_uw)label;
2196 if (compiler_common.dfa_transitions[ind].type == type_char) {
2197 EMIT_CMP(jump, SLJIT_NOT_EQUAL, R_CURR_CHAR, 0, SLJIT_IMM, compiler_common.dfa_transitions[ind].value);
2199 else if (compiler_common.dfa_transitions[ind].type == type_rng_start) {
2200 ind = compile_range_check(&compiler_common, ind);
2201 CHECK(!ind);
2204 SLJIT_ASSERT(compiler_common.dfa_transitions[ind].type == type_newline);
2205 CHECK(compile_newline_check(&compiler_common, ind));
2208 CHECK(trace_transitions(ind, &compiler_common));
2211 printf("(%3d): ", compiler_common.search_states[ind].type);
2213 CHECK(compile_cond_tran(&compiler_common, compiler_common.search_states[ind].type));
2215 if (compiler_common.dfa_transitions[ind].type == type_char) {
2219 else if (compiler_common.dfa_transitions[ind].type == type_rng_end) {
2224 SLJIT_ASSERT(compiler_common.dfa_transitions[ind].type == type_newline);
2228 EMIT_OP1(SLJIT_MOV, R_TEMP, 0, SLJIT_MEM1(R_CURR_STATE), TERM_OFFSET_OF(compiler_common.search_states[ind].type, 1));
2229 EMIT_OP1(SLJIT_MOV, SLJIT_MEM1(R_CURR_STATE), TERM_OFFSET_OF(compiler_common.search_states[ind].type, 1), SLJIT_IMM, -1);
2234 if (ind == compiler_common.dfa_size - 1) {
2275 for (ind = 0; ind < compiler_common.terms_size; ++ind)
2276 compiler_common.machine->entry_addrs[ind] = sljit_get_label_addr((struct sljit_label*)compiler_common.machine->entry_addrs[ind]);
2282 stack_destroy(&compiler_common.stack);
2398 sljit_sw current, ind;
2410 ind = (current / sizeof(sljit_sw)) + 1;
2411 current = current_ptr[ind];
2412 current_ptr[ind] = -1;