/* use inarc, dom, and head to build tree representing structure of program.
Each node v has CHILDNUM(v) children denoted by
LCHILD(v,0), LCHILD(v,1),...
RSIB((v) is right sibling of v or UNDEFINED;
RSIB(v) represents code following v at the same level of nesting,
while LCHILD(v,i) represents code nested within v
gettree(inarc
,dom
,head
) /* build tree */
for ( v
= 0; v
< nodenum
; ++v
)
for (i
= 0; i
< CHILDNUM(v
); ++i
)
for (i
= accessnum
-1; i
> 0; --i
)
from
= oneelt(inarc
[v
]); /* the unique elt of inarc[v] or UNDEFINED */
if (NTYPE(from
) == IFVX
&& (head
[v
] == head
[from
] || asoc(v
,exitsize
) != -1) )
/* place in clause of IFVX if in smallest loop containing it
or if size of code for v is <= exitsize */
ASSERT(ARC(from
,ELSE
) == v
,gettree
);
else if (NTYPE(v
) == ITERVX
|| NTYPE(from
) == ITERVX
)
/* LOOPVX -> ITERVX ->vert always in same loop*/
else if (NTYPE(from
) == SWCHVX
)
ASSERT(0 < ARCNUM(v
),gettree
);
for (j
= 1; j
< ARCNUM(from
); ++j
)
else if (NTYPE(from
) == ICASVX
&& (head
[v
] == head
[from
] || asoc(v
,exitsize
) != -1))
else if (NTYPE(from
) == DUMVX
&& ARC(from
,0) == v
)
if (loomem(v
,head
[dom
[v
]],head
))
/* v is in smallest loop containing dom[v] */
/* make v follow LOOPVX heading largest loop
containing DOM[v] but not v */
ASSERT(DEFINED(head
[dom
[v
]]),gettree
);
for (u
= head
[dom
[v
]]; head
[u
] != head
[v
]; u
= head
[u
])
ASSERT(DEFINED(head
[u
]),gettree
);
ASSERT(NTYPE(u
) == ITERVX
,gettree
);
insib(w
,v
) /* make RSIB(w) = v, and make RSIB(rightmost sib of v) = old RSIB(w) */
for (u
= v
; DEFINED(RSIB(u
)); u
= RSIB(u
))
asoc(v
,n
) /* return # of nodes associated with v if <= n, -1 otherwise */
count
= (NTYPE(v
) == STLNVX
) ? CODELINES(v
) : 1;
for (i
= 0; i
< CHILDNUM(v
); ++i
)
if (!DEFINED(w
)) continue;
if (temp
== -1) return(-1);
if (count
> n
) return(-1);
temp
= asoc(RSIB(v
),n
-count
);
if (temp
== -1) return(-1);
if (count
> n
) return(-1);