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

Function lower_subexp

compat/regex/regcomp.c:1340–1373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1338 {
1339 node->right = lower_subexp (&err, preg, node->right);
1340 if (node->right)
1341 node->right->parent = node;
1342 }
1343
1344 return err;
1345}
1346
1347static bin_tree_t *
1348lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
1349{
1350 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
1351 bin_tree_t *body = node->left;
1352 bin_tree_t *op, *cls, *tree1, *tree;
1353
1354 if (preg->no_sub
1355 /* We do not optimize empty subexpressions, because otherwise we may
1356 have bad CONCAT nodes with NULL children. This is obviously not
1357 very common, so we do not lose much. An example that triggers
1358 this case is the sed "script" /\(\)/x. */
1359 && node->left != NULL
1360 && (node->token.opr.idx >= BITSET_WORD_BITS
1361 || !(dfa->used_bkref_map
1362 & ((bitset_word_t) 1 << node->token.opr.idx))))
1363 return node->left;
1364
1365 /* Convert the SUBEXP node to the concatenation of an
1366 OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */
1367 op = create_tree (dfa, NULL, NULL, OP_OPEN_SUBEXP);
1368 cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
1369 tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
1370 tree = create_tree (dfa, op, tree1, CONCAT);
1371 if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0))
1372 {
1373 *err = REG_ESPACE;
1374 return NULL;
1375 }
1376

Callers 1

lower_subexpsFunction · 0.85

Calls 1

create_treeFunction · 0.85

Tested by

no test coverage detected