| author | |
| committer | |
| log | c760532be04667c8a8d49a7cf1b7582da3d1632d |
| tree | 01b4338c4d686ba9b41e5783603d52cb80605fc3 |
| parent | b988815bf0771dd86a345ce8ed8b0d3eb9d6f55e |
5 files changed, 34 insertions(+), 2 deletions(-)
src/clang.zig+5| ... | ... | @@ -271,6 +271,11 @@ pub const CompoundAssignOperator = opaque { |
| 271 | 271 | extern fn ZigClangCompoundAssignOperator_getRHS(*const CompoundAssignOperator) *const Expr; |
| 272 | 272 | }; |
| 273 | 273 | |
| 274 | pub const CompoundLiteralExpr = opaque { | |
| 275 | pub const getInitializer = ZigClangCompoundLiteralExpr_getInitializer; | |
| 276 | extern fn ZigClangCompoundLiteralExpr_getInitializer(*const CompoundLiteralExpr) *const Expr; | |
| 277 | }; | |
| 278 | ||
| 274 | 279 | pub const CompoundStmt = opaque { |
| 275 | 280 | pub const body_begin = ZigClangCompoundStmt_body_begin; |
| 276 | 281 | extern fn ZigClangCompoundStmt_body_begin(*const CompoundStmt) ConstBodyIterator; |
src/translate_c.zig+6-2| ... | ... | @@ -1054,6 +1054,10 @@ fn transStmt( |
| 1054 | 1054 | return maybeSuppressResult(c, scope, result_used, expr); |
| 1055 | 1055 | }, |
| 1056 | 1056 | .OffsetOfExprClass => return transOffsetOfExpr(c, scope, @ptrCast(*const clang.OffsetOfExpr, stmt), result_used), |
| 1057 | .CompoundLiteralExprClass => { | |
| 1058 | const compound_literal = @ptrCast(*const clang.CompoundLiteralExpr, stmt); | |
| 1059 | return transExpr(c, scope, compound_literal.getInitializer(), result_used); | |
| 1060 | }, | |
| 1057 | 1061 | else => { |
| 1058 | 1062 | return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO implement translation of stmt class {s}", .{@tagName(sc)}); |
| 1059 | 1063 | }, |
| ... | ... | @@ -2560,8 +2564,8 @@ fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: |
| 2560 | 2564 | }); |
| 2561 | 2565 | return maybeSuppressResult(c, scope, used, as_node); |
| 2562 | 2566 | }, |
| 2563 | else => { | |
| 2564 | return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "unsupported constant expression kind", .{}); | |
| 2567 | else => |kind| { | |
| 2568 | return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "unsupported constant expression kind '{s}'", .{kind}); | |
| 2565 | 2569 | }, |
| 2566 | 2570 | } |
| 2567 | 2571 | } |
src/zig_clang.cpp+5| ... | ... | @@ -2808,6 +2808,11 @@ const struct ZigClangExpr *ZigClangCompoundAssignOperator_getRHS(const struct Zi |
| 2808 | 2808 | return reinterpret_cast<const struct ZigClangExpr *>(casted->getRHS()); |
| 2809 | 2809 | } |
| 2810 | 2810 | |
| 2811 | const struct ZigClangExpr *ZigClangCompoundLiteralExpr_getInitializer(const ZigClangCompoundLiteralExpr *self) { | |
| 2812 | auto casted = reinterpret_cast<const clang::CompoundLiteralExpr *>(self); | |
| 2813 | return reinterpret_cast<const ZigClangExpr *>(casted->getInitializer()); | |
| 2814 | } | |
| 2815 | ||
| 2811 | 2816 | enum ZigClangUO ZigClangUnaryOperator_getOpcode(const struct ZigClangUnaryOperator *self) { |
| 2812 | 2817 | auto casted = reinterpret_cast<const clang::UnaryOperator *>(self); |
| 2813 | 2818 | return (ZigClangUO)casted->getOpcode(); |
src/zig_clang.h+2| ... | ... | @@ -1217,6 +1217,8 @@ ZIG_EXTERN_C enum ZigClangBO ZigClangCompoundAssignOperator_getOpcode(const stru |
| 1217 | 1217 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangCompoundAssignOperator_getLHS(const struct ZigClangCompoundAssignOperator *); |
| 1218 | 1218 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangCompoundAssignOperator_getRHS(const struct ZigClangCompoundAssignOperator *); |
| 1219 | 1219 | |
| 1220 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangCompoundLiteralExpr_getInitializer(const struct ZigClangCompoundLiteralExpr *); | |
| 1221 | ||
| 1220 | 1222 | ZIG_EXTERN_C enum ZigClangUO ZigClangUnaryOperator_getOpcode(const struct ZigClangUnaryOperator *); |
| 1221 | 1223 | ZIG_EXTERN_C struct ZigClangQualType ZigClangUnaryOperator_getType(const struct ZigClangUnaryOperator *); |
| 1222 | 1224 | ZIG_EXTERN_C const struct ZigClangExpr *ZigClangUnaryOperator_getSubExpr(const struct ZigClangUnaryOperator *); |
test/run_translated_c.zig+16| ... | ... | @@ -1171,4 +1171,20 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1171 | 1171 | \\ return 0; |
| 1172 | 1172 | \\} |
| 1173 | 1173 | , ""); |
| 1174 | ||
| 1175 | cases.add("Compound literals", | |
| 1176 | \\#include <stdlib.h> | |
| 1177 | \\struct Foo { | |
| 1178 | \\ int a; | |
| 1179 | \\ char b[2]; | |
| 1180 | \\ float c; | |
| 1181 | \\}; | |
| 1182 | \\int main() { | |
| 1183 | \\ struct Foo foo; | |
| 1184 | \\ int x = 1, y = 2; | |
| 1185 | \\ foo = (struct Foo) {x + y, {'a', 'b'}, 42.0f}; | |
| 1186 | \\ if (foo.a != x + y || foo.b[0] != 'a' || foo.b[1] != 'b' || foo.c != 42.0f) abort(); | |
| 1187 | \\ return 0; | |
| 1188 | \\} | |
| 1189 | , ""); | |
| 1174 | 1190 | } |