// Eval implements Expression interface.
170088
func (c *Constant) Eval(_ []types.Datum, _ context.Context) (types.Datum, error) {
	return c.Value, nil
}
56203
func (lsf *LeastSquaresFunction) Eval(x float64) float64 {
	slope := lsf.slope()
	result := lsf.intercept(slope) + slope*x
	return result
}
371242
func (col *Column) Eval(row chunk.Row) (types.Datum, error) {
	return row.GetDatum(col.Index, col.RetType), nil
}
259368
func (s *state) evalExpr(exp parse.Expr) (v Value, e error) {
	switch exp := exp.(type) {
	case *parse.NullExpr:
		return nil, nil
	case *parse.BoolExpr:
		return exp.Value, nil
	case *parse.NameExpr:
		if val, ok := s.scope.Get(exp.Name); ok {
			v = val
		} else {
			e = errors.New("undefined variable \"" + exp.Name + "\"")
		}
	case *parse.NumberExpr:
		num, err := strconv.ParseFloat(exp.Value, 64)
		if err != nil {
			return nil, err
		}
		return num, nil
	case *parse.StringExpr:
		return exp.Text, nil
	case *parse.GroupExpr:
		return s.evalExpr(exp.X)
	case *parse.UnaryExpr:
		in, err := s.evalExpr(exp.X)
		if err != nil {
			return nil, err
		}
		switch exp.Op {
		case parse.OpUnaryNot:
			return !CoerceBool(in), nil
		case parse.OpUnaryPositive:
			// no-op, +1 = 1, +(-1) = -1, +(false) = 0
			return CoerceNumber(in), nil
		case parse.OpUnaryNegative:
			return -CoerceNumber(in), nil
		}
	case *parse.BinaryExpr:
		left, err := s.evalExpr(exp.Left)
		if err != nil {
			return nil, err
		}
		right, err := s.evalExpr(exp.Right)
		if err != nil {
			return nil, err
		}
		switch exp.Op {
		case parse.OpBinaryAdd:
			return CoerceNumber(left) + CoerceNumber(right), nil
		case parse.OpBinarySubtract:
			return CoerceNumber(left) - CoerceNumber(right), nil
		case parse.OpBinaryMultiply:
			return CoerceNumber(left) * CoerceNumber(right), nil
		case parse.OpBinaryDivide:
			return CoerceNumber(left) / CoerceNumber(right), nil
		case parse.OpBinaryFloorDiv:
			return math.Floor(CoerceNumber(left) / CoerceNumber(right)), nil
		case parse.OpBinaryModulo:
			return float64(int(CoerceNumber(left)) % int(CoerceNumber(right))), nil
		case parse.OpBinaryPower:
			return math.Pow(CoerceNumber(left), CoerceNumber(right)), nil
		case parse.OpBinaryConcat:
			return CoerceString(left) + CoerceString(right), nil
		case parse.OpBinaryEndsWith:
			return strings.HasSuffix(CoerceString(left), CoerceString(right)), nil
		case parse.OpBinaryStartsWith:
			return strings.HasPrefix(CoerceString(left), CoerceString(right)), nil
		case parse.OpBinaryIn:
			return Contains(right, left)
		case parse.OpBinaryNotIn:
			res, err := Contains(right, left)
			if err != nil {
				return false, err
			}
			return !res, nil
		case parse.OpBinaryIs:
			if fn, ok := right.(func(v Value) bool); ok {
				return fn(left), nil
			}
			return nil, errors.New("right operand was of unexpected type")
		case parse.OpBinaryIsNot:
			if fn, ok := right.(func(v Value) bool); ok {
				return !fn(left), nil
			}
			return nil, errors.New("right operand was of unexpected type")
		case parse.OpBinaryMatches:
			reg, err := regexp.Compile(CoerceString(right))
			if err != nil {
				return nil, err
			}
			return reg.MatchString(CoerceString(left)), nil
		case parse.OpBinaryEqual:
			return Equal(left, right), nil
		case parse.OpBinaryNotEqual:
			return !Equal(left, right), nil
		case parse.OpBinaryGreaterEqual:
			return CoerceNumber(left) >= CoerceNumber(right), nil
		case parse.OpBinaryGreaterThan:
			return CoerceNumber(left) > CoerceNumber(right), nil
		case parse.OpBinaryLessEqual:
			return CoerceNumber(left) <= CoerceNumber(right), nil
		case parse.OpBinaryLessThan:
			return CoerceNumber(left) < CoerceNumber(right), nil
		case parse.OpBinaryRange:
			l, r := CoerceNumber(left), CoerceNumber(right)
			res := make([]float64, uint(math.Ceil(r-l))+1)
			for i, k := 0, l; k <= r; i, k = i+1, k+1 {
				res[i] = k
			}
			return res, nil
		case parse.OpBinaryBitwiseAnd:
			return int(CoerceNumber(left)) & int(CoerceNumber(right)), nil
		case parse.OpBinaryBitwiseOr:
			return int(CoerceNumber(left)) | int(CoerceNumber(right)), nil
		case parse.OpBinaryBitwiseXor:
			return int(CoerceNumber(left)) ^ int(CoerceNumber(right)), nil
		case parse.OpBinaryAnd:
			return CoerceBool(left) && CoerceBool(right), nil
		case parse.OpBinaryOr:
			return CoerceBool(left) && CoerceBool(right), nil
		}
	case *parse.FuncExpr:
		return s.evalFunction(exp)
	case *parse.FilterExpr:
		return s.evalFilter(exp)
	case *parse.GetAttrExpr:
		c, err := s.evalExpr(exp.Cont)
		if err != nil {
			return nil, err
		}
		k, err := s.evalExpr(exp.Attr)
		if err != nil {
			return nil, err
		}
		exargs := exp.Args
		args := make([]Value, len(exargs))
		for k, e := range exargs {
			v, err := s.evalExpr(e)
			if err != nil {
				return nil, err
			}
			args[k] = v
		}
		if set, ok := c.(macroSet); ok {
			if macro, ok := set.defs[CoerceString(k)]; ok {
				return s.callMacro(macro, args...)
			}
			return nil, errors.New("undefined macro: " + CoerceString(k))
		}
		v, err = GetAttr(c, k, args...)
		if err != nil {
			return nil, err
		}
	case *parse.TestExpr:
		if tfn, ok := s.env.Tests[exp.Name]; ok {
			eargs := exp.Args
			args := make([]Value, len(eargs))
			for i, e := range eargs {
				v, err := s.evalExpr(e)
				if err != nil {
					return nil, err
				}
				args[i] = v
			}
			return func(v Value) bool {
				return tfn(s, v, args...)
			}, nil
		}
		return nil, fmt.Errorf(`unknown test "%v"`, exp.Name)
	case *parse.TernaryIfExpr:
		cond, err := s.evalExpr(exp.Cond)
		if err != nil {
			return nil, err
		}
		if CoerceBool(cond) == true {
			return s.evalExpr(exp.TrueX)
		}
		return s.evalExpr(exp.FalseX)

	case *parse.HashExpr:
		vals := make(map[string]Value)
		for _, v := range exp.Elements {
			var key Value
			var err error
			if k, ok := v.Key.(*parse.NameExpr); ok {
				key = k.Name
			} else {
				key, err = s.evalExpr(v.Key)
				if err != nil {
					return nil, err
				}
			}
			val, err := s.evalExpr(v.Value)
			if err != nil {
				return nil, err
			}
			vals[CoerceString(key)] = val
		}
		return vals, nil

	case *parse.ArrayExpr:
		vals := make([]Value, len(exp.Elements))
		for i, v := range exp.Elements {
			val, err := s.evalExpr(v)
			if err != nil {
				return nil, err
			}
			vals[i] = val
		}
		return vals, nil
	}

	return v, nil
}
362326
func EvalParsedInput(input ast.Value) EvalOption {
	return func(e *EvalContext) {
		e.parsedInput = input
		e.hasInput = true
	}
}
970814
func (j *JSONPath) evalList(value []reflect.Value, node *ListNode) ([]reflect.Value, error) {
	var err error
	curValue := value
	for _, node := range node.Nodes {
		curValue, err = j.walk(curValue, node)
		if err != nil {
			return curValue, err
		}
	}
	return curValue, nil
}
653607
func Eval(expression string) (time.Time, error) {
	return EvalAnchor(time.Now(), expression)
}
874210
func (v *ValuerEval) EvalBool(expr Expr) bool {
	val, _ := v.Eval(expr).(bool)
	return val
}
674844
func Eval(ctx context.Context, usage string, args []string, store storage.Store, bulkSize, builderSize int) int {
	if len(args) < 3 {
		log.Printf("[ERROR] Missing required file path and/or graph names.\n\n%s", usage)
		return 2
	}
	graphs, lb := strings.Split(args[len(args)-1], ","), literal.NewBoundedBuilder(builderSize)
	trplsChan, errChan, doneChan := make(chan *triple.Triple), make(chan error), make(chan bool)
	path := args[len(args)-2]
	go storeTriple(ctx, store, graphs, bulkSize, trplsChan, errChan, doneChan)
	cnt, err := io.ProcessLines(path, func(line string) error {
		t, err := triple.Parse(line, lb)
		if err != nil {
			return err
		}
		trplsChan <- t
		return <-errChan
	})
	if err != nil {
		log.Printf("[ERROR] Failed to process file %q. Ivalid triple on line %d. %v\n", path, cnt, err)
		return 2
	}
	doneChan <- true
	if err := <-errChan; err != nil {
		log.Printf("[ERROR] Failed to process file %q. Ivalid triple on line %d. %v\n", path, cnt, err)
		return 2
	}
	fmt.Printf("Successfully processed %d lines from file %q.\nTriples loaded into graphs:\n\t- %s\n", cnt, path, strings.Join(graphs, "\n\t- "))
	return 0
}
690544
func (b *builtinStringAnyValueSig) evalString(row chunk.Row) (string, bool, error) {
	return b.args[0].EvalString(b.ctx, row)
}
703202
func evalFromCall(expr ast.Node, context Context) (interface{}, callSite, error) {
	//fmt.Println(reflect.TypeOf(expr), time.Now().UnixNano()/int64(10000), expr)
	switch expr.(type) {
	case *ast.Ident:
		i, e := evalIdentFromCall(expr.(*ast.Ident), context)
		return i, callSite{isValid: false}, e
	case *ast.SelectorExpr:
		return evalSelectorExprCall(expr.(*ast.SelectorExpr), context)
	default:
		i, e := eval(expr, context)
		return i, callSite{isValid: false}, e
	}
}
1171886
func NewEval(Expression node.Node) *Eval {
	return &Eval{
		FreeFloating: nil,
		Expr:         Expression,
	}
}
409461
func (sf *ScalarFunction) EvalReal(ctx sessionctx.Context, row chunk.Row) (float64, bool, error) {
	return sf.Function.evalReal(row)
}
645069
func EvalWithVariables(expr string, variables map[string]string) (result *big.Rat, err error) {
	symbolTable = variables
	s := ""
	for k := range symbolTable {
		s += k
	}
	symbols_rx = regexp.MustCompile(fmt.Sprintf("(%s)", s))
	return Eval(expr)
}
214785
func (pq PreparedEvalQuery) Eval(ctx context.Context, options ...EvalOption) (ResultSet, error) {
	ectx, err := pq.newEvalContext(ctx, options)
	if err != nil {
		return nil, err
	}

	ectx.compiledQuery = pq.r.compiledQueries[evalQueryType]

	return pq.r.eval(ctx, ectx)
}
159463
func (c *Constant) Eval(_ chunk.Row) (types.Datum, error) {
	if c.DeferredExpr != nil {
		if sf, sfOK := c.DeferredExpr.(*ScalarFunction); sfOK {
			dt, err := sf.Eval(chunk.Row{})
			if err != nil {
				return c.Value, err
			}
			if dt.IsNull() {
				c.Value.SetNull()
				return c.Value, nil
			}
			val, err := dt.ConvertTo(sf.GetCtx().GetSessionVars().StmtCtx, c.RetType)
			if err != nil {
				return dt, err
			}
			c.Value.SetValue(val.GetValue())
		}
	}
	return c.Value, nil
}
645358
func (c *Client) Eval(script string, numkeys int, keys, args []string) (interface{}, error) {
	a := []interface{}{
		"EVAL",
		script, // escape?
		numkeys,
		strings.Join(keys, " "),
		strings.Join(args, " "),
	}
	v, err := c.execOnFirst(true, a...)
	if err != nil {
		return nil, err
	}
	return v, nil
}