|
|
1.1 root 1: /*ident "@(#)ctrans:src/norm2.c 1.1.5.6" */
2: /************************************************************************
3:
4: C++ source for cfront, the C++ compiler front-end
5: written in the computer science research center of Bell Labs
6:
7: Copyright (c) 1984 AT&T, Inc. All rigths Reserved
8: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
9:
10: norm2.c:
11:
12: "normalization" handles problems which could have been handled
13: by the syntax analyser; but has not been done. The idea is
14: to simplify the grammar and the actions associated with it,
15: and to get a more robust error handling
16:
17: ****************************************************************************/
18:
19: #include "cfront.h"
20: #include "size.h"
21: const NBITE = (CHUNK-8)/sizeof(name)-1;
22: const EBITE = (CHUNK-8)/sizeof(expr)-1;
23: const SBITE = (CHUNK-8)/sizeof(stmt)-1;
24:
25: fct::fct(Ptype t, Pname arg, TOK known)
26: {
27: base = FCT;
28: nargs_known = known;
29: returns = t;
30: argtype = arg;
31:
32: if (arg==0 || arg->base==ELIST) return;
33: //error('d',"fct::fct %d sig %d",this,f_signature);
34: register Pname n;
35: Pname pn = 0;
36: for (n=arg; n; pn=n,n=n->n_list) {
37: switch (n->tp->base) {
38: case VOID:
39: argtype = 0;
40: nargs_known = 1;
41: if (n->string)
42: error("voidFA%n",n);
43: else if (nargs || n->n_list) {
44: error("voidFA");
45: nargs_known = 0;
46: }
47: nargs = 0;
48: break;
49: case CLASS:
50: case ENUM:
51: error("%k defined inAL (will not be in scope at point of call)",n->tp->base);
52: if (n == argtype)
53: argtype = n->n_list;
54: else
55: pn->n_list = n->n_list;
56: break;
57: default:
58: nargs++;
59: }
60: }
61: }
62:
63: Pexpr expr_free;
64:
65: expr::expr(TOK ba, Pexpr a, Pexpr b)
66: {
67: register Pexpr p;
68:
69: if (this) goto ret;
70:
71: if ( (p=expr_free) == 0 ) {
72: register Pexpr q = (Pexpr) chunk(1);
73: for (p=expr_free=&q[EBITE-1]; q<p; p--) p->e1 = p-1;
74: (p+1)->e1 = 0;
75: }
76: else
77: expr_free = p->e1;
78:
79: this = p;
80:
81: permanent = 0;
82: tp = 0;
83: tp2 = 0;
84: ret:
85: base = ba;
86: e1 = a;
87: e2 = b;
88: }
89:
90: expr::~expr()
91: {
92: e1 = expr_free;
93: expr_free = this;
94: this = 0;
95: }
96:
97: Pstmt stmt_free;
98:
99: stmt::stmt(TOK ba, loc ll, Pstmt a)
100: {
101: register Pstmt p;
102:
103: if ( (p=stmt_free) == 0 ) {
104: register Pstmt q = (Pstmt) chunk(1);
105: for (p=stmt_free=&q[SBITE-1]; q<p; p--) p->s_list = p-1;
106: (p+1)->s_list = 0;
107: }
108: else
109: stmt_free = p->s_list;
110:
111: this = p;
112:
113: permanent = 0;
114: e = e2 = 0;
115: memtbl = 0;
116: else_stmt = 0;
117: s_list = 0;
118:
119: // Ns++;
120: base = ba;
121: where = ll;
122: s=a;
123: }
124:
125: stmt::~stmt()
126: {
127: // NFs++;
128: s_list = stmt_free;
129: stmt_free = this;
130: this = 0;
131: }
132:
133: classdef::classdef(TOK b)
134: {
135: base = CLASS;
136: csu = b;
137: memtbl = new table(CTBLSIZE,0,0);
138: }
139:
140: basetype::basetype(TOK b, Pname n)
141: {
142: // Nbt++;
143: switch (b) {
144: case 0: break;
145: case TYPEDEF: b_typedef = 1; break;
146: case INLINE: b_inline = 1; break;
147: case VIRTUAL: b_virtual = 1; break;
148: case CONST: b_const = 1; break;
149: case UNSIGNED: b_unsigned = 1; break;
150: case FRIEND:
151: case OVERLOAD:
152: case EXTERN:
153: case STATIC:
154: case AUTO:
155: case REGISTER: b_sto = b; break;
156: case SHORT: b_short = 1; break;
157: case LONG: b_long = 1; break;
158: case ANY:
159: case ZTYPE:
160: case VOID:
161: case CHAR:
162: case INT:
163: case FLOAT:
164: case LDOUBLE:
165: case DOUBLE: base = b; break;
166: case TYPE:
167: case COBJ:
168: case EOBJ:
169: case FIELD:
170: case ASM:
171: base = b;
172: b_name = n;
173: break;
174: case SIGNED:
175: case VOLATILE:
176: error('w',"\"%k\" not implemented (ignored)",b);
177: break;
178: default:
179: error('i',"badBT:%k",b);
180: }
181: }
182:
183: Pname name_free;
184:
185: name::name(char* s) : (NAME,0,0)
186: {
187: register Pname p;
188:
189: if ( (p=name_free) == 0 ) {
190: register Pname q = (Pname) chunk(1);
191: for (p=name_free=&q[NBITE-1]; q<p; p--) p->n_tbl_list = p-1;
192: (p+1)->n_tbl_list = 0;
193: }
194: else
195: name_free = p->n_tbl_list;
196:
197: this = p;
198:
199: string = s;
200: where = curloc;
201: lex_level = bl_level;
202:
203: // beware of alignment differences & pointer-zeros that is not int-zeros
204: tp = 0;
205: n_initializer = 0;
206: n_table = 0;
207: n_oper = 0;
208: n_sto = 0;
209: n_stclass = 0;
210: n_scope = 0;
211: n_union = 0;
212: n_evaluated = 0;
213: n_xref = 0;
214: n_protect = 0;
215: n_dcl_printed = 0;
216: n_addr_taken = 0;
217: n_used = 0;
218: n_assigned_to = 0;
219: n_val = 0;
220: n_offset = 0;
221: n_list = 0;
222: n_tbl_list = 0;
223: n_qualifier = 0;
224: n_key = 0;
225: n_anon = 0;
226: }
227:
228: name::~name()
229: {
230: n_tbl_list = name_free;
231: name_free = this;
232: this = 0;
233: }
234:
235:
236: nlist::nlist(Pname n)
237: {
238: head = n;
239: for (Pname nn=n; nn->n_list; nn=nn->n_list);
240: tail = nn;
241: }
242:
243: void nlist::add_list(Pname n)
244: {
245: if (n->tp && (n->tp->defined & IN_ERROR)) return;
246:
247: tail->n_list = n;
248: for (Pname nn=n; nn->n_list; nn=nn->n_list);
249: tail = nn;
250: }
251:
252: Pname name_unlist(Pnlist l)
253: {
254: if (l == 0) return 0;
255: Pname n = l->head;
256:
257: delete l;
258: return n;
259: }
260:
261: Pstmt stmt_unlist(Pslist l)
262: {
263: if (l == 0) return 0;
264: Pstmt s = l->head;
265: // NFl++;
266:
267: delete l;
268: return s;
269: }
270:
271: Pexpr expr_unlist(Pelist l)
272: {
273: if (l == 0) return 0;
274: Pexpr e = l->head;
275: // NFl++;
276:
277: delete l;
278: return e;
279: }
280:
281: void sig_name(Pname n)
282: {
283: static char buf[256];
284: buf[0] = '_';
285: buf[1] = '_';
286: buf[2] = 'o';
287: buf[3] = 'p';
288: char* p = n->tp->signature(buf+4);
289: if (255 < p-buf) error('i',"sig_name():N buffer overflow");
290: n->string = buf;
291: n->tp = 0;
292: }
293:
294: Ptype tok_to_type(TOK b)
295: {
296: Ptype t;
297: switch (b) {
298: case CHAR: t = char_type; break;
299: case SHORT: t = short_type; break;
300: case LONG: t = long_type; break;
301: case UNSIGNED: t = uint_type; break;
302: case FLOAT: t = float_type; break;
303: case DOUBLE: t = double_type; break;
304: case LDOUBLE: t = ldouble_type; break;
305: case VOID: t = void_type; break;
306: default: error("illegalK:%k",b);
307: case INT: t = int_type;
308: }
309: return t;
310: }
311:
312: Pbase defa_type;
313: Pbase moe_type;
314: Pexpr dummy;
315: Pexpr zero;
316:
317: Pclass ccl;
318: Plist modified_tn = 0;
319:
320: // local class
321: Plist local_tn = 0;
322: Plist local_blk = 0;
323: Plist local_class = 0;
324:
325: static name sta_name_dummy;
326: Pname sta_name = &sta_name_dummy;
327:
328: TOK back;
329:
330: void memptrdcl(Pname bn, Pname tn, Ptype ft, Pname n)
331: {
332: Pptr p = new ptr(PTR,0);
333: p->memof = Pclass(Pbase(bn->tp)->b_name->tp);
334: Pbase b = new basetype(TYPE,tn);
335: PERM(p);
336: Pfct f = Pfct(ft);
337: Ptype t = n->tp;
338: if (t) {
339: p->typ = t;
340: ltlt:
341: switch (t->base) {
342: case PTR:
343: case RPTR:
344: case VEC:
345: if (Pptr(t)->typ == 0) {
346: Pptr(t)->typ = b;
347: break;
348: }
349: t = Pptr(t)->typ;
350: goto ltlt;
351: default:
352: error('s',"P toMFT too complicated");
353: }
354: }
355: else
356: p->typ = b;
357: f->returns = p;
358: n->tp = f;
359: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.