return t.tconv(0)
}
+// ShortString generates a short description of t.
+// It is used in autogenerated method names, reflection,
+// and itab names.
+func (t *Type) ShortString() string {
+ if fmtmode != FErr {
+ Fatalf("ShortString fmtmode %v", fmtmode)
+ }
+ return t.tconv(FmtLeft)
+}
+
+// LongString generates a complete description of t.
+// It is useful for reflection,
+// or when a unique fingerprint or hash of a type is required.
+func (t *Type) LongString() string {
+ if fmtmode != FErr {
+ Fatalf("LongString fmtmode %v", fmtmode)
+ }
+ return t.tconv(FmtLeft | FmtUnsigned)
+}
+
func fldconv(f *Field, flag FmtFlag) string {
if f == nil {
return "<T>"
}
exported := false
- p := t.tconv(FmtLeft | FmtUnsigned)
+ p := t.LongString()
// If we're writing out type T,
// we are very likely to write out type *T as well.
// Use the string "*T"[1:] for "T", so that the two
}
func typesym(t *Type) *Sym {
- name := t.tconv(FmtLeft)
+ name := t.ShortString()
// Use a separate symbol name for Noalg types for #17752.
if a, bad := algtype1(t); a == ANOEQ && bad.Noalg() {
// tracksym returns the symbol for tracking use of field/method f, assumed
// to be a member of struct/interface type t.
func tracksym(t *Type, f *Field) *Sym {
- return Pkglookup(t.tconv(FmtLeft)+"."+f.Sym.Name, trackpkg)
+ return Pkglookup(t.ShortString()+"."+f.Sym.Name, trackpkg)
}
func typesymprefix(prefix string, t *Type) *Sym {
- p := prefix + "." + t.tconv(FmtLeft)
+ p := prefix + "." + t.ShortString()
s := Pkglookup(p, typepkg)
//print("algsym: %s -> %+S\n", p, s);
if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() || !itype.IsInterface() || itype.IsEmptyInterface() {
Fatalf("itabname(%v, %v)", t, itype)
}
- s := Pkglookup(t.tconv(FmtLeft)+","+itype.tconv(FmtLeft), itabpkg)
+ s := Pkglookup(t.ShortString()+","+itype.ShortString(), itabpkg)
if s.Def == nil {
n := newname(s)
n.Type = Types[TUINT8]
// method functions. None are allocated on heap, so we can use obj.NOPTR.
ggloblsym(i.sym, int32(o), int16(obj.DUPOK|obj.NOPTR))
- ilink := Pkglookup(i.t.tconv(FmtLeft)+","+i.itype.tconv(FmtLeft), itablinkpkg)
+ ilink := Pkglookup(i.t.ShortString()+","+i.itype.ShortString(), itablinkpkg)
dsymptr(ilink, 0, i.sym, 0)
ggloblsym(ilink, int32(Widthptr), int16(obj.DUPOK|obj.RODATA))
}
return s.Def
}
-// typehash computes a hash value for type t to use in type switch
-// statements.
+// typehash computes a hash value for type t to use in type switch statements.
func typehash(t *Type) uint32 {
- // t.tconv(FmtLeft | FmtUnsigned) already contains all the necessary logic
- // to generate a representation that completely describes the type, so using
- // it here avoids duplicating that code.
- // See the comments in exprSwitch.checkDupCases.
- p := t.tconv(FmtLeft | FmtUnsigned)
+ p := t.LongString()
// Using MD5 is overkill, but reduces accidental collisions.
h := md5.Sum([]byte(p))