Skip to content

Commit 57cd074

Browse files
committedNov 14, 2017
parsec supports C comma operator
1 parent 1f28fcd commit 57cd074

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
 

‎src/parsec.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)