|
@@ -4542,7 +4542,7 @@ gb_internal Type *alloc_type_proc_from_types(Type **param_types, unsigned param_
|
|
|
// return type;
|
|
|
// }
|
|
|
|
|
|
-gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) {
|
|
|
+gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false, bool allow_polymorphic=false) {
|
|
|
if (type == nullptr) {
|
|
|
return gb_string_appendc(str, "<no type>");
|
|
|
}
|
|
@@ -4567,24 +4567,24 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
str = gb_string_append_length(str, name.text, name.len);
|
|
|
if (type->Generic.specialized != nullptr) {
|
|
|
str = gb_string_append_rune(str, '/');
|
|
|
- str = write_type_to_string(str, type->Generic.specialized);
|
|
|
+ str = write_type_to_string(str, type->Generic.specialized, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case Type_Pointer:
|
|
|
str = gb_string_append_rune(str, '^');
|
|
|
- str = write_type_to_string(str, type->Pointer.elem);
|
|
|
+ str = write_type_to_string(str, type->Pointer.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_SoaPointer:
|
|
|
str = gb_string_appendc(str, "#soa ^");
|
|
|
- str = write_type_to_string(str, type->SoaPointer.elem);
|
|
|
+ str = write_type_to_string(str, type->SoaPointer.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_MultiPointer:
|
|
|
str = gb_string_appendc(str, "[^]");
|
|
|
- str = write_type_to_string(str, type->Pointer.elem);
|
|
|
+ str = write_type_to_string(str, type->Pointer.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_EnumeratedArray:
|
|
@@ -4592,31 +4592,31 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
str = gb_string_appendc(str, "#sparse");
|
|
|
}
|
|
|
str = gb_string_append_rune(str, '[');
|
|
|
- str = write_type_to_string(str, type->EnumeratedArray.index);
|
|
|
+ str = write_type_to_string(str, type->EnumeratedArray.index, shorthand, allow_polymorphic);
|
|
|
str = gb_string_append_rune(str, ']');
|
|
|
- str = write_type_to_string(str, type->EnumeratedArray.elem);
|
|
|
+ str = write_type_to_string(str, type->EnumeratedArray.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_Array:
|
|
|
str = gb_string_appendc(str, gb_bprintf("[%lld]", cast(long long)type->Array.count));
|
|
|
- str = write_type_to_string(str, type->Array.elem);
|
|
|
+ str = write_type_to_string(str, type->Array.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_Slice:
|
|
|
str = gb_string_appendc(str, "[]");
|
|
|
- str = write_type_to_string(str, type->Array.elem);
|
|
|
+ str = write_type_to_string(str, type->Array.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_DynamicArray:
|
|
|
str = gb_string_appendc(str, "[dynamic]");
|
|
|
- str = write_type_to_string(str, type->DynamicArray.elem);
|
|
|
+ str = write_type_to_string(str, type->DynamicArray.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_Enum:
|
|
|
str = gb_string_appendc(str, "enum");
|
|
|
if (type->Enum.base_type != nullptr) {
|
|
|
str = gb_string_appendc(str, " ");
|
|
|
- str = write_type_to_string(str, type->Enum.base_type);
|
|
|
+ str = write_type_to_string(str, type->Enum.base_type, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
str = gb_string_appendc(str, " {");
|
|
|
for_array(i, type->Enum.fields) {
|
|
@@ -4633,6 +4633,13 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
|
|
|
case Type_Union:
|
|
|
str = gb_string_appendc(str, "union");
|
|
|
+
|
|
|
+ if (allow_polymorphic && type->Struct.polymorphic_params) {
|
|
|
+ str = gb_string_appendc(str, "(");
|
|
|
+ str = write_type_to_string(str, type->Struct.polymorphic_params, shorthand, allow_polymorphic);
|
|
|
+ str = gb_string_appendc(str, ")");
|
|
|
+ }
|
|
|
+
|
|
|
switch (type->Union.kind) {
|
|
|
case UnionType_no_nil: str = gb_string_appendc(str, " #no_nil"); break;
|
|
|
case UnionType_shared_nil: str = gb_string_appendc(str, " #shared_nil"); break;
|
|
@@ -4642,7 +4649,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
for_array(i, type->Union.variants) {
|
|
|
Type *t = type->Union.variants[i];
|
|
|
if (i > 0) str = gb_string_appendc(str, ", ");
|
|
|
- str = write_type_to_string(str, t);
|
|
|
+ str = write_type_to_string(str, t, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
str = gb_string_append_rune(str, '}');
|
|
|
break;
|
|
@@ -4655,17 +4662,24 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
case StructSoa_Dynamic: str = gb_string_appendc(str, "#soa[dynamic]"); break;
|
|
|
default: GB_PANIC("Unknown StructSoaKind"); break;
|
|
|
}
|
|
|
- str = write_type_to_string(str, type->Struct.soa_elem);
|
|
|
+ str = write_type_to_string(str, type->Struct.soa_elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
str = gb_string_appendc(str, "struct");
|
|
|
+
|
|
|
+ if (allow_polymorphic && type->Struct.polymorphic_params) {
|
|
|
+ str = gb_string_appendc(str, "(");
|
|
|
+ str = write_type_to_string(str, type->Struct.polymorphic_params, shorthand, allow_polymorphic);
|
|
|
+ str = gb_string_appendc(str, ")");
|
|
|
+ }
|
|
|
+
|
|
|
if (type->Struct.is_packed) str = gb_string_appendc(str, " #packed");
|
|
|
if (type->Struct.is_raw_union) str = gb_string_appendc(str, " #raw_union");
|
|
|
if (type->Struct.is_no_copy) str = gb_string_appendc(str, " #no_copy");
|
|
|
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, " {");
|
|
|
|
|
|
+ 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);
|
|
@@ -4678,7 +4692,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
}
|
|
|
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 = write_type_to_string(str, f->type, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
}
|
|
|
str = gb_string_append_rune(str, '}');
|
|
@@ -4686,9 +4700,9 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
|
|
|
case Type_Map: {
|
|
|
str = gb_string_appendc(str, "map[");
|
|
|
- str = write_type_to_string(str, type->Map.key);
|
|
|
+ str = write_type_to_string(str, type->Map.key, shorthand, allow_polymorphic);
|
|
|
str = gb_string_append_rune(str, ']');
|
|
|
- str = write_type_to_string(str, type->Map.value);
|
|
|
+ str = write_type_to_string(str, type->Map.value, shorthand, allow_polymorphic);
|
|
|
} break;
|
|
|
|
|
|
case Type_Named:
|
|
@@ -4718,9 +4732,11 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
str = gb_string_append_length(str, name.text, name.len);
|
|
|
if (!is_type_untyped(var->type)) {
|
|
|
str = gb_string_appendc(str, ": ");
|
|
|
- str = write_type_to_string(str, var->type);
|
|
|
- str = gb_string_appendc(str, " = ");
|
|
|
- str = write_exact_value_to_string(str, var->Constant.value);
|
|
|
+ str = write_type_to_string(str, var->type, shorthand, allow_polymorphic);
|
|
|
+ if (var->Constant.value.kind) {
|
|
|
+ str = gb_string_appendc(str, " = ");
|
|
|
+ str = write_exact_value_to_string(str, var->Constant.value);
|
|
|
+ }
|
|
|
} else {
|
|
|
str = gb_string_appendc(str, " := ");
|
|
|
str = write_exact_value_to_string(str, var->Constant.value);
|
|
@@ -4736,20 +4752,31 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
Type *slice = base_type(var->type);
|
|
|
str = gb_string_appendc(str, "..");
|
|
|
GB_ASSERT(var->type->kind == Type_Slice);
|
|
|
- str = write_type_to_string(str, slice->Slice.elem);
|
|
|
+ str = write_type_to_string(str, slice->Slice.elem, shorthand, allow_polymorphic);
|
|
|
} else {
|
|
|
- str = write_type_to_string(str, var->type);
|
|
|
+ str = write_type_to_string(str, var->type, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
} else {
|
|
|
GB_ASSERT(var->kind == Entity_TypeName);
|
|
|
if (var->type->kind == Type_Generic) {
|
|
|
- str = gb_string_appendc(str, "typeid/");
|
|
|
- str = write_type_to_string(str, var->type);
|
|
|
+ if (var->token.string.len != 0) {
|
|
|
+ String name = var->token.string;
|
|
|
+ str = gb_string_appendc(str, "$");
|
|
|
+ str = gb_string_append_length(str, name.text, name.len);
|
|
|
+ str = gb_string_appendc(str, ": typeid");
|
|
|
+ if (var->type->Generic.specialized) {
|
|
|
+ str = gb_string_appendc(str, "/");
|
|
|
+ str = write_type_to_string(str, var->type->Generic.specialized, shorthand, allow_polymorphic);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ str = gb_string_appendc(str, "typeid/");
|
|
|
+ str = write_type_to_string(str, var->type, shorthand, allow_polymorphic);
|
|
|
+ }
|
|
|
} else {
|
|
|
str = gb_string_appendc(str, "$");
|
|
|
str = gb_string_append_length(str, name.text, name.len);
|
|
|
str = gb_string_appendc(str, "=");
|
|
|
- str = write_type_to_string(str, var->type);
|
|
|
+ str = write_type_to_string(str, var->type, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -4795,7 +4822,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
}
|
|
|
str = gb_string_appendc(str, "(");
|
|
|
if (type->Proc.params) {
|
|
|
- str = write_type_to_string(str, type->Proc.params);
|
|
|
+ str = write_type_to_string(str, type->Proc.params, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
str = gb_string_appendc(str, ")");
|
|
|
if (type->Proc.results) {
|
|
@@ -4803,7 +4830,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
if (type->Proc.results->Tuple.variables.count > 1) {
|
|
|
str = gb_string_appendc(str, "(");
|
|
|
}
|
|
|
- str = write_type_to_string(str, type->Proc.results);
|
|
|
+ str = write_type_to_string(str, type->Proc.results, shorthand, allow_polymorphic);
|
|
|
if (type->Proc.results->Tuple.variables.count > 1) {
|
|
|
str = gb_string_appendc(str, ")");
|
|
|
}
|
|
@@ -4815,7 +4842,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
if (type->BitSet.elem == nullptr) {
|
|
|
str = gb_string_appendc(str, "<unresolved>");
|
|
|
} else if (is_type_enum(type->BitSet.elem)) {
|
|
|
- str = write_type_to_string(str, type->BitSet.elem);
|
|
|
+ str = write_type_to_string(str, type->BitSet.elem, shorthand, allow_polymorphic);
|
|
|
} else {
|
|
|
str = gb_string_append_fmt(str, "%lld", type->BitSet.lower);
|
|
|
str = gb_string_append_fmt(str, "..=");
|
|
@@ -4823,14 +4850,14 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
}
|
|
|
if (type->BitSet.underlying != nullptr) {
|
|
|
str = gb_string_appendc(str, "; ");
|
|
|
- str = write_type_to_string(str, type->BitSet.underlying);
|
|
|
+ str = write_type_to_string(str, type->BitSet.underlying, shorthand, allow_polymorphic);
|
|
|
}
|
|
|
str = gb_string_appendc(str, "]");
|
|
|
break;
|
|
|
|
|
|
case Type_SimdVector:
|
|
|
str = gb_string_append_fmt(str, "#simd[%d]", cast(int)type->SimdVector.count);
|
|
|
- str = write_type_to_string(str, type->SimdVector.elem);
|
|
|
+ str = write_type_to_string(str, type->SimdVector.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_Matrix:
|
|
@@ -4838,12 +4865,12 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
str = gb_string_appendc(str, "#row_major ");
|
|
|
}
|
|
|
str = gb_string_appendc(str, gb_bprintf("matrix[%d, %d]", cast(int)type->Matrix.row_count, cast(int)type->Matrix.column_count));
|
|
|
- str = write_type_to_string(str, type->Matrix.elem);
|
|
|
+ str = write_type_to_string(str, type->Matrix.elem, shorthand, allow_polymorphic);
|
|
|
break;
|
|
|
|
|
|
case Type_BitField:
|
|
|
str = gb_string_appendc(str, "bit_field ");
|
|
|
- str = write_type_to_string(str, type->BitField.backing_type);
|
|
|
+ str = write_type_to_string(str, type->BitField.backing_type, shorthand, allow_polymorphic);
|
|
|
str = gb_string_appendc(str, " {");
|
|
|
for (isize i = 0; i < type->BitField.fields.count; i++) {
|
|
|
Entity *f = type->BitField.fields[i];
|
|
@@ -4852,7 +4879,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
|
|
|
}
|
|
|
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 = write_type_to_string(str, f->type, shorthand, allow_polymorphic);
|
|
|
str = gb_string_append_fmt(str, " | %u", type->BitField.bit_sizes[i]);
|
|
|
}
|
|
|
str = gb_string_appendc(str, " }");
|
|
@@ -4870,6 +4897,11 @@ gb_internal gbString type_to_string(Type *type, bool shorthand) {
|
|
|
return write_type_to_string(gb_string_make(heap_allocator(), ""), type, shorthand);
|
|
|
}
|
|
|
|
|
|
+gb_internal gbString type_to_string_polymorphic(Type *type) {
|
|
|
+ return write_type_to_string(gb_string_make(heap_allocator(), ""), type, false, true);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
gb_internal gbString type_to_string_shorthand(Type *type) {
|
|
|
return type_to_string(type, true);
|
|
|
}
|