From 01969818aec859611ca1989783b6e0d7f81bdf9e Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 19 Aug 2022 06:50:12 +0200 Subject: alignof, offsetof --- src/parse.cff | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/parse.cff') diff --git a/src/parse.cff b/src/parse.cff index a2071f8..b42d45a 100644 --- a/src/parse.cff +++ b/src/parse.cff @@ -141,10 +141,10 @@ fn eatspaces(P *Parser) void { // !sorted extern static keyword2str [NUM_KEYWORDS]*const u8 = { - "and", "as", "break", "case", "const", + "alignof", "and", "as", "break", "case", "const", "continue", "def", "defmacro", "do", "else", "enum", "extern", "fn", - "for", "if", "import", "let", + "for", "if", "import", "let", "offsetof", "or", "return", "sizeof", "static", "struct", "switch", "typedef", "typeof", "union", "while", @@ -1152,6 +1152,20 @@ fn pexprimary(P *Parser) Expr { } ex = { tok.loc, ty_usize, :IntLit { ty.size }}; + case :kw_alignof; + let ty *const Type #?; + if lexmatch(P, &tok, '(') { + let ex = parseexpr(P); + lexexpect(P, ')'); + ty = ex.ty; + } else { + ty = parsetype(P); + } + if !completetype(ty) { + err(P, tok.loc, "alignof incomplete type (%t)", ty); + } + ex = { tok.loc, ty_usize, :IntLit { ty.align }}; + case '('; if lexmatch(P, &tok, :kw_do) { let st = parseblock0(P); -- cgit v1.2.3