authorgravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-27 23:12:33-07:00
committergravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-27 23:12:33-07:00
logcc74bf51366c71ba997eb3015f2b687a3a18fd57
treeaf4ed087ca99a3fee39ea959fc8411c2476ac458
parent646268875e04250609d7e355af1618077c4a290f
signaturelock-open Commit is signed but in an unrecognized format.

Translate IntegralCast; add stage2 test coverage


2 files changed, 69 insertions(+), 1 deletions(-)

src-self-hosted/translate_c.zig+9
...@@ -615,6 +615,15 @@ fn transImplicitCastExpr(...@@ -615,6 +615,15 @@ fn transImplicitCastExpr(
615 .child_scope = scope,615 .child_scope = scope,
616 };616 };
617 },617 },
618 .IntegralCast => {
619 const dest_type = ZigClangExpr_getType(@ptrCast(*const ZigClangExpr, expr));
620 const src_type = ZigClangExpr_getType(sub_expr);
621 return TransResult{
622 .node = try transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node.node),
623 .node_scope = scope,
624 .child_scope = scope,
625 };
626 },
618 .FunctionToPointerDecay, .ArrayToPointerDecay => {627 .FunctionToPointerDecay, .ArrayToPointerDecay => {
619 return maybeSuppressResult(rp, scope, result_used, sub_expr_node);628 return maybeSuppressResult(rp, scope, result_used, sub_expr_node);
620 },629 },
test/translate_c.zig+60-1
...@@ -18,7 +18,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -18,7 +18,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18 \\pub extern fn bar() c_int;18 \\pub extern fn bar() c_int;
19 );19 );
2020
21 cases.add_both("simple var decls",
22 \\void foo(void) {
23 \\ int a;
24 \\ char b = 123;
25 \\ const int c;
26 \\ const unsigned d = 440;
27 \\}
28 ,
29 \\pub fn foo() void {
30 \\ var a: c_int = undefined;
31 \\ var b: u8 = u8(123);
32 \\ const c: c_int = undefined;
33 \\ const d: c_uint = c_uint(440);
34 \\}
35 );
36
37 cases.add_both("ignore result, explicit function arguments",
38 \\void foo(void) {
39 \\ int a;
40 \\ 1;
41 \\ "hey";
42 \\ 1 + 1;
43 \\ 1 - 1;
44 \\ a = 1;
45 \\}
46 ,
47 \\pub fn foo() void {
48 \\ var a: c_int = undefined;
49 \\ _ = 1;
50 \\ _ = c"hey";
51 \\ _ = (1 + 1);
52 \\ _ = (1 - 1);
53 \\ a = 1;
54 \\}
55 );
56
21 /////////////// Cases that pass for only stage2 ////////////////57 /////////////// Cases that pass for only stage2 ////////////////
58 // TODO: restore these tests after removing "import mode" concept
59 // https://github.com/ziglang/zig/issues/2780
60
22 // cases.add_2("Parameterless function prototypes",61 // cases.add_2("Parameterless function prototypes",
23 // \\void a() {}62 // \\void a() {}
24 // \\void b(void) {}63 // \\void b(void) {}
...@@ -39,8 +78,28 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -39,8 +78,28 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
39 // \\pub extern fn bar() void {}78 // \\pub extern fn bar() void {}
40 // );79 // );
4180
81 cases.add_2("parameterless function prototypes",
82 \\void a() {}
83 \\void b(void) {}
84 \\void c();
85 \\void d(void);
86 ,
87 \\pub fn a(...) void {}
88 \\pub fn b() void {}
89 \\pub extern fn c(...) void;
90 \\pub extern fn d() void;
91 );
92
42 /////////////// Cases for only stage1 which are TODO items for stage2 ////////////////93 /////////////// Cases for only stage1 which are TODO items for stage2 ////////////////
4394
95 cases.add_both("simple function definition",
96 \\void foo(void) {}
97 \\static void bar(void) {}
98 ,
99 \\pub fn foo() void {}
100 \\pub fn bar() void {}
101 );
102
44 cases.add("macro with left shift",103 cases.add("macro with left shift",
45 \\#define REDISMODULE_READ (1<<0)104 \\#define REDISMODULE_READ (1<<0)
46 ,105 ,
...@@ -132,7 +191,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -132,7 +191,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
132 \\}191 \\}
133 );192 );
134193
135 cases.add("ignore result",194 cases.add("ignore result, no function arguments",
136 \\void foo() {195 \\void foo() {
137 \\ int a;196 \\ int a;
138 \\ 1;197 \\ 1;