Source File
typeterm.go
Belonging Package
go/types
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
// Source: ../../cmd/compile/internal/types2/typeterm.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 types
// A term describes elementary type sets:
//
// β : (*term)(nil) == β // set of no types (empty set)
// π€: &term{} == π€ // set of all types (π€niverse)
// T: &term{false, T} == {T} // set of type T
// ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t
type term struct {
tilde bool // valid if typ != nil
typ Type
}
func ( *term) () string {
switch {
case == nil:
return "β "
case .typ == nil:
return "π€"
case .tilde:
return "~" + .typ.String()
default:
return .typ.String()
}
}
// equal reports whether x and y represent the same type set.
func ( *term) ( *term) bool {
// easy cases
switch {
case == nil || == nil:
return ==
case .typ == nil || .typ == nil:
return .typ == .typ
}
// β β x, y β π€
return .tilde == .tilde && Identical(.typ, .typ)
}
// union returns the union x βͺ y: zero, one, or two non-nil terms.
func ( *term) ( *term) (, *term) {
// easy cases
switch {
case == nil && == nil:
return nil, nil // β βͺ β == β
case == nil:
return , nil // β βͺ y == y
case == nil:
return , nil // x βͺ β == x
case .typ == nil:
return , nil // π€ βͺ y == π€
case .typ == nil:
return , nil // x βͺ π€ == π€
}
// β β x, y β π€
if .disjoint() {
return , // x βͺ y == (x, y) if x β© y == β
}
// x.typ == y.typ
// ~t βͺ ~t == ~t
// ~t βͺ T == ~t
// T βͺ ~t == ~t
// T βͺ T == T
if .tilde || !.tilde {
return , nil
}
return , nil
}
// intersect returns the intersection x β© y.
func ( *term) ( *term) *term {
// easy cases
switch {
case == nil || == nil:
return nil // β β© y == β and β© β == β
case .typ == nil:
return // π€ β© y == y
case .typ == nil:
return // x β© π€ == x
}
// β β x, y β π€
if .disjoint() {
return nil // x β© y == β if x β© y == β
}
// x.typ == y.typ
// ~t β© ~t == ~t
// ~t β© T == T
// T β© ~t == T
// T β© T == T
if !.tilde || .tilde {
return
}
return
}
// includes reports whether t β x.
func ( *term) ( Type) bool {
// easy cases
switch {
case == nil:
return false // t β β == false
case .typ == nil:
return true // t β π€ == true
}
// β β x β π€
:=
if .tilde {
= under()
}
return Identical(.typ, )
}
// subsetOf reports whether x β y.
func ( *term) ( *term) bool {
// easy cases
switch {
case == nil:
return true // β β y == true
case == nil:
return false // x β β == false since x != β
case .typ == nil:
return true // x β π€ == true
case .typ == nil:
return false // π€ β y == false since y != π€
}
// β β x, y β π€
if .disjoint() {
return false // x β y == false if x β© y == β
}
// x.typ == y.typ
// ~t β ~t == true
// ~t β T == false
// T β ~t == true
// T β T == true
return !.tilde || .tilde
}
// disjoint reports whether x β© y == β .
// x.typ and y.typ must not be nil.
func ( *term) ( *term) bool {
if debug && (.typ == nil || .typ == nil) {
panic("invalid argument(s)")
}
:= .typ
if .tilde {
= under()
}
:= .typ
if .tilde {
= under()
}
return !Identical(, )
}
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |