- Sym *head = 0;
- Sym *tail;
- int cycle_top;
- int index;
-
- for (cycle_top = dfn_depth; cycle_top > 0; --cycle_top) {
- head = dfn_stack[cycle_top].sym;
- if (child == head) {
- break;
- } /* if */
- if (child->cg.cyc.head != child && child->cg.cyc.head == head) {
- break;
- } /* if */
- } /* for */
- if (cycle_top <= 0) {
- fprintf(stderr, "[find_cycle] couldn't find head of cycle\n");
- done(1);
- } /* if */
- DBG(DFNDEBUG, printf("[find_cycle] dfn_depth %d cycle_top %d ",
- dfn_depth, cycle_top);
- if (head) {
- print_name(head);
- } else {
- printf("<unknown>");
- } /* if */
- printf("\n"));
- if (cycle_top == dfn_depth) {
- /*
- * This is previous function, e.g. this calls itself. Sort of
- * boring.
- *
- * Since we are taking out self-cycles elsewhere no need for
- * the special case, here.
- */
- DBG(DFNDEBUG,
- printf("[find_cycle] "); print_name(child); printf("\n"));
- } else {
- /*
- * Glom intervening functions that aren't already glommed into
- * this cycle. Things have been glommed when their cyclehead
- * field points to the head of the cycle they are glommed
- * into.
- */
- for (tail = head; tail->cg.cyc.next; tail = tail->cg.cyc.next) {
- /* void: chase down to tail of things already glommed */
- DBG(DFNDEBUG,
- printf("[find_cycle] tail "); print_name(tail); printf("\n"));
- } /* for */
- /*
- * If what we think is the top of the cycle has a cyclehead
- * field, then it's not really the head of the cycle, which is
- * really what we want.
- */
- if (head->cg.cyc.head != head) {
- head = head->cg.cyc.head;
- DBG(DFNDEBUG, printf("[find_cycle] new cyclehead ");
- print_name(head); printf("\n"));
- } /* if */
- for (index = cycle_top + 1; index <= dfn_depth; ++index) {
- child = dfn_stack[index].sym;
- if (child->cg.cyc.head == child) {
- /*
- * Not yet glommed anywhere, glom it and fix any
- * children it has glommed.
- */
- tail->cg.cyc.next = child;
- child->cg.cyc.head = head;
- DBG(DFNDEBUG, printf("[find_cycle] glomming ");
- print_name(child); printf(" onto "); print_name(head);
- printf("\n"));
- for (tail = child; tail->cg.cyc.next; tail = tail->cg.cyc.next)
+ Sym *head = 0;
+ Sym *tail;
+ int cycle_top;
+ int index;
+
+ for (cycle_top = dfn_depth; cycle_top > 0; --cycle_top)
+ {
+ head = dfn_stack[cycle_top].sym;
+ if (child == head)
+ {
+ break;
+ }
+ if (child->cg.cyc.head != child && child->cg.cyc.head == head)
+ {
+ break;
+ }
+ }
+ if (cycle_top <= 0)
+ {
+ fprintf (stderr, "[find_cycle] couldn't find head of cycle\n");
+ done (1);
+ }
+#ifdef DEBUG
+ if (debug_level & DFNDEBUG)
+ {
+ printf ("[find_cycle] dfn_depth %d cycle_top %d ",
+ dfn_depth, cycle_top);
+ if (head)
+ {
+ print_name (head);
+ }
+ else
+ {
+ printf ("<unknown>");
+ }
+ printf ("\n");
+ }
+#endif
+ if (cycle_top == dfn_depth)
+ {
+ /*
+ * This is previous function, e.g. this calls itself. Sort of
+ * boring.
+ *
+ * Since we are taking out self-cycles elsewhere no need for
+ * the special case, here.
+ */
+ DBG (DFNDEBUG,
+ printf ("[find_cycle] ");
+ print_name (child);
+ printf ("\n"));
+ }
+ else
+ {
+ /*
+ * Glom intervening functions that aren't already glommed into
+ * this cycle. Things have been glommed when their cyclehead
+ * field points to the head of the cycle they are glommed
+ * into.
+ */
+ for (tail = head; tail->cg.cyc.next; tail = tail->cg.cyc.next)
+ {
+ /* void: chase down to tail of things already glommed */
+ DBG (DFNDEBUG,
+ printf ("[find_cycle] tail ");
+ print_name (tail);
+ printf ("\n"));
+ }
+ /*
+ * If what we think is the top of the cycle has a cyclehead
+ * field, then it's not really the head of the cycle, which is
+ * really what we want.
+ */
+ if (head->cg.cyc.head != head)
+ {
+ head = head->cg.cyc.head;
+ DBG (DFNDEBUG, printf ("[find_cycle] new cyclehead ");
+ print_name (head);
+ printf ("\n"));
+ }
+ for (index = cycle_top + 1; index <= dfn_depth; ++index)
+ {
+ child = dfn_stack[index].sym;
+ if (child->cg.cyc.head == child)
+ {
+ /*
+ * Not yet glommed anywhere, glom it and fix any
+ * children it has glommed.
+ */
+ tail->cg.cyc.next = child;
+ child->cg.cyc.head = head;
+ DBG (DFNDEBUG, printf ("[find_cycle] glomming ");
+ print_name (child);
+ printf (" onto ");
+ print_name (head);
+ printf ("\n"));
+ for (tail = child; tail->cg.cyc.next; tail = tail->cg.cyc.next)