Stateful version of term leaves iterator.

This commit is contained in:
Cas Cremers 2018-10-22 03:24:47 +02:00
parent fb3b13f4e3
commit 85dbd20869
3 changed files with 38 additions and 0 deletions

View File

@ -9,3 +9,7 @@
term_iterate_deVar term_iterate_deVar
term_iterate_state_deVar term_iterate_state_deVar
term_iterate_leaves
term_iterate_state_leaves

View File

@ -1179,6 +1179,37 @@ term_iterate_state_deVar (Term term, int (*leaf) (Term t, void (*st)),
return true; return true;
} }
//! Iterate over the leaves in a term, stateful
/**
* Note that this function iterates over real leaves; thus closed variables can occur as
* well. It is up to func to decide wether or not to recurse.
*/
int
term_iterate_state_leaves (const Term term, int (*func) (Term t, void (*st)),
void (*state))
{
if (term != NULL)
{
if (realTermLeaf (term))
{
if (!func (term, state))
return 0;
}
else
{
if (realTermTuple (term))
return (term_iterate_state_leaves (TermOp1 (term), func, state)
&& term_iterate_state_leaves (TermOp2 (term), func,
state));
else
return (term_iterate_state_leaves (TermOp (term), func, state)
&& term_iterate_state_leaves (TermKey (term), func,
state));
}
}
return 1;
}
//! Iterate over the leaves in a term //! Iterate over the leaves in a term
/** /**
* Note that this function iterates over real leaves; thus closed variables can occur as * Note that this function iterates over real leaves; thus closed variables can occur as

View File

@ -203,6 +203,9 @@ int term_iterate_state_deVar (Term term, int (*leaf) (Term t, void (*st)),
int (*noder) (Term t, void (*st)), int (*noder) (Term t, void (*st)),
void (*state)); void (*state));
int term_iterate_leaves (const Term t, int (*func) (Term t)); int term_iterate_leaves (const Term t, int (*func) (Term t));
int term_iterate_state_leaves (const Term term,
int (*func) (Term t, void (*st)),
void (*state));
int term_iterate_open_leaves (const Term term, int (*func) (Term t)); int term_iterate_open_leaves (const Term term, int (*func) (Term t));
void term_rolelocals_are_variables (); void term_rolelocals_are_variables ();
int term_encryption_level (const Term term); int term_encryption_level (const Term term);