Parser
- Upgraded the 'bool all' argument to ::collect to a tri-state enum, in a polymorphic method.
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
|
#include <iostream> // TODO Remove.
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -296,6 +297,47 @@ bool Parser::canonicalize (
|
|||||||
return false;
|
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,
|
||||||
|
collectType type /* = collectType::collectLeaf */,
|
||||||
|
Tree* tree /* = NULL */) const
|
||||||
|
{
|
||||||
|
if (tree == NULL)
|
||||||
|
tree = _tree;
|
||||||
|
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
|
||||||
|
{
|
||||||
|
if ((*i)->_branches.size ())
|
||||||
|
{
|
||||||
|
if (type == collectAll)
|
||||||
|
nodes.push_back (*i);
|
||||||
|
|
||||||
|
collect (nodes, type, *i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (type == collectLeaf)
|
||||||
|
{
|
||||||
|
// 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, and create a linear list of node
|
// Recursively scan all nodes, depth first, and create a linear list of node
|
||||||
// pointers, for simple iteration. This eliminates the need for recursion in
|
// pointers, for simple iteration. This eliminates the need for recursion in
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ public:
|
|||||||
bool exactMatch (const std::string&, const std::string&) const;
|
bool exactMatch (const std::string&, const std::string&) const;
|
||||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||||
|
|
||||||
|
enum collectType {collectLeaf, collectAll, collectUnterminated};
|
||||||
|
void collect (std::vector <Tree*>&, collectType = collectLeaf, Tree* tree = NULL) const;
|
||||||
void collect (std::vector <Tree*>&, bool, Tree* tree = NULL) const;
|
void collect (std::vector <Tree*>&, bool, Tree* tree = NULL) const;
|
||||||
|
|
||||||
void findBinary ();
|
void findBinary ();
|
||||||
|
|||||||
Reference in New Issue
Block a user