- Added ::collect method for recursive node gathering that needs some local
  persistence.
This commit is contained in:
Paul Beckingham 2014-08-17 11:37:08 -04:00
parent 6a9cca82d7
commit b84736a05f
2 changed files with 37 additions and 0 deletions

View file

@ -270,6 +270,41 @@ bool Parser::canonicalize (
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Recursively scan all nodes, depth first, and create a linear list of node
// pointers, for simple iteration. This eliminates the need for recursion in
// each ::find* method.
void Parser::collect (std::vector <Tree*>& nodes, bool all, Tree* tree /* = NULL */)
{
if (tree == NULL)
tree = _tree;
std::vector <Tree*>::iterator i;
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
{
if ((*i)->_branches.size ())
{
collect (nodes, all, *i);
}
else
{
if (! all)
{
// Parser override operator.
if ((*i)->hasTag ("TERMINATOR") ||
(*i)->hasTag ("TERMINATED"))
break;
// Skip known args.
if (! (*i)->hasTag ("?"))
continue;
}
nodes.push_back (*i);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Recursively scan all nodes, depth first, skipping terminated nodes, and known
// nodes, and cal the callback function for each node.

View file

@ -47,6 +47,8 @@ public:
bool exactMatch (const std::string&, const std::string&) const;
bool canonicalize (std::string&, const std::string&, const std::string&) const;
void collect (std::vector <Tree*>&, bool, Tree* tree = NULL);
void findBinary ();
void resolveAliases ();
void findOverrides ();