github.com/m10x/go/src@v0.0.0-20220112094212-ba61592315da/builtin/builtin.go (about)

     1  // Copyright 2011 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  /*
     6  	Package builtin provides documentation for Go's predeclared identifiers.
     7  	The items documented here are not actually in package builtin
     8  	but their descriptions here allow godoc to present documentation
     9  	for the language's special identifiers.
    10  */
    11  package builtin
    12  
    13  // bool is the set of boolean values, true and false.
    14  type bool bool
    15  
    16  // true and false are the two untyped boolean values.
    17  const (
    18  	true  = 0 == 0 // Untyped bool.
    19  	false = 0 != 0 // Untyped bool.
    20  )
    21  
    22  // uint8 is the set of all unsigned 8-bit integers.
    23  // Range: 0 through 255.
    24  type uint8 uint8
    25  
    26  // uint16 is the set of all unsigned 16-bit integers.
    27  // Range: 0 through 65535.
    28  type uint16 uint16
    29  
    30  // uint32 is the set of all unsigned 32-bit integers.
    31  // Range: 0 through 4294967295.
    32  type uint32 uint32
    33  
    34  // uint64 is the set of all unsigned 64-bit integers.
    35  // Range: 0 through 18446744073709551615.
    36  type uint64 uint64
    37  
    38  // int8 is the set of all signed 8-bit integers.
    39  // Range: -128 through 127.
    40  type int8 int8
    41  
    42  // int16 is the set of all signed 16-bit integers.
    43  // Range: -32768 through 32767.
    44  type int16 int16
    45  
    46  // int32 is the set of all signed 32-bit integers.
    47  // Range: -2147483648 through 2147483647.
    48  type int32 int32
    49  
    50  // int64 is the set of all signed 64-bit integers.
    51  // Range: -9223372036854775808 through 9223372036854775807.
    52  type int64 int64
    53  
    54  // float32 is the set of all IEEE-754 32-bit floating-point numbers.
    55  type float32 float32
    56  
    57  // float64 is the set of all IEEE-754 64-bit floating-point numbers.
    58  type float64 float64
    59  
    60  // complex64 is the set of all complex numbers with float32 real and
    61  // imaginary parts.
    62  type complex64 complex64
    63  
    64  // complex128 is the set of all complex numbers with float64 real and
    65  // imaginary parts.
    66  type complex128 complex128
    67  
    68  // string is the set of all strings of 8-bit bytes, conventionally but not
    69  // necessarily representing UTF-8-encoded text. A string may be empty, but
    70  // not nil. Values of string type are immutable.
    71  type string string
    72  
    73  // int is a signed integer type that is at least 32 bits in size. It is a
    74  // distinct type, however, and not an alias for, say, int32.
    75  type int int
    76  
    77  // uint is an unsigned integer type that is at least 32 bits in size. It is a
    78  // distinct type, however, and not an alias for, say, uint32.
    79  type uint uint
    80  
    81  // uintptr is an integer type that is large enough to hold the bit pattern of
    82  // any pointer.
    83  type uintptr uintptr
    84  
    85  // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
    86  // used, by convention, to distinguish byte values from 8-bit unsigned
    87  // integer values.
    88  type byte = uint8
    89  
    90  // rune is an alias for int32 and is equivalent to int32 in all ways. It is
    91  // used, by convention, to distinguish character values from integer values.
    92  type rune = int32
    93  
    94  // any is an alias for interface{} and is equivalent to interface{} in all ways.
    95  type any = interface{}
    96  
    97  // comparable is an interface that is implemented by all comparable types
    98  // (booleans, numbers, strings, pointers, channels, interfaces,
    99  // arrays of comparable types, structs whose fields are all comparable types).
   100  // The comparable interface may only be used as a type parameter constraint,
   101  // not as the type of a variable.
   102  type comparable comparable
   103  
   104  // iota is a predeclared identifier representing the untyped integer ordinal
   105  // number of the current const specification in a (usually parenthesized)
   106  // const declaration. It is zero-indexed.
   107  const iota = 0 // Untyped int.
   108  
   109  // nil is a predeclared identifier representing the zero value for a
   110  // pointer, channel, func, interface, map, or slice type.
   111  var nil Type // Type must be a pointer, channel, func, interface, map, or slice type
   112  
   113  // Type is here for the purposes of documentation only. It is a stand-in
   114  // for any Go type, but represents the same type for any given function
   115  // invocation.
   116  type Type int
   117  
   118  // Type1 is here for the purposes of documentation only. It is a stand-in
   119  // for any Go type, but represents the same type for any given function
   120  // invocation.
   121  type Type1 int
   122  
   123  // IntegerType is here for the purposes of documentation only. It is a stand-in
   124  // for any integer type: int, uint, int8 etc.
   125  type IntegerType int
   126  
   127  // FloatType is here for the purposes of documentation only. It is a stand-in
   128  // for either float type: float32 or float64.
   129  type FloatType float32
   130  
   131  // ComplexType is here for the purposes of documentation only. It is a
   132  // stand-in for either complex type: complex64 or complex128.
   133  type ComplexType complex64
   134  
   135  // The append built-in function appends elements to the end of a slice. If
   136  // it has sufficient capacity, the destination is resliced to accommodate the
   137  // new elements. If it does not, a new underlying array will be allocated.
   138  // Append returns the updated slice. It is therefore necessary to store the
   139  // result of append, often in the variable holding the slice itself:
   140  //	slice = append(slice, elem1, elem2)
   141  //	slice = append(slice, anotherSlice...)
   142  // As a special case, it is legal to append a string to a byte slice, like this:
   143  //	slice = append([]byte("hello "), "world"...)
   144  func append(slice []Type, elems ...Type) []Type
   145  
   146  // The copy built-in function copies elements from a source slice into a
   147  // destination slice. (As a special case, it also will copy bytes from a
   148  // string to a slice of bytes.) The source and destination may overlap. Copy
   149  // returns the number of elements copied, which will be the minimum of
   150  // len(src) and len(dst).
   151  func copy(dst, src []Type) int
   152  
   153  // The delete built-in function deletes the element with the specified key
   154  // (m[key]) from the map. If m is nil or there is no such element, delete
   155  // is a no-op.
   156  func delete(m map[Type]Type1, key Type)
   157  
   158  // The len built-in function returns the length of v, according to its type:
   159  //	Array: the number of elements in v.
   160  //	Pointer to array: the number of elements in *v (even if v is nil).
   161  //	Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
   162  //	String: the number of bytes in v.
   163  //	Channel: the number of elements queued (unread) in the channel buffer;
   164  //	         if v is nil, len(v) is zero.
   165  // For some arguments, such as a string literal or a simple array expression, the
   166  // result can be a constant. See the Go language specification's "Length and
   167  // capacity" section for details.
   168  func len(v Type) int
   169  
   170  // The cap built-in function returns the capacity of v, according to its type:
   171  //	Array: the number of elements in v (same as len(v)).
   172  //	Pointer to array: the number of elements in *v (same as len(v)).
   173  //	Slice: the maximum length the slice can reach when resliced;
   174  //	if v is nil, cap(v) is zero.
   175  //	Channel: the channel buffer capacity, in units of elements;
   176  //	if v is nil, cap(v) is zero.
   177  // For some arguments, such as a simple array expression, the result can be a
   178  // constant. See the Go language specification's "Length and capacity" section for
   179  // details.
   180  func cap(v Type) int
   181  
   182  // The make built-in function allocates and initializes an object of type
   183  // slice, map, or chan (only). Like new, the first argument is a type, not a
   184  // value. Unlike new, make's return type is the same as the type of its
   185  // argument, not a pointer to it. The specification of the result depends on
   186  // the type:
   187  //	Slice: The size specifies the length. The capacity of the slice is
   188  //	equal to its length. A second integer argument may be provided to
   189  //	specify a different capacity; it must be no smaller than the
   190  //	length. For example, make([]int, 0, 10) allocates an underlying array
   191  //	of size 10 and returns a slice of length 0 and capacity 10 that is
   192  //	backed by this underlying array.
   193  //	Map: An empty map is allocated with enough space to hold the
   194  //	specified number of elements. The size may be omitted, in which case
   195  //	a small starting size is allocated.
   196  //	Channel: The channel's buffer is initialized with the specified
   197  //	buffer capacity. If zero, or the size is omitted, the channel is
   198  //	unbuffered.
   199  func make(t Type, size ...IntegerType) Type
   200  
   201  // The new built-in function allocates memory. The first argument is a type,
   202  // not a value, and the value returned is a pointer to a newly
   203  // allocated zero value of that type.
   204  func new(Type) *Type
   205  
   206  // The complex built-in function constructs a complex value from two
   207  // floating-point values. The real and imaginary parts must be of the same
   208  // size, either float32 or float64 (or assignable to them), and the return
   209  // value will be the corresponding complex type (complex64 for float32,
   210  // complex128 for float64).
   211  func complex(r, i FloatType) ComplexType
   212  
   213  // The real built-in function returns the real part of the complex number c.
   214  // The return value will be floating point type corresponding to the type of c.
   215  func real(c ComplexType) FloatType
   216  
   217  // The imag built-in function returns the imaginary part of the complex
   218  // number c. The return value will be floating point type corresponding to
   219  // the type of c.
   220  func imag(c ComplexType) FloatType
   221  
   222  // The close built-in function closes a channel, which must be either
   223  // bidirectional or send-only. It should be executed only by the sender,
   224  // never the receiver, and has the effect of shutting down the channel after
   225  // the last sent value is received. After the last value has been received
   226  // from a closed channel c, any receive from c will succeed without
   227  // blocking, returning the zero value for the channel element. The form
   228  //	x, ok := <-c
   229  // will also set ok to false for a closed channel.
   230  func close(c chan<- Type)
   231  
   232  // The panic built-in function stops normal execution of the current
   233  // goroutine. When a function F calls panic, normal execution of F stops
   234  // immediately. Any functions whose execution was deferred by F are run in
   235  // the usual way, and then F returns to its caller. To the caller G, the
   236  // invocation of F then behaves like a call to panic, terminating G's
   237  // execution and running any deferred functions. This continues until all
   238  // functions in the executing goroutine have stopped, in reverse order. At
   239  // that point, the program is terminated with a non-zero exit code. This
   240  // termination sequence is called panicking and can be controlled by the
   241  // built-in function recover.
   242  func panic(v any)
   243  
   244  // The recover built-in function allows a program to manage behavior of a
   245  // panicking goroutine. Executing a call to recover inside a deferred
   246  // function (but not any function called by it) stops the panicking sequence
   247  // by restoring normal execution and retrieves the error value passed to the
   248  // call of panic. If recover is called outside the deferred function it will
   249  // not stop a panicking sequence. In this case, or when the goroutine is not
   250  // panicking, or if the argument supplied to panic was nil, recover returns
   251  // nil. Thus the return value from recover reports whether the goroutine is
   252  // panicking.
   253  func recover() any
   254  
   255  // The print built-in function formats its arguments in an
   256  // implementation-specific way and writes the result to standard error.
   257  // Print is useful for bootstrapping and debugging; it is not guaranteed
   258  // to stay in the language.
   259  func print(args ...Type)
   260  
   261  // The println built-in function formats its arguments in an
   262  // implementation-specific way and writes the result to standard error.
   263  // Spaces are always added between arguments and a newline is appended.
   264  // Println is useful for bootstrapping and debugging; it is not guaranteed
   265  // to stay in the language.
   266  func println(args ...Type)
   267  
   268  // The error built-in interface type is the conventional interface for
   269  // representing an error condition, with the nil value representing no error.
   270  type error interface {
   271  	Error() string
   272  }