From: Robert R. Henry Date: Sat, 12 Feb 1983 07:44:40 +0000 (-0800) Subject: date and time created 83/02/11 15:44:40 by rrh X-Git-Tag: BSD-4_1c_2-Snapshot-Development~494 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/143110cd4d932b72241811bd447986d6bc03ec6b?hp=baa811f72e46598d5619d67df6ed6786f53a0174 date and time created 83/02/11 15:44:40 by rrh SCCS-vsn: usr.bin/struct/struct/3.flow.c 4.1 --- diff --git a/usr/src/usr.bin/struct/struct/3.flow.c b/usr/src/usr.bin/struct/struct/3.flow.c new file mode 100644 index 0000000000..74d583d890 --- /dev/null +++ b/usr/src/usr.bin/struct/struct/3.flow.c @@ -0,0 +1,93 @@ +#ifndef lint +static char sccsid[] = "@(#)3.flow.c 4.1 (Berkeley) %G%"; +#endif not lint + +#include +# +/* +correct the flow of control in the new program - use GOTO's which may +be changed later to NEXT, BREAK, etc. +*/ +#include "def.h" +#include "3.def.h" + +#define BRANCHTYPE(v) (NTYPE(v) == GOVX ) +#define HASLEX(t) (t != GOVX && t != COMPVX && t != ASGOVX && t != ITERVX ) + /* for these, control never flows directly to following statement */ + + +getflow() + { + fixflow(START,UNDEFINED); + } + + +fixflow(v,autolex) +VERT v; +VERT autolex; /* lexical successor of v */ + { + VERT lex,chlex,z,x,w; + int i; + lex = lexval(v,autolex); + if (HASLEX(NTYPE(v)) && NTYPE(v) != ICASVX) + if (DEFINED(REACH(v)) && REACH(v) != lex) + insib(v,makebr(REACH(v))); + else if (NTYPE(v) == DOVX && ARC(v,1) != lex) + insib(v,makebr(ARC(v,1))); + if (NTYPE(v) == ITERVX) + { + BRK(v) = autolex; + chlex = v; + } + else + chlex = lexval(v,autolex); + + for (i = 0; i < CHILDNUM(v); ++i) + { + w = LCHILD(v,i); + if (DEFINED(w)) + fixflow(w,chlex); + else + { + ASSERT(i < ARCNUM(v),fixflow); + z = ARC(v,i); + ASSERT(DEFINED(z), fixflow); + if (z != chlex) + { + x = makebr(z); + LCHILD(v,i) = x; + RSIB(x) = UNDEFINED; + } + } + } + if (DEFINED(RSIB(v))) + fixflow(RSIB(v),autolex); + } + + +lexval(v,lastlex) +VERT v,lastlex; + { + VERT sib; + if (!HASLEX(NTYPE(v))) return(UNDEFINED); + sib = RSIB(v); + if (NTYPE(v) == ICASVX || NTYPE(v) == ACASVX) + return(lastlex); + else if (!DEFINED(sib)) + return(lastlex); + else if (BRANCHTYPE(sib)) + return(ARC(sib,0)); + else return(sib); + } + + +makebr(w) /* make branching node leading to w */ +VERT w; + { + VERT new; + new = create(GOVX,1); + ARC(new,0) = w; + RSIB(new) = UNDEFINED; + REACH(new) = UNDEFINED; + return(new); + }