| ... | ... | @@ -5523,24 +5523,58 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5523 | 5523 | return error.ParseError; |
| 5524 | 5524 | } |
| 5525 | 5525 | |
| 5526 | const lparen = try appendToken(c, .LParen, "("); |
| 5527 | |
| 5526 | 5528 | if (saw_integer_literal) { |
| 5527 | | // @intToPtr(dest, x) |
| 5529 | //( if (@typeInfo(dest) == .Pointer)) |
| 5530 | // @intToPtr(dest, x) |
| 5531 | //else |
| 5532 | // @as(dest, x) ) |
| 5533 | const if_node = try transCreateNodeIf(c); |
| 5534 | const type_info_node = try transCreateNodeBuiltinFnCall(c, "@typeInfo"); |
| 5535 | try type_info_node.params.push(inner_node); |
| 5536 | type_info_node.rparen_token = try appendToken(c, .LParen, ")"); |
| 5537 | const cmp_node = try c.a().create(ast.Node.InfixOp); |
| 5538 | cmp_node.* = .{ |
| 5539 | .op_token = try appendToken(c, .EqualEqual, "=="), |
| 5540 | .lhs = &type_info_node.base, |
| 5541 | .op = .EqualEqual, |
| 5542 | .rhs = try transCreateNodeEnumLiteral(c, "Pointer"), |
| 5543 | }; |
| 5544 | if_node.condition = &cmp_node.base; |
| 5545 | _ = try appendToken(c, .RParen, ")"); |
| 5546 | |
| 5528 | 5547 | const int_to_ptr = try transCreateNodeBuiltinFnCall(c, "@intToPtr"); |
| 5529 | 5548 | try int_to_ptr.params.push(inner_node); |
| 5530 | 5549 | try int_to_ptr.params.push(node_to_cast); |
| 5531 | 5550 | int_to_ptr.rparen_token = try appendToken(c, .RParen, ")"); |
| 5532 | | return &int_to_ptr.base; |
| 5551 | if_node.body = &int_to_ptr.base; |
| 5552 | |
| 5553 | const else_node = try transCreateNodeElse(c); |
| 5554 | if_node.@"else" = else_node; |
| 5555 | |
| 5556 | const as_node = try transCreateNodeBuiltinFnCall(c, "@as"); |
| 5557 | try as_node.params.push(inner_node); |
| 5558 | try as_node.params.push(node_to_cast); |
| 5559 | as_node.rparen_token = try appendToken(c, .RParen, ")"); |
| 5560 | else_node.body = &as_node.base; |
| 5561 | |
| 5562 | const group_node = try c.a().create(ast.Node.GroupedExpression); |
| 5563 | group_node.* = .{ |
| 5564 | .lparen = lparen, |
| 5565 | .expr = &if_node.base, |
| 5566 | .rparen = try appendToken(c, .RParen, ")"), |
| 5567 | }; |
| 5568 | return &group_node.base; |
| 5533 | 5569 | } |
| 5534 | 5570 | |
| 5535 | 5571 | //( if (@typeInfo(@TypeOf(x)) == .Pointer) |
| 5536 | 5572 | // @ptrCast(dest, @alignCast(@alignOf(dest.Child), x)) |
| 5537 | | //else if (@typeInfo(@TypeOf(x)) == .Integer and @typeInfo(dest) == .Pointer)) |
| 5573 | //else if (@typeInfo(@TypeOf(x)) == .Int and @typeInfo(dest) == .Pointer)) |
| 5538 | 5574 | // @intToPtr(dest, x) |
| 5539 | 5575 | //else |
| 5540 | 5576 | // @as(dest, x) ) |
| 5541 | 5577 | |
| 5542 | | const lparen = try appendToken(c, .LParen, "("); |
| 5543 | | |
| 5544 | 5578 | const if_1 = try transCreateNodeIf(c); |
| 5545 | 5579 | const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo"); |
| 5546 | 5580 | const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf"); |