Trying to make an iterative assimilate()

This commit is contained in:
Derek Foreman 2002-12-30 07:28:42 +00:00
parent 624a06fdff
commit ee14d8a3cc

View file

@ -113,37 +113,30 @@ OBBindings::~OBBindings()
static void assimilate(BindingTree *parent, BindingTree *node) static void assimilate(BindingTree *parent, BindingTree *node)
{ {
BindingTree *p, *lastsib, *nextparent, *nextnode = node->first_child; BindingTree *a, *b, *tmp, *last;
if (!parent->first_child) { if (!parent->first_child) {
// there are no nodes at this level yet // there are no nodes at this level yet
parent->first_child = node; parent->first_child = node;
nextparent = node; return;
} else { } else {
p = lastsib = parent->first_child; a = parent->first_child;
last = a;
while (p->next_sibling) { b = node;
p = p->next_sibling; while (a->first_child) {
lastsib = p; // finds the last sibling last = a;
if (p->binding == node->binding) { if (a->binding != b->binding) {
// found an identical binding.. a = a->next_sibling;
assert(node->chain && p->chain); } else {
delete node; // kill the one we aren't using tmp = b;
printf("using existing node\n"); b = b->first_child;
break; delete tmp;
a = a->first_child;
} }
} }
if (!p) { last->first_child = b->first_child;
// couldn't find an existing binding, use this new one, and insert it delete b;
// into the list
p = lastsib->next_sibling = node;
printf("inserting %s\n", p->text.c_str());
}
nextparent = p;
} }
if (nextnode)
assimilate(nextparent, nextnode);
} }