| ... | ... | @@ -6010,16 +6010,20 @@ static void render_const_val_err_set(CodeGen *g, Buf *buf, ConstExprValue *const |
| 6010 | 6010 | } |
| 6011 | 6011 | } |
| 6012 | 6012 | |
| 6013 | | static void render_const_val_array(CodeGen *g, Buf *buf, ConstExprValue *const_val, size_t len) { |
| 6014 | | switch (const_val->data.x_array.special) { |
| 6013 | static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ConstExprValue *const_val, uint64_t start, uint64_t len) { |
| 6014 | ConstArrayValue *array = &const_val->data.x_array; |
| 6015 | switch (array->special) { |
| 6015 | 6016 | case ConstArraySpecialUndef: |
| 6016 | 6017 | buf_append_str(buf, "undefined"); |
| 6017 | 6018 | return; |
| 6018 | 6019 | case ConstArraySpecialBuf: { |
| 6019 | | Buf *array_buf = const_val->data.x_array.data.s_buf; |
| 6020 | Buf *array_buf = array->data.s_buf; |
| 6021 | const char *base = &buf_ptr(array_buf)[start]; |
| 6022 | assert(start + len <= buf_len(array_buf)); |
| 6023 | |
| 6020 | 6024 | buf_append_char(buf, '"'); |
| 6021 | | for (size_t i = 0; i < buf_len(array_buf); i += 1) { |
| 6022 | | uint8_t c = buf_ptr(array_buf)[i]; |
| 6025 | for (size_t i = 0; i < len; i += 1) { |
| 6026 | uint8_t c = base[i]; |
| 6023 | 6027 | if (c == '"') { |
| 6024 | 6028 | buf_append_str(buf, "\\\""); |
| 6025 | 6029 | } else { |
| ... | ... | @@ -6030,12 +6034,13 @@ static void render_const_val_array(CodeGen *g, Buf *buf, ConstExprValue *const_v |
| 6030 | 6034 | return; |
| 6031 | 6035 | } |
| 6032 | 6036 | case ConstArraySpecialNone: { |
| 6033 | | buf_appendf(buf, "%s{", buf_ptr(&const_val->type->name)); |
| 6037 | ConstExprValue *base = &array->data.s_none.elements[start]; |
| 6038 | assert(start + len <= const_val->type->data.array.len); |
| 6039 | |
| 6040 | buf_appendf(buf, "%s{", buf_ptr(type_name)); |
| 6034 | 6041 | for (uint64_t i = 0; i < len; i += 1) { |
| 6035 | | if (i != 0) |
| 6036 | | buf_appendf(buf, ","); |
| 6037 | | ConstExprValue *child_value = &const_val->data.x_array.data.s_none.elements[i]; |
| 6038 | | render_const_value(g, buf, child_value); |
| 6042 | if (i != 0) buf_appendf(buf, ","); |
| 6043 | render_const_value(g, buf, &base[i]); |
| 6039 | 6044 | } |
| 6040 | 6045 | buf_appendf(buf, "}"); |
| 6041 | 6046 | return; |
| ... | ... | @@ -6124,10 +6129,16 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 6124 | 6129 | } |
| 6125 | 6130 | case ZigTypeIdPointer: |
| 6126 | 6131 | return render_const_val_ptr(g, buf, const_val, type_entry); |
| 6127 | | case ZigTypeIdVector: |
| 6128 | | return render_const_val_array(g, buf, const_val, type_entry->data.vector.len); |
| 6129 | | case ZigTypeIdArray: |
| 6130 | | return render_const_val_array(g, buf, const_val, type_entry->data.array.len); |
| 6132 | case ZigTypeIdArray: { |
| 6133 | uint64_t len = type_entry->data.array.len; |
| 6134 | render_const_val_array(g, buf, &type_entry->name, const_val, 0, len); |
| 6135 | return; |
| 6136 | } |
| 6137 | case ZigTypeIdVector: { |
| 6138 | uint32_t len = type_entry->data.vector.len; |
| 6139 | render_const_val_array(g, buf, &type_entry->name, const_val, 0, len); |
| 6140 | return; |
| 6141 | } |
| 6131 | 6142 | case ZigTypeIdNull: |
| 6132 | 6143 | { |
| 6133 | 6144 | buf_appendf(buf, "null"); |
| ... | ... | @@ -6169,7 +6180,19 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 6169 | 6180 | } |
| 6170 | 6181 | case ZigTypeIdStruct: |
| 6171 | 6182 | { |
| 6172 | | buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name)); |
| 6183 | if (is_slice(type_entry)) { |
| 6184 | ConstPtrValue *ptr = &const_val->data.x_struct.fields[slice_ptr_index].data.x_ptr; |
| 6185 | assert(ptr->special == ConstPtrSpecialBaseArray); |
| 6186 | ConstExprValue *array = ptr->data.base_array.array_val; |
| 6187 | size_t start = ptr->data.base_array.elem_index; |
| 6188 | |
| 6189 | ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index]; |
| 6190 | size_t len = bigint_as_unsigned(&len_val->data.x_bigint); |
| 6191 | |
| 6192 | render_const_val_array(g, buf, &type_entry->name, array, start, len); |
| 6193 | } else { |
| 6194 | buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name)); |
| 6195 | } |
| 6173 | 6196 | return; |
| 6174 | 6197 | } |
| 6175 | 6198 | case ZigTypeIdEnum: |