| 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 |
# include "pass1.h" |
| 28 |
|
| 29 |
|
| 30 |
struct symtab spole0 = { 0, 0, 0, 0, 0, 0, 0, "base", "base", }; |
| 31 |
struct symtab *spole = &spole0; |
| 32 |
struct symtab *nscur = &spole0; |
| 33 |
int elnk, nsptr; |
| 34 |
|
| 35 |
static struct symtab *sfind(char *n, struct symtab *sp); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void |
| 40 |
dclns(NODE *attr, char *n) |
| 41 |
{ |
| 42 |
struct symtab *sp; |
| 43 |
#ifdef GCC_COMPAT |
| 44 |
struct attr *ap = gcc_attr_parse(attr); |
| 45 |
#else |
| 46 |
struct attr *ap = NULL; |
| 47 |
#endif |
| 48 |
|
| 49 |
if (cppdebug)printf("declaring namespace %s\n", n); |
| 50 |
n = addname(n); |
| 51 |
|
| 52 |
sp = sfind(n, nscur->sup); |
| 53 |
while (sp != NULL) { |
| 54 |
if (sp->sname == n && sp->sclass == NSPACE) |
| 55 |
break; |
| 56 |
sp = sfind(n, sp->snext); |
| 57 |
} |
| 58 |
if (sp == NULL) { |
| 59 |
|
| 60 |
sp = getsymtab(n, 0); |
| 61 |
sp->sclass = NSPACE; |
| 62 |
INSSYM(sp); |
| 63 |
} |
| 64 |
nscur = sp; |
| 65 |
if (cppdebug)printf("declaring namespace2 %s\n", nscur->sname); |
| 66 |
sp->sap = attr_add(sp->sap, ap); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
static NODE * |
| 73 |
callftn(char *n, ...) |
| 74 |
{ |
| 75 |
struct symtab *sp = getsymtab(n, 0); |
| 76 |
NODE *p, *a, *b; |
| 77 |
va_list ap; |
| 78 |
|
| 79 |
sp->stype = (FTN|VOID) | (PTR << TSHIFT); |
| 80 |
va_start(ap, n); |
| 81 |
|
| 82 |
a = va_arg(ap, NODE *); |
| 83 |
if (a != NULL) { |
| 84 |
do { |
| 85 |
b = va_arg(ap, NODE *); |
| 86 |
if (b != NULL) |
| 87 |
a = buildtree(CM, a, b); |
| 88 |
} while (b != NULL); |
| 89 |
} |
| 90 |
|
| 91 |
p = doacall(sp, nametree(sp), a, 0); |
| 92 |
va_end(ap); |
| 93 |
return p; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
NODE * |
| 100 |
cxx_new(NODE *p) |
| 101 |
{ |
| 102 |
NODE *q = p; |
| 103 |
NODE *t1 = bcon(1); |
| 104 |
int nw = NM_NEW; |
| 105 |
|
| 106 |
while (p->n_op == LB) { |
| 107 |
nw = NM_NWA; |
| 108 |
t1 = buildtree(MUL, t1, eve(p->n_right)); |
| 109 |
p->n_right = bcon(0); |
| 110 |
p = p->n_left; |
| 111 |
} |
| 112 |
if (p->n_op != TYPE) |
| 113 |
uerror("new used illegally"); |
| 114 |
t1 = buildtree(MUL, t1, |
| 115 |
xbcon(tsize(p->n_type, p->n_df, p->n_ap)/SZCHAR, NULL, INTPTR)); |
| 116 |
tfree(q); |
| 117 |
return callftn(decoratename(NULL, nw), t1, NULL); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
NODE * |
| 124 |
cxx_delete(NODE *p, int del) |
| 125 |
{ |
| 126 |
return callftn(decoratename(NULL, del), p, NULL); |
| 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 |
static char chmap[] = { 'v', 'b', 'c', 'h', 's', 't', 'i', 'j', 'l', 'm', |
| 220 |
'x', 'y', 'f', 'd', 'e' }; |
| 221 |
|
| 222 |
static int |
| 223 |
typch(int typ) |
| 224 |
{ |
| 225 |
int c = BTYPE(typ); |
| 226 |
if (c == VOID) |
| 227 |
c = 0; |
| 228 |
return chmap[c]; |
| 229 |
} |
| 230 |
|
| 231 |
#define MAXNM 255 |
| 232 |
static char nmblk[MAXNM]; |
| 233 |
static int nmptr, subptr; |
| 234 |
|
| 235 |
|
| 236 |
static void |
| 237 |
nmch(int c) |
| 238 |
{ |
| 239 |
if (nmptr >= MAXNM) |
| 240 |
cerror("Too long mangled name"); |
| 241 |
nmblk[nmptr++] = c; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
static void |
| 246 |
pshsln(char *c) |
| 247 |
{ |
| 248 |
int i, j, ln = (int)strlen(c); |
| 249 |
|
| 250 |
#define cnt(v,n) for (v = 0; ln >= n; v++, ln -= n) |
| 251 |
cnt(i,100); |
| 252 |
cnt(j,10); |
| 253 |
if (i) nmch(i+'0'); |
| 254 |
if (j || i) nmch(j+'0'); |
| 255 |
nmch(ln+'0'); |
| 256 |
for (; *c; c++) |
| 257 |
nmch(*c); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
static void |
| 262 |
recnpsh(struct symtab *sp) |
| 263 |
{ |
| 264 |
if (sp == spole) |
| 265 |
return; |
| 266 |
if (sp == sp->sdown) |
| 267 |
cerror("sp == sp->sdown"); |
| 268 |
if (sp->sdown) |
| 269 |
recnpsh(sp->sdown); |
| 270 |
pshsln(sp->sname); |
| 271 |
} |
| 272 |
|
| 273 |
static void |
| 274 |
pshargs(union arglist *al) |
| 275 |
{ |
| 276 |
TWORD t; |
| 277 |
|
| 278 |
|
| 279 |
for (; al->type != TNULL; al++) { |
| 280 |
t = al->type; |
| 281 |
if (t == TELLIPSIS) { |
| 282 |
nmch('z'); |
| 283 |
continue; |
| 284 |
} |
| 285 |
while (t > BTMASK) { |
| 286 |
if (ISPTR(t)) |
| 287 |
nmch('P'); |
| 288 |
else |
| 289 |
uerror("pshargs2: %lx\n", t); |
| 290 |
t = DECREF(t); |
| 291 |
} |
| 292 |
if (t > LDOUBLE) |
| 293 |
uerror("pshargs: %lx\n", t); |
| 294 |
|
| 295 |
nmch(typch(t)); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
char * |
| 304 |
decoratename(struct symtab *sp, int type) |
| 305 |
{ |
| 306 |
char *n; |
| 307 |
|
| 308 |
#define QNM(m,s) case m: n = s; break |
| 309 |
switch (type) { |
| 310 |
QNM(NM_NEW,"_Znwm"); |
| 311 |
QNM(NM_NWA,"_Znam"); |
| 312 |
QNM(NM_DEL,"_ZdlPv"); |
| 313 |
QNM(NM_DLA,"_ZdaPv"); |
| 314 |
case NM_NORMAL: |
| 315 |
break; |
| 316 |
default: |
| 317 |
uerror("missed mangling %d\n", type); |
| 318 |
return ""; |
| 319 |
} |
| 320 |
if (type != NM_NORMAL) |
| 321 |
return addname(n); |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
if (elnk == LINK_C || strcmp(sp->sname, "main") == 0 || |
| 329 |
(sp->sdown == spole && !ISFTN(sp->stype))) { |
| 330 |
n = exname(sp->sname); |
| 331 |
return addname(n); |
| 332 |
} |
| 333 |
|
| 334 |
nmptr = 0; |
| 335 |
subptr = 0; |
| 336 |
nmch('_'); nmch('Z'); |
| 337 |
if (sp->sdown != NULL) { |
| 338 |
nmch('N'); |
| 339 |
recnpsh(sp->sdown); |
| 340 |
} |
| 341 |
pshsln(sp->sname); |
| 342 |
if (sp->sdown != NULL) |
| 343 |
nmch('E'); |
| 344 |
if (ISFTN(sp->stype) && sp->sdf->dfun) |
| 345 |
pshargs(sp->sdf->dfun); |
| 346 |
nmch(0); |
| 347 |
return addname(nmblk); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
static struct symtab * |
| 354 |
sfind(char *n, struct symtab *sp) |
| 355 |
{ |
| 356 |
while (sp) { |
| 357 |
if (cppdebug)printf("sfind: checking %s against %s\n", n, sp->sname); |
| 358 |
if (sp->sname == n) |
| 359 |
return sp; |
| 360 |
sp = sp->snext; |
| 361 |
} |
| 362 |
return NULL; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
#define CLORNS(sp) (sp->sclass == STNAME || sp->sclass == CLNAME || \ |
| 367 |
sp->sclass == UNAME || sp->sclass == NSPACE) |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
static struct symtab * |
| 375 |
pfind(NODE *p, struct symtab *sp) |
| 376 |
{ |
| 377 |
char *n; |
| 378 |
|
| 379 |
if (cppdebug)printf("pfind: op %d searching %s\n", p->n_op, p->n_op == NAME ? |
| 380 |
(char *)p->n_sp:(char *)p->n_right->n_sp); |
| 381 |
|
| 382 |
if (p->n_op == NAME) { |
| 383 |
n = (char *)p->n_sp; |
| 384 |
if ((sp = sfind(n, sp)) == NULL) |
| 385 |
return NULL; |
| 386 |
if (cppdebug)printf("pfind: NAME class %d name %s\n", sp->sclass, sp->sname); |
| 387 |
while (!CLORNS(sp)) { |
| 388 |
if ((sp = sfind(n, sp->snext)) == NULL) |
| 389 |
return NULL; |
| 390 |
} |
| 391 |
if (cppdebug)printf("pfind: FOUND %s\n", sp->sname); |
| 392 |
sp = sp->sup; |
| 393 |
} else { |
| 394 |
n = (char *)p->n_right->n_sp; |
| 395 |
if ((sp = sfind(n, sp)) == NULL) |
| 396 |
return NULL; |
| 397 |
if (cppdebug)printf("pfind: NMLIST class %d name %s\n", sp->sclass, sp->sname); |
| 398 |
while (!CLORNS(sp)) { |
| 399 |
if ((sp = sfind(n, sp->snext)) == NULL) |
| 400 |
return NULL; |
| 401 |
} |
| 402 |
sp = pfind(p->n_left, sp->sup); |
| 403 |
} |
| 404 |
return sp; |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
struct symtab * |
| 411 |
cxxdeclvar(NODE *p) |
| 412 |
{ |
| 413 |
struct symtab *sp; |
| 414 |
|
| 415 |
if (blevel && p->n_op == NAME) { |
| 416 |
sp = p->n_sp = lookup((char *)p->n_sp, 0); |
| 417 |
} else { |
| 418 |
sp = cxxlookup(p, SNORMAL); |
| 419 |
} |
| 420 |
return sp; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
char *symclass[] = { "NORMAL", "CLASS", "LABEL", "MOS", "STRING" }; |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
struct symtab * |
| 440 |
cxxlookup(NODE *p, int flags) |
| 441 |
{ |
| 442 |
struct symtab *sp, *ns; |
| 443 |
int ftyp = flags & SMASK; |
| 444 |
NODE *q; |
| 445 |
char *n, *s; |
| 446 |
|
| 447 |
#define SPNAME(p) ((char *)(p->n_op == NAME ? p->n_sp : p->n_right->n_sp)) |
| 448 |
#ifdef PCC_DEBUG |
| 449 |
if (cppdebug){ printf("cxxlookup %s\n", SPNAME(p)); symtree(); } |
| 450 |
#endif |
| 451 |
|
| 452 |
q = p; |
| 453 |
if (p->n_op == NAME) { |
| 454 |
s = (char *)p->n_sp; |
| 455 |
if (blevel) { |
| 456 |
sp = lookup(s, SNOCREAT); |
| 457 |
if (sp == NULL) { |
| 458 |
|
| 459 |
for (ns = nscur; ns != spole; ns = ns->sdown) |
| 460 |
if ((sp = sfind(s, ns->sup))) |
| 461 |
break; |
| 462 |
if (sp == NULL) |
| 463 |
sp = sfind(s, spole->sup); |
| 464 |
} |
| 465 |
if (sp == NULL) |
| 466 |
sp = lookup(s, 0); |
| 467 |
} else { |
| 468 |
ns = nscur; |
| 469 |
sp = sfind(s, ns); |
| 470 |
while (sp != NULL) { |
| 471 |
if ((sp->sflags & SMASK) == ftyp) |
| 472 |
break; |
| 473 |
sp = sfind(s, sp->snext); |
| 474 |
} |
| 475 |
if (sp == NULL) { |
| 476 |
sp = getsymtab(s, ftyp); |
| 477 |
if ((flags & SNOCREAT) == 0) { |
| 478 |
#ifdef PCC_DEBUG |
| 479 |
if (cppdebug)printf("cxxlookup: adding %s %s %s at %s\n", symclass[ftyp], s, sp->soname, nscur ? nscur->sname : "base"); |
| 480 |
#endif |
| 481 |
INSSYM(sp); |
| 482 |
cxxsetname(sp); |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
} else { |
| 487 |
|
| 488 |
n = SPNAME(p); |
| 489 |
ns = pfind(p->n_left, spole->sup); |
| 490 |
if (ns == NULL) { |
| 491 |
uerror("undeclared class in chain"); |
| 492 |
return getsymtab(n, ftyp); |
| 493 |
} |
| 494 |
if ((sp = sfind(n, ns)) == NULL) { |
| 495 |
sp = getsymtab(n, ftyp); |
| 496 |
if ((flags & SNOCREAT) == 0) { |
| 497 |
sp->snext = ns->snext; |
| 498 |
ns->snext = sp; |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
if (q->n_op != NAME) { |
| 505 |
tfree(q->n_left); |
| 506 |
p = q->n_right; |
| 507 |
*q = *q->n_right; |
| 508 |
nfree(p); |
| 509 |
} |
| 510 |
q->n_sp = sp; |
| 511 |
return sp; |
| 512 |
} |
| 513 |
|
| 514 |
void |
| 515 |
cxxsetname(struct symtab *sp) |
| 516 |
{ |
| 517 |
if (elnk == LINK_C) |
| 518 |
return; |
| 519 |
sp->soname = decoratename(sp, NM_NORMAL); |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
struct symtab * |
| 527 |
cxxstrvar(struct symtab *so) |
| 528 |
{ |
| 529 |
struct symtab *sp; |
| 530 |
NODE *p; |
| 531 |
|
| 532 |
sp = lookup("__%THIS", 0); |
| 533 |
p = block(NAME, 0, 0, INCREF(so->stype), so->sdf, so->sap); |
| 534 |
p->n_sp = sp; |
| 535 |
defid(p, PARAM); |
| 536 |
nfree(p); |
| 537 |
return sp; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
struct symtab * |
| 548 |
cxxdclstr(char *n) |
| 549 |
{ |
| 550 |
struct symtab *sp; |
| 551 |
|
| 552 |
sp = sfind(n, nscur->sup); |
| 553 |
while (sp && !CLORNS(sp)) |
| 554 |
sp = sfind(n, sp->snext); |
| 555 |
if (sp == 0) |
| 556 |
sp = getsymtab(n, STAGNAME); |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
if (cppdebug)printf("declaring2 struct %s %p nscur %s\n", n, sp, nscur->sname); |
| 563 |
return sp; |
| 564 |
} |
| 565 |
|
| 566 |
#ifdef PCC_DEBUG |
| 567 |
static void |
| 568 |
symwalk(struct symtab *sp, int indent) |
| 569 |
{ |
| 570 |
int i; |
| 571 |
|
| 572 |
while (sp) { |
| 573 |
for (i = 0; i < indent; i++) |
| 574 |
printf(" "); |
| 575 |
printf("%s (%p) %s\n", sp->sname, sp, scnames(sp->sclass)); |
| 576 |
if (sp->sup) |
| 577 |
symwalk(sp->sup, indent+1); |
| 578 |
sp = sp->snext; |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
void |
| 583 |
symtree(void) |
| 584 |
{ |
| 585 |
symwalk(spole, 0); |
| 586 |
} |
| 587 |
#endif |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
static int |
| 593 |
cxxpcmp(struct symtab *sp, NODE *p) |
| 594 |
{ |
| 595 |
union arglist *a1, *a2; |
| 596 |
int i; |
| 597 |
|
| 598 |
if (!ISFTN(sp->stype) || p->n_df == NULL || sp->sdf == NULL) |
| 599 |
return 0; |
| 600 |
if ((a1 = sp->sdf->dfun) == NULL || (a2 = p->n_df->dfun) == NULL) |
| 601 |
return 0; |
| 602 |
|
| 603 |
for (i = 0; ; i++) { |
| 604 |
if (a1[i].type == TNULL && a2[i].type == TNULL) |
| 605 |
return 1; |
| 606 |
if (a1[i].type != a2[i].type) |
| 607 |
return 1; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
struct ckstr { |
| 612 |
int rv; |
| 613 |
union arglist *al; |
| 614 |
}; |
| 615 |
|
| 616 |
static void |
| 617 |
cxxckproto(NODE *p, void *arg) |
| 618 |
{ |
| 619 |
struct ckstr *cp = arg; |
| 620 |
|
| 621 |
if (cp->rv == -1) |
| 622 |
return; |
| 623 |
|
| 624 |
if (cp->al[0].type != p->n_type) |
| 625 |
goto fail; |
| 626 |
if (BTYPE(cp->al[0].type) > LDOUBLE) |
| 627 |
uerror("cxxckproto"); |
| 628 |
cp->al++; |
| 629 |
return; |
| 630 |
fail: |
| 631 |
cp->rv = -1; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
static int |
| 640 |
cxxptreecmp(struct symtab *sp, NODE *p) |
| 641 |
{ |
| 642 |
struct ckstr ckstr; |
| 643 |
union arglist *a1; |
| 644 |
|
| 645 |
if (!ISFTN(sp->stype) || sp->sdf == NULL || |
| 646 |
(a1 = sp->sdf->dfun) == NULL) |
| 647 |
return 0; |
| 648 |
|
| 649 |
if (p == NULL && a1[0].type == TNULL) |
| 650 |
return 1; |
| 651 |
|
| 652 |
ckstr.rv = 0; |
| 653 |
ckstr.al = a1; |
| 654 |
flist(p, cxxckproto, &ckstr); |
| 655 |
|
| 656 |
if (ckstr.al[0].type != TNULL) |
| 657 |
return -1; |
| 658 |
return ckstr.rv; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
struct symtab * |
| 665 |
cxxftnfind(NODE *p, int flags) |
| 666 |
{ |
| 667 |
struct symtab *sp, *ns; |
| 668 |
char *s; |
| 669 |
|
| 670 |
if (p->n_op == NAME) { |
| 671 |
s = (char *)p->n_sp; |
| 672 |
|
| 673 |
sp = sfind(s, nscur->sup); |
| 674 |
while (sp != NULL) { |
| 675 |
if (cxxpcmp(sp, p)) { |
| 676 |
if (sp->sclass != NSPACE || |
| 677 |
sp->sclass == EXTDEF) { |
| 678 |
uerror("%s redefined", s); |
| 679 |
return sp; |
| 680 |
} else |
| 681 |
break; |
| 682 |
} |
| 683 |
sp = sfind(s, sp->snext); |
| 684 |
} |
| 685 |
if (sp == NULL) { |
| 686 |
sp = getsymtab(s, SNORMAL); |
| 687 |
sp->stype = p->n_type; |
| 688 |
sp->squal = p->n_qual; |
| 689 |
sp->sdf = p->n_df; |
| 690 |
sp->sap = p->n_ap; |
| 691 |
INSSYM(sp); |
| 692 |
if (nscur->sclass != NSPACE && nscur != &spole0) |
| 693 |
uerror("inside struct"); |
| 694 |
} |
| 695 |
sp->sclass = EXTDEF; |
| 696 |
if (sp->soname == 0) |
| 697 |
sp->soname = decoratename(sp, NM_NORMAL); |
| 698 |
} else { |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
s = SPNAME(p); |
| 705 |
if ((ns = pfind(p->n_left, spole->sup)) == NULL) { |
| 706 |
uerror("undeclared class in chain"); |
| 707 |
goto undecl; |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
sp = sfind(s, ns); |
| 712 |
while (sp != NULL) { |
| 713 |
if (sp->sclass == EXTERN || sp->sclass == EXTDEF) { |
| 714 |
if (cxxpcmp(sp, p->n_right)) { |
| 715 |
if (sp->sclass == EXTDEF) |
| 716 |
uerror("%s redefined", s); |
| 717 |
break; |
| 718 |
} |
| 719 |
} |
| 720 |
sp = sfind(s, sp->snext); |
| 721 |
} |
| 722 |
if (sp == NULL) { |
| 723 |
uerror("%s undeclared", s); |
| 724 |
goto undecl; |
| 725 |
} |
| 726 |
sp->sclass = EXTDEF; |
| 727 |
} |
| 728 |
return sp; |
| 729 |
|
| 730 |
undecl: |
| 731 |
return getsymtab(s, SNORMAL); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
NODE * |
| 738 |
cxxrstruct(int soru, NODE *attr, NODE *t, char *n) |
| 739 |
{ |
| 740 |
struct symtab *ns, *sp; |
| 741 |
|
| 742 |
ns = pfind(t, spole->sup); |
| 743 |
if (ns == NULL) |
| 744 |
goto undecl; |
| 745 |
|
| 746 |
tfree(t); |
| 747 |
sp = sfind(n, ns); |
| 748 |
while (sp != NULL) { |
| 749 |
if (sp->sclass == soru) |
| 750 |
return mkty(sp->stype, 0, sp->sap); |
| 751 |
sp = sfind(n, sp->snext); |
| 752 |
} |
| 753 |
undecl: |
| 754 |
uerror("%s undeclared", n); |
| 755 |
return mkty(INT, 0, 0); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
NODE * |
| 766 |
cxxmatchftn(NODE *f, NODE *a) |
| 767 |
{ |
| 768 |
struct attr *ap; |
| 769 |
struct symtab *sp; |
| 770 |
char *n = (char *)f->n_right->n_sp; |
| 771 |
|
| 772 |
f = f->n_left; |
| 773 |
|
| 774 |
if ((ap = attr_find(f->n_ap, ATTR_STRUCT)) == NULL) { |
| 775 |
uerror("undefined class"); |
| 776 |
sp = getsymtab(n, 0); |
| 777 |
} else |
| 778 |
sp = ap->amlist; |
| 779 |
sp = sfind(n, sp); |
| 780 |
while (sp != NULL) { |
| 781 |
if (ISFTN(sp->stype) && cxxptreecmp(sp, a) == 0) |
| 782 |
break; |
| 783 |
sp = sfind(n, sp->snext); |
| 784 |
} |
| 785 |
if (sp == NULL) |
| 786 |
uerror("undefined class member"); |
| 787 |
return nametree(sp); |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
NODE * |
| 794 |
cxxaddhidden(NODE *a, NODE *f) |
| 795 |
{ |
| 796 |
NODE *q; |
| 797 |
|
| 798 |
if (a == NULL) |
| 799 |
return f; |
| 800 |
if (a->n_op != CM) |
| 801 |
return block(CM, f, a, INT, 0, 0); |
| 802 |
for (q = a; q->n_left->n_op == CM; q = q->n_left) |
| 803 |
; |
| 804 |
q->n_left = block(CM, f, q->n_left, INT, 0, 0); |
| 805 |
return a; |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
NODE * |
| 812 |
cxxstructref(NODE *p, int f, char *n) |
| 813 |
{ |
| 814 |
struct symtab *sp = strmemb(p->n_ap); |
| 815 |
|
| 816 |
if (sp == NULL) |
| 817 |
cerror("ref to unknown struct"); |
| 818 |
sp = sfind(n, sp); |
| 819 |
while (sp != NULL) { |
| 820 |
if (!ISFTN(sp->stype)) { |
| 821 |
if (sp->sclass == STATIC || sp->sclass == USTATIC) { |
| 822 |
tfree(p); |
| 823 |
return nametree(sp); |
| 824 |
} |
| 825 |
break; |
| 826 |
} |
| 827 |
sp = sfind(n, sp->snext); |
| 828 |
} |
| 829 |
return structref(p, f, n); |
| 830 |
} |