| ... | ... | @@ -949,6 +949,14 @@ static AstNode * trans_conditional_operator(Context *c, AstNode *block, Conditio |
| 949 | 949 | return node; |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | static AstNode * trans_create_bin_op(Context *c, AstNode *block, Expr *lhs, BinOpType bin_op, Expr *rhs) { |
| 953 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 954 | node->data.bin_op_expr.bin_op = bin_op; |
| 955 | node->data.bin_op_expr.op1 = trans_expr(c, block, lhs); |
| 956 | node->data.bin_op_expr.op2 = trans_expr(c, block, rhs); |
| 957 | return node; |
| 958 | } |
| 959 | |
| 952 | 960 | static AstNode * trans_binary_operator(Context *c, AstNode *block, BinaryOperator *stmt) { |
| 953 | 961 | switch (stmt->getOpcode()) { |
| 954 | 962 | case BO_PtrMemD: |
| ... | ... | @@ -970,19 +978,13 @@ static AstNode * trans_binary_operator(Context *c, AstNode *block, BinaryOperato |
| 970 | 978 | case BO_Shr: |
| 971 | 979 | zig_panic("TODO handle more C binary operators: BO_Shr"); |
| 972 | 980 | case BO_LT: |
| 973 | | { |
| 974 | | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 975 | | node->data.bin_op_expr.bin_op = BinOpTypeCmpLessThan; |
| 976 | | node->data.bin_op_expr.op1 = trans_expr(c, block, stmt->getLHS()); |
| 977 | | node->data.bin_op_expr.op2 = trans_expr(c, block, stmt->getRHS()); |
| 978 | | return node; |
| 979 | | } |
| 981 | return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpLessThan, stmt->getRHS()); |
| 980 | 982 | case BO_GT: |
| 981 | | zig_panic("TODO handle more C binary operators: BO_GT"); |
| 983 | return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpGreaterThan, stmt->getRHS()); |
| 982 | 984 | case BO_LE: |
| 983 | | zig_panic("TODO handle more C binary operators: BO_LE"); |
| 985 | return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpLessOrEq, stmt->getRHS()); |
| 984 | 986 | case BO_GE: |
| 985 | | zig_panic("TODO handle more C binary operators: BO_GE"); |
| 987 | return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS()); |
| 986 | 988 | case BO_EQ: |
| 987 | 989 | zig_panic("TODO handle more C binary operators: BO_EQ"); |
| 988 | 990 | case BO_NE: |
| ... | ... | @@ -1031,7 +1033,14 @@ static AstNode * trans_implicit_cast_expr(Context *c, AstNode *block, ImplicitCa |
| 1031 | 1033 | case CK_LValueToRValue: |
| 1032 | 1034 | return trans_expr(c, block, stmt->getSubExpr()); |
| 1033 | 1035 | case CK_IntegralCast: |
| 1034 | | zig_panic("TODO handle C translation cast CK_IntegralCast"); |
| 1036 | { |
| 1037 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); |
| 1038 | node->data.fn_call_expr.fn_ref_expr = trans_create_symbol_node(c, "bitCast"); |
| 1039 | node->data.fn_call_expr.is_builtin = true; |
| 1040 | node->data.fn_call_expr.params.append(trans_qual_type(c, stmt->getType(), stmt->getExprLoc())); |
| 1041 | node->data.fn_call_expr.params.append(trans_expr(c, block, stmt->getSubExpr())); |
| 1042 | return node; |
| 1043 | } |
| 1035 | 1044 | case CK_Dependent: |
| 1036 | 1045 | zig_panic("TODO handle C translation cast CK_Dependent"); |
| 1037 | 1046 | case CK_BitCast: |
| ... | ... | @@ -1386,6 +1395,13 @@ static AstNode * trans_local_declaration(Context *c, AstNode *block, DeclStmt *s |
| 1386 | 1395 | return nullptr; |
| 1387 | 1396 | } |
| 1388 | 1397 | |
| 1398 | static AstNode *trans_while_loop(Context *c, AstNode *block, WhileStmt *stmt) { |
| 1399 | AstNode *while_node = trans_create_node(c, NodeTypeWhileExpr); |
| 1400 | while_node->data.while_expr.condition = trans_expr(c, block, stmt->getCond()); |
| 1401 | while_node->data.while_expr.body = trans_stmt(c, block, stmt->getBody()); |
| 1402 | return while_node; |
| 1403 | } |
| 1404 | |
| 1389 | 1405 | static AstNode *trans_stmt(Context *c, AstNode *block, Stmt *stmt) { |
| 1390 | 1406 | Stmt::StmtClass sc = stmt->getStmtClass(); |
| 1391 | 1407 | switch (sc) { |
| ... | ... | @@ -1407,14 +1423,14 @@ static AstNode *trans_stmt(Context *c, AstNode *block, Stmt *stmt) { |
| 1407 | 1423 | return trans_unary_operator(c, block, (UnaryOperator *)stmt); |
| 1408 | 1424 | case Stmt::DeclStmtClass: |
| 1409 | 1425 | return trans_local_declaration(c, block, (DeclStmt *)stmt); |
| 1426 | case Stmt::WhileStmtClass: |
| 1427 | return trans_while_loop(c, block, (WhileStmt *)stmt); |
| 1410 | 1428 | case Stmt::CaseStmtClass: |
| 1411 | 1429 | zig_panic("TODO handle C CaseStmtClass"); |
| 1412 | 1430 | case Stmt::DefaultStmtClass: |
| 1413 | 1431 | zig_panic("TODO handle C DefaultStmtClass"); |
| 1414 | 1432 | case Stmt::SwitchStmtClass: |
| 1415 | 1433 | zig_panic("TODO handle C SwitchStmtClass"); |
| 1416 | | case Stmt::WhileStmtClass: |
| 1417 | | zig_panic("TODO handle C WhileStmtClass"); |
| 1418 | 1434 | case Stmt::NoStmtClass: |
| 1419 | 1435 | zig_panic("TODO handle C NoStmtClass"); |
| 1420 | 1436 | case Stmt::GCCAsmStmtClass: |