forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnorm2.c
322 lines (288 loc) · 7.24 KB
/
norm2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*ident "@(#)cls4:src/norm2.c 1.4" */
/*******************************************************************************
C++ source for the C++ Language System, Release 3.0. This product
is a new release of the original cfront developed in the computer
science research center of AT&T Bell Laboratories.
Copyright (c) 1993 UNIX System Laboratories, Inc.
Copyright (c) 1991, 1992 AT&T and UNIX System Laboratories, Inc.
Copyright (c) 1984, 1989, 1990 AT&T. All Rights Reserved.
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX System
Laboratories, Inc. The copyright notice above does not evidence
any actual or intended publication of such source code.
norm2.c:
"normalization" handles problems which could have been handled
by the syntax analyser; but has not been done. The idea is
to simplify the grammar and the actions associated with it,
and to get a more robust error handling
****************************************************************************/
#include "cfront.h"
#include "size.h"
#ifdef DBG
long node_id = 0;
#define DBCHECK() \
if (node::allocated) \
error('i', "allocated node (id %d, base%k) on free list! (src: \"%s\", %d", node::id, \
node::base, __FILE__, __LINE__);
#else
#define DBCHECK() /**/
#endif
fct::fct(Ptype t, Pname arg, TOK known) {
base = FCT;
nargs_known = known;
returns = t;
argtype = arg;
DBID();
if (arg == 0 || arg->base == ELIST)
return;
// error('d',"fct::fct %d sig %d",this,f_signature);
register Pname n;
Pname pn = 0;
for (n = arg; n; pn = n, n = n->n_list) {
if (n->n_sto == EXTERN)
error("cannot specify extern linkage for anA");
if (n->n_sto == STATIC)
error("cannot specify static forA%n", arg);
switch (n->tp->skiptypedefs()->base) {
case VOID:
argtype = 0;
nargs_known = 1;
if (n->n_initializer)
error("voidFA");
else if (n->string)
error("voidFA%n", n);
else if (nargs || n->n_list) {
error("voidFA");
nargs_known = 0;
}
nargs = 0;
break;
case CLASS:
case ENUM:
error("%k defined inAL (will not be in scope at point of call)", n->tp->base);
if (n == argtype)
argtype = n->n_list;
else
pn->n_list = n->n_list;
break;
default:
nargs++;
}
}
}
expr::expr(TOK ba, Pexpr a, Pexpr b) {
DBCHECK();
base = ba;
e1 = a;
e2 = b;
DBID();
}
stmt::stmt(TOK ba, loc ll, Pstmt a) {
DBCHECK();
base = ba;
where = ll;
s = a;
memtbl = 0;
k_tbl = 0; // SYM
DBID();
}
classdef::classdef(TOK b) {
base = CLASS;
csu = b;
memtbl = new table(CTBLSIZE, 0, 0);
k_tbl = 0; // SYM
DBID();
}
classdef::~classdef() {
delete memtbl;
}
basetype::basetype(TOK b, Pname n) {
switch (b) {
case 0:
break;
case TYPEDEF:
b_typedef = 1;
break;
case INLINE:
b_inline = 1;
break;
case VIRTUAL:
b_virtual = 1;
break;
case CONST:
b_const = 1;
break;
case UNSIGNED:
b_unsigned = 1;
break;
case FRIEND:
case OVERLOAD:
case EXTERN:
case STATIC:
case AUTO:
case REGISTER:
b_sto = b;
break;
case SHORT:
b_short = 1;
break;
case LONG:
b_long = 1;
break;
case ANY:
case ZTYPE:
case VOID:
case CHAR:
case INT:
case FLOAT:
case LDOUBLE:
case DOUBLE:
base = b;
break;
case TYPE:
case COBJ:
case EOBJ:
case FIELD:
case ASM:
base = b;
b_name = n;
break;
case SIGNED:
case VOLATILE:
error('w', "\"%k\" not implemented (ignored)", b);
break;
default:
error('i', "badBT:%k", b);
}
DBID();
}
name::name(char *s) : expr(NAME, 0, 0) {
// DBCHECK() called in expr::expr()
string = s;
where = curloc;
lex_level = bl_level;
}
name_list::name_list(Pname ff, Plist ll) {
base = XNLIST;
f = ff;
l = ll;
};
nlist::nlist(Pname n) {
head = n;
for (Pname nn = n; nn->n_list; nn = nn->n_list)
;
tail = nn;
}
void nlist::add_list(Pname n) {
if (n->tp && (n->tp->defined & IN_ERROR))
return;
tail->n_list = n;
for (Pname nn = n; nn->n_list; nn = nn->n_list)
;
tail = nn;
}
Pname name_unlist(Pnlist l) {
if (l == 0)
return 0;
Pname n = l->head;
delete l;
return n;
}
Pstmt stmt_unlist(Pslist l) {
if (l == 0)
return 0;
Pstmt s = l->head;
// NFl++;
delete l;
return s;
}
Pexpr expr_unlist(Pelist l) {
if (l == 0)
return 0;
Pexpr e = l->head;
// NFl++;
delete l;
return e;
}
void sig_name(Pname n) {
static char buf[1024];
buf[0] = '_';
buf[1] = '_';
buf[2] = 'o';
buf[3] = 'p';
char *p = n->tp->signature(buf + 4);
if (255 < p - buf)
error('i', "sig_name():N buffer overflow");
char *s = new char[p - buf + 1];
strcpy(s, buf);
n->string = s;
n->tp = 0;
}
Ptype tok_to_type(TOK b) {
Ptype t;
switch (b) {
case CHAR:
t = char_type;
break;
case SHORT:
t = short_type;
break;
case LONG:
t = long_type;
break;
case UNSIGNED:
t = uint_type;
break;
case FLOAT:
t = float_type;
break;
case DOUBLE:
t = double_type;
break;
case LDOUBLE:
t = ldouble_type;
break;
case VOID:
t = void_type;
break;
default:
error("illegalK:%k", b);
case INT:
t = int_type;
}
return t;
}
Pbase defa_type;
Pbase moe_type;
Pexpr dummy;
Pexpr zero;
Pclass ccl;
// SYM -- tn stuff removed
Plist local_class = 0; // SYM -- preserve for use in del.c
void memptrdcl(Pname bn, Pname tn, Ptype ft, Pname n) {
Pptr p = new ptr(PTR, 0);
p->memof = Pclass(Pbase(bn->tp)->b_name->tp);
Pbase b = new basetype(TYPE, tn);
PERM(p);
Pfct f = Pfct(ft);
Ptype t = n->tp;
if (t) {
p->typ = t;
ltlt:
switch (t->base) {
case PTR:
case RPTR:
case VEC:
if (Pptr(t)->typ == 0) {
Pptr(t)->typ = b;
break;
}
t = Pptr(t)->typ;
goto ltlt;
default:
error('s', "P toMFT too complicated");
}
} else
p->typ = b;
f->returns = p;
n->tp = f;
}