| ... | ... | @@ -581,6 +581,33 @@ static bool qual_type_is_ptr(ZigClangQualType qt) { |
| 581 | 581 | return ZigClangType_getTypeClass(ty) == ZigClangType_Pointer; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | static bool qual_type_is_int(ZigClangQualType qt) { |
| 585 | const ZigClangType *ty = qual_type_canon(qt); |
| 586 | if (ZigClangType_getTypeClass(ty) != ZigClangType_Builtin) |
| 587 | return false; |
| 588 | const clang::BuiltinType *builtin_ty = reinterpret_cast<const clang::BuiltinType*>(ty); |
| 589 | switch (builtin_ty->getKind()) { |
| 590 | case clang::BuiltinType::Char_U: |
| 591 | case clang::BuiltinType::UChar: |
| 592 | case clang::BuiltinType::Char_S: |
| 593 | case clang::BuiltinType::Char8: |
| 594 | case clang::BuiltinType::SChar: |
| 595 | case clang::BuiltinType::UShort: |
| 596 | case clang::BuiltinType::UInt: |
| 597 | case clang::BuiltinType::ULong: |
| 598 | case clang::BuiltinType::ULongLong: |
| 599 | case clang::BuiltinType::Short: |
| 600 | case clang::BuiltinType::Int: |
| 601 | case clang::BuiltinType::Long: |
| 602 | case clang::BuiltinType::LongLong: |
| 603 | case clang::BuiltinType::UInt128: |
| 604 | case clang::BuiltinType::Int128: |
| 605 | return true; |
| 606 | default: |
| 607 | return false; |
| 608 | } |
| 609 | } |
| 610 | |
| 584 | 611 | static const clang::FunctionProtoType *qual_type_get_fn_proto(ZigClangQualType qt, bool *is_ptr) { |
| 585 | 612 | const ZigClangType *ty = qual_type_canon(qt); |
| 586 | 613 | *is_ptr = false; |
| ... | ... | @@ -744,6 +771,17 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location, |
| 744 | 771 | if (qual_type_is_ptr(dest_type) && qual_type_is_ptr(src_type)) { |
| 745 | 772 | return trans_c_ptr_cast(c, source_location, dest_type, src_type, expr); |
| 746 | 773 | } |
| 774 | if (qual_type_is_int(dest_type) && qual_type_is_ptr(src_type)) { |
| 775 | AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt"); |
| 776 | addr_node->data.fn_call_expr.params.append(expr); |
| 777 | return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), addr_node); |
| 778 | } |
| 779 | if (qual_type_is_int(src_type) && qual_type_is_ptr(dest_type)) { |
| 780 | AstNode *ptr_node = trans_create_node_builtin_fn_call_str(c, "intToPtr"); |
| 781 | ptr_node->data.fn_call_expr.params.append(trans_qual_type(c, dest_type, source_location)); |
| 782 | ptr_node->data.fn_call_expr.params.append(expr); |
| 783 | return ptr_node; |
| 784 | } |
| 747 | 785 | // TODO: maybe widen to increase size |
| 748 | 786 | // TODO: maybe bitcast to change sign |
| 749 | 787 | // TODO: maybe truncate to reduce size |