$55 GRAYBYTE WORDPRESS FILE MANAGER $65

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/lib/golang/src/cmd/compile/internal/types2/

HOME
Current File : /usr/lib/golang/src/cmd/compile/internal/types2//interface.go
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package types2

import (
	"cmd/compile/internal/syntax"
	. "internal/types/errors"
)

// ----------------------------------------------------------------------------
// API

// An Interface represents an interface type.
type Interface struct {
	check     *Checker      // for error reporting; nil once type set is computed
	methods   []*Func       // ordered list of explicitly declared methods
	embeddeds []Type        // ordered list of explicitly embedded elements
	embedPos  *[]syntax.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space
	implicit  bool          // interface is wrapper for type set literal (non-interface T, ~T, or A|B)
	complete  bool          // indicates that all fields (except for tset) are set up

	tset *_TypeSet // type set described by this interface, computed lazily
}

// typeSet returns the type set for interface t.
func (t *Interface) typeSet() *_TypeSet { return computeInterfaceTypeSet(t.check, nopos, t) }

// emptyInterface represents the empty interface
var emptyInterface = Interface{complete: true, tset: &topTypeSet}

// NewInterfaceType returns a new interface for the given methods and embedded types.
// NewInterfaceType takes ownership of the provided methods and may modify their types
// by setting missing receivers.
func NewInterfaceType(methods []*Func, embeddeds []Type) *Interface {
	if len(methods) == 0 && len(embeddeds) == 0 {
		return &emptyInterface
	}

	// set method receivers if necessary
	typ := (*Checker)(nil).newInterface()
	for _, m := range methods {
		if sig := m.typ.(*Signature); sig.recv == nil {
			sig.recv = newVar(RecvVar, m.pos, m.pkg, "", typ)
		}
	}

	// sort for API stability
	sortMethods(methods)

	typ.methods = methods
	typ.embeddeds = embeddeds
	typ.complete = true

	return typ
}

// check may be nil
func (check *Checker) newInterface() *Interface {
	typ := &Interface{check: check}
	if check != nil {
		check.needsCleanup(typ)
	}
	return typ
}

// MarkImplicit marks the interface t as implicit, meaning this interface
// corresponds to a constraint literal such as ~T or A|B without explicit
// interface embedding. MarkImplicit should be called before any concurrent use
// of implicit interfaces.
func (t *Interface) MarkImplicit() {
	t.implicit = true
}

// NumExplicitMethods returns the number of explicitly declared methods of interface t.
func (t *Interface) NumExplicitMethods() int { return len(t.methods) }

// ExplicitMethod returns the i'th explicitly declared method of interface t for 0 <= i < t.NumExplicitMethods().
// The methods are ordered by their unique Id.
func (t *Interface) ExplicitMethod(i int) *Func { return t.methods[i] }

// NumEmbeddeds returns the number of embedded types in interface t.
func (t *Interface) NumEmbeddeds() int { return len(t.embeddeds) }

// EmbeddedType returns the i'th embedded type of interface t for 0 <= i < t.NumEmbeddeds().
func (t *Interface) EmbeddedType(i int) Type { return t.embeddeds[i] }

// NumMethods returns the total number of methods of interface t.
func (t *Interface) NumMethods() int { return t.typeSet().NumMethods() }

// Method returns the i'th method of interface t for 0 <= i < t.NumMethods().
// The methods are ordered by their unique Id.
func (t *Interface) Method(i int) *Func { return t.typeSet().Method(i) }

// Empty reports whether t is the empty interface.
func (t *Interface) Empty() bool { return t.typeSet().IsAll() }

// IsComparable reports whether each type in interface t's type set is comparable.
func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable(nil) }

// IsMethodSet reports whether the interface t is fully described by its method set.
func (t *Interface) IsMethodSet() bool { return t.typeSet().IsMethodSet() }

// IsImplicit reports whether the interface t is a wrapper for a type set literal.
func (t *Interface) IsImplicit() bool { return t.implicit }

func (t *Interface) Underlying() Type { return t }
func (t *Interface) String() string   { return TypeString(t, nil) }

// ----------------------------------------------------------------------------
// Implementation

func (t *Interface) cleanup() {
	t.typeSet() // any interface that escapes type checking must be safe for concurrent use
	t.check = nil
	t.embedPos = nil
}

func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType, def *TypeName) {
	addEmbedded := func(pos syntax.Pos, typ Type) {
		ityp.embeddeds = append(ityp.embeddeds, typ)
		if ityp.embedPos == nil {
			ityp.embedPos = new([]syntax.Pos)
		}
		*ityp.embedPos = append(*ityp.embedPos, pos)
	}

	for _, f := range iface.MethodList {
		if f.Name == nil {
			addEmbedded(atPos(f.Type), parseUnion(check, f.Type))
			continue
		}
		// f.Name != nil

		// We have a method with name f.Name.
		name := f.Name.Value
		if name == "_" {
			check.error(f.Name, BlankIfaceMethod, "methods must have a unique non-blank name")
			continue // ignore
		}

		typ := check.typ(f.Type)
		sig, _ := typ.(*Signature)
		if sig == nil {
			if isValid(typ) {
				check.errorf(f.Type, InvalidSyntaxTree, "%s is not a method signature", typ)
			}
			continue // ignore
		}

		// use named receiver type if available (for better error messages)
		var recvTyp Type = ityp
		if def != nil {
			if named := asNamed(def.typ); named != nil {
				recvTyp = named
			}
		}
		sig.recv = newVar(RecvVar, f.Name.Pos(), check.pkg, "", recvTyp)

		m := NewFunc(f.Name.Pos(), check.pkg, name, sig)
		check.recordDef(f.Name, m)
		ityp.methods = append(ityp.methods, m)
	}

	// All methods and embedded elements for this interface are collected;
	// i.e., this interface may be used in a type set computation.
	ityp.complete = true

	if len(ityp.methods) == 0 && len(ityp.embeddeds) == 0 {
		// empty interface
		ityp.tset = &topTypeSet
		return
	}

	// sort for API stability
	// (don't sort embeddeds: they must correspond to *embedPos entries)
	sortMethods(ityp.methods)

	// Compute type set as soon as possible to report any errors.
	// Subsequent uses of type sets will use this computed type
	// set and won't need to pass in a *Checker.
	check.later(func() {
		computeInterfaceTypeSet(check, iface.Pos(), ityp)
	}).describef(iface, "compute type set for %s", ityp)
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
4 Dec 2025 6.06 PM
root / root
0755
README.md
4.551 KB
4 Dec 2025 6.06 PM
root / root
0644
alias.go
5.962 KB
4 Dec 2025 6.06 PM
root / root
0644
api.go
17.76 KB
4 Dec 2025 6.06 PM
root / root
0644
api_predicates.go
3.321 KB
4 Dec 2025 6.06 PM
root / root
0644
array.go
0.784 KB
4 Dec 2025 6.06 PM
root / root
0644
assignments.go
16.821 KB
4 Dec 2025 6.06 PM
root / root
0644
basic.go
1.484 KB
4 Dec 2025 6.06 PM
root / root
0644
builtins.go
29.327 KB
4 Dec 2025 6.06 PM
root / root
0644
call.go
31.94 KB
4 Dec 2025 6.06 PM
root / root
0644
chan.go
0.889 KB
4 Dec 2025 6.06 PM
root / root
0644
check.go
21.714 KB
4 Dec 2025 6.06 PM
root / root
0644
compiler_internal.go
1.362 KB
4 Dec 2025 6.06 PM
root / root
0644
compilersupport.go
1.295 KB
4 Dec 2025 6.06 PM
root / root
0644
const.go
7.528 KB
4 Dec 2025 6.06 PM
root / root
0644
context.go
4.306 KB
4 Dec 2025 6.06 PM
root / root
0644
conversions.go
8.955 KB
4 Dec 2025 6.06 PM
root / root
0644
decl.go
29.765 KB
4 Dec 2025 6.06 PM
root / root
0644
errors.go
6.594 KB
4 Dec 2025 6.06 PM
root / root
0644
errsupport.go
4.402 KB
4 Dec 2025 6.06 PM
root / root
0644
expr.go
41.219 KB
4 Dec 2025 6.06 PM
root / root
0644
format.go
3.931 KB
4 Dec 2025 6.06 PM
root / root
0644
gccgosizes.go
1.017 KB
4 Dec 2025 6.06 PM
root / root
0644
gcsizes.go
4.233 KB
4 Dec 2025 6.06 PM
root / root
0644
index.go
10.974 KB
4 Dec 2025 6.06 PM
root / root
0644
infer.go
27.036 KB
4 Dec 2025 6.06 PM
root / root
0644
initorder.go
10.006 KB
4 Dec 2025 6.06 PM
root / root
0644
instantiate.go
13.105 KB
4 Dec 2025 6.06 PM
root / root
0644
interface.go
6.253 KB
4 Dec 2025 6.06 PM
root / root
0644
labels.go
7.257 KB
4 Dec 2025 6.06 PM
root / root
0644
literals.go
12.751 KB
4 Dec 2025 6.06 PM
root / root
0644
lookup.go
22.531 KB
4 Dec 2025 6.06 PM
root / root
0644
map.go
0.644 KB
4 Dec 2025 6.06 PM
root / root
0644
mono.go
9.09 KB
4 Dec 2025 6.06 PM
root / root
0644
named.go
24.237 KB
4 Dec 2025 6.06 PM
root / root
0644
object.go
21.985 KB
4 Dec 2025 6.06 PM
root / root
0644
objset.go
0.906 KB
4 Dec 2025 6.06 PM
root / root
0644
operand.go
12.072 KB
4 Dec 2025 6.06 PM
root / root
0644
package.go
2.927 KB
4 Dec 2025 6.06 PM
root / root
0644
pointer.go
0.62 KB
4 Dec 2025 6.06 PM
root / root
0644
predicates.go
17.483 KB
4 Dec 2025 6.06 PM
root / root
0644
range.go
9.248 KB
4 Dec 2025 6.06 PM
root / root
0644
recording.go
4.58 KB
4 Dec 2025 6.06 PM
root / root
0644
resolver.go
25.425 KB
4 Dec 2025 6.06 PM
root / root
0644
return.go
4.366 KB
4 Dec 2025 6.06 PM
root / root
0644
scope.go
7.529 KB
4 Dec 2025 6.06 PM
root / root
0644
selection.go
5.781 KB
4 Dec 2025 6.06 PM
root / root
0644
signature.go
16.755 KB
4 Dec 2025 6.06 PM
root / root
0644
sizes.go
8.816 KB
4 Dec 2025 6.06 PM
root / root
0644
slice.go
0.563 KB
4 Dec 2025 6.06 PM
root / root
0644
stmt.go
23.145 KB
4 Dec 2025 6.06 PM
root / root
0644
struct.go
6.564 KB
4 Dec 2025 6.06 PM
root / root
0644
subst.go
10.311 KB
4 Dec 2025 6.06 PM
root / root
0644
termlist.go
3.77 KB
4 Dec 2025 6.06 PM
root / root
0644
tuple.go
0.907 KB
4 Dec 2025 6.06 PM
root / root
0644
type.go
0.309 KB
4 Dec 2025 6.06 PM
root / root
0644
typelists.go
1.842 KB
4 Dec 2025 6.06 PM
root / root
0644
typeparam.go
5.099 KB
4 Dec 2025 6.06 PM
root / root
0644
typeset.go
13.209 KB
4 Dec 2025 6.06 PM
root / root
0644
typestring.go
12.354 KB
4 Dec 2025 6.06 PM
root / root
0644
typeterm.go
3.519 KB
4 Dec 2025 6.06 PM
root / root
0644
typexpr.go
16.229 KB
4 Dec 2025 6.06 PM
root / root
0644
under.go
4.21 KB
4 Dec 2025 6.06 PM
root / root
0644
unify.go
27.768 KB
4 Dec 2025 6.06 PM
root / root
0644
union.go
6.252 KB
4 Dec 2025 6.06 PM
root / root
0644
universe.go
9.233 KB
4 Dec 2025 6.06 PM
root / root
0644
util.go
2.313 KB
4 Dec 2025 6.06 PM
root / root
0644
validtype.go
10.238 KB
4 Dec 2025 6.06 PM
root / root
0644
version.go
2.032 KB
4 Dec 2025 6.06 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF