diff options
Diffstat (limited to 'c')
| -rw-r--r-- | c/builtin.c | 16 | ||||
| -rw-r--r-- | c/c.c | 46 | ||||
| -rw-r--r-- | c/lex.c | 40 |
3 files changed, 51 insertions, 51 deletions
diff --git a/c/builtin.c b/c/builtin.c index 9a8a12b..913d6b3 100644 --- a/c/builtin.c +++ b/c/builtin.c @@ -24,12 +24,12 @@ callcheck(const struct span *span, int nparam, const union type *param, int narg return ok; } -#define DEF_FNLIKE_SEMA(name, retty, ...) \ - static bool \ - name##_sema(struct comp *cm, struct expr *ex) { \ - union type par[] = { {{0}}, __VA_ARGS__ }; \ - ex->ty = retty; \ - return callcheck(&ex->span, arraylength(par)-1, par+1, ex->narg, ex->sub+1); \ +#define DEF_FNLIKE_SEMA(name, retty, ...) \ + static bool \ + name##_sema(struct comp *cm, struct expr *ex) { \ + union type par[] = { {{0}}, __VA_ARGS__ }; \ + ex->ty = retty; \ + return callcheck(&ex->span, countof(par)-1, par+1, ex->narg, ex->sub+1); \ } static bool @@ -111,7 +111,7 @@ static const struct { void putbuiltins(struct env *env) { - for (int i = 0; i < arraylength(tab); ++i) { + for (int i = 0; i < countof(tab); ++i) { const char *intern(const char *); envadddecl(env, &(struct decl) { .name = intern(tab[i].name), @@ -124,7 +124,7 @@ putbuiltins(struct env *env) bool hasbuiltin(const char *name, uint len) { - for (int i = 0; i < arraylength(tab); ++i) + for (int i = 0; i < countof(tab); ++i) if (!strncmp(name, tab[i].name, len)) return 1; return 0; @@ -143,7 +143,7 @@ isdecltok(struct comp *cm) kw(__typeof__), kw(typeof), kw(typeof_unqual), #undef _ }; - return ((uint)tk.t-TKWBEGIN_) < arraylength(kws) && kws[tk.t-TKWBEGIN_]; + return ((uint)tk.t-TKWBEGIN_) < countof(kws) && kws[tk.t-TKWBEGIN_]; } } @@ -158,7 +158,7 @@ struct tagged { /* a tagged type declaration */ struct span span; }; static struct tagged envtaggedbuf[1<<7]; -static vec_of(struct tagged) envtagged = VINIT(envtaggedbuf, arraylength(envtaggedbuf)); +static vec_of(struct tagged) envtagged = VINIT(envtaggedbuf, countof(envtaggedbuf)); struct env { struct env *up; /* list of decls is implicitly envdecls[decl..ndecl] */ @@ -689,7 +689,7 @@ callexpr(struct comp *cm, const struct span *span_, const struct expr *callee) union type ty = callee->ty; const struct typedata *td = NULL; struct expr argbuf[10]; - vec_of(struct expr) args = VINIT(argbuf, arraylength(argbuf)); + vec_of(struct expr) args = VINIT(argbuf, countof(argbuf)); bool spanok = joinspan(&span.ex, span_->ex); bool printsig = 0; const struct builtin *builtin = NULL; @@ -890,7 +890,7 @@ vaargexpr(struct comp *cm, struct span *span) static inline int tkprec(int tt) { - return ((uint)tt < arraylength(bintab)) ? bintab[tt].prec : 0; + return ((uint)tt < countof(bintab)) ? bintab[tt].prec : 0; } static struct expr initializer(struct comp *cm, union type *ty, enum evalmode ev, @@ -944,7 +944,7 @@ Unary: unops[nunop].span = tk.span; unops[nunop].t0 = 0; unops[nunop].tt = tk.t; - if (++nunop >= arraylength(unops)) { + if (++nunop >= countof(unops)) { ex = exprparse(cm, 999, NULL, 0); break; } @@ -972,7 +972,7 @@ Unary: } unops[nunop].span = span; unops[nunop].ty = decl.ty; - if (++nunop >= arraylength(unops)) { + if (++nunop >= countof(unops)) { ex = exprparse(cm, 999, NULL, 0); break; } @@ -1418,7 +1418,7 @@ iniwrite(struct comp *cm, struct initparser *ip, uint off, uint bitsiz, uint bit *init->tail = new; init->tail = &new->next; if (!bitsiz) for (uint i = off, end = i + typesize(ex->ty); i < end; ++i) { - if (BSSIZE(end) > arraylength(init->zero)) break; + if (BSSIZE(end) > countof(init->zero)) break; bsclr(init->zero, i); } } @@ -1439,7 +1439,7 @@ iniwriterec(struct comp *cm, struct initparser *ip, uint off, struct expr *ex) static struct initcur * iniadvance(struct initparser *ip, struct initcur *c, const struct span *span) { - if (c - ip->buf >= arraylength(ip->buf) - 1) + if (c - ip->buf >= countof(ip->buf) - 1) fatal(span, "too many nested initializers"); return c + 1; } @@ -1519,7 +1519,7 @@ Retry: goto Retry; } else if (objectp(targ) && targ.bits != ex.ty.bits) { struct initcur *next = iniadvance(ip, ip->sub, &ex.span); - if (ip->sub - ip->buf == arraylength(ip->buf) - 1) + if (ip->sub - ip->buf == countof(ip->buf) - 1) fatal(&ex.span, "too many nested initializers"); ++ip->sub->idx; *next = (struct initcur) { targ, .off = ip->sub->off + off }; @@ -1705,7 +1705,7 @@ initializer(struct comp *cm, union type *ty, enum evalmode ev, bool globl, return ex; } - assert(arraylength(res.zero) == 1); + assert(countof(res.zero) == 1); if (ev != EVSTATICINI) { memset(res.zero, 0xFF, sizeof res.zero); } @@ -1790,7 +1790,7 @@ initializer(struct comp *cm, union type *ty, enum evalmode ev, bool globl, *ty = mkarrtype(typechild(*ty), ty->flag & TFCHLDQUAL, len); } - assert(arraylength(res.zero) == 1); + assert(countof(res.zero) == 1); siz = typesize(*ty); if (siz && siz <= 64) res.zero->u &= ~0ull >> (64 - siz); @@ -1810,7 +1810,7 @@ buildagg(struct comp *cm, enum typetag tt, const char *name, int id) union type t; struct span flexspan; struct namedfield fbuf[32]; - vec_of(struct namedfield) fld = VINIT(fbuf, arraylength(fbuf)); + vec_of(struct namedfield) fld = VINIT(fbuf, countof(fbuf)); struct typedata td = {tt}; bool isunion = tt == TYUNION; const char *tag = isunion ? "union" : "struct"; @@ -2445,10 +2445,10 @@ decltypes(struct comp *cm, struct decllist *list, const char **name, struct span if (!usingdeclparamtmp) { usingdeclparamtmp = 1; - vinit(¶ms, declparamtmp, arraylength(declparamtmp)); - vinit(&qual, declpqualtmp, arraylength(declpqualtmp)); - vinit(&names, declpnamestmp, arraylength(declpnamestmp)); - vinit(&spans, declpspanstmp, arraylength(declpspanstmp)); + vinit(¶ms, declparamtmp, countof(declparamtmp)); + vinit(&qual, declpqualtmp, countof(declpqualtmp)); + vinit(&names, declpnamestmp, countof(declpnamestmp)); + vinit(&spans, declpspanstmp, countof(declpspanstmp)); } node.span = tk.span; @@ -2527,7 +2527,7 @@ declarator(struct declstate *st, struct comp *cm, struct span span0) { struct span namespan ={0}; if (!inidecltmp) { inidecltmp = 1; - for (int i = 0; i < arraylength(decltmp); ++i) { + for (int i = 0; i < countof(decltmp); ++i) { decltmp[i].next = declfreelist; declfreelist = &decltmp[i]; } @@ -2859,7 +2859,7 @@ geninit(struct function *fn, union type t, union ref dst, const struct expr *src uint align = typealign(t); struct bitset azero[1] = {0}; - if (BSSIZE(siz) <= arraylength(ini->zero)) { + if (BSSIZE(siz) <= countof(ini->zero)) { for (int i = 0; i < siz; i += align) { for (int j = 0; j < align; ++j) { if (bstest(ini->zero, i + j)) { @@ -2868,9 +2868,9 @@ geninit(struct function *fn, union type t, union ref dst, const struct expr *src } } } - if (bscount(azero, arraylength(azero)) < 32) { + if (bscount(azero, countof(azero)) < 32) { /* write individual zeros at non initialized gaps */ - for (uint i = 0; bsiter(&i, azero, arraylength(azero)) && i < siz; i += align) { + for (uint i = 0; bsiter(&i, azero, countof(azero)) && i < siz; i += align) { adr = irbinop(fn, Oadd, KPTR, dst, mkref(RICON, i)); addinstr(fn, mkinstr(Ostore8 + ilog2(align), 0, .l = adr, .r = ZEROREF)); } @@ -3166,7 +3166,7 @@ static union ref condexprvalue(struct function *fn, const struct expr *ex, bool discard) { union ref refbuf[8]; - struct condphis phis = { ex->t == ECOND ? ex->ty : mktype(TYBOOL), VINIT(refbuf, arraylength(refbuf)) }; + struct condphis phis = { ex->t == ECOND ? ex->ty : mktype(TYBOOL), VINIT(refbuf, countof(refbuf)) }; struct block *dst = newblk(fn); condexprrec(fn, ex, discard ? NULL : &phis, dst); useblk(fn, dst); @@ -3191,7 +3191,7 @@ compilecall(struct function *fn, const struct expr *ex) struct expr *sub = ex->sub; const struct typedata *td = &typedata[sub[0].ty.dat]; struct instr insnsbuf[10]; - vec_of(struct instr) insns = VINIT(insnsbuf, arraylength(insnsbuf)); + vec_of(struct instr) insns = VINIT(insnsbuf, countof(insnsbuf)); if (sub[0].t == ESYM && sub[0].sym->isbuiltin) { return sub[0].sym->builtin->comp(fn, (struct expr *)ex, 0); @@ -3701,7 +3701,7 @@ genswitch(struct comp *cm, struct function *fn, const struct expr *ex) struct switchstmt *stsave = cm->switchstmt, st = {0}; enum irclass k = type2cls[scalartypet(ex->ty)]; struct swcase casebuf[8]; - vinit(&st.cases, casebuf, arraylength(casebuf)); + vinit(&st.cases, casebuf, countof(casebuf)); assert(k); end = newblk(fn); @@ -54,7 +54,7 @@ identkeyword(struct token *tk, const char *s, int len) #include "keywords.def" #undef _ }; - int l = 0, h = arraylength(kwtab) - 1, i, cmp; + int l = 0, h = countof(kwtab) - 1, i, cmp; tk->extwarn = 0; tk->blue = 0; @@ -87,7 +87,7 @@ fillchrbuf(struct lexer *lx) { const uchar *p = lx->dat + lx->idx; int i = lx->chrbuf0, idx = lx->idx, c; - int rem = arraylength(lx->chrbuf) - i; + int rem = countof(lx->chrbuf) - i; assert(rem >= 0); if (rem > 0) { for (int j = 0; j < rem; ++j) { @@ -98,7 +98,7 @@ fillchrbuf(struct lexer *lx) lx->chrbuf0 = 0; i = rem; - for (; i < arraylength(lx->chrbuf); ++i) { + for (; i < countof(lx->chrbuf); ++i) { int n; /* skip backslash-newline */ while ((n = 2, (p[0] == '\\') & (p[1] == '\n')) || (ccopt.trigraph && !memcmp(p, "\?\?/\n", n = 4))) { @@ -140,7 +140,7 @@ next(struct lexer *lx) { int c; - if (lx->chrbuf0 >= arraylength(lx->chrbuf)) + if (lx->chrbuf0 >= countof(lx->chrbuf)) fillchrbuf(lx); lx->chridx = lx->chridxbuf[lx->chrbuf0]; c = lx->chrbuf[lx->chrbuf0]; @@ -152,8 +152,8 @@ next(struct lexer *lx) static int peek(struct lexer *lx, int off) { - assert(off < arraylength(lx->chrbuf)); - if (lx->chrbuf0 + off >= arraylength(lx->chrbuf)) + assert(off < countof(lx->chrbuf)); + if (lx->chrbuf0 + off >= countof(lx->chrbuf)) fillchrbuf(lx); return lx->chrbuf[lx->chrbuf0 + off]; } @@ -581,7 +581,7 @@ Begin: int n = 0; tmp[n++] = c; while (isppnum(tmp[n-1], peek(lx, 0))) { - assert(n < arraylength(tmp)-1 && "too big"); + assert(n < countof(tmp)-1 && "too big"); tmp[n++] = next(lx); } tmp[n] = 0; @@ -599,7 +599,7 @@ Begin: int n = 0; tmp[n++] = c; while (!aissep(c = peek(lx, 0))) { - assert(n < arraylength(tmp)-1 && "too big"); + assert(n < countof(tmp)-1 && "too big"); tmp[n++] = next(lx); } tmp[n] = 0; @@ -831,7 +831,7 @@ tokpaste(struct lexer *lx, struct token *dst, const struct token *l, const struc }; struct span span = l->span; - for (int i = 0; i < arraylength(tab); ++i) + for (int i = 0; i < countof(tab); ++i) if (tab[i].s[0] == l->t && tab[i].s[1] == r->t) return dst->t = tab[i].t, 1; @@ -971,7 +971,7 @@ pushmacstk(struct lexer *lx, const struct span *span, const struct macrostack *m { struct macrostack *l = lx->macstk; if (!l) l = mstk; - else if ((++l == mstk+arraylength(mstk))) fatal(span, "macro depth limit reached"); + else if ((++l == mstk+countof(mstk))) fatal(span, "macro depth limit reached"); l->rlist = m->rlist; l->macno = m->macno; l->idx = 0; @@ -1079,7 +1079,7 @@ expandfnmacro(struct lexer *lx, struct span *span, struct macro *mac) excessspan = tk.span; toomany = 1; } else if (i < mac->nparam - mac->variadic) { - assert(i < arraylength(args) || "too many args in fn-like macro"); + assert(i < countof(args) || "too many args in fn-like macro"); args[i].idx = cur; args[i].n = len; cur = argsbuf.n; @@ -1295,7 +1295,7 @@ tkprec(int tt) [TKLOGIOR] = 3, ['?'] = 2, }; - if ((uint)tt < arraylength(tab)) + if ((uint)tt < countof(tab)) return tab[tt] - 1; return -1; } @@ -1314,7 +1314,7 @@ Unary: switch (elex(lx, &tk)) { case '-': case '~': case '!': unops[nunop++] = tk.t; - if (nunop >= arraylength(unops)) { + if (nunop >= countof(unops)) { x = expr(lx, &xu, 999, ignore); break; } @@ -1467,7 +1467,7 @@ static void ppif(struct lexer *lx, const struct span *span) { vlong v = expr(lx, NULL, 0, 0); - assert(nppcnd < arraylength(ppcndstk) && "too many nested #if"); + assert(nppcnd < countof(ppcndstk) && "too many nested #if"); ppcndstk[nppcnd].ifspan = span->sl; ppcndstk[nppcnd].filedepth = includedepth; ppcndstk[nppcnd].cnd = v ? PPCNDTRUE : PPCNDFALSE; @@ -1486,7 +1486,7 @@ ppifxdef(struct lexer *lx, bool defp, const struct span *span) return; } if (!defp && lx->firstdirective) lx->inclguard = tk.s; - assert(nppcnd < arraylength(ppcndstk) && "too many nested #if"); + assert(nppcnd < countof(ppcndstk) && "too many nested #if"); ppcndstk[nppcnd].ifspan = span->sl; ppcndstk[nppcnd].filedepth = includedepth; ppcndstk[nppcnd].cnd = (findmac(tk.s) == NULL) ^ defp ? PPCNDTRUE : PPCNDFALSE; @@ -1734,7 +1734,7 @@ findppcmd(const struct token *tk) "undef", "warning", }; - int l = 0, h = arraylength(tab) - 1, i, cmp; + int l = 0, h = countof(tab) - 1, i, cmp; const char *s = tk->s; if (tk->t == TKWif) return PPIF; @@ -1805,7 +1805,7 @@ lex(struct lexer *lx, struct token *tk_) case PPIF: /* increment nesting level */ case PPIFDEF: case PPIFNDEF: - assert(nppcnd < arraylength(ppcndstk) && "too many nested #if"); + assert(nppcnd < countof(ppcndstk) && "too many nested #if"); ppcndstk[nppcnd].ifspan = tk->span.sl; ppcndstk[nppcnd].cnd = PPCNDTAKEN; ppcndstk[nppcnd++].elsep = 0; @@ -2006,7 +2006,7 @@ addpredefmacros(struct arena **tmparena) case STDC23: tok_ver.s = "202311L"; break; } tok_ver.len = 7; - for (int i = 0; i < arraylength(macs); ++i) { + for (int i = 0; i < countof(macs); ++i) { macs[i].name = intern(macs[i].name); putmac(&macs[i]); } @@ -2027,7 +2027,7 @@ addpredefmacros(struct arena **tmparena) vpushn(&ppcmdline, "\0\0\0\0\0\0", 6); lx->dat = f->p = ppcmdline.p; lx->tmparena = tmparena; - lx->chrbuf0 = arraylength(lx->chrbuf); + lx->chrbuf0 = countof(lx->chrbuf); lx->firstdirective = 1; while (!lx->eof) lex(lx, NULL); } @@ -2059,7 +2059,7 @@ initlexer(struct lexer *lx, const char **err, const char *file) lx->dat = f->p; lx->ndat = f->n; lx->tmparena = &tmparena; - lx->chrbuf0 = arraylength(lx->chrbuf); + lx->chrbuf0 = countof(lx->chrbuf); lx->firstdirective = 1; lx->nppcnd0 = nppcnd; return getfilename(fileid) != file ? LXFILESEEN : LXOK; |