| 1001 | dfa->str_tree = NULL; |
| 1002 | re_free (dfa->org_indices); |
| 1003 | dfa->org_indices = NULL; |
| 1004 | } |
| 1005 | |
| 1006 | /* Create initial states for all contexts. */ |
| 1007 | |
| 1008 | static reg_errcode_t |
| 1009 | create_initial_state (re_dfa_t *dfa) |
| 1010 | { |
| 1011 | int first, i; |
| 1012 | reg_errcode_t err; |
| 1013 | re_node_set init_nodes; |
| 1014 | |
| 1015 | /* Initial states have the epsilon closure of the node which is |
| 1016 | the first node of the regular expression. */ |
| 1017 | first = dfa->str_tree->first->node_idx; |
| 1018 | dfa->init_node = first; |
| 1019 | err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first); |
| 1020 | if (BE (err != REG_NOERROR, 0)) |
| 1021 | return err; |
| 1022 | |
| 1023 | /* The back-references which are in initial states can epsilon transit, |
| 1024 | since in this case all of the subexpressions can be null. |
| 1025 | Then we add epsilon closures of the nodes which are the next nodes of |
| 1026 | the back-references. */ |
| 1027 | if (dfa->nbackref > 0) |
| 1028 | for (i = 0; i < init_nodes.nelem; ++i) |
| 1029 | { |
| 1030 | int node_idx = init_nodes.elems[i]; |
| 1031 | re_token_type_t type = dfa->nodes[node_idx].type; |
| 1032 | |
| 1033 | int clexp_idx; |
| 1034 | if (type != OP_BACK_REF) |
| 1035 | continue; |
| 1036 | for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx) |
| 1037 | { |
| 1038 | re_token_t *clexp_node; |
| 1039 | clexp_node = dfa->nodes + init_nodes.elems[clexp_idx]; |
| 1040 | if (clexp_node->type == OP_CLOSE_SUBEXP |
| 1041 | && clexp_node->opr.idx == dfa->nodes[node_idx].opr.idx) |
| 1042 | break; |
| 1043 | } |
| 1044 | if (clexp_idx == init_nodes.nelem) |
| 1045 | continue; |
| 1046 | |
| 1047 | if (type == OP_BACK_REF) |
| 1048 | { |
| 1049 | int dest_idx = dfa->edests[node_idx].elems[0]; |
| 1050 | if (!re_node_set_contains (&init_nodes, dest_idx)) |
| 1051 | { |
| 1052 | reg_errcode_t err = re_node_set_merge (&init_nodes, |
| 1053 | dfa->eclosures |
| 1054 | + dest_idx); |
| 1055 | if (err != REG_NOERROR) |
| 1056 | return err; |
| 1057 | i = 0; |
| 1058 | } |
| 1059 | } |
| 1060 | } |
no test coverage detected