github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/types/utils.go (about) 1 // Copyright 2017 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/gagliardetto/golang-go/cmd/internal/obj" 9 "fmt" 10 ) 11 12 const BADWIDTH = -1000000000 13 14 // The following variables must be initialized early by the frontend. 15 // They are here to break import cycles. 16 // TODO(gri) eliminate these dependencies. 17 var ( 18 Widthptr int 19 Dowidth func(*Type) 20 Fatalf func(string, ...interface{}) 21 Sconv func(*Sym, int, int) string // orig: func sconv(s *Sym, flag FmtFlag, mode fmtMode) string 22 Tconv func(*Type, int, int) string // orig: func tconv(t *Type, flag FmtFlag, mode fmtMode) string 23 FormatSym func(*Sym, fmt.State, rune, int) // orig: func symFormat(sym *Sym, s fmt.State, verb rune, mode fmtMode) 24 FormatType func(*Type, fmt.State, rune, int) // orig: func typeFormat(t *Type, s fmt.State, verb rune, mode fmtMode) 25 TypeLinkSym func(*Type) *obj.LSym 26 Ctxt *obj.Link 27 28 FmtLeft int 29 FmtUnsigned int 30 FErr int 31 ) 32 33 func (s *Sym) String() string { 34 return Sconv(s, 0, FErr) 35 } 36 37 func (sym *Sym) Format(s fmt.State, verb rune) { 38 FormatSym(sym, s, verb, FErr) 39 } 40 41 func (t *Type) String() string { 42 // The implementation of tconv (including typefmt and fldconv) 43 // must handle recursive types correctly. 44 return Tconv(t, 0, FErr) 45 } 46 47 // ShortString generates a short description of t. 48 // It is used in autogenerated method names, reflection, 49 // and itab names. 50 func (t *Type) ShortString() string { 51 return Tconv(t, FmtLeft, FErr) 52 } 53 54 // LongString generates a complete description of t. 55 // It is useful for reflection, 56 // or when a unique fingerprint or hash of a type is required. 57 func (t *Type) LongString() string { 58 return Tconv(t, FmtLeft|FmtUnsigned, FErr) 59 } 60 61 func (t *Type) Format(s fmt.State, verb rune) { 62 FormatType(t, s, verb, FErr) 63 } 64 65 type bitset8 uint8 66 67 func (f *bitset8) set(mask uint8, b bool) { 68 if b { 69 *(*uint8)(f) |= mask 70 } else { 71 *(*uint8)(f) &^= mask 72 } 73 }