import "v.io/x/ref/lib/vdl/opconst"
Package opconst defines the representation and operations for VDL constants.
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 )
ToBinaryOp converts s into a BinaryOp, or returns InvalidBinaryOp if it couldn't be converted.
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.
Boolean returns an untyped boolean Const.
EvalBinary returns the result of evaluating (x op y).
EvalUnary returns the result of evaluating (op x).
FromValue returns a typed Const based on value v.
Integer returns an untyped integer Const.
Rational returns an untyped rational Const.
String returns an untyped string Const.
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.
IsValid returns true iff the c represents a const; it returns false for the zero Const.
ToValue converts Const c to a Value.
Type returns the type of c. Nil indicates c is an untyped const.
UnaryOp represents a unary operation to be performed on a Const.
const ( InvalidUnaryOp UnaryOp = iota LogicNot // ! logical not Pos // + positive (nop) Neg // - negate BitNot // ^ bitwise not )
ToUnaryOp converts s into a UnaryOp, or returns InvalidUnaryOp if it couldn't be converted.
Package opconst imports 6 packages (graph) and is imported by 2 packages. Updated 2020-06-09. Refresh now. Tools for package owners.