Skip to content

Commit

Permalink
parse-c: support address of operator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Nov 17, 2017
1 parent 3e83597 commit 339d48a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/parsec.cpp
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions test/parsec.zig
Expand Up @@ -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);
\\}
);
}


Expand Down

0 comments on commit 339d48a

Please sign in to comment.