cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 842176df9208931f62d5e3dd62825fe04b9ae44d
parent d77cb90330efd684416cd8b85b95f74bce253716
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 12 Mar 2019 18:34:03 -0700

Sort built-ins

Diffstat:
Mdecl.h | 12++++++------
Mexpr.c | 72++++++++++++++++++++++++++++++++++++------------------------------------
Mscope.c | 14+++++++-------
3 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/decl.h b/decl.h @@ -13,15 +13,15 @@ enum linkage { }; enum builtinkind { - BUILTINVALIST, - BUILTINVASTART, + BUILTINALLOCA, + BUILTININFF, + BUILTINNANF, + BUILTINOFFSETOF, BUILTINVAARG, BUILTINVACOPY, BUILTINVAEND, - BUILTINOFFSETOF, - BUILTINALLOCA, - BUILTINNANF, - BUILTININFF, + BUILTINVALIST, + BUILTINVASTART, }; struct declaration { diff --git a/expr.c b/expr.c @@ -414,13 +414,35 @@ builtinfunc(struct scope *s, enum builtinkind kind) uint64_t offset; switch (kind) { - case BUILTINVASTART: - e = mkexpr(EXPRBUILTIN, &typevoid, 0); - e->builtin.kind = BUILTINVASTART; - e->builtin.arg = exprconvert(assignexpr(s), &typevalistptr); - expect(TCOMMA, "after va_list"); - free(expect(TIDENT, "after ','")); - // XXX: check that this was actually a parameter name? + case BUILTINALLOCA: + e = mkexpr(EXPRBUILTIN, mkpointertype(&typevoid), 0); + e->builtin.kind = BUILTINALLOCA; + e->builtin.arg = exprconvert(assignexpr(s), &typeulong); + break; + case BUILTININFF: + e = mkexpr(EXPRCONST, &typefloat, 0); + /* TODO: use INFINITY here when we can handle musl's math.h */ + e->constant.f = strtod("inf", NULL); + break; + case BUILTINNANF: + e = assignexpr(s); + if (!(e->flags & EXPRFLAG_DECAYED) || e->unary.base->kind != EXPRSTRING || e->unary.base->string.size > 0) + error(&tok.loc, "__builtin_nanf currently only supports empty string literals"); + e = mkexpr(EXPRCONST, &typefloat, 0); + /* TODO: use NAN here when we can handle musl's math.h */ + e->constant.f = strtod("nan", NULL); + break; + case BUILTINOFFSETOF: + t = typename(s); + expect(TCOMMA, "after type name"); + name = expect(TIDENT, "after ','"); + if (t->kind != TYPESTRUCT && t->kind != TYPEUNION) + error(&tok.loc, "type is not a struct/union type"); + offset = 0; + if (!typemember(t, name, &offset)) + error(&tok.loc, "struct/union has no member named '%s'", name); + e = mkconstexpr(&typeulong, offset); + free(name); break; case BUILTINVAARG: e = mkexpr(EXPRBUILTIN, NULL, 0); @@ -441,35 +463,13 @@ builtinfunc(struct scope *s, enum builtinkind kind) e->builtin.kind = BUILTINVAEND; exprconvert(assignexpr(s), &typevalistptr); break; - case BUILTINOFFSETOF: - t = typename(s); - expect(TCOMMA, "after type name"); - name = expect(TIDENT, "after ','"); - if (t->kind != TYPESTRUCT && t->kind != TYPEUNION) - error(&tok.loc, "type is not a struct/union type"); - offset = 0; - if (!typemember(t, name, &offset)) - error(&tok.loc, "struct/union has no member named '%s'", name); - e = mkconstexpr(&typeulong, offset); - free(name); - break; - case BUILTINALLOCA: - e = mkexpr(EXPRBUILTIN, mkpointertype(&typevoid), 0); - e->builtin.kind = BUILTINALLOCA; - e->builtin.arg = exprconvert(assignexpr(s), &typeulong); - break; - case BUILTINNANF: - e = assignexpr(s); - if (!(e->flags & EXPRFLAG_DECAYED) || e->unary.base->kind != EXPRSTRING || e->unary.base->string.size > 0) - error(&tok.loc, "__builtin_nanf currently only supports empty string literals"); - e = mkexpr(EXPRCONST, &typefloat, 0); - /* TODO: use NAN here when we can handle musl's math.h */ - e->constant.f = strtod("nan", NULL); - break; - case BUILTININFF: - e = mkexpr(EXPRCONST, &typefloat, 0); - /* TODO: use INFINITY here when we can handle musl's math.h */ - e->constant.f = strtod("inf", NULL); + case BUILTINVASTART: + e = mkexpr(EXPRBUILTIN, &typevoid, 0); + e->builtin.kind = BUILTINVASTART; + e->builtin.arg = exprconvert(assignexpr(s), &typevalistptr); + expect(TCOMMA, "after va_list"); + free(expect(TIDENT, "after ','")); + // XXX: check that this was actually a parameter name? break; default: fatal("internal error; unknown builtin"); diff --git a/scope.c b/scope.c @@ -17,15 +17,15 @@ scopeinit(void) char *name; struct declaration decl; } builtins[] = { - {"__builtin_va_list", {.kind = DECLTYPE, .type = &typevalist}}, - {"__builtin_va_start", {.kind = DECLBUILTIN, .builtin = BUILTINVASTART}}, - {"__builtin_va_copy", {.kind = DECLBUILTIN, .builtin = BUILTINVACOPY}}, - {"__builtin_va_arg", {.kind = DECLBUILTIN, .builtin = BUILTINVAARG}}, - {"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}}, - {"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}}, {"__builtin_alloca", {.kind = DECLBUILTIN, .builtin = BUILTINALLOCA}}, - {"__builtin_nanf", {.kind = DECLBUILTIN, .builtin = BUILTINNANF}}, {"__builtin_inff", {.kind = DECLBUILTIN, .builtin = BUILTININFF}}, + {"__builtin_nanf", {.kind = DECLBUILTIN, .builtin = BUILTINNANF}}, + {"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}}, + {"__builtin_va_arg", {.kind = DECLBUILTIN, .builtin = BUILTINVAARG}}, + {"__builtin_va_copy", {.kind = DECLBUILTIN, .builtin = BUILTINVACOPY}}, + {"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}}, + {"__builtin_va_list", {.kind = DECLTYPE, .type = &typevalist}}, + {"__builtin_va_start", {.kind = DECLBUILTIN, .builtin = BUILTINVASTART}}, }; struct builtin *b;