...

Source file src/go/types/typelists.go

Documentation: go/types

     1  // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
     2  
     3  // Copyright 2021 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package types
     8  
     9  // TypeParamList holds a list of type parameters.
    10  type TypeParamList struct{ tparams []*TypeParam }
    11  
    12  // Len returns the number of type parameters in the list.
    13  // It is safe to call on a nil receiver.
    14  func (l *TypeParamList) Len() int { return len(l.list()) }
    15  
    16  // At returns the i'th type parameter in the list.
    17  func (l *TypeParamList) At(i int) *TypeParam { return l.tparams[i] }
    18  
    19  // list is for internal use where we expect a []*TypeParam.
    20  // TODO(rfindley): list should probably be eliminated: we can pass around a
    21  // TypeParamList instead.
    22  func (l *TypeParamList) list() []*TypeParam {
    23  	if l == nil {
    24  		return nil
    25  	}
    26  	return l.tparams
    27  }
    28  
    29  // TypeList holds a list of types.
    30  type TypeList struct{ types []Type }
    31  
    32  // newTypeList returns a new TypeList with the types in list.
    33  func newTypeList(list []Type) *TypeList {
    34  	if len(list) == 0 {
    35  		return nil
    36  	}
    37  	return &TypeList{list}
    38  }
    39  
    40  // Len returns the number of types in the list.
    41  // It is safe to call on a nil receiver.
    42  func (l *TypeList) Len() int { return len(l.list()) }
    43  
    44  // At returns the i'th type in the list.
    45  func (l *TypeList) At(i int) Type { return l.types[i] }
    46  
    47  // list is for internal use where we expect a []Type.
    48  // TODO(rfindley): list should probably be eliminated: we can pass around a
    49  // TypeList instead.
    50  func (l *TypeList) list() []Type {
    51  	if l == nil {
    52  		return nil
    53  	}
    54  	return l.types
    55  }
    56  
    57  // ----------------------------------------------------------------------------
    58  // Implementation
    59  
    60  func bindTParams(list []*TypeParam) *TypeParamList {
    61  	if len(list) == 0 {
    62  		return nil
    63  	}
    64  	for i, typ := range list {
    65  		if typ.index >= 0 {
    66  			panic("type parameter bound more than once")
    67  		}
    68  		typ.index = i
    69  	}
    70  	return &TypeParamList{tparams: list}
    71  }
    72  

View as plain text