diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-30 13:18:47 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-30 13:18:47 -0400 |
| commit | 2e27b88c1b9fa8ec9b9f243909f5b793b376f207 (patch) | |
| tree | f70433489c8a1fbf3bae6bf4cce364f6bdf8c9f7 /builtins/pointer.c | |
| parent | 3c0a8f0b899a343f43caf9c95147b2cf77a7b525 (diff) | |
Improved syntax for optionals
Diffstat (limited to 'builtins/pointer.c')
| -rw-r--r-- | builtins/pointer.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/builtins/pointer.c b/builtins/pointer.c index 7fe8c160..d71811b0 100644 --- a/builtins/pointer.c +++ b/builtins/pointer.c @@ -22,7 +22,8 @@ public CORD Pointer$as_text(const void *x, bool colorize, const TypeInfo *type) auto ptr_info = type->PointerInfo; if (!x) { CORD typename = generic_as_text(NULL, false, ptr_info.pointed); - return colorize ? CORD_asprintf("\x1b[34;1m%s%s\x1b[m", ptr_info.sigil, typename) : CORD_cat(ptr_info.sigil, typename); + CORD c = colorize ? CORD_asprintf("\x1b[34;1m%s%s\x1b[m", ptr_info.sigil, typename) : CORD_cat(ptr_info.sigil, typename); + return ptr_info.is_optional ? CORD_cat(c, "?") : c; } const void *ptr = *(const void**)x; if (!ptr) { @@ -36,8 +37,11 @@ public CORD Pointer$as_text(const void *x, bool colorize, const TypeInfo *type) int32_t depth = 0; for (recursion_t *r = recursion; r; r = r->next) { ++depth; - if (r->ptr == ptr) - return CORD_asprintf(colorize ? "\x1b[34;1m%s..%d\x1b[m" : "%s..%d", ptr_info.sigil, depth); + if (r->ptr == ptr) { + CORD c = CORD_asprintf(colorize ? "\x1b[34;1m%s..%d\x1b[m" : "%s..%d", ptr_info.sigil, depth); + if (ptr_info.is_optional) c = CORD_cat(c, colorize ? "\x1b[34;1m?\x1b[m" : "?"); + return c; + } } CORD pointed; @@ -47,7 +51,9 @@ public CORD Pointer$as_text(const void *x, bool colorize, const TypeInfo *type) pointed = generic_as_text(ptr, colorize, ptr_info.pointed); recursion = recursion->next; } - return colorize ? CORD_asprintf("\x1b[34;1m%s\x1b[m%r", ptr_info.sigil, pointed) : CORD_cat(ptr_info.sigil, pointed); + CORD c = colorize ? CORD_asprintf("\x1b[34;1m%s\x1b[m%r", ptr_info.sigil, pointed) : CORD_cat(ptr_info.sigil, pointed); + if (ptr_info.is_optional) c = CORD_cat(c, colorize ? "\x1b[34;1m?\x1b[m" : "?"); + return c; } public int32_t Pointer$compare(const void *x, const void *y, const TypeInfo *type) { |
