// evalList evaluates ListNode
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
}
935299
func (b *builtinLastInsertIDWithIDSig) evalInt(row chunk.Row) (res int64, isNull bool, err error) {
	res, isNull, err = b.args[0].EvalInt(b.ctx, row)
	if isNull || err != nil {
		return res, isNull, err
	}

	b.ctx.GetSessionVars().SetLastInsertID(uint64(res))
	return res, false, nil
}
479870
func (n *NodeApplyableResource) EvalTree() EvalNode {
	addr := n.ResourceAddr()
	config := n.Config
	providerAddr := n.ResolvedProvider

	if config == nil {
		// Nothing to do, then.
		log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", addr)
		return &EvalNoop{}
	}

	return &EvalWriteResourceState{
		Addr:         addr.Resource,
		Config:       config,
		ProviderAddr: providerAddr,
	}
}
65894
func (b *builtinLengthSig) evalInt(row chunk.Row) (int64, bool, error) {
	val, isNull, err := b.args[0].EvalString(b.ctx, row)
	if isNull || err != nil {
		return 0, isNull, err
	}
	return int64(len([]byte(val))), false, nil
}
1299710
func (b *builtinLeastIntSig) evalInt(row chunk.Row) (min int64, isNull bool, err error) {
	min, isNull, err = b.args[0].EvalInt(b.ctx, row)
	if isNull || err != nil {
		return min, isNull, err
	}
	for i := 1; i < len(b.args); i++ {
		var v int64
		v, isNull, err = b.args[i].EvalInt(b.ctx, row)
		if isNull || err != nil {
			return min, isNull, err
		}
		if v < min {
			min = v
		}
	}
	return
}
795919
func (n *NodeDestroyDeposedResourceInstanceObject) EvalTree() EvalNode {
	addr := n.ResourceInstanceAddr()

	var provider providers.Interface
	var providerSchema *ProviderSchema
	var state *states.ResourceInstanceObject
	var change *plans.ResourceInstanceChange
	var err error

	return &EvalSequence{
		Nodes: []EvalNode{
			&EvalGetProvider{
				Addr:   n.ResolvedProvider,
				Output: &provider,
				Schema: &providerSchema,
			},
			&EvalReadStateDeposed{
				Addr:           addr.Resource,
				Output:         &state,
				Key:            n.DeposedKey,
				Provider:       &provider,
				ProviderSchema: &providerSchema,
			},
			&EvalDiffDestroy{
				Addr:         addr.Resource,
				ProviderAddr: n.ResolvedProvider,
				State:        &state,
				Output:       &change,
			},
			// Call pre-apply hook
			&EvalApplyPre{
				Addr:   addr.Resource,
				State:  &state,
				Change: &change,
			},
			&EvalApply{
				Addr:           addr.Resource,
				Config:         nil, // No configuration because we are destroying
				State:          &state,
				Change:         &change,
				Provider:       &provider,
				ProviderAddr:   n.ResolvedProvider,
				ProviderSchema: &providerSchema,
				Output:         &state,
				Error:          &err,
			},
			// Always write the resource back to the state deposed... if it
			// was successfully destroyed it will be pruned. If it was not, it will
			// be caught on the next run.
			&EvalWriteStateDeposed{
				Addr:           addr.Resource,
				Key:            n.DeposedKey,
				ProviderAddr:   n.ResolvedProvider,
				ProviderSchema: &providerSchema,
				State:          &state,
			},
			&EvalApplyPost{
				Addr:  addr.Resource,
				State: &state,
				Error: &err,
			},
			&EvalReturnError{
				Error: &err,
			},
			&EvalUpdateStateHook{},
		},
	}
}
1111723
func (b *builtinBitCountSig) evalInt(row chunk.Row) (int64, bool, error) {
	n, isNull, err := b.args[0].EvalInt(b.ctx, row)
	if err != nil || isNull {
		if err != nil && types.ErrOverflow.Equal(err) {
			return 64, false, nil
		}
		return 0, true, err
	}

	var count int64
	for ; n != 0; n = (n - 1) & n {
		count++
	}
	return count, false, nil
}
883724
func eval(expr ast.Node, context Context) (interface{}, error) {
	//fmt.Println(reflect.TypeOf(expr), time.Now().UnixNano()/int64(10000), expr)
	switch expr.(type) {
	/*
		case *ast.ArrayType:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.AssignStmt:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadDecl:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadExpr:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		case *ast.BadStmt:
			return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
	*/
	case *constNodeBinaryExpr:
		return expr.(*constNodeBinaryExpr).value, nil
	case *constNodeUnaryExpr:
		return expr.(*constNodeUnaryExpr).value, nil
	case *constNodeBasicLit:
		return expr.(*constNodeBasicLit).value, nil
	case *constNodeIdent:
		return expr.(*constNodeIdent).value, nil
	case *constNodeParenExpr:
		return expr.(*constNodeParenExpr).value, nil
	case *ast.BasicLit:
		return evalBasicLit(expr.(*ast.BasicLit), context)
	case *ast.BinaryExpr:
		return evalBinaryExpr(expr.(*ast.BinaryExpr), context)
		/*
			case *ast.BlockStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.BranchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.CallExpr:
		return evalCallExpr(expr.(*ast.CallExpr), context)
		/*
			case *ast.CaseClause:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ChanType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CommClause:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Comment:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CommentGroup:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.CompositeLit:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.DeclStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.DeferStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Ellipsis:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.EmptyStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Field:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FieldList:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ForStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncDecl:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncLit:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.FuncType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.GenDecl:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.GoStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.Ident:
		return evalIdent(expr.(*ast.Ident), context)
		/*
			case *ast.IfStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ImportSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.IncDecStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.IndexExpr:
		return evalIndexExpr(expr.(*ast.IndexExpr), context)
		/*
			case *ast.InterfaceType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.KeyValueExpr:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.LabeledStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.MapType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.Package:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.ParenExpr:
		return evalParenExpr(expr.(*ast.ParenExpr), context)
		/*
			case *ast.RangeStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.ReturnStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.SelectStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.SelectorExpr:
		return evalSelectorExpr(expr.(*ast.SelectorExpr), context)
		/*
			case *ast.SendStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.SliceExpr:
		return evalSliceExpr(expr.(*ast.SliceExpr), context)
	case *ast.StarExpr:
		return evalStarExpr(expr.(*ast.StarExpr), context)
		/*
			case *ast.StructType:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.SwitchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeAssertExpr:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
			case *ast.TypeSwitchStmt:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	case *ast.UnaryExpr:
		return evalUnaryExpr(expr.(*ast.UnaryExpr), context)
		/*
			case *ast.ValueSpec:
				return nil, fmt.Errorf("%s not suported", reflect.TypeOf(expr))
		*/
	default:
		return nilInterf, fmt.Errorf("Default %s not suported", reflect.TypeOf(expr))
	}
}
552972
func (b *builtinStrcmpSig) evalInt(row chunk.Row) (int64, bool, error) {
	var (
		left, right string
		isNull      bool
		err         error
	)

	left, isNull, err = b.args[0].EvalString(b.ctx, row)
	if isNull || err != nil {
		return 0, isNull, err
	}
	right, isNull, err = b.args[1].EvalString(b.ctx, row)
	if isNull || err != nil {
		return 0, isNull, err
	}
	res := types.CompareString(left, right)
	return int64(res), false, nil
}
585366
func (b *builtinSleepSig) evalInt(row chunk.Row) (int64, bool, error) {
	val, isNull, err := b.args[0].EvalReal(b.ctx, row)
	if err != nil {
		return 0, isNull, err
	}
	sessVars := b.ctx.GetSessionVars()
	if isNull {
		if sessVars.StrictSQLMode {
			return 0, true, errIncorrectArgs.GenWithStackByArgs("sleep")
		}
		return 0, true, nil
	}
	// processing argument is negative
	if val < 0 {
		if sessVars.StrictSQLMode {
			return 0, false, errIncorrectArgs.GenWithStackByArgs("sleep")
		}
		return 0, false, nil
	}

	if val > math.MaxFloat64/float64(time.Second.Nanoseconds()) {
		return 0, false, errIncorrectArgs.GenWithStackByArgs("sleep")
	}
	dur := time.Duration(val * float64(time.Second.Nanoseconds()))
	select {
	case <-time.After(dur):
		// TODO: Handle Ctrl-C is pressed in `mysql` client.
		// return 1 when SLEEP() is KILLed
	}
	return 0, false, nil
}
659973
func (s *state) evalField(dot reflect.Value, fieldName string, node expr.Node, args []expr.Node, final, receiver reflect.Value) reflect.Value {

	//u.Debugf("evalField: valid?%v", receiver.IsValid())
	if !receiver.IsValid() {
		//u.Warnf("bailing")
		return zero
	}
	typ := receiver.Type()
	receiver, _ = findValue(receiver)
	// Unless it's an interface, need to get to a value of type *T to guarantee
	// we see all methods of T and *T.
	ptr := receiver
	if ptr.Kind() != reflect.Interface && ptr.CanAddr() {
		ptr = ptr.Addr()
	}
	if method := ptr.MethodByName(fieldName); method.IsValid() {
		//u.Warnf("unimplemented method: %v", fieldName)
		return s.evalCall(dot, method, node, fieldName, args, final)
	}
	hasArgs := len(args) > 1 || final.IsValid()
	// It's not a method; must be a field of a struct or an element of a map. The receiver must not be nil.
	receiver, isNil := findValue(receiver)
	//u.Debugf("fld:%s  receiver kind():%v  val: %v", fieldName, receiver.Kind(), receiver)
	if isNil {
		return zero
	}
	switch receiver.Kind() {
	case reflect.Struct:
		tField, ok := receiver.Type().FieldByName(fieldName)
		if !ok {
			tField, ok = receiver.Type().FieldByNameFunc(lowerFieldMatch(fieldName))
			if !ok {
				tagName := strings.ToLower(fieldName)
				// Wow, this is pretty bruttaly expensive
				// Iterate over all available fields and read the tag value
				for i := 0; i < receiver.NumField(); i++ {
					// Get the field, returns https://golang.org/pkg/reflect/#StructField
					field := receiver.Type().Field(i)

					// Get the field tag value
					tag := field.Tag.Get("json")
					if tag == tagName {
						tField = field
						ok = true
						break
					}
				}
			}
		}
		//u.Infof("got field? %v", fieldName, tField)
		if ok {
			field := receiver.FieldByIndex(tField.Index)
			if tField.PkgPath != "" { // field is unexported
				return s.errorf("%s is an unexported field of struct type %s", fieldName, typ)
			}
			// If it's a function, we must call it.
			if hasArgs {
				return s.errorf("%s has arguments but cannot be invoked as function", fieldName)
			}
			return field
		}
		//context reader doesn't care about empty values
		return zero
	case reflect.Map:
		// If it's a map, attempt to use the field name as a key.
		nameVal := reflect.ValueOf(fieldName)
		if nameVal.Type().AssignableTo(receiver.Type().Key()) {
			if hasArgs {
				return s.errorf("%s is not a method but has arguments", fieldName)
			}
			result := receiver.MapIndex(nameVal)
			if !result.IsValid() {
				u.Errorf("could not evaluate %v", nameVal)
				// switch s.tmpl.option.missingKey {
				// case mapInvalid:
				// 	// Just use the invalid value.
				// case mapZeroValue:
				// 	result = reflect.Zero(receiver.Type().Elem())
				// case mapError:
				// 	s.errorf("map has no entry for key %q", fieldName)
				// }
			}
			return result
		}
	}
	s.errorf("can't evaluate field %s in type %s", fieldName, typ)
	panic("not reached")
}
723260
func (n *NodeEvalableProvider) EvalTree() EvalNode {
	addr := n.Addr
	relAddr := addr.ProviderConfig

	return &EvalInitProvider{
		TypeName: relAddr.Type,
		Addr:     addr.ProviderConfig,
	}
}
1064212
func (b *builtinExtractDurationSig) evalInt(row chunk.Row) (int64, bool, error) {
	unit, isNull, err := b.args[0].EvalString(b.ctx, row)
	if isNull || err != nil {
		return 0, isNull, err
	}
	dur, isNull, err := b.args[1].EvalDuration(b.ctx, row)
	if isNull || err != nil {
		return 0, isNull, err
	}
	res, err := types.ExtractDurationNum(&dur, unit)
	return res, err != nil, err
}
870526
func (s *RPCServer) Eval(arg EvalIn, out *EvalOut) error {
	cfg := arg.Cfg
	if cfg == nil {
		cfg = &api.LoadConfig{true, 1, 64, 64, -1}
	}
	v, err := s.debugger.EvalVariableInScope(arg.Scope, arg.Expr, *api.LoadConfigToProc(cfg))
	if err != nil {
		return err
	}
	out.Variable = v
	return nil
}
170088
func (c *Constant) Eval(_ []types.Datum, _ context.Context) (types.Datum, error) {
	return c.Value, nil
}
1353686
func (n *graphNodeImportState) EvalTree() EvalNode {
	var provider providers.Interface

	// Reset our states
	n.states = nil

	// Return our sequence
	return &EvalSequence{
		Nodes: []EvalNode{
			&EvalGetProvider{
				Addr:   n.ResolvedProvider,
				Output: &provider,
			},
			&EvalImportState{
				Addr:     n.Addr.Resource,
				Provider: &provider,
				ID:       n.ID,
				Output:   &n.states,
			},
		},
	}
}
545771
func (b *builtinTiDBIsDDLOwnerSig) evalInt(_ chunk.Row) (res int64, isNull bool, err error) {
	ddlOwnerChecker := b.ctx.DDLOwnerChecker()
	if ddlOwnerChecker.IsOwner() {
		res = 1
	}

	return res, false, nil
}