aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-03-14 11:02:59 +0000
committerGitHub <noreply@github.com>2022-03-14 11:02:59 +0000
commita7adb2fb6e092e1f37791b1da633b01ff3ca489c (patch)
tree6bff88f90b9b72dcc04ce1c02f86d981c2135fdd /src/types.cpp
parent410b85b5c7f768543e03c9fc6f47f8c2efcd602b (diff)
parentf907516cbd0078b69996929d02742d0c1a48c226 (diff)
Merge branch 'master' into freestanding_amd64
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 74080334a..58ccdf5b9 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -703,7 +703,7 @@ struct TypePath;
i64 type_size_of (Type *t);
i64 type_align_of (Type *t);
i64 type_offset_of (Type *t, i32 index);
-gbString type_to_string (Type *type);
+gbString type_to_string (Type *type, bool shorthand=false);
i64 type_size_of_internal(Type *t, TypePath *path);
void init_map_internal_types(Type *type);
Type * bit_set_to_int(Type *t);
@@ -3936,7 +3936,7 @@ Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type
-gbString write_type_to_string(gbString str, Type *type) {
+gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) {
if (type == nullptr) {
return gb_string_appendc(str, "<no type>");
}
@@ -4051,15 +4051,21 @@ gbString write_type_to_string(gbString str, Type *type) {
if (type->Struct.is_raw_union) str = gb_string_appendc(str, " #raw_union");
if (type->Struct.custom_align != 0) str = gb_string_append_fmt(str, " #align %d", cast(int)type->Struct.custom_align);
str = gb_string_appendc(str, " {");
- for_array(i, type->Struct.fields) {
- Entity *f = type->Struct.fields[i];
- GB_ASSERT(f->kind == Entity_Variable);
- if (i > 0) {
- str = gb_string_appendc(str, ", ");
+
+
+ if (shorthand && type->Struct.fields.count > 16) {
+ str = gb_string_append_fmt(str, "%lld fields...", cast(long long)type->Struct.fields.count);
+ } else {
+ for_array(i, type->Struct.fields) {
+ Entity *f = type->Struct.fields[i];
+ GB_ASSERT(f->kind == Entity_Variable);
+ if (i > 0) {
+ str = gb_string_appendc(str, ", ");
+ }
+ str = gb_string_append_length(str, f->token.string.text, f->token.string.len);
+ str = gb_string_appendc(str, ": ");
+ str = write_type_to_string(str, f->type);
}
- str = gb_string_append_length(str, f->token.string.text, f->token.string.len);
- str = gb_string_appendc(str, ": ");
- str = write_type_to_string(str, f->type);
}
str = gb_string_append_rune(str, '}');
} break;
@@ -4234,13 +4240,16 @@ gbString write_type_to_string(gbString str, Type *type) {
}
-gbString type_to_string(Type *type, gbAllocator allocator) {
- return write_type_to_string(gb_string_make(allocator, ""), type);
+gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand=false) {
+ return write_type_to_string(gb_string_make(allocator, ""), type, shorthand);
}
-gbString type_to_string(Type *type) {
- return write_type_to_string(gb_string_make(heap_allocator(), ""), type);
+gbString type_to_string(Type *type, bool shorthand) {
+ return write_type_to_string(gb_string_make(heap_allocator(), ""), type, shorthand);
}
+gbString type_to_string_shorthand(Type *type) {
+ return type_to_string(type, true);
+}