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 5package types 6 7import ( 8 "cmd/internal/obj" 9 "fmt" 10) 11 12const 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. 17var ( 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 33func (s *Sym) String() string { 34 return Sconv(s, 0, FErr) 35} 36 37func (sym *Sym) Format(s fmt.State, verb rune) { 38 FormatSym(sym, s, verb, FErr) 39} 40 41func (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. 50func (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. 57func (t *Type) LongString() string { 58 return Tconv(t, FmtLeft|FmtUnsigned, FErr) 59} 60 61func (t *Type) Format(s fmt.State, verb rune) { 62 FormatType(t, s, verb, FErr) 63} 64 65type bitset8 uint8 66 67func (f *bitset8) set(mask uint8, b bool) { 68 if b { 69 *(*uint8)(f) |= mask 70 } else { 71 *(*uint8)(f) &^= mask 72 } 73} 74