github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/typestring.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file implements printing of types. 6 7 package types2 8 9 import ( 10 "github.com/shogo82148/std/bytes" 11 ) 12 13 // A Qualifier controls how named package-level objects are printed in 14 // calls to [TypeString], [ObjectString], and [SelectionString]. 15 // 16 // These three formatting routines call the Qualifier for each 17 // package-level object O, and if the Qualifier returns a non-empty 18 // string p, the object is printed in the form p.O. 19 // If it returns an empty string, only the object name O is printed. 20 // 21 // Using a nil Qualifier is equivalent to using (*[Package]).Path: the 22 // object is qualified by the import path, e.g., "encoding/json.Marshal". 23 type Qualifier func(*Package) string 24 25 // RelativeTo returns a [Qualifier] that fully qualifies members of 26 // all packages other than pkg. 27 func RelativeTo(pkg *Package) Qualifier 28 29 // TypeString returns the string representation of typ. 30 // The [Qualifier] controls the printing of 31 // package-level objects, and may be nil. 32 func TypeString(typ Type, qf Qualifier) string 33 34 // WriteType writes the string representation of typ to buf. 35 // The [Qualifier] controls the printing of 36 // package-level objects, and may be nil. 37 func WriteType(buf *bytes.Buffer, typ Type, qf Qualifier) 38 39 // WriteSignature writes the representation of the signature sig to buf, 40 // without a leading "func" keyword. The [Qualifier] controls the printing 41 // of package-level objects, and may be nil. 42 func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier)