| ... | @@ -326,15 +326,9 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { | ... | @@ -326,15 +326,9 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { |
| 326 | .is_inline = is_always_inline, | 326 | .is_inline = is_always_inline, |
| 327 | .is_extern = !has_body, | 327 | .is_extern = !has_body, |
| 328 | .is_export = switch (c.tree.nodes.items(.tag)[@intFromEnum(fn_decl)]) { | 328 | .is_export = switch (c.tree.nodes.items(.tag)[@intFromEnum(fn_decl)]) { |
| 329 | .fn_proto, | 329 | .fn_proto, .fn_def => has_body and !is_always_inline, |
| 330 | .fn_def => has_body and !is_always_inline, | | |
| 331 | | 330 | |
| 332 | .inline_fn_proto, | 331 | .inline_fn_proto, .inline_fn_def, .inline_static_fn_proto, .inline_static_fn_def, .static_fn_proto, .static_fn_def => false, |
| 333 | .inline_fn_def, | | |
| 334 | .inline_static_fn_proto, | | |
| 335 | .inline_static_fn_def, | | |
| 336 | .static_fn_proto, | | |
| 337 | .static_fn_def => false, | | |
| 338 | | 332 | |
| 339 | else => unreachable, | 333 | else => unreachable, |
| 340 | }, | 334 | }, |
| ... | @@ -354,7 +348,6 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { | ... | @@ -354,7 +348,6 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { |
| 354 | | 348 | |
| 355 | // actual function definition with body | 349 | // actual function definition with body |
| 356 | const body_stmt = node_data.decl.node; | 350 | const body_stmt = node_data.decl.node; |
| 357 | _ = body_stmt; | | |
| 358 | var block_scope = try Scope.Block.init(c, &c.global_scope.base, false); | 351 | var block_scope = try Scope.Block.init(c, &c.global_scope.base, false); |
| 359 | block_scope.return_type = fn_ty.data.func.return_type; | 352 | block_scope.return_type = fn_ty.data.func.return_type; |
| 360 | defer block_scope.deinit(); | 353 | defer block_scope.deinit(); |
| ... | @@ -390,19 +383,18 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { | ... | @@ -390,19 +383,18 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void { |
| 390 | param_id += 1; | 383 | param_id += 1; |
| 391 | } | 384 | } |
| 392 | | 385 | |
| 393 | // const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt)); | 386 | transCompoundStmtInline(c, body_stmt, &block_scope) catch |err| switch (err) { |
| 394 | // transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) { | 387 | error.OutOfMemory => |e| return e, |
| 395 | // error.OutOfMemory => |e| return e, | 388 | error.UnsupportedTranslation, |
| 396 | // error.UnsupportedTranslation, | 389 | error.UnsupportedType, |
| 397 | // error.UnsupportedType, | 390 | => { |
| 398 | // => { | 391 | proto_payload.data.is_extern = true; |
| 399 | // proto_payload.data.is_extern = true; | 392 | proto_payload.data.is_export = false; |
| 400 | // proto_payload.data.is_export = false; | 393 | proto_payload.data.is_inline = false; |
| 401 | // proto_payload.data.is_inline = false; | 394 | try warn(c, &c.global_scope.base, fn_decl_loc, "unable to translate function, demoted to extern", .{}); |
| 402 | // try warn(c, &c.global_scope.base, fn_decl_loc, "unable to translate function, demoted to extern", .{}); | 395 | return addTopLevelDecl(c, fn_name, proto_node); |
| 403 | // return addTopLevelDecl(c, fn_name, Node.initPayload(&proto_node.base)); | 396 | }, |
| 404 | // }, | 397 | }; |
| 405 | // }; | | |
| 406 | | 398 | |
| 407 | proto_payload.data.body = try block_scope.complete(c); | 399 | proto_payload.data.body = try block_scope.complete(c); |
| 408 | return addTopLevelDecl(c, fn_name, proto_node); | 400 | return addTopLevelDecl(c, fn_name, proto_node); |
| ... | @@ -629,8 +621,37 @@ fn transFnType( | ... | @@ -629,8 +621,37 @@ fn transFnType( |
| 629 | return ZigNode.initPayload(&payload.base); | 621 | return ZigNode.initPayload(&payload.base); |
| 630 | } | 622 | } |
| 631 | | 623 | |
| 632 | fn transStmt(c: *Context, node: NodeIndex) TransError!void { | 624 | fn transStmt(c: *Context, node: NodeIndex) TransError!ZigNode { |
| 633 | _ = try c.transExpr(node, .unused); | 625 | return transExpr(c, node, .unused); |
| | 626 | } |
| | 627 | |
| | 628 | fn transCompoundStmtInline(c: *Context, compound: NodeIndex, block: *Scope.Block) TransError!void { |
| | 629 | const data = c.tree.nodes.items(.data)[@intFromEnum(compound)]; |
| | 630 | var buf: [2]NodeIndex = undefined; |
| | 631 | // TODO move these helpers to Aro |
| | 632 | const stmts = switch (c.tree.nodes.items(.tag)[@intFromEnum(compound)]) { |
| | 633 | .compound_stmt_two => blk: { |
| | 634 | if (data.bin.lhs != .none) buf[0] = data.bin.lhs; |
| | 635 | if (data.bin.rhs != .none) buf[1] = data.bin.rhs; |
| | 636 | break :blk buf[0 .. @as(u32, @intFromBool(data.bin.lhs != .none)) + @intFromBool(data.bin.rhs != .none)]; |
| | 637 | }, |
| | 638 | .compound_stmt => c.tree.data[data.range.start..data.range.end], |
| | 639 | else => unreachable, |
| | 640 | }; |
| | 641 | for (stmts) |stmt| { |
| | 642 | const result = try transStmt(c, stmt); |
| | 643 | switch (result.tag()) { |
| | 644 | .declaration, .empty_block => {}, |
| | 645 | else => try block.statements.append(result), |
| | 646 | } |
| | 647 | } |
| | 648 | } |
| | 649 | |
| | 650 | fn transCompoundStmt(c: *Context, scope: *Scope, compound: NodeIndex) TransError!ZigNode { |
| | 651 | var block_scope = try Scope.Block.init(c, scope, false); |
| | 652 | defer block_scope.deinit(); |
| | 653 | try transCompoundStmtInline(c, compound, &block_scope); |
| | 654 | return try block_scope.complete(c); |
| 634 | } | 655 | } |
| 635 | | 656 | |
| 636 | fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!ZigNode { | 657 | fn transExpr(c: *Context, node: NodeIndex, result_used: ResultUsed) TransError!ZigNode { |