internal/runtime: structStr

This commit is contained in:
visualfc
2024-12-20 16:09:39 +08:00
parent ef28abe896
commit c1588d70cd
2 changed files with 23 additions and 2 deletions

View File

@@ -487,7 +487,7 @@ func interfaceStr(ft *abi.InterfaceType) string {
repr = append(repr, "interface {"...)
for i, t := range ft.Methods {
if i > 0 {
repr = append(repr, "; "...)
repr = append(repr, ';')
}
repr = append(repr, ' ')
repr = append(repr, t.Name_...)

View File

@@ -153,7 +153,7 @@ func Struct(pkgPath string, size uintptr, fields ...abi.StructField) *Type {
Size_: size,
Hash: uint32(abi.Struct), // TODO(xsw): hash
Kind_: uint8(abi.Struct),
Str_: "struct {...}",
Str_: structStr(fields),
},
PkgPath_: pkgPath,
Fields: fields,
@@ -401,6 +401,27 @@ func ispaddedfield(st *structtype, i int) bool {
return fd.Offset+fd.Typ.Size_ != end
}
func structStr(fields []abi.StructField) string {
repr := make([]byte, 0, 64)
repr = append(repr, "struct {"...)
for i, st := range fields {
if i > 0 {
repr = append(repr, ';')
}
repr = append(repr, ' ')
if !st.Embedded_ {
repr = append(repr, st.Name_...)
repr = append(repr, ' ')
}
repr = append(repr, st.Typ.String()...)
}
if len(fields) > 0 {
repr = append(repr, ' ')
}
repr = append(repr, '}')
return string(repr)
}
type rtypes struct {
types []*abi.Type
}