authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-20 22:41:07-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-20 22:41:16-07:00
log5ac2cf9c28253a7b6144c9f5b19f68df1e26527c
tree7e830a5861c83842647a444c36dbebffa3b5066e
parent1360af847e5cdc8f4dc279cf64e9acd4a32d0b86

fix assignment needing an lvalue


2 files changed, 20 insertions(+), 2 deletions(-)

src/parsec.cpp+16-1
......@@ -942,6 +942,21 @@ static AstNode *trans_create_bin_op(Context *c, AstNode *block, Expr *lhs, BinOp
942942 return node;
943943}
944944
945static AstNode *trans_create_assign(Context *c, AstNode *block, Expr *lhs, Expr *rhs) {
946 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
947 node->data.bin_op_expr.bin_op = BinOpTypeAssign;
948
949 node->data.bin_op_expr.op1 = trans_expr(c, true, block, lhs, TransLValue);
950 if (node->data.bin_op_expr.op1 == nullptr)
951 return nullptr;
952
953 node->data.bin_op_expr.op2 = trans_expr(c, true, block, rhs, TransRValue);
954 if (node->data.bin_op_expr.op2 == nullptr)
955 return nullptr;
956
957 return node;
958}
959
945960static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *block, BinaryOperator *stmt) {
946961 switch (stmt->getOpcode()) {
947962 case BO_PtrMemD:
......@@ -1026,7 +1041,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
10261041 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign with result_used");
10271042 return nullptr;
10281043 }
1029 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeAssign, stmt->getRHS());
1044 return trans_create_assign(c, block, stmt->getLHS(), stmt->getRHS());
10301045 case BO_MulAssign:
10311046 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_MulAssign");
10321047 return nullptr;
test/parsec.zig+4-1
......@@ -455,11 +455,14 @@ pub fn addCases(cases: &tests.ParseCContext) {
455455 \\int max(int a) {
456456 \\ int tmp;
457457 \\ tmp = a;
458 \\ a = tmp;
458459 \\}
459460 ,
460 \\export fn max(a: c_int) -> c_int {
461 \\export fn max(_arg_a: c_int) -> c_int {
462 \\ var a = _arg_a;
461463 \\ var tmp: c_int;
462464 \\ tmp = a;
465 \\ a = tmp;
463466 \\}
464467 );
465468