xref: /original-bsd/usr.bin/pascal/pxp/const.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)const.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * pxp - Pascal execution profiler
14  *
15  * Bill Joy UCB
16  * Version 1.2 January 1979
17  */
18 
19 #include "0.h"
20 #include "tree.h"
21 
22 STATIC	int constcnt = -1;
23 
24 /*
25  * The const declaration part
26  */
27 constbeg(l, cline)
28 	int l, cline;
29 {
30 
31 	line = l;
32 	if (nodecl)
33 		printoff();
34 	puthedr();
35 	putcm();
36 	ppnl();
37 	indent();
38 	ppkw("const");
39 	ppgoin(DECL);
40 	constcnt = 0;
41 	setline(cline);
42 }
43 
44 constant(cline, cid, cdecl)
45 	int cline;
46 	char *cid;
47 	int *cdecl;
48 {
49 
50 	if (constcnt)
51 		putcm();
52 	setline(cline);
53 	ppitem();
54 	ppid(cid);
55 	ppsep(" = ");
56 	gconst(cdecl);
57 	ppsep(";");
58 	constcnt++;
59 	setinfo(cline);
60 	putcml();
61 }
62 
63 constend()
64 {
65 
66 	if (constcnt == -1)
67 		return;
68 	if (nodecl)
69 		return;
70 	if (constcnt == 0)
71 		ppid("{const decls}");
72 	ppgoout(DECL);
73 	constcnt = -1;
74 }
75 
76 /*
77  * A constant in an expression
78  * or a declaration.
79  */
80 gconst(r)
81 	int *r;
82 {
83 	register *cn;
84 
85 	cn = r;
86 loop:
87 	if (cn == NIL) {
88 		ppid("{constant}");
89 		return;
90 	}
91 	switch (cn[0]) {
92 		default:
93 			panic("gconst");
94 		case T_PLUSC:
95 			ppop("+");
96 			cn = cn[1];
97 			goto loop;
98 		case T_MINUSC:
99 			ppop("-");
100 			cn = cn[1];
101 			goto loop;
102 		case T_ID:
103 			ppid(cn[1]);
104 			return;
105 		case T_CBINT:
106 		case T_CINT:
107 		case T_CFINT:
108 			ppnumb(cn[1]);
109 			if (cn[0] == T_CBINT)
110 				ppsep("b");
111 			return;
112 		case T_CSTRNG:
113 			ppstr(cn[1]);
114 			return;
115 	}
116 }
117