Implements translation for the prefix not operator (#628)

This commit is contained in:
Mason Remaley 2017-11-27 21:00:05 -05:00 committed by Andrew Kelley
parent 671183fa9a
commit 3e8fd24547
2 changed files with 17 additions and 2 deletions

View File

@ -1875,8 +1875,13 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
}
}
case UO_Not:
emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_Not");
return nullptr;
{
Expr *op_expr = stmt->getSubExpr();
AstNode *sub_node = trans_expr(c, ResultUsedYes, scope, op_expr, TransRValue);
if (sub_node == nullptr)
return nullptr;
return trans_create_node_prefix_op(c, PrefixOpBinNot, sub_node);
}
case UO_LNot:
emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_LNot");
return nullptr;

View File

@ -1114,4 +1114,14 @@ pub fn addCases(cases: &tests.TranslateCContext) {
\\ return @ptrCast(?&f32, a);
\\}
);
cases.add("bin not",
\\int foo(int x) {
\\ return ~x;
\\}
,
\\pub fn foo(x: c_int) -> c_int {
\\ return ~x;
\\}
);
}