constanth

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assign

func Assign(x constant.Value, t reflect.Type) (r reflect.Value, ok bool)

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

func AssignableTo(x constant.Value, t reflect.Type) bool

AssignableTo checks possibility of assignation constant x to variable of type t using Go assignation rules described in specification.

func BinaryOp

func BinaryOp(x constant.Value, op token.Token, y constant.Value) (r constant.Value, err error)

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 BoolVal

func BoolVal(x constant.Value) (r bool, ok bool)

BoolVal returns the Go boolean value of x and whether operation successful.

func CompareOp

func CompareOp(x constant.Value, op token.Token, y constant.Value) (r bool, err error)

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

func Complex64Val(x constant.Value) (complex64, bool)

Complex64Val returns the Go complex64 value of x and whether operation successful.

func ConvertibleTo

func ConvertibleTo(x constant.Value, t reflect.Type) bool

ConvertibleTo checks possibility of conversion constant x to type t using Go conversion rules described in specification.

func DefaultType

func DefaultType(x constant.Value) reflect.Type

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

func DefaultTypeForKind(k constant.Kind) reflect.Type

DefaultTypeForKind returns default type for specified constant's kind k (as Go specification describes). Result is nil if k is Unknown kind.

func DefaultValue

func DefaultValue(x constant.Value) (r reflect.Value, ok bool)

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

func DefaultValueInterface(x constant.Value) (r interface{}, ok bool)

DefaultValueInterface does the same thing as DefaultValue but returns interface instead of reflect.Value.

func Float32Val

func Float32Val(x constant.Value) (float32, bool)

Float32Val is like Float64Val but for float32 instead of float64.

func Float64Val

func Float64Val(x constant.Value) (float64, bool)

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 Int16Val

func Int16Val(x constant.Value) (int16, bool)

Int16Val returns the Go int16 value of x and whether operation successful.

func Int32Val

func Int32Val(x constant.Value) (int32, bool)

Int32Val returns the Go int32 value of x and whether operation successful.

func Int64Val

func Int64Val(x constant.Value) (int64, bool)

Int64Val returns the Go int64 value of x and whether operation successful.

func Int8Val

func Int8Val(x constant.Value) (int8, bool)

Int8Val returns the Go int8 value of x and whether operation successful.

func IntVal

func IntVal(x constant.Value) (int, bool)

IntVal returns the Go int value of x and whether operation successful.

func IsNumeric

func IsNumeric(k constant.Kind) bool

IsNumeric returns true if passed constant's kind is number (int, float or complex).

func KindString

func KindString(k constant.Kind) (r string)

KindString returns string representation of passed constant's kind.

func MakeBool

func MakeBool(x bool) constant.Value

MakeBool returns the Int value for x.

func MakeComplex128

func MakeComplex128(x complex128) constant.Value

MakeComplex128 returns the Complex constant.Value for x.

func MakeComplex64

func MakeComplex64(x complex64) constant.Value

MakeComplex64 returns the Complex constant.Value for x.

func MakeFloat32

func MakeFloat32(x float32) constant.Value

MakeFloat32 returns the Int value for x.

func MakeFloat64

func MakeFloat64(x float64) constant.Value

MakeFloat64 returns the Int value for x.

func MakeInt

func MakeInt(x int) constant.Value

MakeInt returns the Int value for x.

func MakeInt16

func MakeInt16(x int16) constant.Value

MakeInt16 returns the Int value for x.

func MakeInt32

func MakeInt32(x int32) constant.Value

MakeInt32 returns the Int value for x.

func MakeInt64

func MakeInt64(x int64) constant.Value

MakeInt64 returns the Int value for x.

func MakeInt8

func MakeInt8(x int8) constant.Value

MakeInt8 returns the Int value for x.

func MakeString

func MakeString(x string) constant.Value

MakeString returns the Int value for x.

func MakeUint

func MakeUint(x uint) constant.Value

MakeUint returns the Int value for x.

func MakeUint16

func MakeUint16(x uint16) constant.Value

MakeUint16 returns the Int value for x.

func MakeUint32

func MakeUint32(x uint32) constant.Value

MakeUint32 returns the Int value for x.

func MakeUint64

func MakeUint64(x uint64) constant.Value

MakeUint64 returns the Int value for x.

func MakeUint8

func MakeUint8(x uint8) constant.Value

MakeUint8 returns the Int value for x.

func MustAssign

func MustAssign(x constant.Value, t reflect.Type) reflect.Value

MustAssign does the same thing as Assign but if assignation is impossible it panics.

func RuneVal

func RuneVal(x constant.Value) (rune, bool)

RuneVal returns the Go rune value of x and whether operation successful.

func ShiftOp

func ShiftOp(x constant.Value, op token.Token, s uint) (r constant.Value, err error)

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.

func StringVal

func StringVal(x constant.Value) (string, bool)

StringVal returns the Go string value of x and whether operation successful.

func Uint16Val

func Uint16Val(x constant.Value) (uint16, bool)

Uint16Val returns the Go int16 value of x and whether operation successful.

func Uint32Val

func Uint32Val(x constant.Value) (uint32, bool)

Uint32Val returns the Go int32 value of x and whether operation successful.

func Uint64Val

func Uint64Val(x constant.Value) (uint64, bool)

Uint64Val returns the Go uint64 value of x and whether operation successful.

func Uint8Val

func Uint8Val(x constant.Value) (uint8, bool)

Uint8Val returns the Go int8 value of x and whether operation successful.

func UintVal

func UintVal(x constant.Value) (uint, bool)

UintVal returns the Go int value of x and whether operation successful.

func UnaryOp

func UnaryOp(op token.Token, y constant.Value, prec uint) (r constant.Value, err error)

UnaryOp performs unary operation <op><y> 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

func Convert(x constant.Value, t reflect.Type) (r TypedValue, ok bool)

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

func MakeTypedValue(x constant.Value, t reflect.Type) (r TypedValue, ok bool)

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

func (x TypedValue) Assign(t reflect.Type) (r reflect.Value, ok bool)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL