aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-03-16 00:10:57 +0000
committergingerBill <bill@gingerbill.org>2019-03-16 00:10:57 +0000
commitf7efaf2ba2236329a67103cd5a25524907180987 (patch)
tree5b36e62f4559fbce2f1f9c6750df2175a2e17db7
parent14c6f2f258491a13164129d94240f13679cf1faa (diff)
fmt.printf support for pointer to container (one level deep)
-rw-r--r--core/fmt/fmt.odin27
1 files changed, 27 insertions, 0 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin
index 867d1c7bb..21cc6c79a 100644
--- a/core/fmt/fmt.odin
+++ b/core/fmt/fmt.odin
@@ -31,6 +31,7 @@ Info :: struct {
buf: ^strings.Builder,
arg: any, // Temporary
+ record_level: int,
}
fprint :: proc(fd: os.Handle, args: ..any) -> int {
@@ -1039,6 +1040,32 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
if v.id == typeid_of(^runtime.Type_Info) {
write_type(fi.buf, (^^runtime.Type_Info)(v.data)^);
} else {
+ if verb != 'p' {
+ elem := runtime.type_info_base(info.elem);
+ if elem != nil do switch e in elem.variant {
+ case runtime.Type_Info_Array,
+ runtime.Type_Info_Slice,
+ runtime.Type_Info_Dynamic_Array,
+ runtime.Type_Info_Map:
+ if fi.record_level == 0 {
+ fi.record_level += 1;
+ defer fi.record_level -= 1;
+ strings.write_byte(fi.buf, '&');
+ fmt_value(fi, any{(^rawptr)(v.data)^, info.elem.id}, verb);
+ return;
+ }
+
+ case runtime.Type_Info_Struct,
+ runtime.Type_Info_Union:
+ if fi.record_level == 0 {
+ fi.record_level += 1;
+ defer fi.record_level -= 1;
+ strings.write_byte(fi.buf, '&');
+ fmt_value(fi, any{(^rawptr)(v.data)^, info.elem.id}, verb);
+ return;
+ }
+ }
+ }
fmt_pointer(fi, (^rawptr)(v.data)^, verb);
}