Return true if and only if the given program can be executed by a DFA. Generally, a DFA is always possible. A pathological case where it is not possible is if the number of NFA states exceeds `u32::MAX`, in which case, this function will return false. This function will also return false if the given program has any Unicode instructions (Char or Ranges) since the DFA operates on bytes only.
(insts: &Program)
| 65 | /// This function will also return false if the given program has any Unicode |
| 66 | /// instructions (Char or Ranges) since the DFA operates on bytes only. |
| 67 | pub fn can_exec(insts: &Program) -> bool { |
| 68 | use prog::Inst::*; |
| 69 | // If for some reason we manage to allocate a regex program with more |
| 70 | // than i32::MAX instructions, then we can't execute the DFA because we |
| 71 | // use 32 bit instruction pointer deltas for memory savings. |
| 72 | // If i32::MAX is the largest positive delta, |
| 73 | // then -i32::MAX == i32::MIN + 1 is the largest negative delta, |
| 74 | // and we are OK to use 32 bits. |
| 75 | if insts.dfa_size_limit == 0 || insts.len() > ::std::i32::MAX as usize { |
| 76 | return false; |
| 77 | } |
| 78 | for inst in insts { |
| 79 | match *inst { |
| 80 | Char(_) | Ranges(_) => return false, |
| 81 | EmptyLook(_) | Match(_) | Save(_) | Split(_) | Bytes(_) => {} |
| 82 | } |
| 83 | } |
| 84 | true |
| 85 | } |
| 86 | |
| 87 | /// A reusable cache of DFA states. |
| 88 | /// |