// would lead to import cycles)
types.Widthptr = Widthptr
types.Dowidth = dowidth
- types.Fatalf = base.Fatalf
ir.InstallTypeFormats()
types.TypeLinkSym = func(t *types.Type) *obj.LSym {
return typenamesym(t).Linksym()
}
- types.FmtLeft = int(ir.FmtLeft)
- types.FmtUnsigned = int(ir.FmtUnsigned)
- types.FErr = int(ir.FErr)
- types.Ctxt = base.Ctxt
initUniverse()
ir.AsNode(s.Def).SetSym(lookup("false"))
s = lookup("_")
+ ir.BlankSym = s
s.Block = -100
s.Def = NewName(s)
types.Types[types.TBLANK] = types.New(types.TBLANK)
func smodeString(s *types.Sym, mode FmtMode) string { return sconv(s, 0, mode) }
-// See #16897 before changing the implementation of sconv.
+// See #16897 for details about performance implications
+// before changing the implementation of sconv.
func sconv(s *types.Sym, flag FmtFlag, mode FmtMode) string {
if flag&FmtLong != 0 {
panic("linksymfmt")
}
func InstallTypeFormats() {
- types.Sconv = func(s *types.Sym, flag, mode int) string {
- return sconv(s, FmtFlag(flag), FmtMode(mode))
+ types.SymString = func(s *types.Sym) string {
+ return sconv(s, 0, FErr)
}
- types.Tconv = func(t *types.Type, flag, mode int) string {
- return tconv(t, FmtFlag(flag), FmtMode(mode))
+ types.TypeString = func(t *types.Type) string {
+ return tconv(t, 0, FErr)
}
- types.FormatSym = func(sym *types.Sym, s fmt.State, verb rune, mode int) {
- symFormat(sym, s, verb, FmtMode(mode))
+ types.TypeShortString = func(t *types.Type) string {
+ return tconv(t, FmtLeft, FErr)
}
- types.FormatType = func(t *types.Type, s fmt.State, verb rune, mode int) {
- typeFormat(t, s, verb, FmtMode(mode))
+ types.TypeLongString = func(t *types.Type) string {
+ return tconv(t, FmtLeft|FmtUnsigned, FErr)
+ }
+ types.FormatSym = func(sym *types.Sym, s fmt.State, verb rune) {
+ symFormat(sym, s, verb, FErr)
+ }
+ types.FormatType = func(t *types.Type, s fmt.State, verb rune) {
+ typeFormat(t, s, verb, FErr)
}
}
var BlankNode Node
+var BlankSym *types.Sym
+
// origSym returns the original symbol written by the user.
func OrigSym(s *types.Sym) *types.Sym {
if s == nil {
return nil
case 'b': // originally the blank identifier _
// TODO(mdempsky): Does s.Pkg matter here?
- return BlankNode.Sym()
+ return BlankSym
}
return s
}
"cmd/internal/obj/s390x"
"cmd/internal/obj/x86"
"cmd/internal/src"
- "fmt"
"testing"
)
// Initialize just enough of the universe and the types package to make our tests function.
// TODO(josharian): move universe initialization to the types package,
// so this test setup can share it.
-
- types.Tconv = func(t *types.Type, flag, mode int) string {
- return t.Kind().String()
- }
- types.Sconv = func(s *types.Sym, flag, mode int) string {
- return "sym"
- }
- types.FormatSym = func(sym *types.Sym, s fmt.State, verb rune, mode int) {
- fmt.Fprintf(s, "sym")
- }
- types.FormatType = func(t *types.Type, s fmt.State, verb rune, mode int) {
- fmt.Fprintf(s, "%v", t.Kind())
- }
+ ir.InstallTypeFormats()
types.Dowidth = func(t *types.Type) {}
for _, typ := range [...]struct {
package types
-import "cmd/internal/src"
+import (
+ "cmd/compile/internal/base"
+ "cmd/internal/src"
+)
// Declaration stack & operations
d.sym = nil
d.def = nil
}
- Fatalf("popdcl: no stack mark")
+ base.Fatalf("popdcl: no stack mark")
}
// Markdcl records the start of a new block scope for declarations.
package types
import (
+ "cmd/compile/internal/base"
"cmd/internal/obj"
"cmd/internal/src"
"unicode"
}
if sym.Func() {
// This is a function symbol. Mark it as "internal ABI".
- return Ctxt.LookupABIInit(sym.LinksymName(), obj.ABIInternal, initPkg)
+ return base.Ctxt.LookupABIInit(sym.LinksymName(), obj.ABIInternal, initPkg)
}
- return Ctxt.LookupInit(sym.LinksymName(), initPkg)
+ return base.Ctxt.LookupInit(sym.LinksymName(), initPkg)
}
// Less reports whether symbol a is ordered before symbol b.
case TINTER:
return t.Extra.(*Interface).pkg
default:
- Fatalf("Pkg: unexpected kind: %v", t)
+ base.Fatalf("Pkg: unexpected kind: %v", t)
return nil
}
}
// NewArray returns a new fixed-length array Type.
func NewArray(elem *Type, bound int64) *Type {
if bound < 0 {
- Fatalf("NewArray: invalid bound %v", bound)
+ base.Fatalf("NewArray: invalid bound %v", bound)
}
t := New(TARRAY)
t.Extra = &Array{Elem: elem, Bound: bound}
func NewSlice(elem *Type) *Type {
if t := elem.cache.slice; t != nil {
if t.Elem() != elem {
- Fatalf("elem mismatch")
+ base.Fatalf("elem mismatch")
}
return t
}
// NewPtr returns the pointer type pointing to t.
func NewPtr(elem *Type) *Type {
if elem == nil {
- Fatalf("NewPtr: pointer to elem Type is nil")
+ base.Fatalf("NewPtr: pointer to elem Type is nil")
}
if t := elem.cache.ptr; t != nil {
if t.Elem() != elem {
- Fatalf("NewPtr: elem mismatch")
+ base.Fatalf("NewPtr: elem mismatch")
}
return t
}
case TANY:
if len(*types) == 0 {
- Fatalf("substArgTypes: not enough argument types")
+ base.Fatalf("substArgTypes: not enough argument types")
}
t = (*types)[0]
*types = (*types)[1:]
x := *t.Extra.(*Array)
nt.Extra = &x
case TTUPLE, TSSA, TRESULTS:
- Fatalf("ssa types cannot be copied")
+ base.Fatalf("ssa types cannot be copied")
}
// TODO(mdempsky): Find out why this is necessary and explain.
if t.underlying == t {
func (t *Type) wantEtype(et Kind) {
if t.kind != et {
- Fatalf("want %v, but have %v", et, t)
+ base.Fatalf("want %v, but have %v", et, t)
}
}
case TMAP:
return t.Extra.(*Map).Elem
}
- Fatalf("Type.Elem %s", t.kind)
+ base.Fatalf("Type.Elem %s", t.kind)
return nil
}
Dowidth(t)
return &t.Extra.(*Interface).Fields
}
- Fatalf("Fields: type %v does not have fields", t)
+ base.Fatalf("Fields: type %v does not have fields", t)
return nil
}
// enforce that SetFields cannot be called once
// t's width has been calculated.
if t.WidthCalculated() {
- Fatalf("SetFields of %v: width previously calculated", t)
+ base.Fatalf("SetFields of %v: width previously calculated", t)
}
t.wantEtype(TSTRUCT)
for _, f := range fields {
// ToUnsigned returns the unsigned equivalent of integer type t.
func (t *Type) ToUnsigned() *Type {
if !t.IsInteger() {
- Fatalf("unsignedType(%v)", t)
+ base.Fatalf("unsignedType(%v)", t)
}
return Types[unsignedEType[t.kind]]
}
switch t.kind {
case TSTRUCT:
if t.IsFuncArgStruct() {
- Fatalf("NumComponents func arg struct")
+ base.Fatalf("NumComponents func arg struct")
}
var n int64
for _, f := range t.FieldSlice() {
switch t.kind {
case TSTRUCT:
if t.IsFuncArgStruct() {
- Fatalf("SoleComponent func arg struct")
+ base.Fatalf("SoleComponent func arg struct")
}
if t.NumFields() != 1 {
return nil
// They are here to break import cycles.
// TODO(gri) eliminate these dependencies.
var (
- Widthptr int
- Dowidth func(*Type)
- Fatalf func(string, ...interface{})
- Sconv func(*Sym, int, int) string // orig: func sconv(s *Sym, flag FmtFlag, mode fmtMode) string
- Tconv func(*Type, int, int) string // orig: func tconv(t *Type, flag FmtFlag, mode fmtMode) string
- FormatSym func(*Sym, fmt.State, rune, int) // orig: func symFormat(sym *Sym, s fmt.State, verb rune, mode fmtMode)
- FormatType func(*Type, fmt.State, rune, int) // orig: func typeFormat(t *Type, s fmt.State, verb rune, mode fmtMode)
- TypeLinkSym func(*Type) *obj.LSym
- Ctxt *obj.Link
-
- FmtLeft int
- FmtUnsigned int
- FErr int
+ Widthptr int
+ Dowidth func(*Type)
+ SymString func(*Sym) string
+ TypeString func(*Type) string
+ TypeShortString func(*Type) string
+ TypeLongString func(*Type) string
+ FormatSym func(*Sym, fmt.State, rune)
+ FormatType func(*Type, fmt.State, rune)
+ TypeLinkSym func(*Type) *obj.LSym
)
func (s *Sym) String() string {
- return Sconv(s, 0, FErr)
+ return SymString(s)
}
func (sym *Sym) Format(s fmt.State, verb rune) {
- FormatSym(sym, s, verb, FErr)
+ FormatSym(sym, s, verb)
}
func (t *Type) String() string {
- // The implementation of tconv (including typefmt and fldconv)
+ // The implementation
// must handle recursive types correctly.
- return Tconv(t, 0, FErr)
+ return TypeString(t)
}
// ShortString generates a short description of t.
// It is used in autogenerated method names, reflection,
// and itab names.
func (t *Type) ShortString() string {
- return Tconv(t, FmtLeft, FErr)
+ return TypeShortString(t)
}
// 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 {
- return Tconv(t, FmtLeft|FmtUnsigned, FErr)
+ return TypeLongString(t)
}
func (t *Type) Format(s fmt.State, verb rune) {
- FormatType(t, s, verb, FErr)
+ FormatType(t, s, verb)
}
type bitset8 uint8