codes.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. package pkgbits
  5. // A Code is an enum value that can be encoded into bitstreams.
  6. //
  7. // Code types are preferable for enum types, because they allow
  8. // Decoder to detect desyncs.
  9. type Code interface {
  10. // Marker returns the SyncMarker for the Code's dynamic type.
  11. Marker() SyncMarker
  12. // Value returns the Code's ordinal value.
  13. Value() int
  14. }
  15. // A CodeVal distinguishes among go/constant.Value encodings.
  16. type CodeVal int
  17. func (c CodeVal) Marker() SyncMarker { return SyncVal }
  18. func (c CodeVal) Value() int { return int(c) }
  19. // Note: These values are public and cannot be changed without
  20. // updating the go/types importers.
  21. const (
  22. ValBool CodeVal = iota
  23. ValString
  24. ValInt64
  25. ValBigInt
  26. ValBigRat
  27. ValBigFloat
  28. )
  29. // A CodeType distinguishes among go/types.Type encodings.
  30. type CodeType int
  31. func (c CodeType) Marker() SyncMarker { return SyncType }
  32. func (c CodeType) Value() int { return int(c) }
  33. // Note: These values are public and cannot be changed without
  34. // updating the go/types importers.
  35. const (
  36. TypeBasic CodeType = iota
  37. TypeNamed
  38. TypePointer
  39. TypeSlice
  40. TypeArray
  41. TypeChan
  42. TypeMap
  43. TypeSignature
  44. TypeStruct
  45. TypeInterface
  46. TypeUnion
  47. TypeTypeParam
  48. )
  49. // A CodeObj distinguishes among go/types.Object encodings.
  50. type CodeObj int
  51. func (c CodeObj) Marker() SyncMarker { return SyncCodeObj }
  52. func (c CodeObj) Value() int { return int(c) }
  53. // Note: These values are public and cannot be changed without
  54. // updating the go/types importers.
  55. const (
  56. ObjAlias CodeObj = iota
  57. ObjConst
  58. ObjType
  59. ObjFunc
  60. ObjVar
  61. ObjStub
  62. )