xref: /csrg-svn/usr.bin/pascal/pdx/sym/print.c (revision 30850)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)print.c	5.2 (Berkeley) 04/07/87";
9 #endif not lint
10 /*
11  * Routines to print out symbols.
12  */
13 
14 #include "defs.h"
15 #include "sym.h"
16 #include "process.h"
17 #include "tree.h"
18 #include "runtime.h"
19 #include "classes.h"
20 #include "sym.rep"
21 #include "process/process.rep"
22 
23 /*
24  * Note the entry of the given block, unless it's the main program.
25  */
26 
27 printentry(s)
28 SYM *s;
29 {
30 	if (s != program) {
31 		printf("\nentering %s %s\n", classname(s), s->symbol);
32 	}
33 }
34 
35 /*
36  * Note the exit of the given block
37  */
38 
39 printexit(s)
40 SYM *s;
41 {
42 	if (s != program) {
43 		printf("leaving %s %s\n\n", classname(s), s->symbol);
44 	}
45 }
46 
47 /*
48  * Note the call of s from t.
49  */
50 
51 printcall(s, t)
52 SYM *s, *t;
53 {
54 	printf("calling %s", s->symbol);
55 	printparams(s, NIL);
56 	printf(" from %s %s\n", classname(t), t->symbol);
57 }
58 
59 /*
60  * Note the return from s.  If s is a function, print the value
61  * it is returning.  This is somewhat painful, since the function
62  * has actually just returned.
63  */
64 
65 printrtn(s)
66 SYM *s;
67 {
68 	register int len;
69 
70 	printf("returning ");
71 	if (s->class == FUNC) {
72 		len = size(s->type);
73 		dread(sp, process->sp, len);
74 		sp += len;
75 #ifdef tahoe
76 		alignstack();
77 #endif
78 		printval(s->type);
79 		putchar(' ');
80 	}
81 	printf("from %s\n", s->symbol);
82 }
83 
84 /*
85  * Print the values of the parameters of the given procedure or function.
86  * The frame distinguishes recursive instances of a procedure.
87  */
88 
89 printparams(f, frame)
90 SYM *f;
91 FRAME *frame;
92 {
93 	SYM *param;
94 
95 	for (param = f->chain; param != NIL; param = param->chain) {
96 		if (param == f->chain) {
97 			printf("(");
98 		}
99 		printv(param, frame);
100 		if (param->chain != NIL) {
101 			printf(", ");
102 		} else {
103 			printf(")");
104 		}
105 	}
106 }
107 
108 /*
109  * Print the name and value of a variable.
110  */
111 
112 printv(s, frame)
113 SYM *s;
114 FRAME *frame;
115 {
116 	ADDRESS addr;
117 	int len;
118 
119 	if (s->class == REF) {
120 		dread(&addr, address(s, frame), sizeof(ADDRESS));
121 		len = size(s->type);
122 	} else {
123 		addr = address(s, frame);
124 		len = size(s);
125 	}
126 	printf("%s = ", s->symbol);
127 	if (!rpush(addr, len)) {
128 		printf("*** expression too large ***");
129 	} else {
130 		if (s->class == REF || s->class == VAR) {
131 			printval(s->type);
132 		} else {
133 			printval(s);
134 		}
135 	}
136 }
137 
138 /*
139  * Print the fully specified variable that is described by the given identifer.
140  */
141 
142 printwhich(s)
143 SYM *s;
144 {
145 	printouter(s->func);
146 	printf("%s", s->symbol);
147 }
148 
149 LOCAL printouter(s)
150 SYM *s;
151 {
152 	if (s->func != NIL) {
153 		printouter(s->func);
154 	}
155 	printf("%s.", s->symbol);
156 }
157