// Expressions
// VisitExpression implements corresponding Visitor interface method
351060
func (v *printVisitor) VisitExpression(node *Expression) interface{} {
	if v.inBlock {
		v.indent()
	}

	// path
	node.Path.Accept(v)

	// params
	v.str(" [")
	for i, n := range node.Params {
		if i > 0 {
			v.str(", ")
		}
		n.Accept(v)
	}
	v.str("]")

	// hash
	if node.Hash != nil {
		v.str(" ")
		node.Hash.Accept(v)
	}

	if v.inBlock {
		v.nl()
	}

	return nil
}
633833
func (v *kindSchemaVisitor) VisitKind(result *proto.Kind) {
	v.Result = result
	v.Kind = "kind"
}
1114511
func (s *MetricDataQuery) SetExpression(v string) *MetricDataQuery {
	s.Expression = &v
	return s
}
1105923
func (f *regularFieldsPrinter) VisitArray(a *proto.Array) {
	a.SubType.Accept(f)
}
121507
func (visitor *findEntityVisitor) VisitPrefixedExp(exp *sql.PrefixedExp) {
	if exp.Prefix == "FROM" {
		if len(exp.Binding) == 1 && r.Indirect(r.ValueOf(exp.Binding[0])).Kind() == r.Struct {
			visitor.entity = exp.Binding[0]
		}
	} else if exp.AfterPrefix != nil {
		for _, exp := range exp.AfterPrefix {
			exp.Accept(visitor)
		}
	}
}
738405
func (env *Zlisp) EvalExpressions(xs []Sexp) (Sexp, error) {
	//P("inside EvalExpressions with env %p: xs[0] = %s", env, xs[0].SexpString(0))
	err := env.LoadExpressions(xs)
	if err != nil {
		return SexpNull, err
	}
	return env.Run()
}
1185293
func (a *aggregationEliminateChecker) rewriteExpr(ctx sessionctx.Context, aggFunc *aggregation.AggFuncDesc) expression.Expression {
	switch aggFunc.Name {
	case ast.AggFuncCount:
		if aggFunc.Mode == aggregation.FinalMode {
			return a.wrapCastFunction(ctx, aggFunc.Args[0], aggFunc.RetTp)
		}
		return a.rewriteCount(ctx, aggFunc.Args, aggFunc.RetTp)
	case ast.AggFuncSum, ast.AggFuncAvg, ast.AggFuncFirstRow, ast.AggFuncMax, ast.AggFuncMin, ast.AggFuncGroupConcat:
		return a.wrapCastFunction(ctx, aggFunc.Args[0], aggFunc.RetTp)
	case ast.AggFuncBitAnd, ast.AggFuncBitOr, ast.AggFuncBitXor:
		return a.rewriteBitFunc(ctx, aggFunc.Name, aggFunc.Args[0], aggFunc.RetTp)
	default:
		panic("Unsupported function")
	}
}
456527
func (s *TaskDefinitionPlacementConstraint) SetExpression(v string) *TaskDefinitionPlacementConstraint {
	s.Expression = &v
	return s
}
268449
func (v *printVisitor) VisitMustache(node *MustacheStatement) interface{} {
	v.indent()
	v.str("{{ ")

	node.Expression.Accept(v)

	v.str(" }}")
	v.nl()

	return nil
}
1007525
func (s *SelectObjectContentInput) SetExpression(v string) *SelectObjectContentInput {
	s.Expression = &v
	return s
}
324652
func compileExpression(s string) (expr Expression, err error) {
	tokens := tokenize(s)
	if contains(tokens, "?") {
		return ternaryToken.compile(tokens)
	}
	return constToken.compile(tokens)
}
1351282
func NewExpression(pos int, line int) *Expression {
	return &Expression{
		NodeType: NodeExpression,
		Loc:      Loc{pos, line},
	}
}
477795
func (s *Schedule) SetExpression(v string) *Schedule {
	s.Expression = &v
	return s
}
467228
func (api *API) ValidateFilterExpression(expression string) error {
	uri := fmt.Sprintf("/filters/validate-expr")
	expressionPayload := FilterValidateExpression{Expression: expression}

	_, err := api.makeRequest("POST", uri, expressionPayload)
	if err != nil {
		var filterValidationResponse FilterValidateExpressionResponse

		jsonErr := json.Unmarshal([]byte(err.Error()), &filterValidationResponse)
		if jsonErr != nil {
			return errors.Wrap(jsonErr, errUnmarshalError)
		}

		if filterValidationResponse.Success != true {
			// Unsure why but the API returns `errors` as an array but it only
			// ever shows the issue with one problem at a time ¯\_(ツ)_/¯
			return errors.Errorf(filterValidationResponse.Errors[0].Message)
		}
	}

	return nil
}
760646
func (v *mapSchemaVisitor) VisitMap(result *proto.Map) {
	v.Result = result
	v.Kind = "map"
}
235275
func (v *arraySchemaVisitor) VisitReference(reference proto.Reference) {
	reference.SubSchema().Accept(v)
	if v.Err == nil {
		v.Err = copyExtensions(reference.GetPath().String(), reference.GetExtensions(), v.Result.Extensions)
	}
}
786482
func GetParamExpression(ctx sessionctx.Context, v *driver.ParamMarkerExpr) (Expression, error) {
	useCache := ctx.GetSessionVars().StmtCtx.UseCache
	tp := types.NewFieldType(mysql.TypeUnspecified)
	types.DefaultParamTypeForValue(v.GetValue(), tp)
	value := &Constant{Value: v.Datum, RetType: tp}
	if useCache {
		f, err := NewFunctionBase(ctx, ast.GetParam, &v.Type,
			DatumToConstant(types.NewIntDatum(int64(v.Order)), mysql.TypeLonglong))
		if err != nil {
			return nil, err
		}
		f.GetType().Tp = v.Type.Tp
		value.DeferredExpr = f
	}
	return value, nil
}