From be7b759113e76223025cd025cf0172849385b444 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 2 Aug 2025 02:03:20 +0900 Subject: feat: support sizeof() for variables --- parse.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index b1e65d4..b8ad901 100644 --- a/parse.c +++ b/parse.c @@ -403,7 +403,18 @@ AstNode* parse_prefix_expr(Parser* p) { } else if (op == TokenKind_keyword_sizeof) { next_token(p); expect(p, TokenKind_paren_l); - Type* ty = parse_type(p); + Token* next_tok = peek_token(p); + Type* ty = NULL; + if (next_tok->kind == TokenKind_ident) { + int lvar_idx = find_lvar(p, &next_tok->raw); + if (lvar_idx != -1) { + next_token(p); + ty = p->lvars[lvar_idx].ty; + } + } + if (!ty) { + ty = parse_type(p); + } expect(p, TokenKind_paren_r); return ast_new_int(type_sizeof(ty)); } -- cgit v1.2.3-70-g09d2