authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-11-13 19:59:32-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-11-13 19:59:32-07:00
log57cd074959cd529f0648264e877f9819f0209ddf
tree558b763809c431b8c41f989bc48a5f7356690d20
parent1f28fcdec5210762e1ebcf5d5d386d1427f82126

parsec supports C comma operator


2 files changed, 24 insertions(+), 3 deletions(-)

src/parsec.cpp+11-2
......@@ -1099,8 +1099,17 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
10991099 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_OrAssign");
11001100 return nullptr;
11011101 case BO_Comma:
1102 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Comma");
1103 return nullptr;
1102 {
1103 block = trans_create_node(c, NodeTypeBlock);
1104 AstNode *lhs = trans_expr(c, false, block, stmt->getLHS(), TransRValue);
1105 if (lhs == nullptr) return nullptr;
1106 block->data.block.statements.append(maybe_suppress_result(c, false, lhs));
1107 AstNode *rhs = trans_expr(c, result_used, block, stmt->getRHS(), TransRValue);
1108 if (rhs == nullptr) return nullptr;
1109 block->data.block.statements.append(maybe_suppress_result(c, result_used, rhs));
1110 block->data.block.last_statement_is_result_expression = true;
1111 return block;
1112 }
11041113 }
11051114
11061115 zig_unreachable();
test/parsec.zig+13-1
......@@ -606,8 +606,20 @@ pub fn addCases(cases: &tests.ParseCContext) {
606606 \\ return null;
607607 \\}
608608 );
609}
610609
610 cases.addC("comma operator",
611 \\int foo(void) {
612 \\ return 1, 2;
613 \\}
614 ,
615 \\export fn foo() -> c_int {
616 \\ return {
617 \\ _ = 1;
618 \\ 2
619 \\ };
620 \\}
621 );
622}
611623
612624
613625