Documentation ¶
Index ¶
- Constants
- Variables
- type ErrorInvalid
- type ErrorOverflow
- type ErrorType
- type Kind
- type Value
- func BinaryOp(xv Value, op token.Token, yv Value) Value
- func Make(t *types.Complete, x interface{}) Value
- func MakeFromLiteral(lit string, tok token.Token) Value
- func MakeImag(v Value) Value
- func MakeKind(kind Kind, x interface{}) Value
- func MakeZero(t *types.Complete) Value
- func UnaryOp(op token.Token, v Value) Value
- func (v Value) Bool() bool
- func (v Value) Complex128() (complex128, bool)
- func (v Value) Complex64() (complex64, bool)
- func (v Value) DefaultType() *types.Complete
- func (v Value) Den() Value
- func (v Value) Err() error
- func (v Value) Float32() (float32, bool)
- func (v Value) Float64() (float64, bool)
- func (v Value) Imag() Value
- func (v Value) Int64() (int64, bool)
- func (v Value) IsValid() bool
- func (v Value) Kind() Kind
- func (v Value) Num() Value
- func (v Value) Real() Value
- func (v Value) String() string
- func (v Value) StringVal() (string, bool)
- func (v Value) To(t *types.Complete) Value
- func (v Value) ToKind(kind Kind) Value
- func (v Value) Type() *types.Complete
- func (v Value) Uint64() (uint64, bool)
- func (v Value) Value() interface{}
Constants ¶
const ( Invalid = Kind(token.Invalid) // types for typed constants Bool = Kind(token.Bool) Int = Kind(token.Int) Int8 = Kind(token.Int8) Int16 = Kind(token.Int16) Int32 = Kind(token.Int32) Int64 = Kind(token.Int64) Uint = Kind(token.Uint) Uint8 = Kind(token.Uint8) Uint16 = Kind(token.Uint16) Uint32 = Kind(token.Uint32) Uint64 = Kind(token.Uint64) Uintptr = Kind(token.Uintptr) Float32 = Kind(token.Float32) Float64 = Kind(token.Float64) Complex64 = Kind(token.Complex64) Complex128 = Kind(token.Complex128) String = Kind(token.String) // types for untyped constants UntypedBool = Kind(token.UntypedBool) UntypedInt = Kind(token.UntypedInt) UntypedRune = Kind(token.UntypedRune) UntypedFloat = Kind(token.UntypedFloat) UntypedComplex = Kind(token.UntypedComplex) UntypedString = Kind(token.UntypedString) UntypedNil = Kind(token.UntypedNil) // aliases Byte = Kind(token.Byte) Rune = Kind(token.Rune) )
Variables ¶
var (
ErrInvalid = ErrorInvalid{}
)
Functions ¶
This section is empty.
Types ¶
type ErrorInvalid ¶
type ErrorInvalid struct { }
func (ErrorInvalid) Error ¶
func (e ErrorInvalid) Error() string
type ErrorOverflow ¶
type ErrorOverflow struct {
// contains filtered or unexported fields
}
func (ErrorOverflow) Error ¶
func (e ErrorOverflow) Error() string
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
equivalent to go/constant.Value the zero value i.e. Value{} has .Type() == nil, .Kind() = Invalid and .Err() = ErrInvalid
func Make ¶
*
- Make creates a constant. Allowed x types depend on t.Kind():
- bool if kind is Bool or UntypedBool
- string if kind is String or UntypedString
- int*, uint* or *math/big.Int if kind is Int*, Uint*, UntypedInt or UntypedRune
- float32, float64, *big.Float or *big.Rat if kind is Float* or UntypedFloat
- complex64 or complex128 if kind is Complex* or UntypedComplex
- nil if kind is Invalid or UntypedNil *
- return Value{Invalid, ErrorType} if conversion of val to kind is not allowed.
- return Value{Invalid, ErrorOverflow} if conversion of val to kind is not exact.
func (Value) Complex128 ¶
func (v Value) Complex128() (complex128, bool)
*
- Complex128 returns the complex128 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, Float*, Complex*,
- UntypedInt, UntypedRune, UntypedFloat, UntypedComplex or Invalid
func (Value) Complex64 ¶
*
- Complex64 returns the complex64 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, Float*, Complex*,
- UntypedInt, UntypedRune, UntypedFloat, UntypedComplex or Invalid
func (Value) DefaultType ¶
if v is typed, return Type() if v is untyped, return its default type
func (Value) Den ¶
return denominator of Value. v.Kind() must be Int*, Uint*, Float*, UntypedInt, UntypedRune, UntypedFloat or Invalid
func (Value) Err ¶
*
- Err returns the error of an Invalid constant.
- returns nil if the constant is valid.
func (Value) Float32 ¶
*
- Float32 returns the float32 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, Float*, UntypedInt, UntypedRune, UntypedFloat or Invalid
func (Value) Float64 ¶
*
- Float64 returns the float64 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, Float*, UntypedInt, UntypedRune, UntypedFloat or Invalid
func (Value) Imag ¶
return imaginary part of Value v. v.Kind() must be Int*, Uint*, Float*, Complex*, UntypedInt, UntypedRune, UntypedFloat, UntypedComplex or Invalid
func (Value) Int64 ¶
*
- Int64 returns the int64 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, UntypedInt, UntypedRune or Invalid
func (Value) Num ¶
return numerator of Value v. v.Kind() must be Int*, Uint*, Float*, UntypedInt, UntypedRune, UntypedFloat or Invalid
func (Value) Real ¶
return real part of Value v. v.Kind() must be Int*, Uint*, Float*, Complex*, UntypedInt, UntypedRune, UntypedFloat, UntypedComplex or Invalid
func (Value) StringVal ¶
*
- StringVal returns the string value of v;
- v.Kind() must be String, UntypedString or Invalid
func (Value) To ¶
*
- try to convert Value v to to specified type.
- return Value{Invalid, ErrorBadKind} if conversion is not allowed.
- return Value{Invalid, ErrorOverflow} if conversion is not exact.
- otherwise return converted Value
func (Value) ToKind ¶
*
- try to convert Value v to to specified kind.
- return Value{Invalid, ErrorBadKind} if conversion is not allowed.
- return Value{Invalid, ErrorOverflow} if conversion is not exact.
- otherwise return converted Value
func (Value) Uint64 ¶
*
- Uint64 returns the int64 value of v and whether the result is exact;
- v.Kind() must be Int*, Uint*, UntypedInt, UntypedRune or Invalid
func (Value) Value ¶
func (v Value) Value() interface{}
*
- get the value of a constant. returned type is:
- bool if Kind is Bool
- string if Kind is String
- int64 or *math/big.Int if Kind is Int*, Uint*, UntypedInt or UntypedRune
- *big.Float or *big.Rat if Kind is Float* or UntypedFloat
- nil if Kind is Invalid, Complex*, UntypedComplex or UntypedNil