aboutsummaryrefslogtreecommitdiff
path: root/src/parse.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-19 06:50:12 +0200
committerlemon <lsof@mailbox.org>2022-08-19 06:50:12 +0200
commit01969818aec859611ca1989783b6e0d7f81bdf9e (patch)
tree80324a21b5b4647107d6596eaabd741e9f824f39 /src/parse.cff
parenteb48600f4da4e52dd2cb46a284474c4cba8fe237 (diff)
alignof, offsetof
Diffstat (limited to 'src/parse.cff')
-rw-r--r--src/parse.cff18
1 files changed, 16 insertions, 2 deletions
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);