github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/interface.go (about) 1 // Copyright 2021 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 types2 6 7 import ( 8 "github.com/shogo82148/std/cmd/compile/internal/syntax" 9 ) 10 11 // An Interface represents an interface type. 12 type Interface struct { 13 check *Checker 14 methods []*Func 15 embeddeds []Type 16 embedPos *[]syntax.Pos 17 implicit bool 18 complete bool 19 20 tset *_TypeSet 21 } 22 23 // NewInterfaceType returns a new interface for the given methods and embedded types. 24 // NewInterfaceType takes ownership of the provided methods and may modify their types 25 // by setting missing receivers. 26 func NewInterfaceType(methods []*Func, embeddeds []Type) *Interface 27 28 // MarkImplicit marks the interface t as implicit, meaning this interface 29 // corresponds to a constraint literal such as ~T or A|B without explicit 30 // interface embedding. MarkImplicit should be called before any concurrent use 31 // of implicit interfaces. 32 func (t *Interface) MarkImplicit() 33 34 // NumExplicitMethods returns the number of explicitly declared methods of interface t. 35 func (t *Interface) NumExplicitMethods() int 36 37 // ExplicitMethod returns the i'th explicitly declared method of interface t for 0 <= i < t.NumExplicitMethods(). 38 // The methods are ordered by their unique Id. 39 func (t *Interface) ExplicitMethod(i int) *Func 40 41 // NumEmbeddeds returns the number of embedded types in interface t. 42 func (t *Interface) NumEmbeddeds() int 43 44 // EmbeddedType returns the i'th embedded type of interface t for 0 <= i < t.NumEmbeddeds(). 45 func (t *Interface) EmbeddedType(i int) Type 46 47 // NumMethods returns the total number of methods of interface t. 48 func (t *Interface) NumMethods() int 49 50 // Method returns the i'th method of interface t for 0 <= i < t.NumMethods(). 51 // The methods are ordered by their unique Id. 52 func (t *Interface) Method(i int) *Func 53 54 // Empty reports whether t is the empty interface. 55 func (t *Interface) Empty() bool 56 57 // IsComparable reports whether each type in interface t's type set is comparable. 58 func (t *Interface) IsComparable() bool 59 60 // IsMethodSet reports whether the interface t is fully described by its method set. 61 func (t *Interface) IsMethodSet() bool 62 63 // IsImplicit reports whether the interface t is a wrapper for a type set literal. 64 func (t *Interface) IsImplicit() bool 65 66 func (t *Interface) Underlying() Type 67 func (t *Interface) String() string