| author | |
| committer | |
| log | 0f545e5a2b664d340fe33fe0a8fbc44956485e18 |
| tree | d101d647b181a7565e4f1e84be3a052e0b8adfc8 |
| parent | 84e479d94f9998331bdd73665274684cf3d0ad48 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 40 insertions(+), 0 deletions(-)
src-self-hosted/clang.zig+2| ... | ... | @@ -958,3 +958,5 @@ pub const ZigClangAPValue_ValueKind = extern enum { |
| 958 | 958 | |
| 959 | 959 | pub extern fn ZigClangIntegerLiteral_EvaluateAsInt(*const ZigClangIntegerLiteral, *ZigClangExprEvalResult, *const ZigClangASTContext) bool; |
| 960 | 960 | pub extern fn ZigClangIntegerLiteral_getBeginLoc(*const ZigClangIntegerLiteral) ZigClangSourceLocation; |
| 961 | ||
| 962 | pub extern fn ZigClangReturnStmt_getRetValue(*const ZigClangReturnStmt) ?*const ZigClangExpr; |
src-self-hosted/translate_c.zig+31| ... | ... | @@ -334,6 +334,7 @@ fn transStmt( |
| 334 | 334 | .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const ZigClangDeclRefExpr, stmt), lrvalue), |
| 335 | 335 | .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const ZigClangImplicitCastExpr, stmt), result_used), |
| 336 | 336 | .IntegerLiteralClass => return transIntegerLiteral(rp, scope, @ptrCast(*const ZigClangIntegerLiteral, stmt), result_used), |
| 337 | .ReturnStmtClass => return transReturnStmt(rp, scope, @ptrCast(*const ZigClangReturnStmt, stmt)), | |
| 337 | 338 | else => { |
| 338 | 339 | return revertAndWarn( |
| 339 | 340 | rp, |
| ... | ... | @@ -555,6 +556,24 @@ fn transIntegerLiteral( |
| 555 | 556 | return maybeSuppressResult(rp, scope, result_used, res); |
| 556 | 557 | } |
| 557 | 558 | |
| 559 | fn transReturnStmt( | |
| 560 | rp: RestorePoint, | |
| 561 | scope: *Scope, | |
| 562 | expr: *const ZigClangReturnStmt, | |
| 563 | ) !TransResult { | |
| 564 | const node = try transCreateNodeReturnExpr(rp.c); | |
| 565 | if (ZigClangReturnStmt_getRetValue(expr)) |val_expr| { | |
| 566 | const ret_node = node.cast(ast.Node.ControlFlowExpression).?; | |
| 567 | ret_node.rhs = (try transExpr(rp, scope, val_expr, .used, .r_value)).node; | |
| 568 | } | |
| 569 | _ = try appendToken(rp.c, .Semicolon, ";"); | |
| 570 | return TransResult{ | |
| 571 | .node = node, | |
| 572 | .child_scope = scope, | |
| 573 | .node_scope = scope, | |
| 574 | }; | |
| 575 | } | |
| 576 | ||
| 558 | 577 | fn transCCast( |
| 559 | 578 | rp: RestorePoint, |
| 560 | 579 | scope: *Scope, |
| ... | ... | @@ -848,6 +867,18 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node { |
| 848 | 867 | return &node.base; |
| 849 | 868 | } |
| 850 | 869 | |
| 870 | fn transCreateNodeReturnExpr(c: *Context) !*ast.Node { | |
| 871 | const ltoken = try appendToken(c, .Keyword_return, "return"); | |
| 872 | const node = try c.a().create(ast.Node.ControlFlowExpression); | |
| 873 | node.* = ast.Node.ControlFlowExpression{ | |
| 874 | .base = ast.Node{ .id = .ControlFlowExpression }, | |
| 875 | .ltoken = ltoken, | |
| 876 | .kind = .Return, | |
| 877 | .rhs = null, | |
| 878 | }; | |
| 879 | return &node.base; | |
| 880 | } | |
| 881 | ||
| 851 | 882 | const RestorePoint = struct { |
| 852 | 883 | c: *Context, |
| 853 | 884 | token_index: ast.TokenIndex, |
src/zig_clang.cpp+5| ... | ... | @@ -2017,3 +2017,8 @@ struct ZigClangSourceLocation ZigClangIntegerLiteral_getBeginLoc(const struct Zi |
| 2017 | 2017 | auto casted = reinterpret_cast<const clang::IntegerLiteral *>(self); |
| 2018 | 2018 | return bitcast(casted->getBeginLoc()); |
| 2019 | 2019 | } |
| 2020 | ||
| 2021 | const struct ZigClangExpr *ZigClangReturnStmt_getRetValue(const struct ZigClangReturnStmt *self) { | |
| 2022 | auto casted = reinterpret_cast<const clang::ReturnStmt *>(self); | |
| 2023 | return reinterpret_cast<const struct ZigClangExpr *>(casted->getRetValue()); | |
| 2024 | } |
src/zig_clang.h+2| ... | ... | @@ -919,4 +919,6 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangCStyleCastExpr_getType(const struct |
| 919 | 919 | ZIG_EXTERN_C bool ZigClangIntegerLiteral_EvaluateAsInt(const struct ZigClangIntegerLiteral *, struct ZigClangExprEvalResult *, const struct ZigClangASTContext *); |
| 920 | 920 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangIntegerLiteral_getBeginLoc(const struct ZigClangIntegerLiteral *); |
| 921 | 921 | |
| 922 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangReturnStmt_getRetValue(const struct ZigClangReturnStmt *); | |
| 923 | ||
| 922 | 924 | #endif |