| ... | ... | @@ -4790,6 +4790,52 @@ static TypeTableEntry *analyze_compile_err(CodeGen *g, ImportTableEntry *import, |
| 4790 | 4790 | return g->builtin_types.entry_invalid; |
| 4791 | 4791 | } |
| 4792 | 4792 | |
| 4793 | static TypeTableEntry *analyze_int_type(CodeGen *g, ImportTableEntry *import, |
| 4794 | BlockContext *context, AstNode *node) |
| 4795 | { |
| 4796 | AstNode **is_signed_node = &node->data.fn_call_expr.params.at(0); |
| 4797 | AstNode **bit_count_node = &node->data.fn_call_expr.params.at(1); |
| 4798 | AstNode **is_wrap_node = &node->data.fn_call_expr.params.at(2); |
| 4799 | |
| 4800 | TypeTableEntry *bool_type = g->builtin_types.entry_bool; |
| 4801 | TypeTableEntry *usize_type = g->builtin_types.entry_usize; |
| 4802 | TypeTableEntry *is_signed_type = analyze_expression(g, import, context, bool_type, *is_signed_node); |
| 4803 | TypeTableEntry *bit_count_type = analyze_expression(g, import, context, usize_type, *bit_count_node); |
| 4804 | TypeTableEntry *is_wrap_type = analyze_expression(g, import, context, bool_type, *is_wrap_node); |
| 4805 | |
| 4806 | if (is_signed_type->id == TypeTableEntryIdInvalid || |
| 4807 | bit_count_type->id == TypeTableEntryIdInvalid || |
| 4808 | is_wrap_type->id == TypeTableEntryIdInvalid) |
| 4809 | { |
| 4810 | return g->builtin_types.entry_invalid; |
| 4811 | } |
| 4812 | |
| 4813 | ConstExprValue *is_signed_val = &get_resolved_expr(*is_signed_node)->const_val; |
| 4814 | ConstExprValue *bit_count_val = &get_resolved_expr(*bit_count_node)->const_val; |
| 4815 | ConstExprValue *is_wrap_val = &get_resolved_expr(*is_wrap_node)->const_val; |
| 4816 | |
| 4817 | AstNode *bad_node = nullptr; |
| 4818 | if (!is_signed_val->ok) { |
| 4819 | bad_node = *is_signed_node; |
| 4820 | } else if (!bit_count_val->ok) { |
| 4821 | bad_node = *bit_count_node; |
| 4822 | } else if (!is_wrap_val->ok) { |
| 4823 | bad_node = *is_wrap_node; |
| 4824 | } |
| 4825 | if (bad_node) { |
| 4826 | add_node_error(g, bad_node, buf_sprintf("unable to evaluate constant expression")); |
| 4827 | return g->builtin_types.entry_invalid; |
| 4828 | } |
| 4829 | |
| 4830 | bool depends_on_compile_var = is_signed_val->depends_on_compile_var || |
| 4831 | bit_count_val->depends_on_compile_var || is_wrap_val->depends_on_compile_var; |
| 4832 | |
| 4833 | TypeTableEntry *int_type = get_int_type(g, is_signed_val->data.x_bool, is_wrap_val->data.x_bool, |
| 4834 | bit_count_val->data.x_bignum.data.x_uint); |
| 4835 | return resolve_expr_const_val_as_type(g, node, int_type, depends_on_compile_var); |
| 4836 | |
| 4837 | } |
| 4838 | |
| 4793 | 4839 | static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, |
| 4794 | 4840 | TypeTableEntry *expected_type, AstNode *node) |
| 4795 | 4841 | { |
| ... | ... | @@ -5136,6 +5182,8 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry |
| 5136 | 5182 | return analyze_truncate(g, import, context, node); |
| 5137 | 5183 | case BuiltinFnIdCompileErr: |
| 5138 | 5184 | return analyze_compile_err(g, import, context, node); |
| 5185 | case BuiltinFnIdIntType: |
| 5186 | return analyze_int_type(g, import, context, node); |
| 5139 | 5187 | } |
| 5140 | 5188 | zig_unreachable(); |
| 5141 | 5189 | } |