Debian Codegraph @

cc/cxxcom/cxxcode.c

raw symbols SCIP
1 /* $Id: cxxcode.c,v 1.7 2016/10/11 13:48:24 ragge Exp $ */
2 /*
3 * Copyright (c) 2011 Anders Magnusson ([email protected]).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 * Declare a namespace.
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 /* New namespace */
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); /* XXX check attributes */
67 }
68
69 /*
70 * Generate a call tree to function named n.
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 * Sanitycheck "new" keyword.
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 * Handle "delete" keyword.
122 */
123 NODE *
124 cxx_delete(NODE *p, int del)
125 {
126 return callftn(decoratename(NULL, del), p, NULL);
127 }
128
129 /*
130 <operator-name> ::= nw # new
131 ::= na # new[]
132 ::= dl # delete
133 ::= da # delete[]
134 ::= ps # + (unary)
135 ::= ng # - (unary)
136 ::= ad # & (unary)
137 ::= de # * (unary)
138 ::= co # ~
139 ::= pl # +
140 ::= mi # -
141 ::= ml # *
142 ::= dv # /
143 ::= rm # %
144 ::= an # &
145 ::= or # |
146 ::= eo # ^
147 ::= aS # =
148 ::= pL # +=
149 ::= mI # -=
150 ::= mL # *=
151 ::= dV # /=
152 ::= rM # %=
153 ::= aN # &=
154 ::= oR # |=
155 ::= eO # ^=
156 ::= ls # <<
157 ::= rs # >>
158 ::= lS # <<=
159 ::= rS # >>=
160 ::= eq # ==
161 ::= ne # !=
162 ::= lt # <
163 ::= gt # >
164 ::= le # <=
165 ::= ge # >=
166 ::= nt # !
167 ::= aa # &&
168 ::= oo # ||
169 ::= pp # ++ (postfix in <expression> context)
170 ::= mm # -- (postfix in <expression> context)
171 ::= cm # ,
172 ::= pm # ->*
173 ::= pt # ->
174 ::= cl # ()
175 ::= ix # []
176 ::= qu # ?
177 ::= st # sizeof (a type)
178 ::= sz # sizeof (an expression)
179 ::= at # alignof (a type)
180 ::= az # alignof (an expression)
181 ::= cv <type> # (cast)
182 ::= v <digit> <source-name> # vendor extended operator
183 */
184
185 /*
186 <builtin-type> ::= v # void
187 ::= w # wchar_t
188 ::= b # bool
189 ::= c # char
190 ::= a # signed char
191 ::= h # unsigned char
192 ::= s # short
193 ::= t # unsigned short
194 ::= i # int
195 ::= j # unsigned int
196 ::= l # long
197 ::= m # unsigned long
198 ::= x # long long, __int64
199 ::= y # unsigned long long, __int64
200 ::= n # __int128
201 ::= o # unsigned __int128
202 ::= f # float
203 ::= d # double
204 ::= e # long double, __float80
205 ::= g # __float128
206 ::= z # ellipsis
207 ::= Dd # IEEE 754r decimal floating point (64 bits)
208 ::= De # IEEE 754r decimal floating point (128 bits)
209 ::= Df # IEEE 754r decimal floating point (32 bits)
210 ::= Dh # IEEE 754r half-precision floating point (16 bits)
211 ::= Di # char32_t
212 ::= Ds # char16_t
213 ::= Da # auto (in dependent new-expressions)
214 ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
215 ::= u <source-name> # vendor extended type
216 */
217
218 /* matches type numbering in manifest.h */
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 /* max length of mangled name */
232 static char nmblk[MAXNM];
233 static int nmptr, subptr;
234
235 /* push character */
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 /* Push length and string */
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 /* Recurse to push namespace names */
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 /* XXX - cannot emit const/volatile */
295 nmch(typch(t));
296 }
297 }
298
299 /*
300 * Do name mangling of a symbol table entry.
301 * The resulting name is saved in soname.
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: /* Defined in defid() */
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 /* special non-mangled cases:
324 * "C" linkage
325 * main() function
326 * variables outside namespaces and classes
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 /* Compute the mangled name for other symbols */
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 * find a symtab entry in the given link.
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 /* class or namespace? */
366 #define CLORNS(sp) (sp->sclass == STNAME || sp->sclass == CLNAME || \
367 sp->sclass == UNAME || sp->sclass == NSPACE)
368
369 /*
370 * find a symtab path entry in the given path.
371 * p is expected to be a link of NMNAMEs.
372 * It is supposed to return a sup value of the last found class.
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 * Declare a variable.
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 * class is MOS if variable is member of a CLASS, NORMAL otherwise.
425 * A CLASS as member of a class has symbol type CLASS.
426 */
427 char *symclass[] = { "NORMAL", "CLASS", "LABEL", "MOS", "STRING" };
428
429 /*
430 * Do a name lookup. p can be either just a NAME or NMLIST.
431 * The first symbol instance on its level is returned, which may or
432 * may not be correct.
433 * If no symbol is found, return a new symtab entry.
434 * p should be a NAME after this with n_sp filled in accordingly.
435 * It's the responsibility of the declaration routine to add it to
436 * the symbol table.
437 * nfree() will be called on p after this function.
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); /* check if auto var */
457 if (sp == NULL) {
458 /* check if in classes */
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); /* fallback */
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 /* Search through namespaces/classes for it */
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 /* make top node a NAME */
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; /* leave to target */
519 sp->soname = decoratename(sp, NM_NORMAL);
520 }
521
522 /*
523 * Create a symbol out of a struct.
524 * We call the symbol "__%THIS" to avoid interference.
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 * Declare a struct (class) based on its name n.
542 * Assumed that nmcur is correctly pointing to either:
543 * - nothing (class at level 0)
544 * - current namespace
545 * - parent class
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 // else
558 // uerror("class/namespace redefined");
559 // INSSYM(sp);
560 // nscur = sp;
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 * Compare a matching prototype for a function.
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; /* no dimfun */
600 if ((a1 = sp->sdf->dfun) == NULL || (a2 = p->n_df->dfun) == NULL)
601 return 0; /* no argument */
602
603 for (i = 0; ; i++) {
604 if (a1[i].type == TNULL && a2[i].type == TNULL)
605 return 1; /* equal prototypes */
606 if (a1[i].type != a2[i].type)
607 return 1; /* unequal prototypes */
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 * Compare a matching prototype for an argument tree.
636 * Here we can expand to also do inexact matches.
637 * Return 0 if equal, -1 if failed.
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; /* no dimfun */
648
649 if (p == NULL && a1[0].type == TNULL)
650 return 1; /* arg-less */
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; /* arg number error */
658 return ckstr.rv;
659 }
660
661 /*
662 * Search for (and declare) a function.
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 /* Search for equally named functions */
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 * declared outside class, tree-style reference
701 * Must have been defined already
702 * This will be an external declaration (not spooled).
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 /* Search for an EXTERN or EXTDEF declaration within */
710 /* EXTDEF causes redeclaration. */
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 * Reference to a struct as a :: name.
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 * Search for correct matching function in a struct depending on
760 * argument list a. Return a call node for this function.
761 * Do not touch neither f nor a.
762 * return a name tree suitable for a function call.
763 * We know here that f is a struct reference.
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 * Add hidden argument f first in node list a. Return resulting a.
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 * Watch out for references to static members.
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 }