/* * Declare a namespace. */ void dclns(NODE *attr, char *n) { struct symtab *sp; struct attr *ap = gcc_attr_parse(attr); if (cppdebug)printf("declaring namespace %s\n", n); n = addname(n); sp = sfind(n, nscur->sup); while (sp != NULL) { if (sp->sname == n && sp->sclass == NSPACE) break; sp = sfind(n, sp->snext); } if (sp == NULL) { /* New namespace */ sp = getsymtab(n, 0); sp->sclass = NSPACE; INSSYM(sp); } nscur = sp; if (cppdebug)printf("declaring namespace2 %s\n", nscur->sname); sp->sap = attr_add(sp->sap, ap); /* XXX check attributes */ }
/* * Extract attributes from a node tree and return attribute entries * based on its contents. */ struct attr * gcc_attr_parse(NODE *p) { struct attr *b, *c; if (p == NIL) return NULL; if (p->n_op != CM) { b = gcc_attribs(p); tfree(p); } else { b = gcc_attr_parse(p->n_left); c = gcc_attr_parse(p->n_right); nfree(p); b = b ? attr_add(b, c) : c; } return b; }
/* * Called when a identifier has been declared. */ void fixdef(struct symtab *sp) { struct attr *ga; #ifdef HAVE_WEAKREF /* not many as'es have this directive */ if ((ga = attr_find(sp->sap, GCC_ATYP_WEAKREF)) != NULL) { char *wr = ga->sarg(0); char *sn = getsoname(sp); if (wr == NULL) { if ((ga = attr_find(sp->sap, GCC_ATYP_ALIAS))) { wr = ga->sarg(0); } } if (wr == NULL) printf("\t.weak %s\n", sn); else printf("\t.weakref %s,%s\n", sn, wr); } else if ((ga = attr_find(sp->sap, GCC_ATYP_ALIAS)) != NULL) { char *an = ga->sarg(0); char *sn = getsoname(sp); char *v; v = attr_find(sp->sap, GCC_ATYP_WEAK) ? "weak" : "globl"; printf("\t.%s %s\n", v, sn); printf("\t.set %s,%s\n", sn, an); } if (alias != NULL && (sp->sclass != PARAM)) { char *name = getexname(sp); printf("\t.globl %s\n", name); printf("%s = ", name); printf("%s\n", exname(alias)); alias = NULL; } if ((constructor || destructor) && (sp->sclass != PARAM)) { NODE *p = p1alloc(); p->n_op = NAME; p->n_sp = (struct symtab *)(constructor ? "constructor" : "destructor"); sp->sap = attr_add(sp->sap, gcc_attr_parse(p)); constructor = destructor = 0; } #endif }