private BoundExpression BindAggregateInvocationExpression(FunctionInvocationExpressionSyntax node, AggregateSymbol aggregate) { var argument = node.ArgumentList.Arguments[0]; var argumentBinder = CreateAggregateArgumentBinder(); var boundArgument = argumentBinder.BindExpression(argument); var boundAggregatable = BindAggregatable(node.Span, aggregate, boundArgument); var boundAggregate = new BoundAggregateExpression(aggregate, boundAggregatable, boundArgument); return(BindAggregate(node, boundAggregate)); }
private BoundExpression BindAggregate(ExpressionSyntax aggregate, BoundAggregateExpression boundAggregate) { var affectedQueryScopes = aggregate.DescendantNodes() .Select(GetBoundNode <BoundColumnExpression>) .Where(n => n != null) .Select(b => b.Symbol) .OfType <TableColumnInstanceSymbol>() .Select(c => FindQueryState(c.TableInstance)) .Distinct() .Take(2) .ToImmutableArray(); if (affectedQueryScopes.Length > 1) { Diagnostics.ReportAggregateContainsColumnsFromDifferentQueries(aggregate.Span); } var queryState = affectedQueryScopes.DefaultIfEmpty(QueryState) .First(); if (queryState == null) { Diagnostics.ReportAggregateInvalidInCurrentContext(aggregate.Span); } else { var existingSlot = FindComputedValue(aggregate, queryState.ComputedAggregates); if (existingSlot == null) { var slot = ValueSlotFactory.CreateTemporary(boundAggregate.Type); queryState.ComputedAggregates.Add(new BoundComputedValueWithSyntax(aggregate, boundAggregate, slot)); } } var aggregateBelongsToCurrentQuery = QueryState == queryState; if (InOnClause && aggregateBelongsToCurrentQuery) { Diagnostics.ReportAggregateInOn(aggregate.Span); } else if (InWhereClause && aggregateBelongsToCurrentQuery) { Diagnostics.ReportAggregateInWhere(aggregate.Span); } else if (InGroupByClause && aggregateBelongsToCurrentQuery) { Diagnostics.ReportAggregateInGroupBy(aggregate.Span); } else if (InAggregateArgument) { Diagnostics.ReportAggregateInAggregateArgument(aggregate.Span); } return(boundAggregate); }
private BoundExpression BindCountAllExpression(CountAllExpressionSyntax node) { var aggregates = LookupAggregate(node.Name).ToImmutableArray(); if (aggregates.Length == 0) { Diagnostics.ReportUndeclaredAggregate(node.Name); return(new BoundErrorExpression()); } if (aggregates.Length > 1) { Diagnostics.ReportAmbiguousAggregate(node.Name, aggregates); } var aggregate = aggregates[0]; var boundArgument = new BoundLiteralExpression(0); var boundAggregatable = BindAggregatable(node.Span, aggregate, boundArgument); var boundAggregate = new BoundAggregateExpression(aggregate, boundAggregatable, boundArgument); return(BindAggregate(node, boundAggregate)); }
protected virtual BoundExpression RewriteAggregateExpression(BoundAggregateExpression node) { return(node.Update(node.Aggregate, node.Aggregatable, RewriteExpression(node.Argument))); }
protected virtual void VisitAggregateExpression(BoundAggregateExpression node) { VisitExpression(node.Argument); }