github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types/fmt.go (about) 1 // Copyright 2009 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 package types 6 7 import ( 8 "github.com/shogo82148/std/fmt" 9 ) 10 11 // BuiltinPkg is a fake package that declares the universe block. 12 var BuiltinPkg *Pkg 13 14 // LocalPkg is the package being compiled. 15 var LocalPkg *Pkg 16 17 // UnsafePkg is package unsafe. 18 var UnsafePkg *Pkg 19 20 // BlankSym is the blank (_) symbol. 21 var BlankSym *Sym 22 23 // numImport tracks how often a package with a given name is imported. 24 // It is used to provide a better error message (by using the package 25 // path to disambiguate) if a package that appears multiple times with 26 // the same name appears in an error message. 27 var NumImport = make(map[string]int) 28 29 // Format implements formatting for a Sym. 30 // The valid formats are: 31 // 32 // %v Go syntax: Name for symbols in the local package, PkgName.Name for imported symbols. 33 // %+v Debug syntax: always include PkgName. prefix even for local names. 34 // %S Short syntax: Name only, no matter what. 35 func (s *Sym) Format(f fmt.State, verb rune) 36 37 func (s *Sym) String() string 38 39 var BasicTypeNames = []string{ 40 TINT: "int", 41 TUINT: "uint", 42 TINT8: "int8", 43 TUINT8: "uint8", 44 TINT16: "int16", 45 TUINT16: "uint16", 46 TINT32: "int32", 47 TUINT32: "uint32", 48 TINT64: "int64", 49 TUINT64: "uint64", 50 TUINTPTR: "uintptr", 51 TFLOAT32: "float32", 52 TFLOAT64: "float64", 53 TCOMPLEX64: "complex64", 54 TCOMPLEX128: "complex128", 55 TBOOL: "bool", 56 TANY: "any", 57 TSTRING: "string", 58 TNIL: "nil", 59 TIDEAL: "untyped number", 60 TBLANK: "blank", 61 } 62 63 // Format implements formatting for a Type. 64 // The valid formats are: 65 // 66 // %v Go syntax 67 // %+v Debug syntax: Go syntax with a KIND- prefix for all but builtins. 68 // %L Go syntax for underlying type if t is named 69 // %S short Go syntax: drop leading "func" in function type 70 // %-S special case for method receiver symbol 71 func (t *Type) Format(s fmt.State, verb rune) 72 73 // String returns the Go syntax for the type t. 74 func (t *Type) String() string 75 76 // LinkString returns a string description of t, suitable for use in 77 // link symbols. 78 // 79 // The description corresponds to type identity. That is, for any pair 80 // of types t1 and t2, Identical(t1, t2) == (t1.LinkString() == 81 // t2.LinkString()) is true. Thus it's safe to use as a map key to 82 // implement a type-identity-keyed map. 83 func (t *Type) LinkString() string 84 85 // NameString generates a user-readable, mostly unique string 86 // description of t. NameString always returns the same description 87 // for identical types, even across compilation units. 88 // 89 // NameString qualifies identifiers by package name, so it has 90 // collisions when different packages share the same names and 91 // identifiers. It also does not distinguish function-scope defined 92 // types from package-scoped defined types or from each other. 93 func (t *Type) NameString() string 94 95 // SplitVargenSuffix returns name split into a base string and a ·N 96 // suffix, if any. 97 func SplitVargenSuffix(name string) (base, suffix string) 98 99 // TypeHash computes a hash value for type t to use in type switch statements. 100 func TypeHash(t *Type) uint32