| 1 | // Copyright 2009 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-go file. |
| 4 | |
| 5 | package deepequal |
| 6 | |
| 7 | import "unsafe" |
| 8 | |
| 9 | type value struct { |
| 10 | // typ holds the type of the value represented by a Value. |
| 11 | typ *rtype |
| 12 | |
| 13 | // Pointer-valued data or, if flagIndir is set, pointer to data. |
| 14 | // Valid when either flagIndir is set or typ.pointers() is true. |
| 15 | ptr unsafe.Pointer |
| 16 | |
| 17 | // flag holds metadata about the value. |
| 18 | // |
| 19 | // The lowest five bits give the Kind of the value, mirroring typ.Kind(). |
| 20 | // |
| 21 | // The next set of bits are flag bits: |
| 22 | // - flagStickyRO: obtained via unexported not embedded field, so read-only |
| 23 | // - flagEmbedRO: obtained via unexported embedded field, so read-only |
| 24 | // - flagIndir: val holds a pointer to the data |
| 25 | // - flagAddr: v.CanAddr is true (implies flagIndir and ptr is non-nil) |
| 26 | // - flagMethod: v is a method value. |
| 27 | // If !typ.IsDirectIface(), code can assume that flagIndir is set. |
| 28 | // |
| 29 | // The remaining 22+ bits give a method number for method values. |
| 30 | // If flag.kind() != Func, code can assume that flagMethod is unset. |
| 31 | flag |
| 32 | |
| 33 | // A method value represents a curried method invocation |
| 34 | // like r.Read for some receiver r. The typ+val+flag bits describe |
| 35 | // the receiver r, but the flag's Kind bits say Func (methods are |
| 36 | // functions), and the top bits of the flag give the method number |
| 37 | // in r's type's method table. |
| 38 | } |
| 39 | |
| 40 | type flag uintptr |
| 41 | |
| 42 | const ( |
| 43 | flagKindWidth = 5 // there are 27 kinds |
| 44 | flagKindMask flag = 1<<flagKindWidth - 1 |
| 45 | flagStickyRO flag = 1 << 5 |
| 46 | flagEmbedRO flag = 1 << 6 |
| 47 | flagIndir flag = 1 << 7 |
| 48 | flagAddr flag = 1 << 8 |
| 49 | flagMethod flag = 1 << 9 |
| 50 | flagMethodShift = 10 |
| 51 | flagRO flag = flagStickyRO | flagEmbedRO |
| 52 | ) |