| ... | ... | @@ -457,14 +457,22 @@ fn transImplicitCastExpr( |
| 457 | 457 | expr: *const ZigClangImplicitCastExpr, |
| 458 | 458 | ) !TransResult { |
| 459 | 459 | const c = rp.c; |
| 460 | const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr); |
| 460 | 461 | switch (ZigClangImplicitCastExpr_getCastKind(expr)) { |
| 461 | 462 | .BitCast => { |
| 462 | | const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr); |
| 463 | 463 | const node = try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value); |
| 464 | 464 | const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr)); |
| 465 | 465 | const src_type = getExprQualType(c, sub_expr); |
| 466 | 466 | return try transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, node.node); |
| 467 | 467 | }, |
| 468 | .FunctionToPointerDecay, .ArrayToPointerDecay => { |
| 469 | return maybeSuppressResult( |
| 470 | rp, |
| 471 | scope, |
| 472 | .used, |
| 473 | try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value), |
| 474 | ); |
| 475 | }, |
| 468 | 476 | else => |kind| return revertAndWarn( |
| 469 | 477 | rp, |
| 470 | 478 | error.UnsupportedTranslation, |
| ... | ... | @@ -503,6 +511,30 @@ fn findBlockScope(inner: *Scope) *Scope.Block { |
| 503 | 511 | } |
| 504 | 512 | } |
| 505 | 513 | |
| 514 | fn maybeSuppressResult( |
| 515 | rp: RestorePoint, |
| 516 | scope: *Scope, |
| 517 | used: ResultUsed, |
| 518 | result: TransResult, |
| 519 | ) !TransResult { |
| 520 | if (used == .used) return result; |
| 521 | const lhs = try appendIdentifier(rp.c, "_"); |
| 522 | const op_token = try appendToken(rp.c, .Equal, "="); |
| 523 | const op_node = try rp.c.a().create(ast.Node.InfixOp); |
| 524 | op_node.* = ast.Node.InfixOp{ |
| 525 | .base = ast.Node{ .id = .InfixOp }, |
| 526 | .op_token = op_token, |
| 527 | .lhs = lhs, |
| 528 | .op = .Assign, |
| 529 | .rhs = result.node, |
| 530 | }; |
| 531 | return TransResult{ |
| 532 | .node = &op_node.base, |
| 533 | .child_scope = scope, |
| 534 | .node_scope = scope, |
| 535 | }; |
| 536 | } |
| 537 | |
| 506 | 538 | fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: *ast.Node) !void { |
| 507 | 539 | try c.tree.root_node.decls.push(decl_node); |
| 508 | 540 | } |