Documentation ¶
Overview ¶
Package opconst defines the representation and operations for VDL constants.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryOp ¶
type BinaryOp uint
BinaryOp represents a binary operation to be performed on two Consts.
const ( InvalidBinaryOp BinaryOp = iota LogicAnd // && logical and LogicOr // || logical or EQ // == equal NE // != not equal LT // < less than LE // <= less than or equal GT // > greater than GE // >= greater than or equal Add // + add Sub // - subtract Mul // * multiply Div // / divide Mod // % modulo BitAnd // & bitwise and BitOr // | bitwise or BitXor // ^ bitwise xor LeftShift // << left shift RightShift // >> right shift )
func ToBinaryOp ¶
ToBinaryOp converts s into a BinaryOp, or returns InvalidBinaryOp if it couldn't be converted.
type Const ¶
type Const struct {
// contains filtered or unexported fields
}
Const represents a constant value, similar in spirit to Go constants. Consts may be typed or untyped. Typed consts represent unchanging Values; all Values may be converted into valid typed consts, and all typed consts may be converted into valid Values. Untyped consts belong to one of the following categories:
untyped boolean untyped string untyped integer untyped rational
Literal consts are untyped, as are expressions only containing untyped consts. The result of comparison operations is untyped boolean.
Operations are represented by UnaryOp and BinaryOp, and are supported on Consts, but not Values. We support common logical, bitwise, comparison and arithmetic operations. Not all operations are supported on all consts.
Binary ops where both sides are typed consts return errors on type mismatches; e.g. uint32(1) + uint64(1) is an invalid binary add. Ops on typed consts also return errors on loss of precision; e.g. uint32(1.1) returns an error.
Binary ops where one or both sides are untyped consts perform implicit type conversion. E.g. uint32(1) + 1 is a valid binary add, where the right-hand-side is the untyped integer const 1, which is coerced to the uint32 type before the op is performed. Operations only containing untyped consts are performed with "infinite" precision.
The zero Const is invalid.
func EvalBinary ¶
EvalBinary returns the result of evaluating (x op y).
func (Const) Convert ¶
Convert converts c to the target type t, and returns the resulting const. Returns an error if t is nil; you're not allowed to convert into an untyped const.
func (Const) IsValid ¶
IsValid returns true iff the c represents a const; it returns false for the zero Const.