6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE perl_matcher_common.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Definitions of perl_matcher member functions that are
17 * specific to the non-recursive implementation.
20 #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
21 #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
25 #ifdef BOOST_HAS_ABI_HEADERS
26 # include BOOST_ABI_PREFIX
33 inline void inplace_destroy(T* p)
35 (void)p; // warning suppression
43 // these ensure that this struct gets the same alignment as derived structs:
46 std::ptrdiff_t padding3;
48 saved_state(unsigned i) : id(i) {}
51 template <class BidiIterator>
52 struct saved_matched_paren : public saved_state
55 sub_match<BidiIterator> sub;
56 saved_matched_paren(int i, const sub_match<BidiIterator>& s) : saved_state(1), index(i), sub(s){};
59 template <class BidiIterator>
60 struct saved_position : public saved_state
62 const re_syntax_base* pstate;
63 BidiIterator position;
64 saved_position(const re_syntax_base* ps, BidiIterator pos, int i) : saved_state(i), pstate(ps), position(pos){};
67 template <class BidiIterator>
68 struct saved_assertion : public saved_position<BidiIterator>
71 saved_assertion(bool p, const re_syntax_base* ps, BidiIterator pos)
72 : saved_position<BidiIterator>(ps, pos, saved_type_assertion), positive(p){};
75 template <class BidiIterator>
76 struct saved_repeater : public saved_state
78 repeater_count<BidiIterator> count;
79 saved_repeater(int i, repeater_count<BidiIterator>** s, BidiIterator start)
80 : saved_state(saved_state_repeater_count), count(i,s,start){}
83 struct saved_extra_block : public saved_state
85 saved_state *base, *end;
86 saved_extra_block(saved_state* b, saved_state* e)
87 : saved_state(saved_state_extra_block), base(b), end(e) {}
90 struct save_state_init
93 save_state_init(saved_state** base, saved_state** end)
96 *base = static_cast<saved_state*>(get_mem_block());
97 *end = reinterpret_cast<saved_state*>(reinterpret_cast<char*>(*base)+BOOST_REGEX_BLOCKSIZE);
99 (void) new (*end)saved_state(0);
100 assert(*end > *base);
104 put_mem_block(*stack);
109 template <class BidiIterator>
110 struct saved_single_repeat : public saved_state
113 const re_repeat* rep;
114 BidiIterator last_position;
115 saved_single_repeat(unsigned c, const re_repeat* r, BidiIterator lp, int arg_id)
116 : saved_state(arg_id), count(c), rep(r), last_position(lp){}
119 template <class BidiIterator, class Allocator, class traits, class Allocator2>
120 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states()
122 static matcher_proc_type const s_match_vtable[26] =
124 (&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark),
125 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark,
126 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal,
127 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line,
128 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line,
129 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild,
130 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match,
131 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary,
132 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word,
133 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start,
134 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end,
135 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start,
136 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end,
137 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref,
138 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set,
139 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set,
140 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump,
141 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt,
142 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep,
143 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining,
144 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end,
145 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue,
146 (::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow),
147 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat,
148 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat,
149 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat,
152 push_recursion_stopper();
156 matcher_proc_type proc = s_match_vtable[pstate->type];
160 if(state_count > max_state_count)
161 raise_error(traits_inst, REG_ESPACE);
162 if((m_match_flags & match_partial) && (position == last))
163 m_has_partial_match = true;
164 if(false == unwind(false))
165 return m_recursive_result;
168 }while(unwind(true));
169 return m_recursive_result;
172 template <class BidiIterator, class Allocator, class traits, class Allocator2>
173 void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::extend_stack()
178 saved_state* stack_base;
179 saved_state* backup_state;
180 stack_base = static_cast<saved_state*>(get_mem_block());
181 backup_state = reinterpret_cast<saved_state*>(reinterpret_cast<char*>(stack_base)+BOOST_REGEX_BLOCKSIZE);
182 saved_extra_block* block = static_cast<saved_extra_block*>(backup_state);
184 (void) new (block) saved_extra_block(m_stack_base, m_backup_state);
185 m_stack_base = stack_base;
186 m_backup_state = block;
189 raise_error(traits_inst, REG_E_MEMORY);
192 template <class BidiIterator, class Allocator, class traits, class Allocator2>
193 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
196 saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
198 if(pmp < m_stack_base)
201 pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
204 (void) new (pmp)saved_matched_paren<BidiIterator>(index, sub);
205 m_backup_state = pmp;
208 template <class BidiIterator, class Allocator, class traits, class Allocator2>
209 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_recursion_stopper()
211 saved_state* pmp = m_backup_state;
213 if(pmp < m_stack_base)
216 pmp = m_backup_state;
219 (void) new (pmp)saved_state(saved_type_recurse);
220 m_backup_state = pmp;
223 template <class BidiIterator, class Allocator, class traits, class Allocator2>
224 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_assertion(const re_syntax_base* ps, bool positive)
226 saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
228 if(pmp < m_stack_base)
231 pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
234 (void) new (pmp)saved_assertion<BidiIterator>(positive, ps, position);
235 m_backup_state = pmp;
238 template <class BidiIterator, class Allocator, class traits, class Allocator2>
239 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_alt(const re_syntax_base* ps)
241 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
243 if(pmp < m_stack_base)
246 pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
249 (void) new (pmp)saved_position<BidiIterator>(ps, position, saved_state_alt);
250 m_backup_state = pmp;
253 template <class BidiIterator, class Allocator, class traits, class Allocator2>
254 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_non_greedy_repeat(const re_syntax_base* ps)
256 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
258 if(pmp < m_stack_base)
261 pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
264 (void) new (pmp)saved_position<BidiIterator>(ps, position, saved_state_non_greedy_long_repeat);
265 m_backup_state = pmp;
268 template <class BidiIterator, class Allocator, class traits, class Allocator2>
269 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
271 saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
273 if(pmp < m_stack_base)
276 pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
279 (void) new (pmp)saved_repeater<BidiIterator>(i, s, position);
280 m_backup_state = pmp;
283 template <class BidiIterator, class Allocator, class traits, class Allocator2>
284 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_single_repeat(unsigned c, const re_repeat* r, BidiIterator last_position, int id)
286 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
288 if(pmp < m_stack_base)
291 pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
294 (void) new (pmp)saved_single_repeat<BidiIterator>(c, r, last_position, id);
295 m_backup_state = pmp;
298 template <class BidiIterator, class Allocator, class traits, class Allocator2>
299 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark()
301 int index = static_cast<const re_brace*>(pstate)->index;
305 pstate = pstate->next.p;
310 // forward lookahead assert:
311 const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
312 pstate = pstate->next.p->next.p;
313 push_assertion(next_pstate, index == -1);
318 // independent sub-expression, currently this is always recursive:
319 const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
320 pstate = pstate->next.p->next.p;
321 bool r = match_all_states();
322 pstate = next_pstate;
323 #ifdef BOOST_REGEX_MATCH_EXTRA
324 if(r && (m_match_flags & match_extra))
327 // our captures have been stored in *m_presult
328 // we need to unpack them, and insert them
329 // back in the right order when we unwind the stack:
331 match_results<BidiIterator, Allocator> temp_match(*m_presult);
333 for(i = 0; i < temp_match.size(); ++i)
334 (*m_presult)[i].get_captures().clear();
335 // match everything else:
336 r = match_all_states();
337 // now place the stored captures back:
338 for(i = 0; i < temp_match.size(); ++i)
340 typedef typename sub_match<BidiIterator>::capture_sequence_type seq;
341 seq& s1 = (*m_presult)[i].get_captures();
342 const seq& s2 = temp_match[i].captures();
355 if((m_match_flags & match_nosubs) == 0)
357 push_matched_paren(index, (*m_presult)[index]);
358 m_presult->set_first(position, index);
360 pstate = pstate->next.p;
367 template <class BidiIterator, class Allocator, class traits, class Allocator2>
368 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
370 bool take_first, take_second;
371 const re_jump* jmp = static_cast<const re_jump*>(pstate);
373 // find out which of these two alternatives we need to take:
376 take_first = jmp->can_be_null & mask_take;
377 take_second = jmp->can_be_null & mask_skip;
381 take_first = access::can_start(*position, jmp->_map, (unsigned char)mask_take);
382 take_second = access::can_start(*position, jmp->_map, (unsigned char)mask_skip);
387 // we can take the first alternative,
388 // see if we need to push next alternative:
391 push_alt(jmp->alt.p);
393 pstate = pstate->next.p;
401 return false; // neither option is possible
404 template <class BidiIterator, class Allocator, class traits, class Allocator2>
405 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
408 #pragma warning(push)
409 #pragma warning(disable:4127 4244)
412 #pragma option push -w-8008 -w-8066 -w-8004
414 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
416 // find out which of these two alternatives we need to take:
417 bool take_first, take_second;
420 take_first = rep->can_be_null & mask_take;
421 take_second = rep->can_be_null & mask_skip;
425 take_first = access::can_start(*position, rep->_map, (unsigned char)mask_take);
426 take_second = access::can_start(*position, rep->_map, (unsigned char)mask_skip);
429 if(take_first || (next_count->get_id() != rep->id))
431 // we're moving to a different repeat from the last
432 // one, so set up a counter object:
433 push_repeater_count(rep->id, &next_count);
436 // If we've had at least one repeat already, and the last one
437 // matched the NULL string then set the repeat count to
440 next_count->check_null_repeat(position, rep->max);
442 if(next_count->get_count() < rep->min)
444 // we must take the repeat:
447 // increase the counter:
449 pstate = rep->next.p;
457 // try and take the repeat if we can:
458 if((next_count->get_count() < rep->max) && take_first)
462 // store position in case we fail:
463 push_alt(rep->alt.p);
465 // increase the counter:
467 pstate = rep->next.p;
475 return false; // can't take anything, fail...
479 // try and skip the repeat if we can:
482 // store position in case we fail:
483 push_non_greedy_repeat(rep->next.p);
487 if((next_count->get_count() < rep->max) && take_first)
489 // increase the counter:
491 pstate = rep->next.p;
504 template <class BidiIterator, class Allocator, class traits, class Allocator2>
505 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow()
508 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
509 re_syntax_base* psingle = rep->next.p;
510 // match compulsary repeats first:
511 while(count < rep->min)
520 // repeat for as long as we can:
521 while(count < rep->max)
528 // remember where we got to if this is a leading repeat:
529 if((rep->leading) && (count < rep->max))
531 // push backtrack info if available:
533 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
534 // jump to next state:
540 // non-greedy, push state and return true if we can skip:
542 push_single_repeat(count, rep, position, saved_state_rep_slow_dot);
544 return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
548 template <class BidiIterator, class Allocator, class traits, class Allocator2>
549 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast()
551 if(m_match_flags & (match_not_dot_newline | match_not_dot_null))
552 return match_dot_repeat_slow();
554 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
555 unsigned count = (std::min)(static_cast<unsigned>(re_detail::distance(position, last)), static_cast<unsigned>(rep->greedy ? rep->max : rep->min));
557 return false; // not enough text left to match
558 std::advance(position, count);
562 if((rep->leading) && (count < rep->max))
564 // push backtrack info if available:
566 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
567 // jump to next state:
573 // non-greedy, push state and return true if we can skip:
575 push_single_repeat(count, rep, position, saved_state_rep_fast_dot);
577 return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
581 template <class BidiIterator, class Allocator, class traits, class Allocator2>
582 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
585 #pragma warning(push)
586 #pragma warning(disable:4127)
589 #pragma option push -w-8008 -w-8066 -w-8004
591 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
592 assert(1 == static_cast<const re_literal*>(rep->next.p)->length);
593 const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(rep->next.p) + 1);
596 // start by working out how much we can skip:
598 unsigned desired = rep->greedy ? rep->max : rep->min;
599 if(::boost::is_random_access_iterator<BidiIterator>::value)
601 BidiIterator end = position;
602 std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
603 BidiIterator origin(position);
604 while((position != end) && (traits_inst.translate(*position, icase) == what))
608 count = (unsigned)re_detail::distance(origin, position);
612 while((count < desired) && (position != last) && (traits_inst.translate(*position, icase) == what))
624 if((rep->leading) && (count < rep->max))
626 // push backtrack info if available:
628 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
629 // jump to next state:
635 // non-greedy, push state and return true if we can skip:
637 push_single_repeat(count, rep, position, saved_state_rep_char);
639 return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
649 template <class BidiIterator, class Allocator, class traits, class Allocator2>
650 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
653 #pragma warning(push)
654 #pragma warning(disable:4127)
657 #pragma option push -w-8008 -w-8066 -w-8004
659 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
660 const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
663 // start by working out how much we can skip:
665 unsigned desired = rep->greedy ? rep->max : rep->min;
666 if(::boost::is_random_access_iterator<BidiIterator>::value)
668 BidiIterator end = position;
669 std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
670 BidiIterator origin(position);
671 while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
675 count = (unsigned)re_detail::distance(origin, position);
679 while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
691 if((rep->leading) && (count < rep->max))
693 // push backtrack info if available:
695 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
696 // jump to next state:
702 // non-greedy, push state and return true if we can skip:
704 push_single_repeat(count, rep, position, saved_state_rep_short_set);
706 return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
716 template <class BidiIterator, class Allocator, class traits, class Allocator2>
717 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
720 #pragma warning(push)
721 #pragma warning(disable:4127)
724 #pragma option push -w-8008 -w-8066 -w-8004
726 const re_repeat* rep = static_cast<const re_repeat*>(pstate);
727 const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
730 // start by working out how much we can skip:
732 unsigned desired = rep->greedy ? rep->max : rep->min;
733 if(::boost::is_random_access_iterator<BidiIterator>::value)
735 BidiIterator end = position;
736 std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
737 BidiIterator origin(position);
738 while((position != end) && (position != re_is_set_member(position, last, set, re)))
742 count = (unsigned)re_detail::distance(origin, position);
746 while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
758 if((rep->leading) && (count < rep->max))
760 // push backtrack info if available:
762 push_single_repeat(count, rep, position, saved_state_greedy_single_repeat);
763 // jump to next state:
769 // non-greedy, push state and return true if we can skip:
771 push_single_repeat(count, rep, position, saved_state_rep_long_set);
773 return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
783 /****************************************************************************
785 Unwind and associated proceedures follow, these perform what normal stack
786 unwinding does in the recursive implementation.
788 ****************************************************************************/
790 template <class BidiIterator, class Allocator, class traits, class Allocator2>
791 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind(bool have_match)
793 static unwind_proc_type const s_unwind_table[14] =
795 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end,
796 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren,
797 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper,
798 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion,
799 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt,
800 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter,
801 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block,
802 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat,
803 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat,
804 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat,
805 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat,
806 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat,
807 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat,
808 &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat,
811 m_recursive_result = have_match;
812 unwind_proc_type unwinder;
815 // keep unwinding our stack until we have something to do:
819 unwinder = s_unwind_table[m_backup_state->id];
820 cont = (this->*unwinder)(m_recursive_result);
823 // return true if we have more states to try:
825 return pstate ? true : false;
828 template <class BidiIterator, class Allocator, class traits, class Allocator2>
829 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end(bool)
831 pstate = 0; // nothing left to search
832 return false; // end of stack nothing more to search
835 template <class BidiIterator, class Allocator, class traits, class Allocator2>
836 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren(bool have_match)
838 saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
839 // restore previous values if no match was found:
840 if(have_match == false)
842 m_presult->set_first(pmp->sub.first, pmp->index);
843 m_presult->set_second(pmp->sub.second, pmp->index, pmp->sub.matched);
845 #ifdef BOOST_REGEX_MATCH_EXTRA
847 // we have a match, push the capture information onto the stack:
849 else if(pmp->sub.matched && (match_extra & m_match_flags))
850 ((*m_presult)[pmp->index]).get_captures().push_back(pmp->sub);
853 m_backup_state = pmp+1;
854 boost::re_detail::inplace_destroy(pmp);
855 return true; // keep looking
858 template <class BidiIterator, class Allocator, class traits, class Allocator2>
859 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper(bool)
861 boost::re_detail::inplace_destroy(m_backup_state++);
862 pstate = 0; // nothing left to search
863 return false; // end of stack nothing more to search
866 template <class BidiIterator, class Allocator, class traits, class Allocator2>
867 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion(bool r)
869 saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
870 pstate = pmp->pstate;
871 position = pmp->position;
872 bool result = (r == pmp->positive);
873 m_recursive_result = pmp->positive ? r : !r;
874 boost::re_detail::inplace_destroy(pmp++);
875 m_backup_state = pmp;
876 return !result; // return false if the assertion was matched to stop search.
879 template <class BidiIterator, class Allocator, class traits, class Allocator2>
880 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt(bool r)
882 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
885 pstate = pmp->pstate;
886 position = pmp->position;
888 boost::re_detail::inplace_destroy(pmp++);
889 m_backup_state = pmp;
893 template <class BidiIterator, class Allocator, class traits, class Allocator2>
894 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter(bool)
896 saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
897 boost::re_detail::inplace_destroy(pmp++);
898 m_backup_state = pmp;
899 return true; // keep looking
902 template <class BidiIterator, class Allocator, class traits, class Allocator2>
903 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block(bool)
905 saved_extra_block* pmp = static_cast<saved_extra_block*>(m_backup_state);
906 void* condemmed = m_stack_base;
907 m_stack_base = pmp->base;
908 m_backup_state = pmp->end;
909 boost::re_detail::inplace_destroy(pmp);
910 put_mem_block(condemmed);
911 return true; // keep looking
914 template <class BidiIterator, class Allocator, class traits, class Allocator2>
915 inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::destroy_single_repeat()
917 saved_single_repeat<BidiIterator>* p = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
918 boost::re_detail::inplace_destroy(p++);
922 template <class BidiIterator, class Allocator, class traits, class Allocator2>
923 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat(bool r)
925 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
927 // if we have a match, just discard this state:
930 destroy_single_repeat();
934 const re_repeat* rep = pmp->rep;
935 unsigned count = pmp->count;
936 assert(rep->next.p != 0);
937 assert(rep->alt.p != 0);
941 if((m_match_flags & match_partial) && (position == last))
942 m_has_partial_match = true;
945 position = pmp->last_position;
947 // backtrack till we can skip out:
953 }while(count && !access::can_start(*position, rep->_map, mask_skip));
955 // if we've hit base, destroy this state:
958 destroy_single_repeat();
959 if(!access::can_start(*position, rep->_map, mask_skip))
964 pmp->count = count + rep->min;
965 pmp->last_position = position;
971 template <class BidiIterator, class Allocator, class traits, class Allocator2>
972 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat(bool r)
974 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
976 // if we have a match, just discard this state:
979 destroy_single_repeat();
983 const re_repeat* rep = pmp->rep;
984 unsigned count = pmp->count;
985 assert(rep->type == syntax_element_dot_rep);
986 assert(rep->next.p != 0);
987 assert(rep->alt.p != 0);
988 assert(rep->next.p->type == syntax_element_wild);
990 assert(count < rep->max);
991 pstate = rep->next.p;
992 position = pmp->last_position;
996 // wind forward until we can skip out of the repeat:
1001 // failed repeat match, discard this state and look for another:
1002 destroy_single_repeat();
1007 pstate = rep->next.p;
1008 }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
1010 if(position == last)
1012 // can't repeat any more, remove the pushed state:
1013 destroy_single_repeat();
1014 if(0 == (rep->can_be_null & mask_skip))
1017 else if(count == rep->max)
1019 // can't repeat any more, remove the pushed state:
1020 destroy_single_repeat();
1021 if(!access::can_start(*position, rep->_map, mask_skip))
1027 pmp->last_position = position;
1029 pstate = rep->alt.p;
1033 template <class BidiIterator, class Allocator, class traits, class Allocator2>
1034 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat(bool r)
1036 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1038 // if we have a match, just discard this state:
1041 destroy_single_repeat();
1045 const re_repeat* rep = pmp->rep;
1046 unsigned count = pmp->count;
1048 assert(count < rep->max);
1049 position = pmp->last_position;
1050 if(position != last)
1053 // wind forward until we can skip out of the repeat:
1059 }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
1062 if(position == last)
1064 // can't repeat any more, remove the pushed state:
1065 destroy_single_repeat();
1066 if(0 == (rep->can_be_null & mask_skip))
1069 else if(count == rep->max)
1071 // can't repeat any more, remove the pushed state:
1072 destroy_single_repeat();
1073 if(!access::can_start(*position, rep->_map, mask_skip))
1079 pmp->last_position = position;
1081 pstate = rep->alt.p;
1085 template <class BidiIterator, class Allocator, class traits, class Allocator2>
1086 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat(bool r)
1088 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1090 // if we have a match, just discard this state:
1093 destroy_single_repeat();
1097 const re_repeat* rep = pmp->rep;
1098 unsigned count = pmp->count;
1099 pstate = rep->next.p;
1100 const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);
1101 position = pmp->last_position;
1103 assert(rep->type == syntax_element_char_rep);
1104 assert(rep->next.p != 0);
1105 assert(rep->alt.p != 0);
1106 assert(rep->next.p->type == syntax_element_literal);
1107 assert(count < rep->max);
1109 if(position != last)
1111 // wind forward until we can skip out of the repeat:
1114 if(traits_inst.translate(*position, icase) != what)
1116 // failed repeat match, discard this state and look for another:
1117 destroy_single_repeat();
1123 pstate = rep->next.p;
1124 }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
1126 if(position == last)
1128 // can't repeat any more, remove the pushed state:
1129 destroy_single_repeat();
1130 if(0 == (rep->can_be_null & mask_skip))
1133 else if(count == rep->max)
1135 // can't repeat any more, remove the pushed state:
1136 destroy_single_repeat();
1137 if(!access::can_start(*position, rep->_map, mask_skip))
1143 pmp->last_position = position;
1145 pstate = rep->alt.p;
1149 template <class BidiIterator, class Allocator, class traits, class Allocator2>
1150 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat(bool r)
1152 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1154 // if we have a match, just discard this state:
1157 destroy_single_repeat();
1161 const re_repeat* rep = pmp->rep;
1162 unsigned count = pmp->count;
1163 pstate = rep->next.p;
1164 const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
1165 position = pmp->last_position;
1167 assert(rep->type == syntax_element_short_set_rep);
1168 assert(rep->next.p != 0);
1169 assert(rep->alt.p != 0);
1170 assert(rep->next.p->type == syntax_element_set);
1171 assert(count < rep->max);
1173 if(position != last)
1175 // wind forward until we can skip out of the repeat:
1178 if(!map[(traits_uchar_type)traits_inst.translate(*position, icase)])
1180 // failed repeat match, discard this state and look for another:
1181 destroy_single_repeat();
1187 pstate = rep->next.p;
1188 }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
1190 if(position == last)
1192 // can't repeat any more, remove the pushed state:
1193 destroy_single_repeat();
1194 if(0 == (rep->can_be_null & mask_skip))
1197 else if(count == rep->max)
1199 // can't repeat any more, remove the pushed state:
1200 destroy_single_repeat();
1201 if(!access::can_start(*position, rep->_map, mask_skip))
1207 pmp->last_position = position;
1209 pstate = rep->alt.p;
1213 template <class BidiIterator, class Allocator, class traits, class Allocator2>
1214 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat(bool r)
1216 saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
1218 // if we have a match, just discard this state:
1221 destroy_single_repeat();
1225 const re_repeat* rep = pmp->rep;
1226 unsigned count = pmp->count;
1227 pstate = rep->next.p;
1228 const re_set_long* set = static_cast<const re_set_long*>(pstate);
1229 position = pmp->last_position;
1231 assert(rep->type == syntax_element_long_set_rep);
1232 assert(rep->next.p != 0);
1233 assert(rep->alt.p != 0);
1234 assert(rep->next.p->type == syntax_element_long_set);
1235 assert(position != last);
1236 assert(count < rep->max);
1238 if(position != last)
1240 // wind forward until we can skip out of the repeat:
1243 if(position == re_is_set_member(position, last, set, re))
1245 // failed repeat match, discard this state and look for another:
1246 destroy_single_repeat();
1252 pstate = rep->next.p;
1253 }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
1255 if(position == last)
1257 // can't repeat any more, remove the pushed state:
1258 destroy_single_repeat();
1259 if(0 == (rep->can_be_null & mask_skip))
1262 else if(count == rep->max)
1264 // can't repeat any more, remove the pushed state:
1265 destroy_single_repeat();
1266 if(!access::can_start(*position, rep->_map, mask_skip))
1272 pmp->last_position = position;
1274 pstate = rep->alt.p;
1278 template <class BidiIterator, class Allocator, class traits, class Allocator2>
1279 bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat(bool r)
1281 saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
1284 position = pmp->position;
1285 pstate = pmp->pstate;
1288 boost::re_detail::inplace_destroy(pmp++);
1289 m_backup_state = pmp;
1293 } // namespace re_detail
1294 } // namespace boost
1296 #ifdef BOOST_HAS_ABI_HEADERS
1297 # include BOOST_ABI_SUFFIX