summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
Diffstat (limited to 'types.c')
-rw-r--r--types.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/types.c b/types.c
index 712c8d8..eabb79d 100644
--- a/types.c
+++ b/types.c
@@ -2605,7 +2605,8 @@ static Status types_expr(Typer *tr, Expression *e) {
case UNARY_DALIGNOF: {
Type *queried_type;
if (!type_is_builtin(&of->type, BUILTIN_TYPE)) {
- err_print(e->where, "Argument of #sizeof or #alignof must be a Type. Did you mean #sizeof(typeof ...)?");
+ char *s = e->unary.op == UNARY_DSIZEOF ? "sizeof" : "alignof";
+ err_print(e->where, "Argument of #%s must be a Type. Did you mean #%s(typeof ...)?", s, s);
return false;
}
Value val;
@@ -2620,6 +2621,22 @@ static Status types_expr(Typer *tr, Expression *e) {
t->kind = TYPE_BUILTIN;
t->builtin = BUILTIN_I64;
} break;
+ case UNARY_SIZEOF:
+ case UNARY_ALIGNOF: {
+ /* eval of */
+ if (!type_is_builtin(&of->type, BUILTIN_TYPE)) {
+ char *s = e->unary.op == UNARY_SIZEOF ? "sizeof" : "alignof";
+ err_print(e->where, "Argument of %s must be a Type. Did you mean %s(typeof ...)?", s, s);
+ return false;
+ }
+ Value val;
+ if (!eval_expr(tr->evalr, of, &val))
+ return false;
+ of->kind = EXPR_VAL;
+ of->val = val;
+ t->kind = TYPE_BUILTIN;
+ t->builtin = BUILTIN_I64;
+ } break;
}
} break;
case EXPR_BINARY_OP: {