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...@@ -942,6 +942,21 @@ static AstNode *trans_create_bin_op(Context *c, AstNode *block, Expr *lhs, BinOp
942 return node;942 return node;
943}943}
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
945static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *block, BinaryOperator *stmt) {960static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *block, BinaryOperator *stmt) {
946 switch (stmt->getOpcode()) {961 switch (stmt->getOpcode()) {
947 case BO_PtrMemD:962 case BO_PtrMemD:
...@@ -1026,7 +1041,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo...@@ -1026,7 +1041,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
1026 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign with result_used");1041 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Assign with result_used");
1027 return nullptr;1042 return nullptr;
1028 }1043 }
1029 return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeAssign, stmt->getRHS());1044 return trans_create_assign(c, block, stmt->getLHS(), stmt->getRHS());
1030 case BO_MulAssign:1045 case BO_MulAssign:
1031 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_MulAssign");1046 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_MulAssign");
1032 return nullptr;1047 return nullptr;
test/parsec.zig+4-1
...@@ -455,11 +455,14 @@ pub fn addCases(cases: &tests.ParseCContext) {...@@ -455,11 +455,14 @@ pub fn addCases(cases: &tests.ParseCContext) {
455 \\int max(int a) {455 \\int max(int a) {
456 \\ int tmp;456 \\ int tmp;
457 \\ tmp = a;457 \\ tmp = a;
458 \\ a = tmp;
458 \\}459 \\}
459 ,460 ,
460 \\export fn max(a: c_int) -> c_int {461 \\export fn max(_arg_a: c_int) -> c_int {
462 \\ var a = _arg_a;
461 \\ var tmp: c_int;463 \\ var tmp: c_int;
462 \\ tmp = a;464 \\ tmp = a;
465 \\ a = tmp;
463 \\}466 \\}
464 );467 );
465468