| 3219 | |
| 3220 | |
| 3221 | /* For all the back references in the current state, calculate the |
| 3222 | destination of the back references by the appropriate entry |
| 3223 | in MCTX->BKREF_ENTS. */ |
| 3224 | |
| 3225 | static reg_errcode_t |
| 3226 | internal_function |
| 3227 | expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, |
| 3228 | int cur_str, int subexp_num, int type) |
| 3229 | { |
| 3230 | const re_dfa_t *const dfa = mctx->dfa; |
| 3231 | reg_errcode_t err; |
| 3232 | int cache_idx_start = search_cur_bkref_entry (mctx, cur_str); |
| 3233 | struct re_backref_cache_entry *ent; |
| 3234 | |
| 3235 | if (cache_idx_start == -1) |
| 3236 | return REG_NOERROR; |
| 3237 | |
| 3238 | restart: |
| 3239 | ent = mctx->bkref_ents + cache_idx_start; |
| 3240 | do |
| 3241 | { |
| 3242 | int to_idx, next_node; |
| 3243 | |
| 3244 | /* Is this entry ENT is appropriate? */ |
| 3245 | if (!re_node_set_contains (cur_nodes, ent->node)) |
| 3246 | continue; /* No. */ |
| 3247 | |
| 3248 | to_idx = cur_str + ent->subexp_to - ent->subexp_from; |
| 3249 | /* Calculate the destination of the back reference, and append it |
| 3250 | to MCTX->STATE_LOG. */ |
| 3251 | if (to_idx == cur_str) |
| 3252 | { |
| 3253 | /* The backreference did epsilon transit, we must re-check all the |
| 3254 | node in the current state. */ |
| 3255 | re_node_set new_dests; |
| 3256 | reg_errcode_t err2, err3; |
| 3257 | next_node = dfa->edests[ent->node].elems[0]; |
| 3258 | if (re_node_set_contains (cur_nodes, next_node)) |
| 3259 | continue; |
| 3260 | err = re_node_set_init_1 (&new_dests, next_node); |
| 3261 | err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type); |
| 3262 | err3 = re_node_set_merge (cur_nodes, &new_dests); |
| 3263 | re_node_set_free (&new_dests); |
| 3264 | if (BE (err != REG_NOERROR || err2 != REG_NOERROR |
| 3265 | || err3 != REG_NOERROR, 0)) |
| 3266 | { |
| 3267 | err = (err != REG_NOERROR ? err |
| 3268 | : (err2 != REG_NOERROR ? err2 : err3)); |
| 3269 | return err; |
| 3270 | } |
| 3271 | /* TODO: It is still inefficient... */ |
| 3272 | goto restart; |
| 3273 | } |
| 3274 | else |
| 3275 | { |
| 3276 | re_node_set union_set; |
| 3277 | next_node = dfa->nexts[ent->node]; |
| 3278 | if (mctx->state_log[to_idx]) |
no test coverage detected