From 3083cf126cf3989b257546aa3b1b69608aac7923 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 6 Aug 2022 05:25:16 +0200 Subject: sizeof --- bootstrap/parse.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bootstrap/parse.c') diff --git a/bootstrap/parse.c b/bootstrap/parse.c index d55339d..4372cdc 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -922,6 +922,17 @@ pexprimary(struct parser *P) { ex = parsestructini(P, P->targty); else if (P->targty->t == TYarr) ex = parsearrini(P, P->targty); + } else if (lexmatch(P, &tok, TKkw_sizeof)) { + ex.t = Eintlit; + ex.ty = ty_usize; + if (lexmatch(P, &tok, '(')) { + struct expr exp = parseexpr(P); + ex.i = exp.ty->size; + lexexpect(P, ')'); + } else { + const struct type *ty = parsetype(P); + ex.i = ty->size; + } } else { experr: fatal(P, tok.span, "expected expression (near %s)", tok2str(tok)); -- cgit v1.2.3