diff options
| author | gingerBill <bill@gingerbill.org> | 2024-02-22 19:48:44 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-02-22 19:48:44 +0000 |
| commit | 5c5b78cbbe6e9a3443448fd986f6068cfba9e136 (patch) | |
| tree | e4b330e6106663dfce2935dccdc59ebfe3705354 /core/fmt | |
| parent | 54515af8ccff67cae71982d1bbf5bd1c31628af3 (diff) | |
Improve `bit_field` printing
Diffstat (limited to 'core/fmt')
| -rw-r--r-- | core/fmt/fmt.odin | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 38e125c30..8c63055ed 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -2173,6 +2173,8 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) #partial switch b in info.base.variant { case runtime.Type_Info_Struct: fmt_struct(fi, v, verb, b, info.name) + case runtime.Type_Info_Bit_Field: + fmt_bit_field(fi, v, verb, b, info.name) case runtime.Type_Info_Bit_Set: fmt_bit_set(fi, v, verb = verb) case: @@ -2284,7 +2286,7 @@ fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Matrix } } -fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit_Field) { +fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit_Field, type_name: string) { read_bits :: proc(ptr: [^]byte, offset, size: uintptr) -> (res: u64) { for i in 0..<size { j := i+offset @@ -2314,7 +2316,8 @@ fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit return false } - io.write_string(fi.writer, "bit_field{", &fi.n) + io.write_string(fi.writer, type_name if len(type_name) != 0 else "bit_field", &fi.n) + io.write_string(fi.writer, "{", &fi.n) hash := fi.hash; defer fi.hash = hash indent := fi.indent; defer fi.indent -= 1 @@ -2702,7 +2705,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { fmt_matrix(fi, v, verb, info) case runtime.Type_Info_Bit_Field: - fmt_bit_field(fi, v, verb, info) + fmt_bit_field(fi, v, verb, info, "") } } // Formats a complex number based on the given formatting verb |