Documentation ¶
Index ¶
- func Assign(x constant.Value, t reflect.Type) (r reflect.Value, ok bool)
- func AssignableTo(x constant.Value, t reflect.Type) bool
- func BinaryOp(x constant.Value, op token.Token, y constant.Value) (r constant.Value, err error)
- func BoolVal(x constant.Value) (r bool, ok bool)
- func CompareOp(x constant.Value, op token.Token, y constant.Value) (r bool, err error)
- func CompareOpTyped(x TypedValue, op token.Token, y TypedValue) (r bool, err error)
- func Complex128Val(x constant.Value) (complex128, bool)
- func Complex64Val(x constant.Value) (complex64, bool)
- func ConvertibleTo(x constant.Value, t reflect.Type) bool
- func DefaultType(x constant.Value) reflect.Type
- func DefaultTypeForKind(k constant.Kind) reflect.Type
- func DefaultValue(x constant.Value) (r reflect.Value, ok bool)
- func DefaultValueInterface(x constant.Value) (r interface{}, ok bool)
- func Float32Val(x constant.Value) (float32, bool)
- func Float64Val(x constant.Value) (float64, bool)
- func Int16Val(x constant.Value) (int16, bool)
- func Int32Val(x constant.Value) (int32, bool)
- func Int64Val(x constant.Value) (int64, bool)
- func Int8Val(x constant.Value) (int8, bool)
- func IntVal(x constant.Value) (int, bool)
- func IsNumeric(k constant.Kind) bool
- func KindString(k constant.Kind) (r string)
- func MakeBool(x bool) constant.Value
- func MakeComplex128(x complex128) constant.Value
- func MakeComplex64(x complex64) constant.Value
- func MakeFloat32(x float32) constant.Value
- func MakeFloat64(x float64) constant.Value
- func MakeInt(x int) constant.Value
- func MakeInt16(x int16) constant.Value
- func MakeInt32(x int32) constant.Value
- func MakeInt64(x int64) constant.Value
- func MakeInt8(x int8) constant.Value
- func MakeString(x string) constant.Value
- func MakeUint(x uint) constant.Value
- func MakeUint16(x uint16) constant.Value
- func MakeUint32(x uint32) constant.Value
- func MakeUint64(x uint64) constant.Value
- func MakeUint8(x uint8) constant.Value
- func MustAssign(x constant.Value, t reflect.Type) reflect.Value
- func RuneVal(x constant.Value) (rune, bool)
- func ShiftOp(x constant.Value, op token.Token, s uint) (r constant.Value, err error)
- func StringVal(x constant.Value) (string, bool)
- func Uint16Val(x constant.Value) (uint16, bool)
- func Uint32Val(x constant.Value) (uint32, bool)
- func Uint64Val(x constant.Value) (uint64, bool)
- func Uint8Val(x constant.Value) (uint8, bool)
- func UintVal(x constant.Value) (uint, bool)
- func UnaryOp(op token.Token, y constant.Value, prec uint) (r constant.Value, err error)
- type TypedValue
- func BinaryOpTyped(x TypedValue, op token.Token, y TypedValue) (r TypedValue, err error)
- func Convert(x constant.Value, t reflect.Type) (r TypedValue, ok bool)
- func MakeTypedValue(x constant.Value, t reflect.Type) (r TypedValue, ok bool)
- func MustConvert(x constant.Value, t reflect.Type) TypedValue
- func MustMakeTypedValue(x constant.Value, t reflect.Type) TypedValue
- func ShiftOpTyped(x TypedValue, op token.Token, s uint) (r TypedValue, err error)
- func UnaryOpTyped(op token.Token, y TypedValue, prec uint) (r TypedValue, err error)
- func (x TypedValue) Assign(t reflect.Type) (r reflect.Value, ok bool)
- func (x TypedValue) AssignableTo(t reflect.Type) bool
- func (x TypedValue) Convert(t reflect.Type) (TypedValue, bool)
- func (x TypedValue) ConvertibleTo(t reflect.Type) bool
- func (x TypedValue) Equal(y TypedValue) bool
- func (x TypedValue) ExactString() string
- func (x TypedValue) ExactStringType() string
- func (x TypedValue) MustAssign(t reflect.Type) reflect.Value
- func (x TypedValue) MustConvert(t reflect.Type) TypedValue
- func (x TypedValue) String() string
- func (x TypedValue) StringType() string
- func (x TypedValue) Type() reflect.Type
- func (x TypedValue) Untyped() constant.Value
- func (x TypedValue) Value() reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶
Assign creates reflect.Value of type t and tries to assign constant x to it using Go assignation rules described in specification. It returns reflect.Value and boolean flag ok. ok will be true if assignation done successfully.
func AssignableTo ¶
AssignableTo checks possibility of assignation constant x to variable of type t using Go assignation rules described in specification.
func BinaryOp ¶
BinaryOp performs binary operation <x><op><y> on untyped constants as Go language specification describes. Supported operations: && || + - * / % & | ^ &^ . If operation cannot be performed then error will be returned.
func CompareOp ¶
CompareOp performs compare operation <x><op><y> on untyped constants as Go language specification describes. Supported operations: < <= >= > == != . If operation cannot be performed then error will be returned.
func CompareOpTyped ¶
func CompareOpTyped(x TypedValue, op token.Token, y TypedValue) (r bool, err error)
CompareOpTyped performs compare operation <x><op><y> on typed constants as Go language specification describes. Supported operations: < <= >= > == != . If operation cannot be performed then error will be returned.
func Complex128Val ¶
func Complex128Val(x constant.Value) (complex128, bool)
Complex128Val returns the Go complex128 value of x and whether operation successful.
func Complex64Val ¶
Complex64Val returns the Go complex64 value of x and whether operation successful.
func ConvertibleTo ¶
ConvertibleTo checks possibility of conversion constant x to type t using Go conversion rules described in specification.
func DefaultType ¶
DefaultType returns default type for specified constant x (as Go specification describes). There is no guarantee what constant x can be represented as returned type.
func DefaultTypeForKind ¶
DefaultTypeForKind returns default type for specified constant's kind k (as Go specification describes). Result is nil if k is Unknown kind.
func DefaultValue ¶
DefaultValue returns reflect.Value equivalent of passed constant x. Type of result is the default type for constant x. If constant can not be represented as variable with constant's default type then ok will be false.
func DefaultValueInterface ¶
DefaultValueInterface does the same thing as DefaultValue but returns interface instead of reflect.Value.
func Float32Val ¶
Float32Val is like Float64Val but for float32 instead of float64.
func Float64Val ¶
Float64Val returns the nearest Go float64 value of x and whether operation successful. For values too small (too close to 0) to represent as float64, Float64Val silently underflows to 0. The result sign always matches the sign of x, even for 0.
func IsNumeric ¶
IsNumeric returns true if passed constant's kind is number (int, float or complex).
func KindString ¶
KindString returns string representation of passed constant's kind.
func MakeComplex128 ¶
func MakeComplex128(x complex128) constant.Value
MakeComplex128 returns the Complex constant.Value for x.
func MakeComplex64 ¶
MakeComplex64 returns the Complex constant.Value for x.
func MakeFloat32 ¶
MakeFloat32 returns the Int value for x.
func MakeFloat64 ¶
MakeFloat64 returns the Int value for x.
func MustAssign ¶
MustAssign does the same thing as Assign but if assignation is impossible it panics.
func ShiftOp ¶
ShiftOp performs shift operation <x><op><s> on untyped constant as Go language specification describes. Supported operations: << >> . If operation cannot be performed then error will be returned.
Types ¶
type TypedValue ¶
type TypedValue struct {
// contains filtered or unexported fields
}
A TypedValue represents a Go typed constant.
func BinaryOpTyped ¶
func BinaryOpTyped(x TypedValue, op token.Token, y TypedValue) (r TypedValue, err error)
BinaryOpTyped performs binary operation <x><op><y> on typed constants as Go language specification describes. Supported operations: && || + - * / % & | ^ &^ . If operation cannot be performed then error will be returned.
func Convert ¶
Convert tries to convert constant x to type t using Go conversion rules described in specification. It returns typed constant and boolean flag ok. ok will be true if conversion done successfully. Convert returns ok = false if type t is an interface, use Assign instead (this is because Convert returns TypedValue which used to stores typed constant, but result of conversion untyped constant to interface is not typed constant, it is variable).
func MakeTypedValue ¶
MakeTypedValue tries to create typed constant from given untyped constant x with specified type t. If x can not be represented as type t then ok will be false.
func MustConvert ¶
func MustConvert(x constant.Value, t reflect.Type) TypedValue
MustConvert does the same thing as Convert but if conversion is impossible it panics.
func MustMakeTypedValue ¶
func MustMakeTypedValue(x constant.Value, t reflect.Type) TypedValue
MustMakeTypedValue is a panic version of MakeTypedValue. It panics if x can not be represented as type t.
func ShiftOpTyped ¶
func ShiftOpTyped(x TypedValue, op token.Token, s uint) (r TypedValue, err error)
ShiftOpTyped performs shift operation <x><op><s> on typed constant as Go language specification describes. Supported operations: << >> . If operation cannot be performed then error will be returned.
func UnaryOpTyped ¶
func UnaryOpTyped(op token.Token, y TypedValue, prec uint) (r TypedValue, err error)
UnaryOpTyped performs unary operation <op><y> on typed constant as Go language specification describes. Supported operations: + - ^ ! . If operation cannot be performed then error will be returned.
func (TypedValue) Assign ¶
Assign creates reflect.Value of type t and tries to assign typed constant x to it using Go assignation rules described in specification. It returns reflect.Value and boolean flag ok. ok will be true if assignation done successfully.
func (TypedValue) AssignableTo ¶
func (x TypedValue) AssignableTo(t reflect.Type) bool
AssignableTo checks possibility of assignation typed constant x to variable of type t using Go assignation rules described in specification.
func (TypedValue) Convert ¶
func (x TypedValue) Convert(t reflect.Type) (TypedValue, bool)
Convert tries to convert typed constant x to type t using Go conversion rules described in specification. It returns typed constant and boolean flag ok. ok will be true if conversion done successfully. Convert returns boolean flag = false if type t is an interface, use Assign instead (this is because Convert returns TypedValue which used to stores typed constant, but result of conversion typed constant to interface is not typed constant, it is variable).
func (TypedValue) ConvertibleTo ¶
func (x TypedValue) ConvertibleTo(t reflect.Type) bool
ConvertibleTo checks possibility of conversion typed constant x to type t using Go conversion rules described in specification.
func (TypedValue) Equal ¶
func (x TypedValue) Equal(y TypedValue) bool
Equal compares two typed constants.
func (TypedValue) ExactString ¶
func (x TypedValue) ExactString() string
ExactString return string representation of underlying untyped constant (example: "15432/125").
func (TypedValue) ExactStringType ¶
func (x TypedValue) ExactStringType() string
ExactStringType return exact string representations of underlying untyped constant and type (example: "15432/125 (type float32)").
func (TypedValue) MustAssign ¶
func (x TypedValue) MustAssign(t reflect.Type) reflect.Value
MustAssign does the same thing as Assign but if assignation is impossible it panics.
func (TypedValue) MustConvert ¶
func (x TypedValue) MustConvert(t reflect.Type) TypedValue
MustConvert does the same thing as Convert but if conversion is impossible it panics.
func (TypedValue) String ¶
func (x TypedValue) String() string
String return string representation of underlying untyped constant (example: "123.456").
func (TypedValue) StringType ¶
func (x TypedValue) StringType() string
StringType return string representations of underlying untyped constant and type (example: "123.456 (type float32)").
func (TypedValue) Type ¶
func (x TypedValue) Type() reflect.Type
Type returns type of typed constant.
func (TypedValue) Untyped ¶
func (x TypedValue) Untyped() constant.Value
Untyped returns underlying untyped constant which contains typed constant value.
func (TypedValue) Value ¶
func (x TypedValue) Value() reflect.Value
Value returns typed constant as reflect.Value (as regular Go variable).