github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/types2/compilersupport.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  // Helper functions exported for the compiler.
     6  // Do not use internally.
     7  
     8  package types2
     9  
    10  // If t is a pointer, AsPointer returns that type, otherwise it returns nil.
    11  func AsPointer(t Type) *Pointer {
    12  	u, _ := t.Underlying().(*Pointer)
    13  	return u
    14  }
    15  
    16  // If t is a signature, AsSignature returns that type, otherwise it returns nil.
    17  func AsSignature(t Type) *Signature {
    18  	u, _ := t.Underlying().(*Signature)
    19  	return u
    20  }
    21  
    22  // If typ is a type parameter, CoreType returns the single underlying
    23  // type of all types in the corresponding type constraint if it exists, or
    24  // nil otherwise. If the type set contains only unrestricted and restricted
    25  // channel types (with identical element types), the single underlying type
    26  // is the restricted channel type if the restrictions are always the same.
    27  // If typ is not a type parameter, CoreType returns the underlying type.
    28  func CoreType(t Type) Type {
    29  	return coreType(t)
    30  }