aboutsummaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-03-12 18:34:03 -0700
committerMichael Forney <mforney@mforney.org>2019-03-12 18:34:03 -0700
commit842176df9208931f62d5e3dd62825fe04b9ae44d (patch)
tree7aa65abce4d20dd2a3e881ce7a2482af9cb08058 /expr.c
parentd77cb90330efd684416cd8b85b95f74bce253716 (diff)
Sort built-ins
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/expr.c b/expr.c
index eec41ab..4dd16a8 100644
--- 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");