aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decl.h12
-rw-r--r--expr.c72
-rw-r--r--scope.c14
3 files changed, 49 insertions, 49 deletions
diff --git a/decl.h b/decl.h
index 314926b..4abbbac 100644
--- 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
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");
diff --git a/scope.c b/scope.c
index be561f5..1bcd31f 100644
--- 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;