overload

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotLogical = iota
	MayLogical
	MustLogical
)
View Source
const (
	Unary = iota
	Multi
	Binary
)
View Source
const (
	// unary operator
	UnaryMinus = iota
	Not

	// binary operator
	Or
	And
	Plus
	Minus
	Mult
	Div
	IntegerDiv
	Mod
	Like
	NotLike
	Typecast

	// binary operator - comparison operator
	EQ
	LT
	LE
	GT
	GE
	NE
)

Variables

View Source
var (
	// ErrDivByZero is reported on a division by zero.
	ErrDivByZero = errors.New(errno.SyntaxErrororAccessRuleViolation, "division by zero")
	// ErrModByZero is reported when computing the rest of a division by zero.
	ErrModByZero = errors.New(errno.SyntaxErrororAccessRuleViolation, "zero modulus")

	// BinOps contains the binary operations indexed by operation type.
	BinOps = map[int][]*BinOp{}
)
View Source
var (
	// OperatorCastRules records implicit type conversion rule for all operators and built-in functions
	// map's key is operator id or function id (eg: overload.Plus)
	OperatorCastRules = make(map[int][]castRule)

	// OperatorReturnType records return type for all operator and built-in functions
	// first map : key is operator or function id (eg: overload.Minus), value is second map :
	// key is numbers of args, and value is a slice of struct retType (contains information about arg types and return type)
	OperatorReturnType = make(map[int]map[uint8][]retType)
)
View Source
var LogicalOps = map[int]uint8{
	Or:      MayLogical,
	And:     MayLogical,
	Like:    MustLogical,
	NotLike: MustLogical,
	EQ:      MustLogical,
	LT:      MustLogical,
	LE:      MustLogical,
	GT:      MustLogical,
	GE:      MustLogical,
	NE:      MustLogical,
}
View Source
var MultiOps = map[int][]*MultiOp{}
View Source
var NegOps = map[int]int{
	Or:   And,
	And:  Or,
	EQ:   NE,
	LT:   GE,
	LE:   GT,
	GT:   LE,
	GE:   LT,
	Like: NotLike,
}
View Source
var OpName = map[int]string{
	UnaryMinus: "-",
	Not:        "not",

	Or:         "or",
	And:        "and",
	Plus:       "+",
	Minus:      "-",
	Mult:       "*",
	Div:        "/",
	IntegerDiv: "div",
	Mod:        "%",

	Like:    "like",
	NotLike: "notLike",

	Typecast: "cast",

	EQ: "=",
	LT: "<",
	LE: "<=",
	GT: ">",
	GE: ">=",
	NE: "<>",
}
View Source
var OpTypes = map[int]int{
	UnaryMinus: Unary,
	Or:         Binary,
	And:        Binary,
	Plus:       Binary,
	Minus:      Binary,
	Mult:       Binary,
	Div:        Binary,
	Mod:        Binary,
	Like:       Binary,
	NotLike:    Binary,
	Typecast:   Binary,
	EQ:         Binary,
	LT:         Binary,
	LE:         Binary,
	GT:         Binary,
	GE:         Binary,
	NE:         Binary,
}
View Source
var SelsType = types.Type{Oid: types.T_sel, Size: 8}
View Source
var (
	// UnaryOps contains the unary operations indexed by operation type.
	UnaryOps = map[int][]*UnaryOp{}
)

Functions

func AppendCastRules

func AppendCastRules(op int, numArgs uint8, sourceTypes []types.T, targetTypes []types.Type)

func AppendFunctionRets

func AppendFunctionRets(op int, args []types.T, ret types.T)

AppendFunctionRets will add function-return-type information into related structure op is function id args is a slice of argument types ret is return type of this function

func BinaryEval

func BinaryEval(op int, ltyp, rtyp types.T, lc, rc bool, lv, rv *vector.Vector, p *process.Process) (*vector.Vector, error)

func GetBinOpReturnType

func GetBinOpReturnType(op int, lt, rt types.T) types.T

GetBinOpReturnType returns the returnType of binary ops or binary functions

func GetMultiReturnType

func GetMultiReturnType(op int, ts []types.T) types.T

GetMultiReturnType returns the returnType of multi ops or multi functions

func GetUnaryOpReturnType

func GetUnaryOpReturnType(op int, arg types.T) types.T

GetUnaryOpReturnType returns the returnType of unary ops or binary functions

func IsLogical

func IsLogical(op int) uint8

func MultiEval

func MultiEval(op int, typ types.T, bs []bool, vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error)

func OperatorType

func OperatorType(op int) int

func UnaryEval

func UnaryEval(op int, typ types.T, c bool, v *vector.Vector, p *process.Process) (*vector.Vector, error)

func UpdateEval

func UpdateEval(typ, toTyp types.T, c bool, v *vector.Vector, p *process.Process) (*vector.Vector, error)

Types

type BinOp

type BinOp struct {
	LeftType   types.T
	RightType  types.T
	ReturnType types.T

	Fn func(*vector.Vector, *vector.Vector, *process.Process, bool, bool) (*vector.Vector, error)
}

BinOp is a binary operator.

type MultiOp

type MultiOp struct {
	Min        int // minimum number of parameters
	Max        int // maximum number of parameters, -1 means unlimited
	Typ        types.T
	ReturnType types.T

	Fn func([]*vector.Vector, *process.Process, []bool) (*vector.Vector, error)
}

MultiOp is a multiple operator.

type UnaryOp

type UnaryOp struct {
	Typ        types.T
	ReturnType types.T
	Fn         func(*vector.Vector, *process.Process, bool) (*vector.Vector, error)
}

UnaryOp is a unary operator.

Jump to

Keyboard shortcuts

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