parse-c: support address of operator

This commit is contained in:
Andrew Kelley
2017-11-17 12:11:03 -05:00
parent 3e835973db
commit 339d48ac15
2 changed files with 22 additions and 3 deletions
+9 -3
View File
@@ -1586,12 +1586,18 @@ static AstNode *trans_unary_operator(Context *c, bool result_used, AstNode *bloc
emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_PreDec");
return nullptr;
case UO_AddrOf:
emit_warning(c, stmt->getLocStart(), "TODO handle C translation UO_AddrOf");
return nullptr;
{
AstNode *value_node = trans_expr(c, result_used, block, stmt->getSubExpr(), TransLValue);
if (value_node == nullptr)
return value_node;
return trans_create_node_addr_of(c, false, false, value_node);
}
case UO_Deref:
{
bool is_fn_ptr = qual_type_is_fn_ptr(c, stmt->getSubExpr()->getType());
AstNode *value_node = trans_expr(c, result_used, block, stmt->getSubExpr(), TransRValue);
if (value_node == nullptr)
return nullptr;
bool is_fn_ptr = qual_type_is_fn_ptr(c, stmt->getSubExpr()->getType());
if (is_fn_ptr)
return value_node;
AstNode *unwrapped = trans_create_node_prefix_op(c, PrefixOpUnwrapMaybe, value_node);
+13
View File
@@ -872,6 +872,19 @@ pub fn addCases(cases: &tests.ParseCContext) {
\\pub const Foo = union_Foo;
);
cases.add("address of operator",
\\int foo(void) {
\\ int x = 1234;
\\ int *ptr = &x;
\\ return *ptr;
\\}
,
\\pub fn foo() -> c_int {
\\ var x: c_int = 1234;
\\ var ptr: ?&c_int = &x;
\\ return *(??ptr);
\\}
);
}