github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/signature.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  // A Signature represents a (non-builtin) function or method type.
     8  // The receiver is ignored when comparing signatures for identity.
     9  type Signature struct {
    10  	// We need to keep the scope in Signature (rather than passing it around
    11  	// and store it in the Func Object) because when type-checking a function
    12  	// literal we call the general type checker which returns a general Type.
    13  	// We then unpack the *Signature and use the scope for the literal body.
    14  	rparams  *TypeParamList
    15  	tparams  *TypeParamList
    16  	scope    *Scope
    17  	recv     *Var
    18  	params   *Tuple
    19  	results  *Tuple
    20  	variadic bool
    21  }
    22  
    23  // NewSignatureType creates a new function type for the given receiver,
    24  // receiver type parameters, type parameters, parameters, and results. If
    25  // variadic is set, params must hold at least one parameter and the last
    26  // parameter's core type must be of unnamed slice or bytestring type.
    27  // If recv is non-nil, typeParams must be empty. If recvTypeParams is
    28  // non-empty, recv must be non-nil.
    29  func NewSignatureType(recv *Var, recvTypeParams, typeParams []*TypeParam, params, results *Tuple, variadic bool) *Signature
    30  
    31  // Recv returns the receiver of signature s (if a method), or nil if a
    32  // function. It is ignored when comparing signatures for identity.
    33  //
    34  // For an abstract method, Recv returns the enclosing interface either
    35  // as a *Named or an *Interface. Due to embedding, an interface may
    36  // contain methods whose receiver type is a different interface.
    37  func (s *Signature) Recv() *Var
    38  
    39  // TypeParams returns the type parameters of signature s, or nil.
    40  func (s *Signature) TypeParams() *TypeParamList
    41  
    42  // SetTypeParams sets the type parameters of signature s.
    43  func (s *Signature) SetTypeParams(tparams []*TypeParam)
    44  
    45  // RecvTypeParams returns the receiver type parameters of signature s, or nil.
    46  func (s *Signature) RecvTypeParams() *TypeParamList
    47  
    48  // Params returns the parameters of signature s, or nil.
    49  func (s *Signature) Params() *Tuple
    50  
    51  // Results returns the results of signature s, or nil.
    52  func (s *Signature) Results() *Tuple
    53  
    54  // Variadic reports whether the signature s is variadic.
    55  func (s *Signature) Variadic() bool
    56  
    57  func (s *Signature) Underlying() Type
    58  func (s *Signature) String() string