| ... | ... | @@ -121,15 +121,20 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s |
| 121 | 121 | AstNode **out_node, TransScope **out_child_scope, |
| 122 | 122 | TransScope **out_node_scope); |
| 123 | 123 | static TransScope *trans_stmt(Context *c, TransScope *scope, const ZigClangStmt *stmt, AstNode **out_node); |
| 124 | | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval); |
| 124 | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr, TransLRValue lrval); |
| 125 | 125 | static AstNode *trans_qual_type(Context *c, ZigClangQualType qt, ZigClangSourceLocation source_loc); |
| 126 | | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval); |
| 126 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, |
| 127 | const ZigClangExpr *expr, TransLRValue lrval); |
| 127 | 128 | static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQualType qt, ZigClangSourceLocation source_loc); |
| 128 | 129 | |
| 129 | 130 | static const ZigClangStmt *bitcast(const clang::Stmt *src) { |
| 130 | 131 | return reinterpret_cast<const ZigClangStmt *>(src); |
| 131 | 132 | } |
| 132 | 133 | |
| 134 | static const ZigClangExpr *bitcast(const clang::Expr *src) { |
| 135 | return reinterpret_cast<const ZigClangExpr *>(src); |
| 136 | } |
| 137 | |
| 133 | 138 | static ZigClangSourceLocation bitcast(clang::SourceLocation src) { |
| 134 | 139 | ZigClangSourceLocation dest; |
| 135 | 140 | memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangSourceLocation)); |
| ... | ... | @@ -511,14 +516,14 @@ static const ZigClangType *qual_type_canon(ZigClangQualType qt) { |
| 511 | 516 | return ZigClangQualType_getTypePtr(canon); |
| 512 | 517 | } |
| 513 | 518 | |
| 514 | | static ZigClangQualType get_expr_qual_type(Context *c, const clang::Expr *expr) { |
| 519 | static ZigClangQualType get_expr_qual_type(Context *c, const ZigClangExpr *expr) { |
| 515 | 520 | // String literals in C are `char *` but they should really be `const char *`. |
| 516 | | if ((ZigClangStmtClass)expr->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) { |
| 517 | | const clang::ImplicitCastExpr *cast_expr = static_cast<const clang::ImplicitCastExpr *>(expr); |
| 518 | | if (cast_expr->getCastKind() == clang::CK_ArrayToPointerDecay) { |
| 519 | | const clang::Expr *sub_expr = cast_expr->getSubExpr(); |
| 520 | | if ((ZigClangStmtClass)sub_expr->getStmtClass() == ZigClangStmt_StringLiteralClass) { |
| 521 | | ZigClangQualType array_qt = bitcast(sub_expr->getType()); |
| 521 | if (ZigClangExpr_getStmtClass(expr) == ZigClangStmt_ImplicitCastExprClass) { |
| 522 | const clang::ImplicitCastExpr *cast_expr = reinterpret_cast<const clang::ImplicitCastExpr *>(expr); |
| 523 | if ((ZigClangCK)cast_expr->getCastKind() == ZigClangCK_ArrayToPointerDecay) { |
| 524 | const ZigClangExpr *sub_expr = bitcast(cast_expr->getSubExpr()); |
| 525 | if (ZigClangExpr_getStmtClass(sub_expr) == ZigClangStmt_StringLiteralClass) { |
| 526 | ZigClangQualType array_qt = ZigClangExpr_getType(sub_expr); |
| 522 | 527 | const clang::ArrayType *array_type = reinterpret_cast<const clang::ArrayType *>( |
| 523 | 528 | ZigClangQualType_getTypePtr(array_qt)); |
| 524 | 529 | ZigClangQualType pointee_qt = bitcast(array_type->getElementType()); |
| ... | ... | @@ -527,26 +532,26 @@ static ZigClangQualType get_expr_qual_type(Context *c, const clang::Expr *expr) |
| 527 | 532 | } |
| 528 | 533 | } |
| 529 | 534 | } |
| 530 | | return bitcast(expr->getType()); |
| 535 | return ZigClangExpr_getType(expr); |
| 531 | 536 | } |
| 532 | 537 | |
| 533 | | static ZigClangQualType get_expr_qual_type_before_implicit_cast(Context *c, const clang::Expr *expr) { |
| 534 | | if ((ZigClangStmtClass)expr->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) { |
| 535 | | const clang::ImplicitCastExpr *cast_expr = static_cast<const clang::ImplicitCastExpr *>(expr); |
| 536 | | return get_expr_qual_type(c, cast_expr->getSubExpr()); |
| 538 | static ZigClangQualType get_expr_qual_type_before_implicit_cast(Context *c, const ZigClangExpr *expr) { |
| 539 | if (ZigClangExpr_getStmtClass(expr) == ZigClangStmt_ImplicitCastExprClass) { |
| 540 | const clang::ImplicitCastExpr *cast_expr = reinterpret_cast<const clang::ImplicitCastExpr *>(expr); |
| 541 | return get_expr_qual_type(c, bitcast(cast_expr->getSubExpr())); |
| 537 | 542 | } |
| 538 | | return bitcast(expr->getType()); |
| 543 | return ZigClangExpr_getType(expr); |
| 539 | 544 | } |
| 540 | 545 | |
| 541 | | static AstNode *get_expr_type(Context *c, const clang::Expr *expr) { |
| 542 | | return trans_qual_type(c, get_expr_qual_type(c, expr), bitcast(expr->getBeginLoc())); |
| 546 | static AstNode *get_expr_type(Context *c, const ZigClangExpr *expr) { |
| 547 | return trans_qual_type(c, get_expr_qual_type(c, expr), ZigClangExpr_getBeginLoc(expr)); |
| 543 | 548 | } |
| 544 | 549 | |
| 545 | 550 | static bool is_c_void_type(AstNode *node) { |
| 546 | 551 | return (node->type == NodeTypeSymbol && buf_eql_str(node->data.symbol_expr.symbol, "c_void")); |
| 547 | 552 | } |
| 548 | 553 | |
| 549 | | static bool expr_types_equal(Context *c, const clang::Expr *expr1, const clang::Expr *expr2) { |
| 554 | static bool expr_types_equal(Context *c, const ZigClangExpr *expr1, const ZigClangExpr *expr2) { |
| 550 | 555 | ZigClangQualType t1 = get_expr_qual_type(c, expr1); |
| 551 | 556 | ZigClangQualType t2 = get_expr_qual_type(c, expr2); |
| 552 | 557 | |
| ... | ... | @@ -1272,7 +1277,7 @@ static AstNode *trans_stmt_expr(Context *c, ResultUsed result_used, TransScope * |
| 1272 | 1277 | } |
| 1273 | 1278 | |
| 1274 | 1279 | static AstNode *trans_return_stmt(Context *c, TransScope *scope, const clang::ReturnStmt *stmt) { |
| 1275 | | const clang::Expr *value_expr = stmt->getRetValue(); |
| 1280 | const ZigClangExpr *value_expr = bitcast(stmt->getRetValue()); |
| 1276 | 1281 | if (value_expr == nullptr) { |
| 1277 | 1282 | return trans_create_node(c, NodeTypeReturnExpr); |
| 1278 | 1283 | } else { |
| ... | ... | @@ -1311,9 +1316,9 @@ static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, T |
| 1311 | 1316 | { |
| 1312 | 1317 | AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr); |
| 1313 | 1318 | |
| 1314 | | clang::Expr *cond_expr = stmt->getCond(); |
| 1315 | | clang::Expr *true_expr = stmt->getTrueExpr(); |
| 1316 | | clang::Expr *false_expr = stmt->getFalseExpr(); |
| 1319 | const ZigClangExpr *cond_expr = bitcast(stmt->getCond()); |
| 1320 | const ZigClangExpr *true_expr = bitcast(stmt->getTrueExpr()); |
| 1321 | const ZigClangExpr *false_expr = bitcast(stmt->getFalseExpr()); |
| 1317 | 1322 | |
| 1318 | 1323 | node->data.if_bool_expr.condition = trans_expr(c, ResultUsedYes, scope, cond_expr, TransRValue); |
| 1319 | 1324 | if (node->data.if_bool_expr.condition == nullptr) |
| ... | ... | @@ -1330,7 +1335,9 @@ static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, T |
| 1330 | 1335 | return maybe_suppress_result(c, result_used, node); |
| 1331 | 1336 | } |
| 1332 | 1337 | |
| 1333 | | static AstNode *trans_create_bin_op(Context *c, TransScope *scope, clang::Expr *lhs, BinOpType bin_op, clang::Expr *rhs) { |
| 1338 | static AstNode *trans_create_bin_op(Context *c, TransScope *scope, const ZigClangExpr *lhs, |
| 1339 | BinOpType bin_op, const ZigClangExpr *rhs) |
| 1340 | { |
| 1334 | 1341 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 1335 | 1342 | node->data.bin_op_expr.bin_op = bin_op; |
| 1336 | 1343 | |
| ... | ... | @@ -1345,7 +1352,9 @@ static AstNode *trans_create_bin_op(Context *c, TransScope *scope, clang::Expr * |
| 1345 | 1352 | return node; |
| 1346 | 1353 | } |
| 1347 | 1354 | |
| 1348 | | static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, clang::Expr *lhs, BinOpType bin_op, clang::Expr *rhs) { |
| 1355 | static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, const ZigClangExpr *lhs, |
| 1356 | BinOpType bin_op, const ZigClangExpr *rhs) |
| 1357 | { |
| 1349 | 1358 | assert(bin_op == BinOpTypeBoolAnd || bin_op == BinOpTypeBoolOr); |
| 1350 | 1359 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 1351 | 1360 | node->data.bin_op_expr.bin_op = bin_op; |
| ... | ... | @@ -1361,7 +1370,9 @@ static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, clang::E |
| 1361 | 1370 | return node; |
| 1362 | 1371 | } |
| 1363 | 1372 | |
| 1364 | | static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransScope *scope, clang::Expr *lhs, clang::Expr *rhs) { |
| 1373 | static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransScope *scope, |
| 1374 | const ZigClangExpr *lhs, const ZigClangExpr *rhs) |
| 1375 | { |
| 1365 | 1376 | if (result_used == ResultUsedNo) { |
| 1366 | 1377 | // common case |
| 1367 | 1378 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| ... | ... | @@ -1413,9 +1424,9 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco |
| 1413 | 1424 | } |
| 1414 | 1425 | |
| 1415 | 1426 | static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQualType result_type, |
| 1416 | | clang::Expr *lhs_expr, BinOpType bin_op, clang::Expr *rhs_expr) |
| 1427 | const ZigClangExpr *lhs_expr, BinOpType bin_op, const ZigClangExpr *rhs_expr) |
| 1417 | 1428 | { |
| 1418 | | ZigClangSourceLocation rhs_location = bitcast(rhs_expr->getBeginLoc()); |
| 1429 | ZigClangSourceLocation rhs_location = ZigClangExpr_getBeginLoc(rhs_expr); |
| 1419 | 1430 | AstNode *rhs_type = qual_type_to_log2_int_ref(c, result_type, rhs_location); |
| 1420 | 1431 | // lhs >> u5(rh) |
| 1421 | 1432 | |
| ... | ... | @@ -1441,23 +1452,23 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS |
| 1441 | 1452 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle more C binary operators: BO_Cmp"); |
| 1442 | 1453 | return nullptr; |
| 1443 | 1454 | case clang::BO_Mul: { |
| 1444 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), |
| 1455 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), |
| 1445 | 1456 | qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeMultWrap : BinOpTypeMult, |
| 1446 | | stmt->getRHS()); |
| 1457 | bitcast(stmt->getRHS())); |
| 1447 | 1458 | return maybe_suppress_result(c, result_used, node); |
| 1448 | 1459 | } |
| 1449 | 1460 | case clang::BO_Div: |
| 1450 | 1461 | if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) { |
| 1451 | 1462 | // unsigned/float division uses the operator |
| 1452 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeDiv, stmt->getRHS()); |
| 1463 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeDiv, bitcast(stmt->getRHS())); |
| 1453 | 1464 | return maybe_suppress_result(c, result_used, node); |
| 1454 | 1465 | } else { |
| 1455 | 1466 | // signed integer division uses @divTrunc |
| 1456 | 1467 | AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "divTrunc"); |
| 1457 | | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, stmt->getLHS(), TransLValue); |
| 1468 | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getLHS()), TransLValue); |
| 1458 | 1469 | if (lhs == nullptr) return nullptr; |
| 1459 | 1470 | fn_call->data.fn_call_expr.params.append(lhs); |
| 1460 | | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransLValue); |
| 1471 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getRHS()), TransLValue); |
| 1461 | 1472 | if (rhs == nullptr) return nullptr; |
| 1462 | 1473 | fn_call->data.fn_call_expr.params.append(rhs); |
| 1463 | 1474 | return maybe_suppress_result(c, result_used, fn_call); |
| ... | ... | @@ -1465,97 +1476,97 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS |
| 1465 | 1476 | case clang::BO_Rem: |
| 1466 | 1477 | if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) { |
| 1467 | 1478 | // unsigned/float division uses the operator |
| 1468 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeMod, stmt->getRHS()); |
| 1479 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeMod, bitcast(stmt->getRHS())); |
| 1469 | 1480 | return maybe_suppress_result(c, result_used, node); |
| 1470 | 1481 | } else { |
| 1471 | 1482 | // signed integer division uses @rem |
| 1472 | 1483 | AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "rem"); |
| 1473 | | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, stmt->getLHS(), TransLValue); |
| 1484 | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getLHS()), TransLValue); |
| 1474 | 1485 | if (lhs == nullptr) return nullptr; |
| 1475 | 1486 | fn_call->data.fn_call_expr.params.append(lhs); |
| 1476 | | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransLValue); |
| 1487 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getRHS()), TransLValue); |
| 1477 | 1488 | if (rhs == nullptr) return nullptr; |
| 1478 | 1489 | fn_call->data.fn_call_expr.params.append(rhs); |
| 1479 | 1490 | return maybe_suppress_result(c, result_used, fn_call); |
| 1480 | 1491 | } |
| 1481 | 1492 | case clang::BO_Add: { |
| 1482 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), |
| 1493 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), |
| 1483 | 1494 | qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeAddWrap : BinOpTypeAdd, |
| 1484 | | stmt->getRHS()); |
| 1495 | bitcast(stmt->getRHS())); |
| 1485 | 1496 | return maybe_suppress_result(c, result_used, node); |
| 1486 | 1497 | } |
| 1487 | 1498 | case clang::BO_Sub: { |
| 1488 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), |
| 1499 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), |
| 1489 | 1500 | qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeSubWrap : BinOpTypeSub, |
| 1490 | | stmt->getRHS()); |
| 1501 | bitcast(stmt->getRHS())); |
| 1491 | 1502 | return maybe_suppress_result(c, result_used, node); |
| 1492 | 1503 | } |
| 1493 | 1504 | case clang::BO_Shl: { |
| 1494 | | AstNode *node = trans_create_shift_op(c, scope, bitcast(stmt->getType()), stmt->getLHS(), BinOpTypeBitShiftLeft, stmt->getRHS()); |
| 1505 | AstNode *node = trans_create_shift_op(c, scope, bitcast(stmt->getType()), bitcast(stmt->getLHS()), BinOpTypeBitShiftLeft, bitcast(stmt->getRHS())); |
| 1495 | 1506 | return maybe_suppress_result(c, result_used, node); |
| 1496 | 1507 | } |
| 1497 | 1508 | case clang::BO_Shr: { |
| 1498 | | AstNode *node = trans_create_shift_op(c, scope, bitcast(stmt->getType()), stmt->getLHS(), BinOpTypeBitShiftRight, stmt->getRHS()); |
| 1509 | AstNode *node = trans_create_shift_op(c, scope, bitcast(stmt->getType()), bitcast(stmt->getLHS()), BinOpTypeBitShiftRight, bitcast(stmt->getRHS())); |
| 1499 | 1510 | return maybe_suppress_result(c, result_used, node); |
| 1500 | 1511 | } |
| 1501 | 1512 | case clang::BO_LT: { |
| 1502 | | AstNode *node =trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessThan, stmt->getRHS()); |
| 1513 | AstNode *node =trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpLessThan, bitcast(stmt->getRHS())); |
| 1503 | 1514 | return maybe_suppress_result(c, result_used, node); |
| 1504 | 1515 | } |
| 1505 | 1516 | case clang::BO_GT: { |
| 1506 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterThan, stmt->getRHS()); |
| 1517 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpGreaterThan, bitcast(stmt->getRHS())); |
| 1507 | 1518 | return maybe_suppress_result(c, result_used, node); |
| 1508 | 1519 | } |
| 1509 | 1520 | case clang::BO_LE: { |
| 1510 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessOrEq, stmt->getRHS()); |
| 1521 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpLessOrEq, bitcast(stmt->getRHS())); |
| 1511 | 1522 | return maybe_suppress_result(c, result_used, node); |
| 1512 | 1523 | } |
| 1513 | 1524 | case clang::BO_GE: { |
| 1514 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS()); |
| 1525 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpGreaterOrEq, bitcast(stmt->getRHS())); |
| 1515 | 1526 | return maybe_suppress_result(c, result_used, node); |
| 1516 | 1527 | } |
| 1517 | 1528 | case clang::BO_EQ: { |
| 1518 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS()); |
| 1529 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpEq, bitcast(stmt->getRHS())); |
| 1519 | 1530 | return maybe_suppress_result(c, result_used, node); |
| 1520 | 1531 | } |
| 1521 | 1532 | case clang::BO_NE: { |
| 1522 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpNotEq, stmt->getRHS()); |
| 1533 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeCmpNotEq, bitcast(stmt->getRHS())); |
| 1523 | 1534 | return maybe_suppress_result(c, result_used, node); |
| 1524 | 1535 | } |
| 1525 | 1536 | case clang::BO_And: { |
| 1526 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinAnd, stmt->getRHS()); |
| 1537 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeBinAnd, bitcast(stmt->getRHS())); |
| 1527 | 1538 | return maybe_suppress_result(c, result_used, node); |
| 1528 | 1539 | } |
| 1529 | 1540 | case clang::BO_Xor: { |
| 1530 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinXor, stmt->getRHS()); |
| 1541 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeBinXor, bitcast(stmt->getRHS())); |
| 1531 | 1542 | return maybe_suppress_result(c, result_used, node); |
| 1532 | 1543 | } |
| 1533 | 1544 | case clang::BO_Or: { |
| 1534 | | AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinOr, stmt->getRHS()); |
| 1545 | AstNode *node = trans_create_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeBinOr, bitcast(stmt->getRHS())); |
| 1535 | 1546 | return maybe_suppress_result(c, result_used, node); |
| 1536 | 1547 | } |
| 1537 | 1548 | case clang::BO_LAnd: { |
| 1538 | | AstNode *node = trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolAnd, stmt->getRHS()); |
| 1549 | AstNode *node = trans_create_bool_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeBoolAnd, bitcast(stmt->getRHS())); |
| 1539 | 1550 | return maybe_suppress_result(c, result_used, node); |
| 1540 | 1551 | } |
| 1541 | 1552 | case clang::BO_LOr: { |
| 1542 | | AstNode *node = trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolOr, stmt->getRHS()); |
| 1553 | AstNode *node = trans_create_bool_bin_op(c, scope, bitcast(stmt->getLHS()), BinOpTypeBoolOr, bitcast(stmt->getRHS())); |
| 1543 | 1554 | return maybe_suppress_result(c, result_used, node); |
| 1544 | 1555 | } |
| 1545 | 1556 | case clang::BO_Assign: |
| 1546 | | return trans_create_assign(c, result_used, scope, stmt->getLHS(), stmt->getRHS()); |
| 1557 | return trans_create_assign(c, result_used, scope, bitcast(stmt->getLHS()), bitcast(stmt->getRHS())); |
| 1547 | 1558 | case clang::BO_Comma: |
| 1548 | 1559 | { |
| 1549 | 1560 | TransScopeBlock *scope_block = trans_scope_block_create(c, scope); |
| 1550 | 1561 | Buf *label_name = buf_create_from_str("x"); |
| 1551 | 1562 | scope_block->node->data.block.name = label_name; |
| 1552 | 1563 | |
| 1553 | | AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, stmt->getLHS(), TransRValue); |
| 1564 | AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, bitcast(stmt->getLHS()), TransRValue); |
| 1554 | 1565 | if (lhs == nullptr) |
| 1555 | 1566 | return nullptr; |
| 1556 | 1567 | scope_block->node->data.block.statements.append(lhs); |
| 1557 | 1568 | |
| 1558 | | AstNode *rhs = trans_expr(c, ResultUsedYes, &scope_block->base, stmt->getRHS(), TransRValue); |
| 1569 | AstNode *rhs = trans_expr(c, ResultUsedYes, &scope_block->base, bitcast(stmt->getRHS()), TransRValue); |
| 1559 | 1570 | if (rhs == nullptr) |
| 1560 | 1571 | return nullptr; |
| 1561 | 1572 | |
| ... | ... | @@ -1589,10 +1600,10 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result |
| 1589 | 1600 | if (!use_intermediate_casts && result_used == ResultUsedNo) { |
| 1590 | 1601 | // simple common case, where the C and Zig are identical: |
| 1591 | 1602 | // lhs >>= rhs |
| 1592 | | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, stmt->getLHS(), TransLValue); |
| 1603 | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getLHS()), TransLValue); |
| 1593 | 1604 | if (lhs == nullptr) return nullptr; |
| 1594 | 1605 | |
| 1595 | | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransRValue); |
| 1606 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getRHS()), TransRValue); |
| 1596 | 1607 | if (rhs == nullptr) return nullptr; |
| 1597 | 1608 | AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs); |
| 1598 | 1609 | |
| ... | ... | @@ -1612,7 +1623,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result |
| 1612 | 1623 | child_scope->node->data.block.name = label_name; |
| 1613 | 1624 | |
| 1614 | 1625 | // const _ref = &lhs; |
| 1615 | | AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue); |
| 1626 | AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, bitcast(stmt->getLHS()), TransLValue); |
| 1616 | 1627 | if (lhs == nullptr) return nullptr; |
| 1617 | 1628 | AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs); |
| 1618 | 1629 | // TODO: avoid name collisions with generated variable names |
| ... | ... | @@ -1622,7 +1633,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result |
| 1622 | 1633 | |
| 1623 | 1634 | // *_ref = result_type(operation_type(*_ref) >> u5(rhs)); |
| 1624 | 1635 | |
| 1625 | | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getRHS(), TransRValue); |
| 1636 | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, bitcast(stmt->getRHS()), TransRValue); |
| 1626 | 1637 | if (rhs == nullptr) return nullptr; |
| 1627 | 1638 | AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs); |
| 1628 | 1639 | |
| ... | ... | @@ -1667,9 +1678,9 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used, |
| 1667 | 1678 | if (result_used == ResultUsedNo) { |
| 1668 | 1679 | // simple common case, where the C and Zig are identical: |
| 1669 | 1680 | // lhs += rhs |
| 1670 | | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, stmt->getLHS(), TransLValue); |
| 1681 | AstNode *lhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getLHS()), TransLValue); |
| 1671 | 1682 | if (lhs == nullptr) return nullptr; |
| 1672 | | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransRValue); |
| 1683 | AstNode *rhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getRHS()), TransRValue); |
| 1673 | 1684 | if (rhs == nullptr) return nullptr; |
| 1674 | 1685 | return trans_create_node_bin_op(c, lhs, assign_op, rhs); |
| 1675 | 1686 | } else { |
| ... | ... | @@ -1686,7 +1697,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used, |
| 1686 | 1697 | child_scope->node->data.block.name = label_name; |
| 1687 | 1698 | |
| 1688 | 1699 | // const _ref = &lhs; |
| 1689 | | AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue); |
| 1700 | AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, bitcast(stmt->getLHS()), TransLValue); |
| 1690 | 1701 | if (lhs == nullptr) return nullptr; |
| 1691 | 1702 | AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs); |
| 1692 | 1703 | // TODO: avoid name collisions with generated variable names |
| ... | ... | @@ -1696,7 +1707,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used, |
| 1696 | 1707 | |
| 1697 | 1708 | // *_ref = *_ref + rhs; |
| 1698 | 1709 | |
| 1699 | | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getRHS(), TransRValue); |
| 1710 | AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, bitcast(stmt->getRHS()), TransRValue); |
| 1700 | 1711 | if (rhs == nullptr) return nullptr; |
| 1701 | 1712 | |
| 1702 | 1713 | AstNode *assign_statement = trans_create_node_bin_op(c, |
| ... | ... | @@ -1788,201 +1799,201 @@ static AstNode *trans_compound_assign_operator(Context *c, ResultUsed result_use |
| 1788 | 1799 | } |
| 1789 | 1800 | |
| 1790 | 1801 | static AstNode *trans_implicit_cast_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ImplicitCastExpr *stmt) { |
| 1791 | | switch (stmt->getCastKind()) { |
| 1792 | | case clang::CK_LValueToRValue: |
| 1793 | | return trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue); |
| 1794 | | case clang::CK_IntegralCast: |
| 1802 | switch ((ZigClangCK)stmt->getCastKind()) { |
| 1803 | case ZigClangCK_LValueToRValue: |
| 1804 | return trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 1805 | case ZigClangCK_IntegralCast: |
| 1795 | 1806 | { |
| 1796 | | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue); |
| 1807 | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 1797 | 1808 | if (target_node == nullptr) |
| 1798 | 1809 | return nullptr; |
| 1799 | 1810 | AstNode *node = trans_c_cast(c, bitcast(stmt->getExprLoc()), bitcast(stmt->getType()), |
| 1800 | 1811 | bitcast(stmt->getSubExpr()->getType()), target_node); |
| 1801 | 1812 | return maybe_suppress_result(c, result_used, node); |
| 1802 | 1813 | } |
| 1803 | | case clang::CK_FunctionToPointerDecay: |
| 1804 | | case clang::CK_ArrayToPointerDecay: |
| 1814 | case ZigClangCK_FunctionToPointerDecay: |
| 1815 | case ZigClangCK_ArrayToPointerDecay: |
| 1805 | 1816 | { |
| 1806 | | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue); |
| 1817 | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 1807 | 1818 | if (target_node == nullptr) |
| 1808 | 1819 | return nullptr; |
| 1809 | 1820 | return maybe_suppress_result(c, result_used, target_node); |
| 1810 | 1821 | } |
| 1811 | | case clang::CK_BitCast: |
| 1822 | case ZigClangCK_BitCast: |
| 1812 | 1823 | { |
| 1813 | | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue); |
| 1824 | AstNode *target_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 1814 | 1825 | if (target_node == nullptr) |
| 1815 | 1826 | return nullptr; |
| 1816 | 1827 | |
| 1817 | | if (expr_types_equal(c, stmt, stmt->getSubExpr())) { |
| 1828 | if (expr_types_equal(c, (const ZigClangExpr *)stmt, bitcast(stmt->getSubExpr()))) { |
| 1818 | 1829 | return target_node; |
| 1819 | 1830 | } |
| 1820 | 1831 | |
| 1821 | | AstNode *dest_type_node = get_expr_type(c, stmt); |
| 1832 | AstNode *dest_type_node = get_expr_type(c, (const ZigClangExpr *)stmt); |
| 1822 | 1833 | |
| 1823 | 1834 | AstNode *node = trans_create_node_builtin_fn_call_str(c, "ptrCast"); |
| 1824 | 1835 | node->data.fn_call_expr.params.append(dest_type_node); |
| 1825 | 1836 | node->data.fn_call_expr.params.append(target_node); |
| 1826 | 1837 | return maybe_suppress_result(c, result_used, node); |
| 1827 | 1838 | } |
| 1828 | | case clang::CK_NullToPointer: |
| 1839 | case ZigClangCK_NullToPointer: |
| 1829 | 1840 | return trans_create_node_unsigned(c, 0); |
| 1830 | | case clang::CK_NoOp: |
| 1831 | | return trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue); |
| 1832 | | case clang::CK_Dependent: |
| 1841 | case ZigClangCK_NoOp: |
| 1842 | return trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 1843 | case ZigClangCK_Dependent: |
| 1833 | 1844 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dependent"); |
| 1834 | 1845 | return nullptr; |
| 1835 | | case clang::CK_LValueBitCast: |
| 1846 | case ZigClangCK_LValueBitCast: |
| 1836 | 1847 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_LValueBitCast"); |
| 1837 | 1848 | return nullptr; |
| 1838 | | case clang::CK_BaseToDerived: |
| 1849 | case ZigClangCK_BaseToDerived: |
| 1839 | 1850 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerived"); |
| 1840 | 1851 | return nullptr; |
| 1841 | | case clang::CK_DerivedToBase: |
| 1852 | case ZigClangCK_DerivedToBase: |
| 1842 | 1853 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBase"); |
| 1843 | 1854 | return nullptr; |
| 1844 | | case clang::CK_UncheckedDerivedToBase: |
| 1855 | case ZigClangCK_UncheckedDerivedToBase: |
| 1845 | 1856 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UncheckedDerivedToBase"); |
| 1846 | 1857 | return nullptr; |
| 1847 | | case clang::CK_Dynamic: |
| 1858 | case ZigClangCK_Dynamic: |
| 1848 | 1859 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dynamic"); |
| 1849 | 1860 | return nullptr; |
| 1850 | | case clang::CK_ToUnion: |
| 1861 | case ZigClangCK_ToUnion: |
| 1851 | 1862 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ToUnion"); |
| 1852 | 1863 | return nullptr; |
| 1853 | | case clang::CK_NullToMemberPointer: |
| 1864 | case ZigClangCK_NullToMemberPointer: |
| 1854 | 1865 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_NullToMemberPointer"); |
| 1855 | 1866 | return nullptr; |
| 1856 | | case clang::CK_BaseToDerivedMemberPointer: |
| 1867 | case ZigClangCK_BaseToDerivedMemberPointer: |
| 1857 | 1868 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerivedMemberPointer"); |
| 1858 | 1869 | return nullptr; |
| 1859 | | case clang::CK_DerivedToBaseMemberPointer: |
| 1870 | case ZigClangCK_DerivedToBaseMemberPointer: |
| 1860 | 1871 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBaseMemberPointer"); |
| 1861 | 1872 | return nullptr; |
| 1862 | | case clang::CK_MemberPointerToBoolean: |
| 1873 | case ZigClangCK_MemberPointerToBoolean: |
| 1863 | 1874 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_MemberPointerToBoolean"); |
| 1864 | 1875 | return nullptr; |
| 1865 | | case clang::CK_ReinterpretMemberPointer: |
| 1876 | case ZigClangCK_ReinterpretMemberPointer: |
| 1866 | 1877 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ReinterpretMemberPointer"); |
| 1867 | 1878 | return nullptr; |
| 1868 | | case clang::CK_UserDefinedConversion: |
| 1879 | case ZigClangCK_UserDefinedConversion: |
| 1869 | 1880 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UserDefinedConversion"); |
| 1870 | 1881 | return nullptr; |
| 1871 | | case clang::CK_ConstructorConversion: |
| 1882 | case ZigClangCK_ConstructorConversion: |
| 1872 | 1883 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ConstructorConversion"); |
| 1873 | 1884 | return nullptr; |
| 1874 | | case clang::CK_IntegralToPointer: |
| 1885 | case ZigClangCK_IntegralToPointer: |
| 1875 | 1886 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToPointer"); |
| 1876 | 1887 | return nullptr; |
| 1877 | | case clang::CK_PointerToIntegral: |
| 1888 | case ZigClangCK_PointerToIntegral: |
| 1878 | 1889 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToIntegral"); |
| 1879 | 1890 | return nullptr; |
| 1880 | | case clang::CK_PointerToBoolean: |
| 1891 | case ZigClangCK_PointerToBoolean: |
| 1881 | 1892 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToBoolean"); |
| 1882 | 1893 | return nullptr; |
| 1883 | | case clang::CK_ToVoid: |
| 1894 | case ZigClangCK_ToVoid: |
| 1884 | 1895 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ToVoid"); |
| 1885 | 1896 | return nullptr; |
| 1886 | | case clang::CK_VectorSplat: |
| 1897 | case ZigClangCK_VectorSplat: |
| 1887 | 1898 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_VectorSplat"); |
| 1888 | 1899 | return nullptr; |
| 1889 | | case clang::CK_IntegralToBoolean: |
| 1900 | case ZigClangCK_IntegralToBoolean: |
| 1890 | 1901 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToBoolean"); |
| 1891 | 1902 | return nullptr; |
| 1892 | | case clang::CK_IntegralToFloating: |
| 1903 | case ZigClangCK_IntegralToFloating: |
| 1893 | 1904 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToFloating"); |
| 1894 | 1905 | return nullptr; |
| 1895 | | case clang::CK_FixedPointCast: |
| 1906 | case ZigClangCK_FixedPointCast: |
| 1896 | 1907 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointCast"); |
| 1897 | 1908 | return nullptr; |
| 1898 | | case clang::CK_FixedPointToBoolean: |
| 1909 | case ZigClangCK_FixedPointToBoolean: |
| 1899 | 1910 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointToBoolean"); |
| 1900 | 1911 | return nullptr; |
| 1901 | | case clang::CK_FloatingToIntegral: |
| 1912 | case ZigClangCK_FloatingToIntegral: |
| 1902 | 1913 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToIntegral"); |
| 1903 | 1914 | return nullptr; |
| 1904 | | case clang::CK_FloatingToBoolean: |
| 1915 | case ZigClangCK_FloatingToBoolean: |
| 1905 | 1916 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToBoolean"); |
| 1906 | 1917 | return nullptr; |
| 1907 | | case clang::CK_BooleanToSignedIntegral: |
| 1918 | case ZigClangCK_BooleanToSignedIntegral: |
| 1908 | 1919 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BooleanToSignedIntegral"); |
| 1909 | 1920 | return nullptr; |
| 1910 | | case clang::CK_FloatingCast: |
| 1921 | case ZigClangCK_FloatingCast: |
| 1911 | 1922 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingCast"); |
| 1912 | 1923 | return nullptr; |
| 1913 | | case clang::CK_CPointerToObjCPointerCast: |
| 1924 | case ZigClangCK_CPointerToObjCPointerCast: |
| 1914 | 1925 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CPointerToObjCPointerCast"); |
| 1915 | 1926 | return nullptr; |
| 1916 | | case clang::CK_BlockPointerToObjCPointerCast: |
| 1927 | case ZigClangCK_BlockPointerToObjCPointerCast: |
| 1917 | 1928 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BlockPointerToObjCPointerCast"); |
| 1918 | 1929 | return nullptr; |
| 1919 | | case clang::CK_AnyPointerToBlockPointerCast: |
| 1930 | case ZigClangCK_AnyPointerToBlockPointerCast: |
| 1920 | 1931 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AnyPointerToBlockPointerCast"); |
| 1921 | 1932 | return nullptr; |
| 1922 | | case clang::CK_ObjCObjectLValueCast: |
| 1933 | case ZigClangCK_ObjCObjectLValueCast: |
| 1923 | 1934 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ObjCObjectLValueCast"); |
| 1924 | 1935 | return nullptr; |
| 1925 | | case clang::CK_FloatingRealToComplex: |
| 1936 | case ZigClangCK_FloatingRealToComplex: |
| 1926 | 1937 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingRealToComplex"); |
| 1927 | 1938 | return nullptr; |
| 1928 | | case clang::CK_FloatingComplexToReal: |
| 1939 | case ZigClangCK_FloatingComplexToReal: |
| 1929 | 1940 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToReal"); |
| 1930 | 1941 | return nullptr; |
| 1931 | | case clang::CK_FloatingComplexToBoolean: |
| 1942 | case ZigClangCK_FloatingComplexToBoolean: |
| 1932 | 1943 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToBoolean"); |
| 1933 | 1944 | return nullptr; |
| 1934 | | case clang::CK_FloatingComplexCast: |
| 1945 | case ZigClangCK_FloatingComplexCast: |
| 1935 | 1946 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexCast"); |
| 1936 | 1947 | return nullptr; |
| 1937 | | case clang::CK_FloatingComplexToIntegralComplex: |
| 1948 | case ZigClangCK_FloatingComplexToIntegralComplex: |
| 1938 | 1949 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToIntegralComplex"); |
| 1939 | 1950 | return nullptr; |
| 1940 | | case clang::CK_IntegralRealToComplex: |
| 1951 | case ZigClangCK_IntegralRealToComplex: |
| 1941 | 1952 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralRealToComplex"); |
| 1942 | 1953 | return nullptr; |
| 1943 | | case clang::CK_IntegralComplexToReal: |
| 1954 | case ZigClangCK_IntegralComplexToReal: |
| 1944 | 1955 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToReal"); |
| 1945 | 1956 | return nullptr; |
| 1946 | | case clang::CK_IntegralComplexToBoolean: |
| 1957 | case ZigClangCK_IntegralComplexToBoolean: |
| 1947 | 1958 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToBoolean"); |
| 1948 | 1959 | return nullptr; |
| 1949 | | case clang::CK_IntegralComplexCast: |
| 1960 | case ZigClangCK_IntegralComplexCast: |
| 1950 | 1961 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexCast"); |
| 1951 | 1962 | return nullptr; |
| 1952 | | case clang::CK_IntegralComplexToFloatingComplex: |
| 1963 | case ZigClangCK_IntegralComplexToFloatingComplex: |
| 1953 | 1964 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToFloatingComplex"); |
| 1954 | 1965 | return nullptr; |
| 1955 | | case clang::CK_ARCProduceObject: |
| 1966 | case ZigClangCK_ARCProduceObject: |
| 1956 | 1967 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCProduceObject"); |
| 1957 | 1968 | return nullptr; |
| 1958 | | case clang::CK_ARCConsumeObject: |
| 1969 | case ZigClangCK_ARCConsumeObject: |
| 1959 | 1970 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCConsumeObject"); |
| 1960 | 1971 | return nullptr; |
| 1961 | | case clang::CK_ARCReclaimReturnedObject: |
| 1972 | case ZigClangCK_ARCReclaimReturnedObject: |
| 1962 | 1973 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCReclaimReturnedObject"); |
| 1963 | 1974 | return nullptr; |
| 1964 | | case clang::CK_ARCExtendBlockObject: |
| 1975 | case ZigClangCK_ARCExtendBlockObject: |
| 1965 | 1976 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCExtendBlockObject"); |
| 1966 | 1977 | return nullptr; |
| 1967 | | case clang::CK_AtomicToNonAtomic: |
| 1978 | case ZigClangCK_AtomicToNonAtomic: |
| 1968 | 1979 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AtomicToNonAtomic"); |
| 1969 | 1980 | return nullptr; |
| 1970 | | case clang::CK_NonAtomicToAtomic: |
| 1981 | case ZigClangCK_NonAtomicToAtomic: |
| 1971 | 1982 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_NonAtomicToAtomic"); |
| 1972 | 1983 | return nullptr; |
| 1973 | | case clang::CK_CopyAndAutoreleaseBlockObject: |
| 1984 | case ZigClangCK_CopyAndAutoreleaseBlockObject: |
| 1974 | 1985 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CopyAndAutoreleaseBlockObject"); |
| 1975 | 1986 | return nullptr; |
| 1976 | | case clang::CK_BuiltinFnToFnPtr: |
| 1987 | case ZigClangCK_BuiltinFnToFnPtr: |
| 1977 | 1988 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BuiltinFnToFnPtr"); |
| 1978 | 1989 | return nullptr; |
| 1979 | | case clang::CK_ZeroToOCLOpaqueType: |
| 1990 | case ZigClangCK_ZeroToOCLOpaqueType: |
| 1980 | 1991 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ZeroToOCLOpaqueType"); |
| 1981 | 1992 | return nullptr; |
| 1982 | | case clang::CK_AddressSpaceConversion: |
| 1993 | case ZigClangCK_AddressSpaceConversion: |
| 1983 | 1994 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AddressSpaceConversion"); |
| 1984 | 1995 | return nullptr; |
| 1985 | | case clang::CK_IntToOCLSampler: |
| 1996 | case ZigClangCK_IntToOCLSampler: |
| 1986 | 1997 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntToOCLSampler"); |
| 1987 | 1998 | return nullptr; |
| 1988 | 1999 | } |
| ... | ... | @@ -2002,7 +2013,7 @@ static AstNode *trans_decl_ref_expr(Context *c, TransScope *scope, const clang:: |
| 2002 | 2013 | static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, TransScope *scope, |
| 2003 | 2014 | const clang::UnaryOperator *stmt, BinOpType assign_op) |
| 2004 | 2015 | { |
| 2005 | | clang::Expr *op_expr = stmt->getSubExpr(); |
| 2016 | const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr()); |
| 2006 | 2017 | |
| 2007 | 2018 | if (result_used == ResultUsedNo) { |
| 2008 | 2019 | // common case |
| ... | ... | @@ -2058,7 +2069,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr |
| 2058 | 2069 | static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, TransScope *scope, |
| 2059 | 2070 | const clang::UnaryOperator *stmt, BinOpType assign_op) |
| 2060 | 2071 | { |
| 2061 | | clang::Expr *op_expr = stmt->getSubExpr(); |
| 2072 | const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr()); |
| 2062 | 2073 | |
| 2063 | 2074 | if (result_used == ResultUsedNo) { |
| 2064 | 2075 | // common case |
| ... | ... | @@ -2129,14 +2140,14 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2129 | 2140 | return trans_create_pre_crement(c, result_used, scope, stmt, BinOpTypeAssignMinus); |
| 2130 | 2141 | case clang::UO_AddrOf: |
| 2131 | 2142 | { |
| 2132 | | AstNode *value_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), TransLValue); |
| 2143 | AstNode *value_node = trans_expr(c, result_used, scope, bitcast(stmt->getSubExpr()), TransLValue); |
| 2133 | 2144 | if (value_node == nullptr) |
| 2134 | 2145 | return value_node; |
| 2135 | 2146 | return trans_create_node_addr_of(c, value_node); |
| 2136 | 2147 | } |
| 2137 | 2148 | case clang::UO_Deref: |
| 2138 | 2149 | { |
| 2139 | | AstNode *value_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), TransRValue); |
| 2150 | AstNode *value_node = trans_expr(c, result_used, scope, bitcast(stmt->getSubExpr()), TransRValue); |
| 2140 | 2151 | if (value_node == nullptr) |
| 2141 | 2152 | return nullptr; |
| 2142 | 2153 | bool is_fn_ptr = qual_type_is_fn_ptr(bitcast(stmt->getSubExpr()->getType())); |
| ... | ... | @@ -2150,8 +2161,8 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2150 | 2161 | return nullptr; |
| 2151 | 2162 | case clang::UO_Minus: |
| 2152 | 2163 | { |
| 2153 | | clang::Expr *op_expr = stmt->getSubExpr(); |
| 2154 | | if (!qual_type_has_wrapping_overflow(c, bitcast(op_expr->getType()))) { |
| 2164 | const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr()); |
| 2165 | if (!qual_type_has_wrapping_overflow(c, ZigClangExpr_getType(op_expr))) { |
| 2155 | 2166 | AstNode *node = trans_create_node(c, NodeTypePrefixOpExpr); |
| 2156 | 2167 | node->data.prefix_op_expr.prefix_op = PrefixOpNegation; |
| 2157 | 2168 | |
| ... | ... | @@ -2160,7 +2171,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2160 | 2171 | return nullptr; |
| 2161 | 2172 | |
| 2162 | 2173 | return node; |
| 2163 | | } else if (c_is_unsigned_integer(c, bitcast(op_expr->getType()))) { |
| 2174 | } else if (c_is_unsigned_integer(c, ZigClangExpr_getType(op_expr))) { |
| 2164 | 2175 | // we gotta emit 0 -% x |
| 2165 | 2176 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 2166 | 2177 | node->data.bin_op_expr.op1 = trans_create_node_unsigned(c, 0); |
| ... | ... | @@ -2178,7 +2189,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2178 | 2189 | } |
| 2179 | 2190 | case clang::UO_Not: |
| 2180 | 2191 | { |
| 2181 | | clang::Expr *op_expr = stmt->getSubExpr(); |
| 2192 | const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr()); |
| 2182 | 2193 | AstNode *sub_node = trans_expr(c, ResultUsedYes, scope, op_expr, TransRValue); |
| 2183 | 2194 | if (sub_node == nullptr) |
| 2184 | 2195 | return nullptr; |
| ... | ... | @@ -2187,7 +2198,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2187 | 2198 | } |
| 2188 | 2199 | case clang::UO_LNot: |
| 2189 | 2200 | { |
| 2190 | | clang::Expr *op_expr = stmt->getSubExpr(); |
| 2201 | const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr()); |
| 2191 | 2202 | AstNode *sub_node = trans_bool_expr(c, ResultUsedYes, scope, op_expr, TransRValue); |
| 2192 | 2203 | if (sub_node == nullptr) |
| 2193 | 2204 | return nullptr; |
| ... | ... | @@ -2201,7 +2212,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 2201 | 2212 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Imag"); |
| 2202 | 2213 | return nullptr; |
| 2203 | 2214 | case clang::UO_Extension: |
| 2204 | | return trans_expr(c, result_used, scope, stmt->getSubExpr(), TransLValue); |
| 2215 | return trans_expr(c, result_used, scope, bitcast(stmt->getSubExpr()), TransLValue); |
| 2205 | 2216 | case clang::UO_Coawait: |
| 2206 | 2217 | emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Coawait"); |
| 2207 | 2218 | return nullptr; |
| ... | ... | @@ -2226,7 +2237,7 @@ static int trans_local_declaration(Context *c, TransScope *scope, const clang::D |
| 2226 | 2237 | ZigClangQualType qual_type = bitcast(var_decl->getTypeSourceInfo()->getType()); |
| 2227 | 2238 | AstNode *init_node = nullptr; |
| 2228 | 2239 | if (var_decl->hasInit()) { |
| 2229 | | init_node = trans_expr(c, ResultUsedYes, scope, var_decl->getInit(), TransRValue); |
| 2240 | init_node = trans_expr(c, ResultUsedYes, scope, bitcast(var_decl->getInit()), TransRValue); |
| 2230 | 2241 | if (init_node == nullptr) |
| 2231 | 2242 | return ErrorUnexpected; |
| 2232 | 2243 | |
| ... | ... | @@ -2492,7 +2503,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type) |
| 2492 | 2503 | return trans_create_node_bin_op(c, expr, BinOpTypeCmpNotEq, bitcast); |
| 2493 | 2504 | } |
| 2494 | 2505 | |
| 2495 | | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval) { |
| 2506 | static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr, TransLRValue lrval) { |
| 2496 | 2507 | AstNode *res = trans_expr(c, result_used, scope, expr, lrval); |
| 2497 | 2508 | if (res == nullptr) |
| 2498 | 2509 | return nullptr; |
| ... | ... | @@ -2689,7 +2700,7 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope * |
| 2689 | 2700 | switch (elaborated_ty->getKeyword()) { |
| 2690 | 2701 | case clang::ETK_Enum: { |
| 2691 | 2702 | AstNode *enum_type = trans_qual_type(c, bitcast(elaborated_ty->getNamedType()), |
| 2692 | | bitcast(expr->getBeginLoc())); |
| 2703 | ZigClangExpr_getBeginLoc(expr)); |
| 2693 | 2704 | return to_enum_zero_cmp(c, res, enum_type); |
| 2694 | 2705 | } |
| 2695 | 2706 | case clang::ETK_Struct: |
| ... | ... | @@ -2752,7 +2763,8 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope * |
| 2752 | 2763 | static AstNode *trans_while_loop(Context *c, TransScope *scope, const clang::WhileStmt *stmt) { |
| 2753 | 2764 | TransScopeWhile *while_scope = trans_scope_while_create(c, scope); |
| 2754 | 2765 | |
| 2755 | | while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, scope, stmt->getCond(), TransRValue); |
| 2766 | while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, scope, |
| 2767 | bitcast(stmt->getCond()), TransRValue); |
| 2756 | 2768 | if (while_scope->node->data.while_expr.condition == nullptr) |
| 2757 | 2769 | return nullptr; |
| 2758 | 2770 | |
| ... | ... | @@ -2779,7 +2791,8 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I |
| 2779 | 2791 | return nullptr; |
| 2780 | 2792 | } |
| 2781 | 2793 | |
| 2782 | | if_node->data.if_bool_expr.condition = trans_bool_expr(c, ResultUsedYes, scope, stmt->getCond(), TransRValue); |
| 2794 | if_node->data.if_bool_expr.condition = trans_bool_expr(c, ResultUsedYes, scope, bitcast(stmt->getCond()), |
| 2795 | TransRValue); |
| 2783 | 2796 | if (if_node->data.if_bool_expr.condition == nullptr) |
| 2784 | 2797 | return nullptr; |
| 2785 | 2798 | |
| ... | ... | @@ -2789,7 +2802,7 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I |
| 2789 | 2802 | static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::CallExpr *stmt) { |
| 2790 | 2803 | AstNode *node = trans_create_node(c, NodeTypeFnCallExpr); |
| 2791 | 2804 | |
| 2792 | | AstNode *callee_raw_node = trans_expr(c, ResultUsedYes, scope, stmt->getCallee(), TransRValue); |
| 2805 | AstNode *callee_raw_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getCallee()), TransRValue); |
| 2793 | 2806 | if (callee_raw_node == nullptr) |
| 2794 | 2807 | return nullptr; |
| 2795 | 2808 | |
| ... | ... | @@ -2799,7 +2812,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope * |
| 2799 | 2812 | if (is_ptr && fn_ty) { |
| 2800 | 2813 | if ((ZigClangStmtClass)stmt->getCallee()->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) { |
| 2801 | 2814 | const clang::ImplicitCastExpr *implicit_cast = static_cast<const clang::ImplicitCastExpr *>(stmt->getCallee()); |
| 2802 | | if (implicit_cast->getCastKind() == clang::CK_FunctionToPointerDecay) { |
| 2815 | if ((ZigClangCK)implicit_cast->getCastKind() == ZigClangCK_FunctionToPointerDecay) { |
| 2803 | 2816 | if ((ZigClangStmtClass)implicit_cast->getSubExpr()->getStmtClass() == ZigClangStmt_DeclRefExprClass) { |
| 2804 | 2817 | const clang::DeclRefExpr *decl_ref = static_cast<const clang::DeclRefExpr *>(implicit_cast->getSubExpr()); |
| 2805 | 2818 | const clang::Decl *decl = decl_ref->getFoundDecl(); |
| ... | ... | @@ -2819,7 +2832,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope * |
| 2819 | 2832 | node->data.fn_call_expr.fn_ref_expr = callee_node; |
| 2820 | 2833 | |
| 2821 | 2834 | unsigned num_args = stmt->getNumArgs(); |
| 2822 | | const clang::Expr * const* args = stmt->getArgs(); |
| 2835 | const ZigClangExpr * const* args = reinterpret_cast<const ZigClangExpr * const*>(stmt->getArgs()); |
| 2823 | 2836 | for (unsigned i = 0; i < num_args; i += 1) { |
| 2824 | 2837 | AstNode *arg_node = trans_expr(c, ResultUsedYes, scope, args[i], TransRValue); |
| 2825 | 2838 | if (arg_node == nullptr) |
| ... | ... | @@ -2840,7 +2853,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope * |
| 2840 | 2853 | static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope *scope, |
| 2841 | 2854 | const clang::MemberExpr *stmt) |
| 2842 | 2855 | { |
| 2843 | | AstNode *container_node = trans_expr(c, ResultUsedYes, scope, stmt->getBase(), TransRValue); |
| 2856 | AstNode *container_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getBase()), TransRValue); |
| 2844 | 2857 | if (container_node == nullptr) |
| 2845 | 2858 | return nullptr; |
| 2846 | 2859 | |
| ... | ... | @@ -2855,11 +2868,11 @@ static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope |
| 2855 | 2868 | } |
| 2856 | 2869 | |
| 2857 | 2870 | static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ArraySubscriptExpr *stmt) { |
| 2858 | | AstNode *container_node = trans_expr(c, ResultUsedYes, scope, stmt->getBase(), TransRValue); |
| 2871 | AstNode *container_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getBase()), TransRValue); |
| 2859 | 2872 | if (container_node == nullptr) |
| 2860 | 2873 | return nullptr; |
| 2861 | 2874 | |
| 2862 | | AstNode *idx_node = trans_expr(c, ResultUsedYes, scope, stmt->getIdx(), TransRValue); |
| 2875 | AstNode *idx_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getIdx()), TransRValue); |
| 2863 | 2876 | if (idx_node == nullptr) |
| 2864 | 2877 | return nullptr; |
| 2865 | 2878 | |
| ... | ... | @@ -2873,7 +2886,7 @@ static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, T |
| 2873 | 2886 | static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, TransScope *scope, |
| 2874 | 2887 | const clang::CStyleCastExpr *stmt, TransLRValue lrvalue) |
| 2875 | 2888 | { |
| 2876 | | AstNode *sub_expr_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), lrvalue); |
| 2889 | AstNode *sub_expr_node = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), lrvalue); |
| 2877 | 2890 | if (sub_expr_node == nullptr) |
| 2878 | 2891 | return nullptr; |
| 2879 | 2892 | |
| ... | ... | @@ -2943,7 +2956,7 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const clang: |
| 2943 | 2956 | } |
| 2944 | 2957 | |
| 2945 | 2958 | // if (!cond) break; |
| 2946 | | AstNode *condition_node = trans_expr(c, ResultUsedYes, child_scope, stmt->getCond(), TransRValue); |
| 2959 | AstNode *condition_node = trans_expr(c, ResultUsedYes, child_scope, bitcast(stmt->getCond()), TransRValue); |
| 2947 | 2960 | if (condition_node == nullptr) return nullptr; |
| 2948 | 2961 | AstNode *terminator_node = trans_create_node(c, NodeTypeIfBoolExpr); |
| 2949 | 2962 | terminator_node->data.if_bool_expr.condition = trans_create_node_prefix_op(c, PrefixOpBoolNot, condition_node); |
| ... | ... | @@ -2982,29 +2995,21 @@ static AstNode *trans_for_loop(Context *c, TransScope *parent_scope, const clang |
| 2982 | 2995 | child_scope->node->data.block.statements.append(while_scope->node); |
| 2983 | 2996 | } |
| 2984 | 2997 | |
| 2985 | | const ZigClangStmt *cond_stmt = bitcast(stmt->getCond()); |
| 2986 | | if (cond_stmt == nullptr) { |
| 2998 | const ZigClangExpr *cond_expr = bitcast(stmt->getCond()); |
| 2999 | if (cond_expr == nullptr) { |
| 2987 | 3000 | while_scope->node->data.while_expr.condition = trans_create_node_bool(c, true); |
| 2988 | 3001 | } else { |
| 2989 | | if (ZigClangStmt_classof_Expr(cond_stmt)) { |
| 2990 | | const clang::Expr *cond_expr = reinterpret_cast<const clang::Expr*>(cond_stmt); |
| 2991 | | while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, cond_scope, cond_expr, TransRValue); |
| 3002 | while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, cond_scope, |
| 3003 | cond_expr, TransRValue); |
| 2992 | 3004 | |
| 2993 | | if (while_scope->node->data.while_expr.condition == nullptr) |
| 2994 | | return nullptr; |
| 2995 | | } else { |
| 2996 | | TransScope *end_cond_scope = trans_stmt(c, cond_scope, cond_stmt, |
| 2997 | | &while_scope->node->data.while_expr.condition); |
| 2998 | | if (end_cond_scope == nullptr) |
| 2999 | | return nullptr; |
| 3000 | | } |
| 3005 | if (while_scope->node->data.while_expr.condition == nullptr) |
| 3006 | return nullptr; |
| 3001 | 3007 | } |
| 3002 | 3008 | |
| 3003 | | const ZigClangStmt *inc_stmt = bitcast(stmt->getInc()); |
| 3004 | | if (inc_stmt != nullptr) { |
| 3005 | | AstNode *inc_node; |
| 3006 | | TransScope *inc_scope = trans_stmt(c, cond_scope, inc_stmt, &inc_node); |
| 3007 | | if (inc_scope == nullptr) |
| 3009 | const ZigClangExpr *inc_expr = bitcast(stmt->getInc()); |
| 3010 | if (inc_expr != nullptr) { |
| 3011 | AstNode *inc_node = trans_expr(c, ResultUsedNo, cond_scope, inc_expr, TransRValue); |
| 3012 | if (inc_node == nullptr) |
| 3008 | 3013 | return nullptr; |
| 3009 | 3014 | while_scope->node->data.while_expr.continue_expr = inc_node; |
| 3010 | 3015 | } |
| ... | ... | @@ -3047,7 +3052,7 @@ static AstNode *trans_switch_stmt(Context *c, TransScope *parent_scope, const cl |
| 3047 | 3052 | switch_scope->end_label_name = end_label_name; |
| 3048 | 3053 | block_scope->node->data.block.name = end_label_name; |
| 3049 | 3054 | |
| 3050 | | const clang::Expr *cond_expr = stmt->getCond(); |
| 3055 | const ZigClangExpr *cond_expr = bitcast(stmt->getCond()); |
| 3051 | 3056 | assert(cond_expr != nullptr); |
| 3052 | 3057 | |
| 3053 | 3058 | AstNode *expr_node = trans_expr(c, ResultUsedYes, &block_scope->base, cond_expr, TransRValue); |
| ... | ... | @@ -3108,7 +3113,7 @@ static int trans_switch_case(Context *c, TransScope *parent_scope, const clang:: |
| 3108 | 3113 | { |
| 3109 | 3114 | // Add the prong |
| 3110 | 3115 | AstNode *prong_node = trans_create_node(c, NodeTypeSwitchProng); |
| 3111 | | AstNode *item_node = trans_expr(c, ResultUsedYes, &switch_scope->base, stmt->getLHS(), TransRValue); |
| 3116 | AstNode *item_node = trans_expr(c, ResultUsedYes, &switch_scope->base, bitcast(stmt->getLHS()), TransRValue); |
| 3112 | 3117 | if (item_node == nullptr) |
| 3113 | 3118 | return ErrorUnexpected; |
| 3114 | 3119 | prong_node->data.switch_prong.items.append(item_node); |
| ... | ... | @@ -3313,7 +3318,8 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s |
| 3313 | 3318 | trans_continue_stmt(c, scope, (const clang::ContinueStmt *)stmt)); |
| 3314 | 3319 | case ZigClangStmt_ParenExprClass: |
| 3315 | 3320 | return wrap_stmt(out_node, out_child_scope, scope, |
| 3316 | | trans_expr(c, result_used, scope, ((const clang::ParenExpr*)stmt)->getSubExpr(), lrvalue)); |
| 3321 | trans_expr(c, result_used, scope, |
| 3322 | bitcast(((const clang::ParenExpr*)stmt)->getSubExpr()), lrvalue)); |
| 3317 | 3323 | case ZigClangStmt_SwitchStmtClass: |
| 3318 | 3324 | return wrap_stmt(out_node, out_child_scope, scope, |
| 3319 | 3325 | trans_switch_stmt(c, scope, (const clang::SwitchStmt *)stmt)); |
| ... | ... | @@ -3836,7 +3842,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s |
| 3836 | 3842 | } |
| 3837 | 3843 | |
| 3838 | 3844 | // Returns null if there was an error |
| 3839 | | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, |
| 3845 | static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr, |
| 3840 | 3846 | TransLRValue lrval) |
| 3841 | 3847 | { |
| 3842 | 3848 | AstNode *result_node; |
| ... | ... | @@ -4304,7 +4310,7 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua |
| 4304 | 4310 | case clang::APValue::LValue: { |
| 4305 | 4311 | const clang::APValue::LValueBase lval_base = ap_value->getLValueBase(); |
| 4306 | 4312 | if (const clang::Expr *expr = lval_base.dyn_cast<const clang::Expr *>()) { |
| 4307 | | return trans_expr(c, ResultUsedYes, &c->global_scope->base, expr, TransRValue); |
| 4313 | return trans_expr(c, ResultUsedYes, &c->global_scope->base, bitcast(expr), TransRValue); |
| 4308 | 4314 | } |
| 4309 | 4315 | //const clang::ValueDecl *value_decl = lval_base.get<const clang::ValueDecl *>(); |
| 4310 | 4316 | emit_warning(c, source_loc, "TODO handle initializer LValue clang::ValueDecl"); |