authorgravatar for mason@anthropicstudios.comMason Remaley <mason@anthropicstudios.com> 2017-11-27 21:00:05-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-27 21:00:05-05:00
log3e8fd245473a6e532fa4f9b42c51bd8257c15b3c
treef0add539ecd6463dd96afbdcf0b31f63bc0898fc
parent671183fa9a0be28851002d07ad7ddf0d3bd29b46

Implements translation for the prefix not operator (#628)


2 files changed, 17 insertions(+), 2 deletions(-)

src/translate_c.cpp+7-2
......@@ -1875,8 +1875,13 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
18751875 }
18761876 }
18771877 case UO_Not:
1878 emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_Not");
1879 return nullptr;
1878 {
1879 Expr *op_expr = stmt->getSubExpr();
1880 AstNode *sub_node = trans_expr(c, ResultUsedYes, scope, op_expr, TransRValue);
1881 if (sub_node == nullptr)
1882 return nullptr;
1883 return trans_create_node_prefix_op(c, PrefixOpBinNot, sub_node);
1884 }
18801885 case UO_LNot:
18811886 emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_LNot");
18821887 return nullptr;
test/translate_c.zig+10
......@@ -1114,4 +1114,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {
11141114 \\ return @ptrCast(?&f32, a);
11151115 \\}
11161116 );
1117
1118 cases.add("bin not",
1119 \\int foo(int x) {
1120 \\ return ~x;
1121 \\}
1122 ,
1123 \\pub fn foo(x: c_int) -> c_int {
1124 \\ return ~x;
1125 \\}
1126 );
11171127}