authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-15 00:32:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-15 00:32:27-04:00
log5cb18e9c6f5ee49541579ba3e45d9de4fcec8bcb
tree1ab15408d340a7656ab3a6fbbfc4c2f1322c5d7c
parentcc8cf94cb275198f06e6f7456b366f98d0710373
signaturelock-open Commit is signed but in an unrecognized format.

translate-c: move some code to the C API

See #1964

3 files changed, 387 insertions(+), 234 deletions(-)

src/translate_c.cpp+182-176
...@@ -121,15 +121,20 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s...@@ -121,15 +121,20 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s
121 AstNode **out_node, TransScope **out_child_scope,121 AstNode **out_node, TransScope **out_child_scope,
122 TransScope **out_node_scope);122 TransScope **out_node_scope);
123static TransScope *trans_stmt(Context *c, TransScope *scope, const ZigClangStmt *stmt, AstNode **out_node);123static TransScope *trans_stmt(Context *c, TransScope *scope, const ZigClangStmt *stmt, AstNode **out_node);
124static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval);124static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr, TransLRValue lrval);
125static AstNode *trans_qual_type(Context *c, ZigClangQualType qt, ZigClangSourceLocation source_loc);125static AstNode *trans_qual_type(Context *c, ZigClangQualType qt, ZigClangSourceLocation source_loc);
126static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval);126static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope,
127 const ZigClangExpr *expr, TransLRValue lrval);
127static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQualType qt, ZigClangSourceLocation source_loc);128static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQualType qt, ZigClangSourceLocation source_loc);
128129
129static const ZigClangStmt *bitcast(const clang::Stmt *src) {130static const ZigClangStmt *bitcast(const clang::Stmt *src) {
130 return reinterpret_cast<const ZigClangStmt *>(src);131 return reinterpret_cast<const ZigClangStmt *>(src);
131}132}
132133
134static const ZigClangExpr *bitcast(const clang::Expr *src) {
135 return reinterpret_cast<const ZigClangExpr *>(src);
136}
137
133static ZigClangSourceLocation bitcast(clang::SourceLocation src) {138static ZigClangSourceLocation bitcast(clang::SourceLocation src) {
134 ZigClangSourceLocation dest;139 ZigClangSourceLocation dest;
135 memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangSourceLocation));140 memcpy(&dest, static_cast<void *>(&src), sizeof(ZigClangSourceLocation));
...@@ -511,14 +516,14 @@ static const ZigClangType *qual_type_canon(ZigClangQualType qt) {...@@ -511,14 +516,14 @@ static const ZigClangType *qual_type_canon(ZigClangQualType qt) {
511 return ZigClangQualType_getTypePtr(canon);516 return ZigClangQualType_getTypePtr(canon);
512}517}
513518
514static ZigClangQualType get_expr_qual_type(Context *c, const clang::Expr *expr) {519static ZigClangQualType get_expr_qual_type(Context *c, const ZigClangExpr *expr) {
515 // String literals in C are `char *` but they should really be `const char *`.520 // String literals in C are `char *` but they should really be `const char *`.
516 if ((ZigClangStmtClass)expr->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) {521 if (ZigClangExpr_getStmtClass(expr) == ZigClangStmt_ImplicitCastExprClass) {
517 const clang::ImplicitCastExpr *cast_expr = static_cast<const clang::ImplicitCastExpr *>(expr);522 const clang::ImplicitCastExpr *cast_expr = reinterpret_cast<const clang::ImplicitCastExpr *>(expr);
518 if (cast_expr->getCastKind() == clang::CK_ArrayToPointerDecay) {523 if ((ZigClangCK)cast_expr->getCastKind() == ZigClangCK_ArrayToPointerDecay) {
519 const clang::Expr *sub_expr = cast_expr->getSubExpr();524 const ZigClangExpr *sub_expr = bitcast(cast_expr->getSubExpr());
520 if ((ZigClangStmtClass)sub_expr->getStmtClass() == ZigClangStmt_StringLiteralClass) {525 if (ZigClangExpr_getStmtClass(sub_expr) == ZigClangStmt_StringLiteralClass) {
521 ZigClangQualType array_qt = bitcast(sub_expr->getType());526 ZigClangQualType array_qt = ZigClangExpr_getType(sub_expr);
522 const clang::ArrayType *array_type = reinterpret_cast<const clang::ArrayType *>(527 const clang::ArrayType *array_type = reinterpret_cast<const clang::ArrayType *>(
523 ZigClangQualType_getTypePtr(array_qt));528 ZigClangQualType_getTypePtr(array_qt));
524 ZigClangQualType pointee_qt = bitcast(array_type->getElementType());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,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}
532537
533static ZigClangQualType get_expr_qual_type_before_implicit_cast(Context *c, const clang::Expr *expr) {538static ZigClangQualType get_expr_qual_type_before_implicit_cast(Context *c, const ZigClangExpr *expr) {
534 if ((ZigClangStmtClass)expr->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) {539 if (ZigClangExpr_getStmtClass(expr) == ZigClangStmt_ImplicitCastExprClass) {
535 const clang::ImplicitCastExpr *cast_expr = static_cast<const clang::ImplicitCastExpr *>(expr);540 const clang::ImplicitCastExpr *cast_expr = reinterpret_cast<const clang::ImplicitCastExpr *>(expr);
536 return get_expr_qual_type(c, cast_expr->getSubExpr());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}
540545
541static AstNode *get_expr_type(Context *c, const clang::Expr *expr) {546static AstNode *get_expr_type(Context *c, const ZigClangExpr *expr) {
542 return trans_qual_type(c, get_expr_qual_type(c, expr), bitcast(expr->getBeginLoc()));547 return trans_qual_type(c, get_expr_qual_type(c, expr), ZigClangExpr_getBeginLoc(expr));
543}548}
544549
545static bool is_c_void_type(AstNode *node) {550static bool is_c_void_type(AstNode *node) {
546 return (node->type == NodeTypeSymbol && buf_eql_str(node->data.symbol_expr.symbol, "c_void"));551 return (node->type == NodeTypeSymbol && buf_eql_str(node->data.symbol_expr.symbol, "c_void"));
547}552}
548553
549static bool expr_types_equal(Context *c, const clang::Expr *expr1, const clang::Expr *expr2) {554static bool expr_types_equal(Context *c, const ZigClangExpr *expr1, const ZigClangExpr *expr2) {
550 ZigClangQualType t1 = get_expr_qual_type(c, expr1);555 ZigClangQualType t1 = get_expr_qual_type(c, expr1);
551 ZigClangQualType t2 = get_expr_qual_type(c, expr2);556 ZigClangQualType t2 = get_expr_qual_type(c, expr2);
552557
...@@ -1272,7 +1277,7 @@ static AstNode *trans_stmt_expr(Context *c, ResultUsed result_used, TransScope *...@@ -1272,7 +1277,7 @@ static AstNode *trans_stmt_expr(Context *c, ResultUsed result_used, TransScope *
1272}1277}
12731278
1274static AstNode *trans_return_stmt(Context *c, TransScope *scope, const clang::ReturnStmt *stmt) {1279static 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 if (value_expr == nullptr) {1281 if (value_expr == nullptr) {
1277 return trans_create_node(c, NodeTypeReturnExpr);1282 return trans_create_node(c, NodeTypeReturnExpr);
1278 } else {1283 } else {
...@@ -1311,9 +1316,9 @@ static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, T...@@ -1311,9 +1316,9 @@ static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, T
1311{1316{
1312 AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr);1317 AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr);
13131318
1314 clang::Expr *cond_expr = stmt->getCond();1319 const ZigClangExpr *cond_expr = bitcast(stmt->getCond());
1315 clang::Expr *true_expr = stmt->getTrueExpr();1320 const ZigClangExpr *true_expr = bitcast(stmt->getTrueExpr());
1316 clang::Expr *false_expr = stmt->getFalseExpr();1321 const ZigClangExpr *false_expr = bitcast(stmt->getFalseExpr());
13171322
1318 node->data.if_bool_expr.condition = trans_expr(c, ResultUsedYes, scope, cond_expr, TransRValue);1323 node->data.if_bool_expr.condition = trans_expr(c, ResultUsedYes, scope, cond_expr, TransRValue);
1319 if (node->data.if_bool_expr.condition == nullptr)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,7 +1335,9 @@ static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, T
1330 return maybe_suppress_result(c, result_used, node);1335 return maybe_suppress_result(c, result_used, node);
1331}1336}
13321337
1333static AstNode *trans_create_bin_op(Context *c, TransScope *scope, clang::Expr *lhs, BinOpType bin_op, clang::Expr *rhs) {1338static AstNode *trans_create_bin_op(Context *c, TransScope *scope, const ZigClangExpr *lhs,
1339 BinOpType bin_op, const ZigClangExpr *rhs)
1340{
1334 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);1341 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
1335 node->data.bin_op_expr.bin_op = bin_op;1342 node->data.bin_op_expr.bin_op = bin_op;
13361343
...@@ -1345,7 +1352,9 @@ static AstNode *trans_create_bin_op(Context *c, TransScope *scope, clang::Expr *...@@ -1345,7 +1352,9 @@ static AstNode *trans_create_bin_op(Context *c, TransScope *scope, clang::Expr *
1345 return node;1352 return node;
1346}1353}
13471354
1348static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, clang::Expr *lhs, BinOpType bin_op, clang::Expr *rhs) {1355static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, const ZigClangExpr *lhs,
1356 BinOpType bin_op, const ZigClangExpr *rhs)
1357{
1349 assert(bin_op == BinOpTypeBoolAnd || bin_op == BinOpTypeBoolOr);1358 assert(bin_op == BinOpTypeBoolAnd || bin_op == BinOpTypeBoolOr);
1350 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);1359 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
1351 node->data.bin_op_expr.bin_op = bin_op;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,7 +1370,9 @@ static AstNode *trans_create_bool_bin_op(Context *c, TransScope *scope, clang::E
1361 return node;1370 return node;
1362}1371}
13631372
1364static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransScope *scope, clang::Expr *lhs, clang::Expr *rhs) {1373static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransScope *scope,
1374 const ZigClangExpr *lhs, const ZigClangExpr *rhs)
1375{
1365 if (result_used == ResultUsedNo) {1376 if (result_used == ResultUsedNo) {
1366 // common case1377 // common case
1367 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);1378 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
...@@ -1413,9 +1424,9 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco...@@ -1413,9 +1424,9 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco
1413}1424}
14141425
1415static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQualType result_type,1426static 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 AstNode *rhs_type = qual_type_to_log2_int_ref(c, result_type, rhs_location);1430 AstNode *rhs_type = qual_type_to_log2_int_ref(c, result_type, rhs_location);
1420 // lhs >> u5(rh)1431 // lhs >> u5(rh)
14211432
...@@ -1441,23 +1452,23 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS...@@ -1441,23 +1452,23 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
1441 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle more C binary operators: BO_Cmp");1452 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle more C binary operators: BO_Cmp");
1442 return nullptr;1453 return nullptr;
1443 case clang::BO_Mul: {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 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeMultWrap : BinOpTypeMult,1456 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeMultWrap : BinOpTypeMult,
1446 stmt->getRHS());1457 bitcast(stmt->getRHS()));
1447 return maybe_suppress_result(c, result_used, node);1458 return maybe_suppress_result(c, result_used, node);
1448 }1459 }
1449 case clang::BO_Div:1460 case clang::BO_Div:
1450 if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) {1461 if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) {
1451 // unsigned/float division uses the operator1462 // 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 return maybe_suppress_result(c, result_used, node);1464 return maybe_suppress_result(c, result_used, node);
1454 } else {1465 } else {
1455 // signed integer division uses @divTrunc1466 // signed integer division uses @divTrunc
1456 AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "divTrunc");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 if (lhs == nullptr) return nullptr;1469 if (lhs == nullptr) return nullptr;
1459 fn_call->data.fn_call_expr.params.append(lhs);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 if (rhs == nullptr) return nullptr;1472 if (rhs == nullptr) return nullptr;
1462 fn_call->data.fn_call_expr.params.append(rhs);1473 fn_call->data.fn_call_expr.params.append(rhs);
1463 return maybe_suppress_result(c, result_used, fn_call);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,97 +1476,97 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
1465 case clang::BO_Rem:1476 case clang::BO_Rem:
1466 if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) {1477 if (qual_type_has_wrapping_overflow(c, bitcast(stmt->getType()))) {
1467 // unsigned/float division uses the operator1478 // 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 return maybe_suppress_result(c, result_used, node);1480 return maybe_suppress_result(c, result_used, node);
1470 } else {1481 } else {
1471 // signed integer division uses @rem1482 // signed integer division uses @rem
1472 AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "rem");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 if (lhs == nullptr) return nullptr;1485 if (lhs == nullptr) return nullptr;
1475 fn_call->data.fn_call_expr.params.append(lhs);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 if (rhs == nullptr) return nullptr;1488 if (rhs == nullptr) return nullptr;
1478 fn_call->data.fn_call_expr.params.append(rhs);1489 fn_call->data.fn_call_expr.params.append(rhs);
1479 return maybe_suppress_result(c, result_used, fn_call);1490 return maybe_suppress_result(c, result_used, fn_call);
1480 }1491 }
1481 case clang::BO_Add: {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 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeAddWrap : BinOpTypeAdd,1494 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeAddWrap : BinOpTypeAdd,
1484 stmt->getRHS());1495 bitcast(stmt->getRHS()));
1485 return maybe_suppress_result(c, result_used, node);1496 return maybe_suppress_result(c, result_used, node);
1486 }1497 }
1487 case clang::BO_Sub: {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 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeSubWrap : BinOpTypeSub,1500 qual_type_has_wrapping_overflow(c, bitcast(stmt->getType())) ? BinOpTypeSubWrap : BinOpTypeSub,
1490 stmt->getRHS());1501 bitcast(stmt->getRHS()));
1491 return maybe_suppress_result(c, result_used, node);1502 return maybe_suppress_result(c, result_used, node);
1492 }1503 }
1493 case clang::BO_Shl: {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 return maybe_suppress_result(c, result_used, node);1506 return maybe_suppress_result(c, result_used, node);
1496 }1507 }
1497 case clang::BO_Shr: {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 return maybe_suppress_result(c, result_used, node);1510 return maybe_suppress_result(c, result_used, node);
1500 }1511 }
1501 case clang::BO_LT: {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 return maybe_suppress_result(c, result_used, node);1514 return maybe_suppress_result(c, result_used, node);
1504 }1515 }
1505 case clang::BO_GT: {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 return maybe_suppress_result(c, result_used, node);1518 return maybe_suppress_result(c, result_used, node);
1508 }1519 }
1509 case clang::BO_LE: {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 return maybe_suppress_result(c, result_used, node);1522 return maybe_suppress_result(c, result_used, node);
1512 }1523 }
1513 case clang::BO_GE: {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 return maybe_suppress_result(c, result_used, node);1526 return maybe_suppress_result(c, result_used, node);
1516 }1527 }
1517 case clang::BO_EQ: {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 return maybe_suppress_result(c, result_used, node);1530 return maybe_suppress_result(c, result_used, node);
1520 }1531 }
1521 case clang::BO_NE: {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 return maybe_suppress_result(c, result_used, node);1534 return maybe_suppress_result(c, result_used, node);
1524 }1535 }
1525 case clang::BO_And: {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 return maybe_suppress_result(c, result_used, node);1538 return maybe_suppress_result(c, result_used, node);
1528 }1539 }
1529 case clang::BO_Xor: {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 return maybe_suppress_result(c, result_used, node);1542 return maybe_suppress_result(c, result_used, node);
1532 }1543 }
1533 case clang::BO_Or: {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 return maybe_suppress_result(c, result_used, node);1546 return maybe_suppress_result(c, result_used, node);
1536 }1547 }
1537 case clang::BO_LAnd: {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 return maybe_suppress_result(c, result_used, node);1550 return maybe_suppress_result(c, result_used, node);
1540 }1551 }
1541 case clang::BO_LOr: {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 return maybe_suppress_result(c, result_used, node);1554 return maybe_suppress_result(c, result_used, node);
1544 }1555 }
1545 case clang::BO_Assign: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 case clang::BO_Comma:1558 case clang::BO_Comma:
1548 {1559 {
1549 TransScopeBlock *scope_block = trans_scope_block_create(c, scope);1560 TransScopeBlock *scope_block = trans_scope_block_create(c, scope);
1550 Buf *label_name = buf_create_from_str("x");1561 Buf *label_name = buf_create_from_str("x");
1551 scope_block->node->data.block.name = label_name;1562 scope_block->node->data.block.name = label_name;
15521563
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 if (lhs == nullptr)1565 if (lhs == nullptr)
1555 return nullptr;1566 return nullptr;
1556 scope_block->node->data.block.statements.append(lhs);1567 scope_block->node->data.block.statements.append(lhs);
15571568
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 if (rhs == nullptr)1570 if (rhs == nullptr)
1560 return nullptr;1571 return nullptr;
15611572
...@@ -1589,10 +1600,10 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result...@@ -1589,10 +1600,10 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
1589 if (!use_intermediate_casts && result_used == ResultUsedNo) {1600 if (!use_intermediate_casts && result_used == ResultUsedNo) {
1590 // simple common case, where the C and Zig are identical:1601 // simple common case, where the C and Zig are identical:
1591 // lhs >>= rhs1602 // 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 if (lhs == nullptr) return nullptr;1604 if (lhs == nullptr) return nullptr;
15941605
1595 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransRValue);1606 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getRHS()), TransRValue);
1596 if (rhs == nullptr) return nullptr;1607 if (rhs == nullptr) return nullptr;
1597 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);1608 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
15981609
...@@ -1612,7 +1623,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result...@@ -1612,7 +1623,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
1612 child_scope->node->data.block.name = label_name;1623 child_scope->node->data.block.name = label_name;
16131624
1614 // const _ref = &lhs;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 if (lhs == nullptr) return nullptr;1627 if (lhs == nullptr) return nullptr;
1617 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);1628 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
1618 // TODO: avoid name collisions with generated variable names1629 // TODO: avoid name collisions with generated variable names
...@@ -1622,7 +1633,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result...@@ -1622,7 +1633,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
16221633
1623 // *_ref = result_type(operation_type(*_ref) >> u5(rhs));1634 // *_ref = result_type(operation_type(*_ref) >> u5(rhs));
16241635
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 if (rhs == nullptr) return nullptr;1637 if (rhs == nullptr) return nullptr;
1627 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);1638 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
16281639
...@@ -1667,9 +1678,9 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,...@@ -1667,9 +1678,9 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
1667 if (result_used == ResultUsedNo) {1678 if (result_used == ResultUsedNo) {
1668 // simple common case, where the C and Zig are identical:1679 // simple common case, where the C and Zig are identical:
1669 // lhs += rhs1680 // 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 if (lhs == nullptr) return nullptr;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 if (rhs == nullptr) return nullptr;1684 if (rhs == nullptr) return nullptr;
1674 return trans_create_node_bin_op(c, lhs, assign_op, rhs);1685 return trans_create_node_bin_op(c, lhs, assign_op, rhs);
1675 } else {1686 } else {
...@@ -1686,7 +1697,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,...@@ -1686,7 +1697,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
1686 child_scope->node->data.block.name = label_name;1697 child_scope->node->data.block.name = label_name;
16871698
1688 // const _ref = &lhs;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 if (lhs == nullptr) return nullptr;1701 if (lhs == nullptr) return nullptr;
1691 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);1702 AstNode *addr_of_lhs = trans_create_node_addr_of(c, lhs);
1692 // TODO: avoid name collisions with generated variable names1703 // TODO: avoid name collisions with generated variable names
...@@ -1696,7 +1707,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,...@@ -1696,7 +1707,7 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
16961707
1697 // *_ref = *_ref + rhs;1708 // *_ref = *_ref + rhs;
16981709
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 if (rhs == nullptr) return nullptr;1711 if (rhs == nullptr) return nullptr;
17011712
1702 AstNode *assign_statement = trans_create_node_bin_op(c,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,201 +1799,201 @@ static AstNode *trans_compound_assign_operator(Context *c, ResultUsed result_use
1788}1799}
17891800
1790static AstNode *trans_implicit_cast_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ImplicitCastExpr *stmt) {1801static AstNode *trans_implicit_cast_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ImplicitCastExpr *stmt) {
1791 switch (stmt->getCastKind()) {1802 switch ((ZigClangCK)stmt->getCastKind()) {
1792 case clang::CK_LValueToRValue:1803 case ZigClangCK_LValueToRValue:
1793 return trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue);1804 return trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue);
1794 case clang::CK_IntegralCast: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 if (target_node == nullptr)1808 if (target_node == nullptr)
1798 return nullptr;1809 return nullptr;
1799 AstNode *node = trans_c_cast(c, bitcast(stmt->getExprLoc()), bitcast(stmt->getType()),1810 AstNode *node = trans_c_cast(c, bitcast(stmt->getExprLoc()), bitcast(stmt->getType()),
1800 bitcast(stmt->getSubExpr()->getType()), target_node);1811 bitcast(stmt->getSubExpr()->getType()), target_node);
1801 return maybe_suppress_result(c, result_used, node);1812 return maybe_suppress_result(c, result_used, node);
1802 }1813 }
1803 case clang::CK_FunctionToPointerDecay:1814 case ZigClangCK_FunctionToPointerDecay:
1804 case clang::CK_ArrayToPointerDecay: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 if (target_node == nullptr)1818 if (target_node == nullptr)
1808 return nullptr;1819 return nullptr;
1809 return maybe_suppress_result(c, result_used, target_node);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 if (target_node == nullptr)1825 if (target_node == nullptr)
1815 return nullptr;1826 return nullptr;
18161827
1817 if (expr_types_equal(c, stmt, stmt->getSubExpr())) {1828 if (expr_types_equal(c, (const ZigClangExpr *)stmt, bitcast(stmt->getSubExpr()))) {
1818 return target_node;1829 return target_node;
1819 }1830 }
18201831
1821 AstNode *dest_type_node = get_expr_type(c, stmt);1832 AstNode *dest_type_node = get_expr_type(c, (const ZigClangExpr *)stmt);
18221833
1823 AstNode *node = trans_create_node_builtin_fn_call_str(c, "ptrCast");1834 AstNode *node = trans_create_node_builtin_fn_call_str(c, "ptrCast");
1824 node->data.fn_call_expr.params.append(dest_type_node);1835 node->data.fn_call_expr.params.append(dest_type_node);
1825 node->data.fn_call_expr.params.append(target_node);1836 node->data.fn_call_expr.params.append(target_node);
1826 return maybe_suppress_result(c, result_used, node);1837 return maybe_suppress_result(c, result_used, node);
1827 }1838 }
1828 case clang::CK_NullToPointer:1839 case ZigClangCK_NullToPointer:
1829 return trans_create_node_unsigned(c, 0);1840 return trans_create_node_unsigned(c, 0);
1830 case clang::CK_NoOp:1841 case ZigClangCK_NoOp:
1831 return trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue);1842 return trans_expr(c, ResultUsedYes, scope, bitcast(stmt->getSubExpr()), TransRValue);
1832 case clang::CK_Dependent:1843 case ZigClangCK_Dependent:
1833 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dependent");1844 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dependent");
1834 return nullptr;1845 return nullptr;
1835 case clang::CK_LValueBitCast:1846 case ZigClangCK_LValueBitCast:
1836 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_LValueBitCast");1847 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_LValueBitCast");
1837 return nullptr;1848 return nullptr;
1838 case clang::CK_BaseToDerived:1849 case ZigClangCK_BaseToDerived:
1839 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerived");1850 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerived");
1840 return nullptr;1851 return nullptr;
1841 case clang::CK_DerivedToBase:1852 case ZigClangCK_DerivedToBase:
1842 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBase");1853 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBase");
1843 return nullptr;1854 return nullptr;
1844 case clang::CK_UncheckedDerivedToBase:1855 case ZigClangCK_UncheckedDerivedToBase:
1845 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UncheckedDerivedToBase");1856 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UncheckedDerivedToBase");
1846 return nullptr;1857 return nullptr;
1847 case clang::CK_Dynamic:1858 case ZigClangCK_Dynamic:
1848 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dynamic");1859 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_Dynamic");
1849 return nullptr;1860 return nullptr;
1850 case clang::CK_ToUnion:1861 case ZigClangCK_ToUnion:
1851 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ToUnion");1862 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ToUnion");
1852 return nullptr;1863 return nullptr;
1853 case clang::CK_NullToMemberPointer:1864 case ZigClangCK_NullToMemberPointer:
1854 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_NullToMemberPointer");1865 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_NullToMemberPointer");
1855 return nullptr;1866 return nullptr;
1856 case clang::CK_BaseToDerivedMemberPointer:1867 case ZigClangCK_BaseToDerivedMemberPointer:
1857 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerivedMemberPointer");1868 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_BaseToDerivedMemberPointer");
1858 return nullptr;1869 return nullptr;
1859 case clang::CK_DerivedToBaseMemberPointer:1870 case ZigClangCK_DerivedToBaseMemberPointer:
1860 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBaseMemberPointer");1871 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_DerivedToBaseMemberPointer");
1861 return nullptr;1872 return nullptr;
1862 case clang::CK_MemberPointerToBoolean:1873 case ZigClangCK_MemberPointerToBoolean:
1863 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_MemberPointerToBoolean");1874 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_MemberPointerToBoolean");
1864 return nullptr;1875 return nullptr;
1865 case clang::CK_ReinterpretMemberPointer:1876 case ZigClangCK_ReinterpretMemberPointer:
1866 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ReinterpretMemberPointer");1877 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_ReinterpretMemberPointer");
1867 return nullptr;1878 return nullptr;
1868 case clang::CK_UserDefinedConversion:1879 case ZigClangCK_UserDefinedConversion:
1869 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UserDefinedConversion");1880 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation cast CK_UserDefinedConversion");
1870 return nullptr;1881 return nullptr;
1871 case clang::CK_ConstructorConversion:1882 case ZigClangCK_ConstructorConversion:
1872 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ConstructorConversion");1883 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ConstructorConversion");
1873 return nullptr;1884 return nullptr;
1874 case clang::CK_IntegralToPointer:1885 case ZigClangCK_IntegralToPointer:
1875 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToPointer");1886 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToPointer");
1876 return nullptr;1887 return nullptr;
1877 case clang::CK_PointerToIntegral:1888 case ZigClangCK_PointerToIntegral:
1878 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToIntegral");1889 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToIntegral");
1879 return nullptr;1890 return nullptr;
1880 case clang::CK_PointerToBoolean:1891 case ZigClangCK_PointerToBoolean:
1881 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToBoolean");1892 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_PointerToBoolean");
1882 return nullptr;1893 return nullptr;
1883 case clang::CK_ToVoid:1894 case ZigClangCK_ToVoid:
1884 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ToVoid");1895 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ToVoid");
1885 return nullptr;1896 return nullptr;
1886 case clang::CK_VectorSplat:1897 case ZigClangCK_VectorSplat:
1887 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_VectorSplat");1898 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_VectorSplat");
1888 return nullptr;1899 return nullptr;
1889 case clang::CK_IntegralToBoolean:1900 case ZigClangCK_IntegralToBoolean:
1890 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToBoolean");1901 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToBoolean");
1891 return nullptr;1902 return nullptr;
1892 case clang::CK_IntegralToFloating:1903 case ZigClangCK_IntegralToFloating:
1893 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToFloating");1904 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralToFloating");
1894 return nullptr;1905 return nullptr;
1895 case clang::CK_FixedPointCast:1906 case ZigClangCK_FixedPointCast:
1896 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointCast");1907 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointCast");
1897 return nullptr;1908 return nullptr;
1898 case clang::CK_FixedPointToBoolean:1909 case ZigClangCK_FixedPointToBoolean:
1899 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointToBoolean");1910 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FixedPointToBoolean");
1900 return nullptr;1911 return nullptr;
1901 case clang::CK_FloatingToIntegral:1912 case ZigClangCK_FloatingToIntegral:
1902 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToIntegral");1913 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToIntegral");
1903 return nullptr;1914 return nullptr;
1904 case clang::CK_FloatingToBoolean:1915 case ZigClangCK_FloatingToBoolean:
1905 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToBoolean");1916 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingToBoolean");
1906 return nullptr;1917 return nullptr;
1907 case clang::CK_BooleanToSignedIntegral:1918 case ZigClangCK_BooleanToSignedIntegral:
1908 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BooleanToSignedIntegral");1919 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BooleanToSignedIntegral");
1909 return nullptr;1920 return nullptr;
1910 case clang::CK_FloatingCast:1921 case ZigClangCK_FloatingCast:
1911 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingCast");1922 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingCast");
1912 return nullptr;1923 return nullptr;
1913 case clang::CK_CPointerToObjCPointerCast:1924 case ZigClangCK_CPointerToObjCPointerCast:
1914 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CPointerToObjCPointerCast");1925 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CPointerToObjCPointerCast");
1915 return nullptr;1926 return nullptr;
1916 case clang::CK_BlockPointerToObjCPointerCast:1927 case ZigClangCK_BlockPointerToObjCPointerCast:
1917 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BlockPointerToObjCPointerCast");1928 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BlockPointerToObjCPointerCast");
1918 return nullptr;1929 return nullptr;
1919 case clang::CK_AnyPointerToBlockPointerCast:1930 case ZigClangCK_AnyPointerToBlockPointerCast:
1920 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AnyPointerToBlockPointerCast");1931 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AnyPointerToBlockPointerCast");
1921 return nullptr;1932 return nullptr;
1922 case clang::CK_ObjCObjectLValueCast:1933 case ZigClangCK_ObjCObjectLValueCast:
1923 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ObjCObjectLValueCast");1934 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ObjCObjectLValueCast");
1924 return nullptr;1935 return nullptr;
1925 case clang::CK_FloatingRealToComplex:1936 case ZigClangCK_FloatingRealToComplex:
1926 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingRealToComplex");1937 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingRealToComplex");
1927 return nullptr;1938 return nullptr;
1928 case clang::CK_FloatingComplexToReal:1939 case ZigClangCK_FloatingComplexToReal:
1929 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToReal");1940 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToReal");
1930 return nullptr;1941 return nullptr;
1931 case clang::CK_FloatingComplexToBoolean:1942 case ZigClangCK_FloatingComplexToBoolean:
1932 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToBoolean");1943 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToBoolean");
1933 return nullptr;1944 return nullptr;
1934 case clang::CK_FloatingComplexCast:1945 case ZigClangCK_FloatingComplexCast:
1935 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexCast");1946 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexCast");
1936 return nullptr;1947 return nullptr;
1937 case clang::CK_FloatingComplexToIntegralComplex:1948 case ZigClangCK_FloatingComplexToIntegralComplex:
1938 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToIntegralComplex");1949 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_FloatingComplexToIntegralComplex");
1939 return nullptr;1950 return nullptr;
1940 case clang::CK_IntegralRealToComplex:1951 case ZigClangCK_IntegralRealToComplex:
1941 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralRealToComplex");1952 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralRealToComplex");
1942 return nullptr;1953 return nullptr;
1943 case clang::CK_IntegralComplexToReal:1954 case ZigClangCK_IntegralComplexToReal:
1944 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToReal");1955 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToReal");
1945 return nullptr;1956 return nullptr;
1946 case clang::CK_IntegralComplexToBoolean:1957 case ZigClangCK_IntegralComplexToBoolean:
1947 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToBoolean");1958 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToBoolean");
1948 return nullptr;1959 return nullptr;
1949 case clang::CK_IntegralComplexCast:1960 case ZigClangCK_IntegralComplexCast:
1950 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexCast");1961 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexCast");
1951 return nullptr;1962 return nullptr;
1952 case clang::CK_IntegralComplexToFloatingComplex:1963 case ZigClangCK_IntegralComplexToFloatingComplex:
1953 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToFloatingComplex");1964 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntegralComplexToFloatingComplex");
1954 return nullptr;1965 return nullptr;
1955 case clang::CK_ARCProduceObject:1966 case ZigClangCK_ARCProduceObject:
1956 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCProduceObject");1967 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCProduceObject");
1957 return nullptr;1968 return nullptr;
1958 case clang::CK_ARCConsumeObject:1969 case ZigClangCK_ARCConsumeObject:
1959 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCConsumeObject");1970 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCConsumeObject");
1960 return nullptr;1971 return nullptr;
1961 case clang::CK_ARCReclaimReturnedObject:1972 case ZigClangCK_ARCReclaimReturnedObject:
1962 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCReclaimReturnedObject");1973 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCReclaimReturnedObject");
1963 return nullptr;1974 return nullptr;
1964 case clang::CK_ARCExtendBlockObject:1975 case ZigClangCK_ARCExtendBlockObject:
1965 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCExtendBlockObject");1976 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ARCExtendBlockObject");
1966 return nullptr;1977 return nullptr;
1967 case clang::CK_AtomicToNonAtomic:1978 case ZigClangCK_AtomicToNonAtomic:
1968 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AtomicToNonAtomic");1979 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AtomicToNonAtomic");
1969 return nullptr;1980 return nullptr;
1970 case clang::CK_NonAtomicToAtomic:1981 case ZigClangCK_NonAtomicToAtomic:
1971 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_NonAtomicToAtomic");1982 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_NonAtomicToAtomic");
1972 return nullptr;1983 return nullptr;
1973 case clang::CK_CopyAndAutoreleaseBlockObject:1984 case ZigClangCK_CopyAndAutoreleaseBlockObject:
1974 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CopyAndAutoreleaseBlockObject");1985 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_CopyAndAutoreleaseBlockObject");
1975 return nullptr;1986 return nullptr;
1976 case clang::CK_BuiltinFnToFnPtr:1987 case ZigClangCK_BuiltinFnToFnPtr:
1977 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BuiltinFnToFnPtr");1988 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_BuiltinFnToFnPtr");
1978 return nullptr;1989 return nullptr;
1979 case clang::CK_ZeroToOCLOpaqueType:1990 case ZigClangCK_ZeroToOCLOpaqueType:
1980 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ZeroToOCLOpaqueType");1991 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_ZeroToOCLOpaqueType");
1981 return nullptr;1992 return nullptr;
1982 case clang::CK_AddressSpaceConversion:1993 case ZigClangCK_AddressSpaceConversion:
1983 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AddressSpaceConversion");1994 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_AddressSpaceConversion");
1984 return nullptr;1995 return nullptr;
1985 case clang::CK_IntToOCLSampler:1996 case ZigClangCK_IntToOCLSampler:
1986 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntToOCLSampler");1997 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C CK_IntToOCLSampler");
1987 return nullptr;1998 return nullptr;
1988 }1999 }
...@@ -2002,7 +2013,7 @@ static AstNode *trans_decl_ref_expr(Context *c, TransScope *scope, const clang::...@@ -2002,7 +2013,7 @@ static AstNode *trans_decl_ref_expr(Context *c, TransScope *scope, const clang::
2002static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, TransScope *scope,2013static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, TransScope *scope,
2003 const clang::UnaryOperator *stmt, BinOpType assign_op)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());
20062017
2007 if (result_used == ResultUsedNo) {2018 if (result_used == ResultUsedNo) {
2008 // common case2019 // common case
...@@ -2058,7 +2069,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr...@@ -2058,7 +2069,7 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
2058static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, TransScope *scope,2069static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, TransScope *scope,
2059 const clang::UnaryOperator *stmt, BinOpType assign_op)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());
20622073
2063 if (result_used == ResultUsedNo) {2074 if (result_used == ResultUsedNo) {
2064 // common case2075 // common case
...@@ -2129,14 +2140,14 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -2129,14 +2140,14 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2129 return trans_create_pre_crement(c, result_used, scope, stmt, BinOpTypeAssignMinus);2140 return trans_create_pre_crement(c, result_used, scope, stmt, BinOpTypeAssignMinus);
2130 case clang::UO_AddrOf: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 if (value_node == nullptr)2144 if (value_node == nullptr)
2134 return value_node;2145 return value_node;
2135 return trans_create_node_addr_of(c, value_node);2146 return trans_create_node_addr_of(c, value_node);
2136 }2147 }
2137 case clang::UO_Deref: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 if (value_node == nullptr)2151 if (value_node == nullptr)
2141 return nullptr;2152 return nullptr;
2142 bool is_fn_ptr = qual_type_is_fn_ptr(bitcast(stmt->getSubExpr()->getType()));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,8 +2161,8 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2150 return nullptr;2161 return nullptr;
2151 case clang::UO_Minus:2162 case clang::UO_Minus:
2152 {2163 {
2153 clang::Expr *op_expr = stmt->getSubExpr();2164 const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr());
2154 if (!qual_type_has_wrapping_overflow(c, bitcast(op_expr->getType()))) {2165 if (!qual_type_has_wrapping_overflow(c, ZigClangExpr_getType(op_expr))) {
2155 AstNode *node = trans_create_node(c, NodeTypePrefixOpExpr);2166 AstNode *node = trans_create_node(c, NodeTypePrefixOpExpr);
2156 node->data.prefix_op_expr.prefix_op = PrefixOpNegation;2167 node->data.prefix_op_expr.prefix_op = PrefixOpNegation;
21572168
...@@ -2160,7 +2171,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -2160,7 +2171,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2160 return nullptr;2171 return nullptr;
21612172
2162 return node;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 // we gotta emit 0 -% x2175 // we gotta emit 0 -% x
2165 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);2176 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
2166 node->data.bin_op_expr.op1 = trans_create_node_unsigned(c, 0);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,7 +2189,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2178 }2189 }
2179 case clang::UO_Not:2190 case clang::UO_Not:
2180 {2191 {
2181 clang::Expr *op_expr = stmt->getSubExpr();2192 const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr());
2182 AstNode *sub_node = trans_expr(c, ResultUsedYes, scope, op_expr, TransRValue);2193 AstNode *sub_node = trans_expr(c, ResultUsedYes, scope, op_expr, TransRValue);
2183 if (sub_node == nullptr)2194 if (sub_node == nullptr)
2184 return nullptr;2195 return nullptr;
...@@ -2187,7 +2198,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -2187,7 +2198,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2187 }2198 }
2188 case clang::UO_LNot:2199 case clang::UO_LNot:
2189 {2200 {
2190 clang::Expr *op_expr = stmt->getSubExpr();2201 const ZigClangExpr *op_expr = bitcast(stmt->getSubExpr());
2191 AstNode *sub_node = trans_bool_expr(c, ResultUsedYes, scope, op_expr, TransRValue);2202 AstNode *sub_node = trans_bool_expr(c, ResultUsedYes, scope, op_expr, TransRValue);
2192 if (sub_node == nullptr)2203 if (sub_node == nullptr)
2193 return nullptr;2204 return nullptr;
...@@ -2201,7 +2212,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -2201,7 +2212,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
2201 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Imag");2212 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Imag");
2202 return nullptr;2213 return nullptr;
2203 case clang::UO_Extension: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 case clang::UO_Coawait:2216 case clang::UO_Coawait:
2206 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Coawait");2217 emit_warning(c, bitcast(stmt->getBeginLoc()), "TODO handle C translation UO_Coawait");
2207 return nullptr;2218 return nullptr;
...@@ -2226,7 +2237,7 @@ static int trans_local_declaration(Context *c, TransScope *scope, const clang::D...@@ -2226,7 +2237,7 @@ static int trans_local_declaration(Context *c, TransScope *scope, const clang::D
2226 ZigClangQualType qual_type = bitcast(var_decl->getTypeSourceInfo()->getType());2237 ZigClangQualType qual_type = bitcast(var_decl->getTypeSourceInfo()->getType());
2227 AstNode *init_node = nullptr;2238 AstNode *init_node = nullptr;
2228 if (var_decl->hasInit()) {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 if (init_node == nullptr)2241 if (init_node == nullptr)
2231 return ErrorUnexpected;2242 return ErrorUnexpected;
22322243
...@@ -2492,7 +2503,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type)...@@ -2492,7 +2503,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type)
2492 return trans_create_node_bin_op(c, expr, BinOpTypeCmpNotEq, bitcast);2503 return trans_create_node_bin_op(c, expr, BinOpTypeCmpNotEq, bitcast);
2493}2504}
24942505
2495static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr, TransLRValue lrval) {2506static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr, TransLRValue lrval) {
2496 AstNode *res = trans_expr(c, result_used, scope, expr, lrval);2507 AstNode *res = trans_expr(c, result_used, scope, expr, lrval);
2497 if (res == nullptr)2508 if (res == nullptr)
2498 return nullptr;2509 return nullptr;
...@@ -2689,7 +2700,7 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2689,7 +2700,7 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *
2689 switch (elaborated_ty->getKeyword()) {2700 switch (elaborated_ty->getKeyword()) {
2690 case clang::ETK_Enum: {2701 case clang::ETK_Enum: {
2691 AstNode *enum_type = trans_qual_type(c, bitcast(elaborated_ty->getNamedType()),2702 AstNode *enum_type = trans_qual_type(c, bitcast(elaborated_ty->getNamedType()),
2692 bitcast(expr->getBeginLoc()));2703 ZigClangExpr_getBeginLoc(expr));
2693 return to_enum_zero_cmp(c, res, enum_type);2704 return to_enum_zero_cmp(c, res, enum_type);
2694 }2705 }
2695 case clang::ETK_Struct:2706 case clang::ETK_Struct:
...@@ -2752,7 +2763,8 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2752,7 +2763,8 @@ static AstNode *trans_bool_expr(Context *c, ResultUsed result_used, TransScope *
2752static AstNode *trans_while_loop(Context *c, TransScope *scope, const clang::WhileStmt *stmt) {2763static AstNode *trans_while_loop(Context *c, TransScope *scope, const clang::WhileStmt *stmt) {
2753 TransScopeWhile *while_scope = trans_scope_while_create(c, scope);2764 TransScopeWhile *while_scope = trans_scope_while_create(c, scope);
27542765
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 if (while_scope->node->data.while_expr.condition == nullptr)2768 if (while_scope->node->data.while_expr.condition == nullptr)
2757 return nullptr;2769 return nullptr;
27582770
...@@ -2779,7 +2791,8 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I...@@ -2779,7 +2791,8 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I
2779 return nullptr;2791 return nullptr;
2780 }2792 }
27812793
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 if (if_node->data.if_bool_expr.condition == nullptr)2796 if (if_node->data.if_bool_expr.condition == nullptr)
2784 return nullptr;2797 return nullptr;
27852798
...@@ -2789,7 +2802,7 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I...@@ -2789,7 +2802,7 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const clang::I
2789static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::CallExpr *stmt) {2802static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::CallExpr *stmt) {
2790 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);2803 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
27912804
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 if (callee_raw_node == nullptr)2806 if (callee_raw_node == nullptr)
2794 return nullptr;2807 return nullptr;
27952808
...@@ -2799,7 +2812,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2799,7 +2812,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
2799 if (is_ptr && fn_ty) {2812 if (is_ptr && fn_ty) {
2800 if ((ZigClangStmtClass)stmt->getCallee()->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) {2813 if ((ZigClangStmtClass)stmt->getCallee()->getStmtClass() == ZigClangStmt_ImplicitCastExprClass) {
2801 const clang::ImplicitCastExpr *implicit_cast = static_cast<const clang::ImplicitCastExpr *>(stmt->getCallee());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 if ((ZigClangStmtClass)implicit_cast->getSubExpr()->getStmtClass() == ZigClangStmt_DeclRefExprClass) {2816 if ((ZigClangStmtClass)implicit_cast->getSubExpr()->getStmtClass() == ZigClangStmt_DeclRefExprClass) {
2804 const clang::DeclRefExpr *decl_ref = static_cast<const clang::DeclRefExpr *>(implicit_cast->getSubExpr());2817 const clang::DeclRefExpr *decl_ref = static_cast<const clang::DeclRefExpr *>(implicit_cast->getSubExpr());
2805 const clang::Decl *decl = decl_ref->getFoundDecl();2818 const clang::Decl *decl = decl_ref->getFoundDecl();
...@@ -2819,7 +2832,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2819,7 +2832,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
2819 node->data.fn_call_expr.fn_ref_expr = callee_node;2832 node->data.fn_call_expr.fn_ref_expr = callee_node;
28202833
2821 unsigned num_args = stmt->getNumArgs();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 for (unsigned i = 0; i < num_args; i += 1) {2836 for (unsigned i = 0; i < num_args; i += 1) {
2824 AstNode *arg_node = trans_expr(c, ResultUsedYes, scope, args[i], TransRValue);2837 AstNode *arg_node = trans_expr(c, ResultUsedYes, scope, args[i], TransRValue);
2825 if (arg_node == nullptr)2838 if (arg_node == nullptr)
...@@ -2840,7 +2853,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2840,7 +2853,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
2840static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope *scope,2853static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope *scope,
2841 const clang::MemberExpr *stmt)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 if (container_node == nullptr)2857 if (container_node == nullptr)
2845 return nullptr;2858 return nullptr;
28462859
...@@ -2855,11 +2868,11 @@ static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope...@@ -2855,11 +2868,11 @@ static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope
2855}2868}
28562869
2857static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ArraySubscriptExpr *stmt) {2870static 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 if (container_node == nullptr)2872 if (container_node == nullptr)
2860 return nullptr;2873 return nullptr;
28612874
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 if (idx_node == nullptr)2876 if (idx_node == nullptr)
2864 return nullptr;2877 return nullptr;
28652878
...@@ -2873,7 +2886,7 @@ static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, T...@@ -2873,7 +2886,7 @@ static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, T
2873static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, TransScope *scope,2886static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, TransScope *scope,
2874 const clang::CStyleCastExpr *stmt, TransLRValue lrvalue)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 if (sub_expr_node == nullptr)2890 if (sub_expr_node == nullptr)
2878 return nullptr;2891 return nullptr;
28792892
...@@ -2943,7 +2956,7 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const clang:...@@ -2943,7 +2956,7 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const clang:
2943 }2956 }
29442957
2945 // if (!cond) break;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 if (condition_node == nullptr) return nullptr;2960 if (condition_node == nullptr) return nullptr;
2948 AstNode *terminator_node = trans_create_node(c, NodeTypeIfBoolExpr);2961 AstNode *terminator_node = trans_create_node(c, NodeTypeIfBoolExpr);
2949 terminator_node->data.if_bool_expr.condition = trans_create_node_prefix_op(c, PrefixOpBoolNot, condition_node);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,29 +2995,21 @@ static AstNode *trans_for_loop(Context *c, TransScope *parent_scope, const clang
2982 child_scope->node->data.block.statements.append(while_scope->node);2995 child_scope->node->data.block.statements.append(while_scope->node);
2983 }2996 }
29842997
2985 const ZigClangStmt *cond_stmt = bitcast(stmt->getCond());2998 const ZigClangExpr *cond_expr = bitcast(stmt->getCond());
2986 if (cond_stmt == nullptr) {2999 if (cond_expr == nullptr) {
2987 while_scope->node->data.while_expr.condition = trans_create_node_bool(c, true);3000 while_scope->node->data.while_expr.condition = trans_create_node_bool(c, true);
2988 } else {3001 } else {
2989 if (ZigClangStmt_classof_Expr(cond_stmt)) {3002 while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, cond_scope,
2990 const clang::Expr *cond_expr = reinterpret_cast<const clang::Expr*>(cond_stmt);3003 cond_expr, TransRValue);
2991 while_scope->node->data.while_expr.condition = trans_bool_expr(c, ResultUsedYes, cond_scope, cond_expr, TransRValue);
29923004
2993 if (while_scope->node->data.while_expr.condition == nullptr)3005 if (while_scope->node->data.while_expr.condition == nullptr)
2994 return nullptr;3006 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 }
3001 }3007 }
30023008
3003 const ZigClangStmt *inc_stmt = bitcast(stmt->getInc());3009 const ZigClangExpr *inc_expr = bitcast(stmt->getInc());
3004 if (inc_stmt != nullptr) {3010 if (inc_expr != nullptr) {
3005 AstNode *inc_node;3011 AstNode *inc_node = trans_expr(c, ResultUsedNo, cond_scope, inc_expr, TransRValue);
3006 TransScope *inc_scope = trans_stmt(c, cond_scope, inc_stmt, &inc_node);3012 if (inc_node == nullptr)
3007 if (inc_scope == nullptr)
3008 return nullptr;3013 return nullptr;
3009 while_scope->node->data.while_expr.continue_expr = inc_node;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,7 +3052,7 @@ static AstNode *trans_switch_stmt(Context *c, TransScope *parent_scope, const cl
3047 switch_scope->end_label_name = end_label_name;3052 switch_scope->end_label_name = end_label_name;
3048 block_scope->node->data.block.name = end_label_name;3053 block_scope->node->data.block.name = end_label_name;
30493054
3050 const clang::Expr *cond_expr = stmt->getCond();3055 const ZigClangExpr *cond_expr = bitcast(stmt->getCond());
3051 assert(cond_expr != nullptr);3056 assert(cond_expr != nullptr);
30523057
3053 AstNode *expr_node = trans_expr(c, ResultUsedYes, &block_scope->base, cond_expr, TransRValue);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,7 +3113,7 @@ static int trans_switch_case(Context *c, TransScope *parent_scope, const clang::
3108 {3113 {
3109 // Add the prong3114 // Add the prong
3110 AstNode *prong_node = trans_create_node(c, NodeTypeSwitchProng);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 if (item_node == nullptr)3117 if (item_node == nullptr)
3113 return ErrorUnexpected;3118 return ErrorUnexpected;
3114 prong_node->data.switch_prong.items.append(item_node);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,7 +3318,8 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s
3313 trans_continue_stmt(c, scope, (const clang::ContinueStmt *)stmt));3318 trans_continue_stmt(c, scope, (const clang::ContinueStmt *)stmt));
3314 case ZigClangStmt_ParenExprClass:3319 case ZigClangStmt_ParenExprClass:
3315 return wrap_stmt(out_node, out_child_scope, scope,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 case ZigClangStmt_SwitchStmtClass:3323 case ZigClangStmt_SwitchStmtClass:
3318 return wrap_stmt(out_node, out_child_scope, scope,3324 return wrap_stmt(out_node, out_child_scope, scope,
3319 trans_switch_stmt(c, scope, (const clang::SwitchStmt *)stmt));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,7 +3842,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const ZigClangStmt *s
3836}3842}
38373843
3838// Returns null if there was an error3844// Returns null if there was an error
3839static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::Expr *expr,3845static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const ZigClangExpr *expr,
3840 TransLRValue lrval)3846 TransLRValue lrval)
3841{3847{
3842 AstNode *result_node;3848 AstNode *result_node;
...@@ -4304,7 +4310,7 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua...@@ -4304,7 +4310,7 @@ static AstNode *trans_ap_value(Context *c, clang::APValue *ap_value, ZigClangQua
4304 case clang::APValue::LValue: {4310 case clang::APValue::LValue: {
4305 const clang::APValue::LValueBase lval_base = ap_value->getLValueBase();4311 const clang::APValue::LValueBase lval_base = ap_value->getLValueBase();
4306 if (const clang::Expr *expr = lval_base.dyn_cast<const clang::Expr *>()) {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 //const clang::ValueDecl *value_decl = lval_base.get<const clang::ValueDecl *>();4315 //const clang::ValueDecl *value_decl = lval_base.get<const clang::ValueDecl *>();
4310 emit_warning(c, source_loc, "TODO handle initializer LValue clang::ValueDecl");4316 emit_warning(c, source_loc, "TODO handle initializer LValue clang::ValueDecl");
src/zig_clang.cpp+141
...@@ -137,6 +137,132 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, "...@@ -137,6 +137,132 @@ static_assert((clang::UnaryOperatorKind)ZigClangUO_PreDec == clang::UO_PreDec, "
137static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "");137static_assert((clang::UnaryOperatorKind)ZigClangUO_PreInc == clang::UO_PreInc, "");
138static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, "");138static_assert((clang::UnaryOperatorKind)ZigClangUO_Real == clang::UO_Real, "");
139139
140// Detect additions to the enum
141void zig2clang_CK(clang::CastKind x) {
142 switch (x) {
143 case clang::CK_ARCConsumeObject:
144 case clang::CK_ARCExtendBlockObject:
145 case clang::CK_ARCProduceObject:
146 case clang::CK_ARCReclaimReturnedObject:
147 case clang::CK_AddressSpaceConversion:
148 case clang::CK_AnyPointerToBlockPointerCast:
149 case clang::CK_ArrayToPointerDecay:
150 case clang::CK_AtomicToNonAtomic:
151 case clang::CK_BaseToDerived:
152 case clang::CK_BaseToDerivedMemberPointer:
153 case clang::CK_BitCast:
154 case clang::CK_BlockPointerToObjCPointerCast:
155 case clang::CK_BooleanToSignedIntegral:
156 case clang::CK_BuiltinFnToFnPtr:
157 case clang::CK_CPointerToObjCPointerCast:
158 case clang::CK_ConstructorConversion:
159 case clang::CK_CopyAndAutoreleaseBlockObject:
160 case clang::CK_Dependent:
161 case clang::CK_DerivedToBase:
162 case clang::CK_DerivedToBaseMemberPointer:
163 case clang::CK_Dynamic:
164 case clang::CK_FloatingCast:
165 case clang::CK_FloatingComplexCast:
166 case clang::CK_FloatingComplexToBoolean:
167 case clang::CK_FloatingComplexToIntegralComplex:
168 case clang::CK_FloatingComplexToReal:
169 case clang::CK_FloatingRealToComplex:
170 case clang::CK_FloatingToBoolean:
171 case clang::CK_FloatingToIntegral:
172 case clang::CK_FunctionToPointerDecay:
173 case clang::CK_IntToOCLSampler:
174 case clang::CK_IntegralCast:
175 case clang::CK_IntegralComplexCast:
176 case clang::CK_IntegralComplexToBoolean:
177 case clang::CK_IntegralComplexToFloatingComplex:
178 case clang::CK_IntegralComplexToReal:
179 case clang::CK_IntegralRealToComplex:
180 case clang::CK_IntegralToBoolean:
181 case clang::CK_IntegralToFloating:
182 case clang::CK_IntegralToPointer:
183 case clang::CK_LValueBitCast:
184 case clang::CK_LValueToRValue:
185 case clang::CK_MemberPointerToBoolean:
186 case clang::CK_NoOp:
187 case clang::CK_NonAtomicToAtomic:
188 case clang::CK_NullToMemberPointer:
189 case clang::CK_NullToPointer:
190 case clang::CK_ObjCObjectLValueCast:
191 case clang::CK_PointerToBoolean:
192 case clang::CK_PointerToIntegral:
193 case clang::CK_ReinterpretMemberPointer:
194 case clang::CK_ToUnion:
195 case clang::CK_ToVoid:
196 case clang::CK_UncheckedDerivedToBase:
197 case clang::CK_UserDefinedConversion:
198 case clang::CK_VectorSplat:
199 case clang::CK_ZeroToOCLOpaqueType:
200 case clang::CK_FixedPointCast:
201 case clang::CK_FixedPointToBoolean:
202 break;
203 }
204};
205
206static_assert((clang::CastKind)ZigClangCK_Dependent == clang::CK_Dependent, "");
207static_assert((clang::CastKind)ZigClangCK_BitCast == clang::CK_BitCast, "");
208static_assert((clang::CastKind)ZigClangCK_LValueBitCast == clang::CK_LValueBitCast, "");
209static_assert((clang::CastKind)ZigClangCK_LValueToRValue == clang::CK_LValueToRValue, "");
210static_assert((clang::CastKind)ZigClangCK_NoOp == clang::CK_NoOp, "");
211static_assert((clang::CastKind)ZigClangCK_BaseToDerived == clang::CK_BaseToDerived, "");
212static_assert((clang::CastKind)ZigClangCK_DerivedToBase == clang::CK_DerivedToBase, "");
213static_assert((clang::CastKind)ZigClangCK_UncheckedDerivedToBase == clang::CK_UncheckedDerivedToBase, "");
214static_assert((clang::CastKind)ZigClangCK_Dynamic == clang::CK_Dynamic, "");
215static_assert((clang::CastKind)ZigClangCK_ToUnion == clang::CK_ToUnion, "");
216static_assert((clang::CastKind)ZigClangCK_ArrayToPointerDecay == clang::CK_ArrayToPointerDecay, "");
217static_assert((clang::CastKind)ZigClangCK_FunctionToPointerDecay == clang::CK_FunctionToPointerDecay, "");
218static_assert((clang::CastKind)ZigClangCK_NullToPointer == clang::CK_NullToPointer, "");
219static_assert((clang::CastKind)ZigClangCK_NullToMemberPointer == clang::CK_NullToMemberPointer, "");
220static_assert((clang::CastKind)ZigClangCK_BaseToDerivedMemberPointer == clang::CK_BaseToDerivedMemberPointer, "");
221static_assert((clang::CastKind)ZigClangCK_DerivedToBaseMemberPointer == clang::CK_DerivedToBaseMemberPointer, "");
222static_assert((clang::CastKind)ZigClangCK_MemberPointerToBoolean == clang::CK_MemberPointerToBoolean, "");
223static_assert((clang::CastKind)ZigClangCK_ReinterpretMemberPointer == clang::CK_ReinterpretMemberPointer, "");
224static_assert((clang::CastKind)ZigClangCK_UserDefinedConversion == clang::CK_UserDefinedConversion, "");
225static_assert((clang::CastKind)ZigClangCK_ConstructorConversion == clang::CK_ConstructorConversion, "");
226static_assert((clang::CastKind)ZigClangCK_IntegralToPointer == clang::CK_IntegralToPointer, "");
227static_assert((clang::CastKind)ZigClangCK_PointerToIntegral == clang::CK_PointerToIntegral, "");
228static_assert((clang::CastKind)ZigClangCK_PointerToBoolean == clang::CK_PointerToBoolean, "");
229static_assert((clang::CastKind)ZigClangCK_ToVoid == clang::CK_ToVoid, "");
230static_assert((clang::CastKind)ZigClangCK_VectorSplat == clang::CK_VectorSplat, "");
231static_assert((clang::CastKind)ZigClangCK_IntegralCast == clang::CK_IntegralCast, "");
232static_assert((clang::CastKind)ZigClangCK_IntegralToBoolean == clang::CK_IntegralToBoolean, "");
233static_assert((clang::CastKind)ZigClangCK_IntegralToFloating == clang::CK_IntegralToFloating, "");
234static_assert((clang::CastKind)ZigClangCK_FixedPointCast == clang::CK_FixedPointCast, "");
235static_assert((clang::CastKind)ZigClangCK_FixedPointToBoolean == clang::CK_FixedPointToBoolean, "");
236static_assert((clang::CastKind)ZigClangCK_FloatingToIntegral == clang::CK_FloatingToIntegral, "");
237static_assert((clang::CastKind)ZigClangCK_FloatingToBoolean == clang::CK_FloatingToBoolean, "");
238static_assert((clang::CastKind)ZigClangCK_BooleanToSignedIntegral == clang::CK_BooleanToSignedIntegral, "");
239static_assert((clang::CastKind)ZigClangCK_FloatingCast == clang::CK_FloatingCast, "");
240static_assert((clang::CastKind)ZigClangCK_CPointerToObjCPointerCast == clang::CK_CPointerToObjCPointerCast, "");
241static_assert((clang::CastKind)ZigClangCK_BlockPointerToObjCPointerCast == clang::CK_BlockPointerToObjCPointerCast, "");
242static_assert((clang::CastKind)ZigClangCK_AnyPointerToBlockPointerCast == clang::CK_AnyPointerToBlockPointerCast, "");
243static_assert((clang::CastKind)ZigClangCK_ObjCObjectLValueCast == clang::CK_ObjCObjectLValueCast, "");
244static_assert((clang::CastKind)ZigClangCK_FloatingRealToComplex == clang::CK_FloatingRealToComplex, "");
245static_assert((clang::CastKind)ZigClangCK_FloatingComplexToReal == clang::CK_FloatingComplexToReal, "");
246static_assert((clang::CastKind)ZigClangCK_FloatingComplexToBoolean == clang::CK_FloatingComplexToBoolean, "");
247static_assert((clang::CastKind)ZigClangCK_FloatingComplexCast == clang::CK_FloatingComplexCast, "");
248static_assert((clang::CastKind)ZigClangCK_FloatingComplexToIntegralComplex == clang::CK_FloatingComplexToIntegralComplex, "");
249static_assert((clang::CastKind)ZigClangCK_IntegralRealToComplex == clang::CK_IntegralRealToComplex, "");
250static_assert((clang::CastKind)ZigClangCK_IntegralComplexToReal == clang::CK_IntegralComplexToReal, "");
251static_assert((clang::CastKind)ZigClangCK_IntegralComplexToBoolean == clang::CK_IntegralComplexToBoolean, "");
252static_assert((clang::CastKind)ZigClangCK_IntegralComplexCast == clang::CK_IntegralComplexCast, "");
253static_assert((clang::CastKind)ZigClangCK_IntegralComplexToFloatingComplex == clang::CK_IntegralComplexToFloatingComplex, "");
254static_assert((clang::CastKind)ZigClangCK_ARCProduceObject == clang::CK_ARCProduceObject, "");
255static_assert((clang::CastKind)ZigClangCK_ARCConsumeObject == clang::CK_ARCConsumeObject, "");
256static_assert((clang::CastKind)ZigClangCK_ARCReclaimReturnedObject == clang::CK_ARCReclaimReturnedObject, "");
257static_assert((clang::CastKind)ZigClangCK_ARCExtendBlockObject == clang::CK_ARCExtendBlockObject, "");
258static_assert((clang::CastKind)ZigClangCK_AtomicToNonAtomic == clang::CK_AtomicToNonAtomic, "");
259static_assert((clang::CastKind)ZigClangCK_NonAtomicToAtomic == clang::CK_NonAtomicToAtomic, "");
260static_assert((clang::CastKind)ZigClangCK_CopyAndAutoreleaseBlockObject == clang::CK_CopyAndAutoreleaseBlockObject, "");
261static_assert((clang::CastKind)ZigClangCK_BuiltinFnToFnPtr == clang::CK_BuiltinFnToFnPtr, "");
262static_assert((clang::CastKind)ZigClangCK_ZeroToOCLOpaqueType == clang::CK_ZeroToOCLOpaqueType, "");
263static_assert((clang::CastKind)ZigClangCK_AddressSpaceConversion == clang::CK_AddressSpaceConversion, "");
264static_assert((clang::CastKind)ZigClangCK_IntToOCLSampler == clang::CK_IntToOCLSampler, "");
265
140// Detect additions to the enum266// Detect additions to the enum
141void zig2clang_TypeClass(clang::Type::TypeClass ty) {267void zig2clang_TypeClass(clang::Type::TypeClass ty) {
142 switch (ty) {268 switch (ty) {
...@@ -885,3 +1011,18 @@ ZigClangStmtClass ZigClangStmt_getStmtClass(const ZigClangStmt *self) {...@@ -885,3 +1011,18 @@ ZigClangStmtClass ZigClangStmt_getStmtClass(const ZigClangStmt *self) {
885 auto casted = reinterpret_cast<const clang::Stmt *>(self);1011 auto casted = reinterpret_cast<const clang::Stmt *>(self);
886 return (ZigClangStmtClass)casted->getStmtClass();1012 return (ZigClangStmtClass)casted->getStmtClass();
887}1013}
1014
1015ZigClangStmtClass ZigClangExpr_getStmtClass(const ZigClangExpr *self) {
1016 auto casted = reinterpret_cast<const clang::Expr *>(self);
1017 return (ZigClangStmtClass)casted->getStmtClass();
1018}
1019
1020ZigClangQualType ZigClangExpr_getType(const ZigClangExpr *self) {
1021 auto casted = reinterpret_cast<const clang::Expr *>(self);
1022 return bitcast(casted->getType());
1023}
1024
1025ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self) {
1026 auto casted = reinterpret_cast<const clang::Expr *>(self);
1027 return bitcast(casted->getBeginLoc());
1028}
src/zig_clang.h+64-58
...@@ -418,64 +418,67 @@ enum ZigClangStmtClass {...@@ -418,64 +418,67 @@ enum ZigClangStmtClass {
418//struct ZigClangCC_X86VectorCall;418//struct ZigClangCC_X86VectorCall;
419//struct ZigClangCC_X86_64SysV;419//struct ZigClangCC_X86_64SysV;
420420
421//struct ZigClangCK_ARCConsumeObject;421enum ZigClangCK {
422//struct ZigClangCK_ARCExtendBlockObject;422 ZigClangCK_Dependent,
423//struct ZigClangCK_ARCProduceObject;423 ZigClangCK_BitCast,
424//struct ZigClangCK_ARCReclaimReturnedObject;424 ZigClangCK_LValueBitCast,
425//struct ZigClangCK_AddressSpaceConversion;425 ZigClangCK_LValueToRValue,
426//struct ZigClangCK_AnyPointerToBlockPointerCast;426 ZigClangCK_NoOp,
427//struct ZigClangCK_ArrayToPointerDecay;427 ZigClangCK_BaseToDerived,
428//struct ZigClangCK_AtomicToNonAtomic;428 ZigClangCK_DerivedToBase,
429//struct ZigClangCK_BaseToDerived;429 ZigClangCK_UncheckedDerivedToBase,
430//struct ZigClangCK_BaseToDerivedMemberPointer;430 ZigClangCK_Dynamic,
431//struct ZigClangCK_BitCast;431 ZigClangCK_ToUnion,
432//struct ZigClangCK_BlockPointerToObjCPointerCast;432 ZigClangCK_ArrayToPointerDecay,
433//struct ZigClangCK_BooleanToSignedIntegral;433 ZigClangCK_FunctionToPointerDecay,
434//struct ZigClangCK_BuiltinFnToFnPtr;434 ZigClangCK_NullToPointer,
435//struct ZigClangCK_CPointerToObjCPointerCast;435 ZigClangCK_NullToMemberPointer,
436//struct ZigClangCK_ConstructorConversion;436 ZigClangCK_BaseToDerivedMemberPointer,
437//struct ZigClangCK_CopyAndAutoreleaseBlockObject;437 ZigClangCK_DerivedToBaseMemberPointer,
438//struct ZigClangCK_Dependent;438 ZigClangCK_MemberPointerToBoolean,
439//struct ZigClangCK_DerivedToBase;439 ZigClangCK_ReinterpretMemberPointer,
440//struct ZigClangCK_DerivedToBaseMemberPointer;440 ZigClangCK_UserDefinedConversion,
441//struct ZigClangCK_Dynamic;441 ZigClangCK_ConstructorConversion,
442//struct ZigClangCK_FloatingCast;442 ZigClangCK_IntegralToPointer,
443//struct ZigClangCK_FloatingComplexCast;443 ZigClangCK_PointerToIntegral,
444//struct ZigClangCK_FloatingComplexToBoolean;444 ZigClangCK_PointerToBoolean,
445//struct ZigClangCK_FloatingComplexToIntegralComplex;445 ZigClangCK_ToVoid,
446//struct ZigClangCK_FloatingComplexToReal;446 ZigClangCK_VectorSplat,
447//struct ZigClangCK_FloatingRealToComplex;447 ZigClangCK_IntegralCast,
448//struct ZigClangCK_FloatingToBoolean;448 ZigClangCK_IntegralToBoolean,
449//struct ZigClangCK_FloatingToIntegral;449 ZigClangCK_IntegralToFloating,
450//struct ZigClangCK_FunctionToPointerDecay;450 ZigClangCK_FixedPointCast,
451//struct ZigClangCK_IntToOCLSampler;451 ZigClangCK_FixedPointToBoolean,
452//struct ZigClangCK_IntegralCast;452 ZigClangCK_FloatingToIntegral,
453//struct ZigClangCK_IntegralComplexCast;453 ZigClangCK_FloatingToBoolean,
454//struct ZigClangCK_IntegralComplexToBoolean;454 ZigClangCK_BooleanToSignedIntegral,
455//struct ZigClangCK_IntegralComplexToFloatingComplex;455 ZigClangCK_FloatingCast,
456//struct ZigClangCK_IntegralComplexToReal;456 ZigClangCK_CPointerToObjCPointerCast,
457//struct ZigClangCK_IntegralRealToComplex;457 ZigClangCK_BlockPointerToObjCPointerCast,
458//struct ZigClangCK_IntegralToBoolean;458 ZigClangCK_AnyPointerToBlockPointerCast,
459//struct ZigClangCK_IntegralToFloating;459 ZigClangCK_ObjCObjectLValueCast,
460//struct ZigClangCK_IntegralToPointer;460 ZigClangCK_FloatingRealToComplex,
461//struct ZigClangCK_LValueBitCast;461 ZigClangCK_FloatingComplexToReal,
462//struct ZigClangCK_LValueToRValue;462 ZigClangCK_FloatingComplexToBoolean,
463//struct ZigClangCK_MemberPointerToBoolean;463 ZigClangCK_FloatingComplexCast,
464//struct ZigClangCK_NoOp;464 ZigClangCK_FloatingComplexToIntegralComplex,
465//struct ZigClangCK_NonAtomicToAtomic;465 ZigClangCK_IntegralRealToComplex,
466//struct ZigClangCK_NullToMemberPointer;466 ZigClangCK_IntegralComplexToReal,
467//struct ZigClangCK_NullToPointer;467 ZigClangCK_IntegralComplexToBoolean,
468//struct ZigClangCK_ObjCObjectLValueCast;468 ZigClangCK_IntegralComplexCast,
469//struct ZigClangCK_PointerToBoolean;469 ZigClangCK_IntegralComplexToFloatingComplex,
470//struct ZigClangCK_PointerToIntegral;470 ZigClangCK_ARCProduceObject,
471//struct ZigClangCK_ReinterpretMemberPointer;471 ZigClangCK_ARCConsumeObject,
472//struct ZigClangCK_ToUnion;472 ZigClangCK_ARCReclaimReturnedObject,
473//struct ZigClangCK_ToVoid;473 ZigClangCK_ARCExtendBlockObject,
474//struct ZigClangCK_UncheckedDerivedToBase;474 ZigClangCK_AtomicToNonAtomic,
475//struct ZigClangCK_UserDefinedConversion;475 ZigClangCK_NonAtomicToAtomic,
476//struct ZigClangCK_VectorSplat;476 ZigClangCK_CopyAndAutoreleaseBlockObject,
477//struct ZigClangCK_ZeroToOCLEvent;477 ZigClangCK_BuiltinFnToFnPtr,
478//struct ZigClangCK_ZeroToOCLQueue;478 ZigClangCK_ZeroToOCLOpaqueType,
479 ZigClangCK_AddressSpaceConversion,
480 ZigClangCK_IntToOCLSampler,
481};
479482
480//struct ZigClangETK_Class;483//struct ZigClangETK_Class;
481//struct ZigClangETK_Enum;484//struct ZigClangETK_Enum;
...@@ -552,4 +555,7 @@ ZIG_EXTERN_C ZigClangSourceLocation ZigClangStmt_getBeginLoc(const ZigClangStmt...@@ -552,4 +555,7 @@ ZIG_EXTERN_C ZigClangSourceLocation ZigClangStmt_getBeginLoc(const ZigClangStmt
552ZIG_EXTERN_C ZigClangStmtClass ZigClangStmt_getStmtClass(const ZigClangStmt *self);555ZIG_EXTERN_C ZigClangStmtClass ZigClangStmt_getStmtClass(const ZigClangStmt *self);
553ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const ZigClangStmt *self);556ZIG_EXTERN_C bool ZigClangStmt_classof_Expr(const ZigClangStmt *self);
554557
558ZIG_EXTERN_C ZigClangStmtClass ZigClangExpr_getStmtClass(const ZigClangExpr *self);
559ZIG_EXTERN_C ZigClangQualType ZigClangExpr_getType(const ZigClangExpr *self);
560ZIG_EXTERN_C ZigClangSourceLocation ZigClangExpr_getBeginLoc(const ZigClangExpr *self);
555#endif561#endif