builtin.go 11 KB

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