// ConvertValueToColumnTypeIfNeeded checks if the expr in PatternInExpr is column name,
// and casts function to the items in the list.
423474
func (v *typeInferrer) convertValueToColumnTypeIfNeeded(x *ast.PatternInExpr) {
	if cn, ok := x.Expr.(*ast.ColumnNameExpr); ok && cn.Refer != nil {
		ft := cn.Refer.Column.FieldType
		for _, expr := range x.List {
			if valueExpr, ok := expr.(*ast.ValueExpr); ok {
				newDatum, err := valueExpr.Datum.ConvertTo(v.sc, &ft)
				if err != nil {
					v.err = errors.Trace(err)
				}
				cmp, err := newDatum.CompareDatum(v.sc, valueExpr.Datum)
				if err != nil {
					v.err = errors.Trace(err)
				}
				if cmp != 0 {
					// The value will never match the column, do not set newDatum.
					continue
				}
				valueExpr.SetDatum(newDatum)
			}
		}
		if v.err != nil {
			// TODO: Errors should be handled differently according to query context.
			log.Printf("inferor type for pattern in error %v", v.err)
			v.err = nil
		}
	}
}
689931
func (t SimpleType) ConvertFromModel(value interface{}) (interface{}, error) {
	if value == nil {
		return nil, nil
	}
	valueType := reflect.TypeOf(value)
	switch t.GetKind() {
	case KindString, KindURL, KindUser, KindInteger, KindFloat, KindIteration, KindArea, KindLabel, KindBoardColumn, KindBoolean:
		return value, nil
	case KindRemoteTracker:
		return AnyToUUID(value)
	case KindInstant:
		switch valueType.Kind() {
		case reflect.Float64:
			v, ok := value.(float64)
			if !ok {
				return nil, errs.Errorf("value %v could not be converted into an %s", value, reflect.Float64)
			}
			if v != math.Trunc(v) {
				return nil, errs.Errorf("value %v is not a whole number", value)
			}
			return time.Unix(0, int64(v)), nil
		case reflect.Int64:
			v, ok := value.(int64)
			if !ok {
				return nil, errs.Errorf("value %v could not be converted into an %s", value, reflect.Int64)
			}
			return time.Unix(0, v), nil
		default:
			return nil, errs.Errorf("value %v must be either %s or %s but has an unknown type %s", value, reflect.Int64, reflect.Float64, valueType.Name())
		}
	case KindMarkup:
		if valueType.Kind() != reflect.Map {
			return nil, errs.Errorf("value %v should be %s, but is %s", value, reflect.Map, valueType.Name())
		}
		markupContent := rendering.NewMarkupContentFromMap(value.(map[string]interface{}))
		return markupContent, nil
	case KindCodebase:
		if valueType.Kind() != reflect.Map {
			return nil, errs.Errorf("value %v should be %s, but is %s", value, reflect.Map, valueType.Name())
		}
		cb, err := codebase.NewCodebaseContent(value.(map[string]interface{}))
		if err != nil {
			return nil, err
		}
		return cb, nil
	default:
		return nil, errs.Errorf("unexpected field type: %s", t.GetKind())
	}
}
326812
func (self *Collection) ConvertValue(name string, value interface{}) interface{} {
	if field, ok := self.GetField(name); ok {
		if v, err := field.ConvertValue(value); err == nil {
			return v
		}
	}

	return value
}
967483
func convertValue(v reflect.Value, to reflect.Type) (reflect.Value, error) {
	if v.Type().AssignableTo(to) {
		return v, nil
	}
	switch kind := to.Kind(); {
	case kind == reflect.String:
		s, err := toString(v)
		return reflect.ValueOf(s), err
	case isNumber(kind):
		return convertNumber(v, kind)
	default:
		return reflect.Value{}, errors.Errorf("%s is not assignable to %s", v.Type(), to)
	}
}
798191
func (c *Cell) FormattedValue() (string, error) {
	fullFormat := c.getNumberFormat()
	returnVal, err := fullFormat.FormatValue(c)
	if fullFormat.parseEncounteredError != nil {
		return returnVal, *fullFormat.parseEncounteredError
	}
	return returnVal, err
}
329281
func (meta *Meta) GetFormattedValuer() func(interface{}, *qor.Context) interface{} {
	if meta.FormattedValuer != nil {
		return meta.FormattedValuer
	}
	return meta.Valuer
}
193172
func (cs ContinuousSeries) GetValueFormatters() (x, y ValueFormatter) {
	if cs.XValueFormatter != nil {
		x = cs.XValueFormatter
	} else {
		x = FloatValueFormatter
	}
	if cs.YValueFormatter != nil {
		y = cs.YValueFormatter
	} else {
		y = FloatValueFormatter
	}
	return
}
235244
func (eg *exampleGenerator) generateValidatedPatternExample() interface{} {
	if !eg.hasPatternValidation() {
		return false
	}
	pattern := eg.a.Validation.Pattern
	example, err := regen.Generate(pattern)
	if err != nil {
		return eg.r.faker.Name()
	}
	return example
}
478433
func newValueExpr(value interface{}) ast.ValueExpr {
	if ve, ok := value.(*ValueExpr); ok {
		return ve
	}
	ve := &ValueExpr{}
	ve.SetValue(value)
	types.DefaultTypeForValue(value, &ve.Type)
	ve.projectionOffset = -1
	return ve
}
1205750
func tryToConvertConstantInt(ctx sessionctx.Context, isUnsigned bool, con *Constant) (_ *Constant, isAlwaysFalse bool) {
	if con.GetType().EvalType() == types.ETInt {
		return con, false
	}
	dt, err := con.Eval(chunk.Row{})
	if err != nil {
		return con, false
	}
	sc := ctx.GetSessionVars().StmtCtx
	fieldType := types.NewFieldType(mysql.TypeLonglong)
	if isUnsigned {
		fieldType.Flag |= mysql.UnsignedFlag
	}
	dt, err = dt.ConvertTo(sc, fieldType)
	if err != nil {
		return con, terror.ErrorEqual(err, types.ErrOverflow)
	}
	return &Constant{
		Value:        dt,
		RetType:      fieldType,
		DeferredExpr: con.DeferredExpr,
	}, false
}
1152701
func InvalidValueForTypeError(val, typedObj interface{}) error {
	if verboseErrors {
		return pretty.Errorf("for type (%s), unrecognized value\n%# v", reflect.TypeOf(typedObj), val)
	}

	return pretty.Errorf("for type (%s), unrecognized (%s) value", reflect.TypeOf(typedObj), reflect.TypeOf(val))
}
891657
func NewValueExpr(value interface{}) *ValueExpr {
	if ve, ok := value.(*ValueExpr); ok {
		return ve
	}
	ve := &ValueExpr{}
	ve.SetValue(value)
	types.DefaultTypeForValue(value, &ve.Type)
	return ve
}
849604
func (schema *Schema) arrayOfEnumValuesValue(v interface{}) *[]SchemaEnumValue {
	a := make([]SchemaEnumValue, 0)
	switch v := v.(type) {
	default:
		fmt.Printf("arrayOfEnumValuesValue: unexpected type %T\n", v)
	case []interface{}:
		for _, v2 := range v {
			switch v2 := v2.(type) {
			default:
				fmt.Printf("arrayOfEnumValuesValue: unexpected type %T\n", v2)
			case string:
				a = append(a, SchemaEnumValue{String: &v2})
			case bool:
				a = append(a, SchemaEnumValue{Bool: &v2})
			}
		}
	}
	return &a
}
1339904
func toCaseInsensitiveValue(value interface{}) interface{} {
	switch v := value.(type) {
	case map[interface{}]interface{}:
		value = copyAndInsensitiviseMap(cast.ToStringMap(v))
	case map[string]interface{}:
		value = copyAndInsensitiviseMap(v)
	}

	return value
}
356852
func equalValueType(st1, st2 *ValueType) bool {
	return st1.Type == st2.Type && st1.Unit == st2.Unit
}
430709
func valuePrefix(typeName string) string {
	if v, ok := refValueMap[typeName]; ok {
		return v
	}

	return strings.ToLower(typeName)
}
1177873
func (a *expr) asValue() func(t *Thread) Value {
	var fct func(t *Thread) Value
	switch ty := a.t.lit().(type) {
	case *boolType:
		fct = func(t *Thread) Value {
			b := boolV(a.asBool()(t))
			var val Value = &b
			return val
		}
	case *uintType:
		v := a.asUint()
		switch ty.Bits {
		case 0:
			switch ty.Ptr {
			case true:
				fct = func(t *Thread) Value {
					vv := uintptrV(v(t))
					var val Value = &vv
					return val
				}
			case false:
				fct = func(t *Thread) Value {
					vv := uintV(v(t))
					var val Value = &vv
					return val
				}
			}
		case 8:
			fct = func(t *Thread) Value {
				vv := uint8V(v(t))
				return &vv
			}
		case 16:
			fct = func(t *Thread) Value {
				vv := uint16V(v(t))
				return &vv
			}
		case 32:
			fct = func(t *Thread) Value {
				vv := uint32V(v(t))
				return &vv
			}
		case 64:
			fct = func(t *Thread) Value {
				vv := uint64V(v(t))
				return &vv
			}
		}
	case *intType:
		v := a.asInt()
		switch ty.Bits {
		case 0:
			fct = func(t *Thread) Value {
				vv := intV(v(t))
				return &vv
			}
		case 8:
			fct = func(t *Thread) Value {
				vv := int8V(v(t))
				return &vv
			}
		case 16:
			fct = func(t *Thread) Value {
				vv := int16V(v(t))
				return &vv
			}
		case 32:
			fct = func(t *Thread) Value {
				vv := int32V(v(t))
				return &vv
			}
		case 64:
			fct = func(t *Thread) Value {
				vv := int64V(v(t))
				return &vv
			}
		}
	case *idealIntType:
		fct = func(t *Thread) Value {
			v := a.asIdealInt()()
			vv := idealIntV{v}
			return &vv
		}
	case *floatType:
		v := a.asFloat()
		switch ty.Bits {
		case 32:
			fct = func(t *Thread) Value {
				vv := float32V(v(t))
				return &vv
			}
		case 64:
			fct = func(t *Thread) Value {
				vv := float64V(v(t))
				return &vv
			}
		}
	case *idealFloatType:
		fct = func(t *Thread) Value {
			v := a.asIdealFloat()()
			vv := idealFloatV{v}
			return &vv
		}
	case *stringType:
		fct = func(t *Thread) Value {
			v := a.asString()
			vv := stringV(v(t))
			return &vv
		}
	case *ArrayType:
		fct = func(t *Thread) Value {
			v := a.asArray()
			vv := v(t).Get(t)
			return vv
		}
	case *StructType:
		fct = func(t *Thread) Value {
			v := a.asStruct()
			vv := v(t).Get(t)
			return vv
		}
	case *PtrType:
		fct = func(t *Thread) Value {
			return a.asPtr()(t)
		}
		//case *FuncType:
		//case *InterfaceType:
		//case *SliceType:
		//case *MapType:
		//case *ChanType:
		//case *NamedType:
		//case *MultiType:
	case *packageType:
		fct = func(t *Thread) Value {
			return a.asPackage()(t)
		}
	default:
		a.diag("unhandled type: %v", ty.String())
	}
	return fct
}