MCPcopy Create free account
hub / github.com/git/git / analyze

Function analyze

compat/regex/regcomp.c:1159–1217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1157 dfa->is_utf8 = 0;
1158 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
1159}
1160#endif
1161
1162
1163/* Analyze the structure tree, and calculate "first", "next", "edest",
1164 "eclosure", and "inveclosure". */
1165
1166static reg_errcode_t
1167analyze (regex_t *preg)
1168{
1169 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
1170 reg_errcode_t ret;
1171
1172 /* Allocate arrays. */
1173 dfa->nexts = re_malloc (int, dfa->nodes_alloc);
1174 dfa->org_indices = re_malloc (int, dfa->nodes_alloc);
1175 dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
1176 dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
1177 if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
1178 || dfa->eclosures == NULL, 0))
1179 return REG_ESPACE;
1180
1181 dfa->subexp_map = re_malloc (int, preg->re_nsub);
1182 if (dfa->subexp_map != NULL)
1183 {
1184 int i;
1185 for (i = 0; i < preg->re_nsub; i++)
1186 dfa->subexp_map[i] = i;
1187 preorder (dfa->str_tree, optimize_subexps, dfa);
1188 for (i = 0; i < preg->re_nsub; i++)
1189 if (dfa->subexp_map[i] != i)
1190 break;
1191 if (i == preg->re_nsub)
1192 {
1193 free (dfa->subexp_map);
1194 dfa->subexp_map = NULL;
1195 }
1196 }
1197
1198 ret = postorder (dfa->str_tree, lower_subexps, preg);
1199 if (BE (ret != REG_NOERROR, 0))
1200 return ret;
1201 ret = postorder (dfa->str_tree, calc_first, dfa);
1202 if (BE (ret != REG_NOERROR, 0))
1203 return ret;
1204 preorder (dfa->str_tree, calc_next, dfa);
1205 ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
1206 if (BE (ret != REG_NOERROR, 0))
1207 return ret;
1208 ret = calc_eclosure (dfa);
1209 if (BE (ret != REG_NOERROR, 0))
1210 return ret;
1211
1212 /* We only need this during the prune_impossible_nodes pass in regexec.c;
1213 skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
1214 if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
1215 || dfa->nbackref)
1216 {

Callers 1

re_compile_internalFunction · 0.85

Calls 4

preorderFunction · 0.85
postorderFunction · 0.85
calc_eclosureFunction · 0.85
calc_inveclosureFunction · 0.85

Tested by

no test coverage detected