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

Function create_cd_newstate

compat/regex/regex_internal.c:1675–1746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1673}
1674
1675/* Create the new state which is depend on the context CONTEXT.
1676 Return the new state if succeeded, otherwise return NULL. */
1677
1678static re_dfastate_t *
1679internal_function
1680create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1681 unsigned int context, unsigned int hash)
1682{
1683 int i, nctx_nodes = 0;
1684 reg_errcode_t err;
1685 re_dfastate_t *newstate;
1686
1687 newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));
1688 if (BE (newstate == NULL, 0))
1689 return NULL;
1690 err = re_node_set_init_copy (&newstate->nodes, nodes);
1691 if (BE (err != REG_NOERROR, 0))
1692 {
1693 re_free (newstate);
1694 return NULL;
1695 }
1696
1697 newstate->context = context;
1698 newstate->entrance_nodes = &newstate->nodes;
1699
1700 for (i = 0 ; i < nodes->nelem ; i++)
1701 {
1702 re_token_t *node = dfa->nodes + nodes->elems[i];
1703 re_token_type_t type = node->type;
1704 unsigned int constraint = node->constraint;
1705
1706 if (type == CHARACTER && !constraint)
1707 continue;
1708#ifdef RE_ENABLE_I18N
1709 newstate->accept_mb |= node->accept_mb;
1710#endif /* RE_ENABLE_I18N */
1711
1712 /* If the state has the halt node, the state is a halt state. */
1713 if (type == END_OF_RE)
1714 newstate->halt = 1;
1715 else if (type == OP_BACK_REF)
1716 newstate->has_backref = 1;
1717
1718 if (constraint)
1719 {
1720 if (newstate->entrance_nodes == &newstate->nodes)
1721 {
1722 newstate->entrance_nodes = re_malloc (re_node_set, 1);
1723 if (BE (newstate->entrance_nodes == NULL, 0))
1724 {
1725 free_state (newstate);
1726 return NULL;
1727 }
1728 if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
1729 != REG_NOERROR)
1730 return NULL;
1731 nctx_nodes = 0;
1732 newstate->has_constraint = 1;

Callers 1

re_acquire_state_contextFunction · 0.85

Calls 4

re_node_set_init_copyFunction · 0.85
free_stateFunction · 0.85
re_node_set_remove_atFunction · 0.85
register_stateFunction · 0.85

Tested by

no test coverage detected