| ... | ... | @@ -22835,167 +22835,9 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 22835 | 22835 | bool ptr_is_volatile = false; |
| 22836 | 22836 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val, |
| 22837 | 22837 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22838 | | } else if (child_type->id == ZigTypeIdInt) { |
| 22839 | | if (buf_eql_str(field_name, "bit_count")) { |
| 22840 | | bool ptr_is_const = true; |
| 22841 | | bool ptr_is_volatile = false; |
| 22842 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22843 | | create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int, |
| 22844 | | child_type->data.integral.bit_count, false), |
| 22845 | | ira->codegen->builtin_types.entry_num_lit_int, |
| 22846 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22847 | | } else if (buf_eql_str(field_name, "is_signed")) { |
| 22848 | | bool ptr_is_const = true; |
| 22849 | | bool ptr_is_volatile = false; |
| 22850 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22851 | | create_const_bool(ira->codegen, child_type->data.integral.is_signed), |
| 22852 | | ira->codegen->builtin_types.entry_bool, |
| 22853 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22854 | | } else { |
| 22855 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22856 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22857 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22858 | | return ira->codegen->invalid_inst_gen; |
| 22859 | | } |
| 22860 | | } else if (child_type->id == ZigTypeIdFloat) { |
| 22861 | | if (buf_eql_str(field_name, "bit_count")) { |
| 22862 | | bool ptr_is_const = true; |
| 22863 | | bool ptr_is_volatile = false; |
| 22864 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22865 | | create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int, |
| 22866 | | child_type->data.floating.bit_count, false), |
| 22867 | | ira->codegen->builtin_types.entry_num_lit_int, |
| 22868 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22869 | | } else { |
| 22870 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22871 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22872 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22873 | | return ira->codegen->invalid_inst_gen; |
| 22874 | | } |
| 22875 | | } else if (child_type->id == ZigTypeIdPointer) { |
| 22876 | | if (buf_eql_str(field_name, "Child")) { |
| 22877 | | bool ptr_is_const = true; |
| 22878 | | bool ptr_is_volatile = false; |
| 22879 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22880 | | create_const_type(ira->codegen, child_type->data.pointer.child_type), |
| 22881 | | ira->codegen->builtin_types.entry_type, |
| 22882 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22883 | | } else if (buf_eql_str(field_name, "alignment")) { |
| 22884 | | bool ptr_is_const = true; |
| 22885 | | bool ptr_is_volatile = false; |
| 22886 | | if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type, |
| 22887 | | ResolveStatusAlignmentKnown))) |
| 22888 | | { |
| 22889 | | return ira->codegen->invalid_inst_gen; |
| 22890 | | } |
| 22891 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22892 | | create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int, |
| 22893 | | get_ptr_align(ira->codegen, child_type), false), |
| 22894 | | ira->codegen->builtin_types.entry_num_lit_int, |
| 22895 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22896 | | } else { |
| 22897 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22898 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22899 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22900 | | return ira->codegen->invalid_inst_gen; |
| 22901 | | } |
| 22902 | | } else if (child_type->id == ZigTypeIdArray) { |
| 22903 | | if (buf_eql_str(field_name, "Child")) { |
| 22904 | | bool ptr_is_const = true; |
| 22905 | | bool ptr_is_volatile = false; |
| 22906 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22907 | | create_const_type(ira->codegen, child_type->data.array.child_type), |
| 22908 | | ira->codegen->builtin_types.entry_type, |
| 22909 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22910 | | } else if (buf_eql_str(field_name, "len")) { |
| 22911 | | bool ptr_is_const = true; |
| 22912 | | bool ptr_is_volatile = false; |
| 22913 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22914 | | create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int, |
| 22915 | | child_type->data.array.len, false), |
| 22916 | | ira->codegen->builtin_types.entry_num_lit_int, |
| 22917 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22918 | | } else { |
| 22919 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22920 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22921 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22922 | | return ira->codegen->invalid_inst_gen; |
| 22923 | | } |
| 22924 | | } else if (child_type->id == ZigTypeIdErrorUnion) { |
| 22925 | | if (buf_eql_str(field_name, "Payload")) { |
| 22926 | | bool ptr_is_const = true; |
| 22927 | | bool ptr_is_volatile = false; |
| 22928 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22929 | | create_const_type(ira->codegen, child_type->data.error_union.payload_type), |
| 22930 | | ira->codegen->builtin_types.entry_type, |
| 22931 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22932 | | } else if (buf_eql_str(field_name, "ErrorSet")) { |
| 22933 | | bool ptr_is_const = true; |
| 22934 | | bool ptr_is_volatile = false; |
| 22935 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22936 | | create_const_type(ira->codegen, child_type->data.error_union.err_set_type), |
| 22937 | | ira->codegen->builtin_types.entry_type, |
| 22938 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22939 | | } else { |
| 22940 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22941 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22942 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22943 | | return ira->codegen->invalid_inst_gen; |
| 22944 | | } |
| 22945 | | } else if (child_type->id == ZigTypeIdOptional) { |
| 22946 | | if (buf_eql_str(field_name, "Child")) { |
| 22947 | | bool ptr_is_const = true; |
| 22948 | | bool ptr_is_volatile = false; |
| 22949 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22950 | | create_const_type(ira->codegen, child_type->data.maybe.child_type), |
| 22951 | | ira->codegen->builtin_types.entry_type, |
| 22952 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22953 | | } else { |
| 22954 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22955 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22956 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22957 | | return ira->codegen->invalid_inst_gen; |
| 22958 | | } |
| 22959 | | } else if (child_type->id == ZigTypeIdFn) { |
| 22960 | | if (buf_eql_str(field_name, "ReturnType")) { |
| 22961 | | if (child_type->data.fn.fn_type_id.return_type == nullptr) { |
| 22962 | | // Return type can only ever be null, if the function is generic |
| 22963 | | assert(child_type->data.fn.is_generic); |
| 22964 | | |
| 22965 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22966 | | buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name))); |
| 22967 | | return ira->codegen->invalid_inst_gen; |
| 22968 | | } |
| 22969 | | |
| 22970 | | bool ptr_is_const = true; |
| 22971 | | bool ptr_is_volatile = false; |
| 22972 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22973 | | create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type), |
| 22974 | | ira->codegen->builtin_types.entry_type, |
| 22975 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22976 | | } else if (buf_eql_str(field_name, "is_var_args")) { |
| 22977 | | bool ptr_is_const = true; |
| 22978 | | bool ptr_is_volatile = false; |
| 22979 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22980 | | create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args), |
| 22981 | | ira->codegen->builtin_types.entry_bool, |
| 22982 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22983 | | } else if (buf_eql_str(field_name, "arg_count")) { |
| 22984 | | bool ptr_is_const = true; |
| 22985 | | bool ptr_is_volatile = false; |
| 22986 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 22987 | | create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count), |
| 22988 | | ira->codegen->builtin_types.entry_usize, |
| 22989 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 22990 | | } else { |
| 22991 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22992 | | buf_sprintf("type '%s' has no member called '%s'", |
| 22993 | | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 22994 | | return ira->codegen->invalid_inst_gen; |
| 22995 | | } |
| 22996 | 22838 | } else { |
| 22997 | 22839 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 22998 | | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 22840 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 22999 | 22841 | return ira->codegen->invalid_inst_gen; |
| 23000 | 22842 | } |
| 23001 | 22843 | } else if (field_ptr_instruction->initializing) { |