| ... | @@ -5899,6 +5899,10 @@ fn parseCPrimaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*ast.N | ... | @@ -5899,6 +5899,10 @@ fn parseCPrimaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*ast.N |
| 5899 | saw_l_paren = true; | 5899 | saw_l_paren = true; |
| 5900 | _ = m.next(); | 5900 | _ = m.next(); |
| 5901 | }, | 5901 | }, |
| | 5902 | // (type)sizeof(x) |
| | 5903 | .Keyword_sizeof, |
| | 5904 | // (type)alignof(x) |
| | 5905 | .Keyword_alignof, |
| 5902 | // (type)identifier | 5906 | // (type)identifier |
| 5903 | .Identifier => {}, | 5907 | .Identifier => {}, |
| 5904 | // (type)integer | 5908 | // (type)integer |
| ... | @@ -6309,6 +6313,40 @@ fn parseCPrefixOpExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*ast. | ... | @@ -6309,6 +6313,40 @@ fn parseCPrefixOpExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*ast. |
| 6309 | node.rhs = try parseCPrefixOpExpr(c, m, scope); | 6313 | node.rhs = try parseCPrefixOpExpr(c, m, scope); |
| 6310 | return &node.base; | 6314 | return &node.base; |
| 6311 | }, | 6315 | }, |
| | 6316 | .Keyword_sizeof => { |
| | 6317 | const inner = if (m.peek().? == .LParen) blk: { |
| | 6318 | _ = m.next(); |
| | 6319 | const inner = try parseCExpr(c, m, scope); |
| | 6320 | if (m.next().? != .RParen) { |
| | 6321 | try m.fail(c, "unable to translate C expr: expected ')'", .{}); |
| | 6322 | return error.ParseError; |
| | 6323 | } |
| | 6324 | break :blk inner; |
| | 6325 | } else try parseCPrefixOpExpr(c, m, scope); |
| | 6326 | |
| | 6327 | const builtin_call = try c.createBuiltinCall("@sizeOf", 1); |
| | 6328 | builtin_call.params()[0] = inner; |
| | 6329 | builtin_call.rparen_token = try appendToken(c, .RParen, ")"); |
| | 6330 | return &builtin_call.base; |
| | 6331 | }, |
| | 6332 | .Keyword_alignof => { |
| | 6333 | // TODO this won't work if using <stdalign.h>'s |
| | 6334 | // #define alignof _Alignof |
| | 6335 | if (m.next().? != .LParen) { |
| | 6336 | try m.fail(c, "unable to translate C expr: expected '('", .{}); |
| | 6337 | return error.ParseError; |
| | 6338 | } |
| | 6339 | const inner = try parseCExpr(c, m, scope); |
| | 6340 | if (m.next().? != .RParen) { |
| | 6341 | try m.fail(c, "unable to translate C expr: expected ')'", .{}); |
| | 6342 | return error.ParseError; |
| | 6343 | } |
| | 6344 | |
| | 6345 | const builtin_call = try c.createBuiltinCall("@alignOf", 1); |
| | 6346 | builtin_call.params()[0] = inner; |
| | 6347 | builtin_call.rparen_token = try appendToken(c, .RParen, ")"); |
| | 6348 | return &builtin_call.base; |
| | 6349 | }, |
| 6312 | else => { | 6350 | else => { |
| 6313 | m.i -= 1; | 6351 | m.i -= 1; |
| 6314 | return try parseCSuffixOpExpr(c, m, scope); | 6352 | return try parseCSuffixOpExpr(c, m, scope); |