1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)4.brace.c	8.1 (Berkeley) 06/06/93";
7 #endif /* not lint */
8 
9 #include <stdio.h>
10 #include "def.h"
11 #include "4.def.h"
12 #include "3.def.h"
13 
14 ndbrace(v)			/* determine whether braces needed around subparts of v */
15 				/* return TRUE if v ends with IF THEN not in braces */
16 VERT v;
17 	{
18 	VERT w;
19 	int i;
20 	LOGICAL endif;
21 	endif = FALSE;
22 	for (i = 0; i < CHILDNUM(v); ++i)
23 		{
24 		endif = FALSE;
25 		for (w = LCHILD(v,i); DEFINED(w); w = RSIB(w))
26 			endif = ndbrace(w);
27 		if (NTYPE(v) != DUMVX && NTYPE(v) != ITERVX &&
28 			(!DEFINED(LCHILD(v,i)) || compound(v,i) ||
29 			(endif && NTYPE(v) == IFVX && !IFTHEN(v) && i == THEN )))
30 				/* DUMVX doesn't nest, ITERVX doen't nest since
31 					nesting is done at LOOPNODE, etc., must
32 					check for IFTHEN followed by unrelated ELSE */
33 			{
34 			YESBRACE(v,i);
35 			endif = FALSE;
36 			}
37 		}
38 	return(endif || IFTHEN(v) );
39 	}
40 
41 
42 compound(v,ch)		/* return TRUE iff subpart ch of v has multiple statements */
43 VERT v;
44 int ch;
45 	{
46 	VERT w;
47 	w = LCHILD(v,ch);
48 	if (!DEFINED(w))
49 		return(FALSE);
50 	if (NTYPE(w) == ITERVX)
51 		{
52 		ASSERT(DEFINED(NXT(w)),compound);
53 		if (LABEL(NXT(w)))
54 			return(TRUE);		/* loop ends with labeled CONTINUE statement */
55 		else
56 			return(compound(w,0));
57 		}
58 	else if (DEFINED(RSIB(w)))
59 		return(TRUE);
60 	else if (NTYPE(w) == STLNVX && CODELINES(w) > 1)
61 		return(TRUE);
62 	else
63 		return(FALSE);
64 	}
65