public void VisitFromClause(FromClauseSyntax node) { if (node == null) throw new ArgumentNullException("node"); if ( !_writer.Configuration.LineBreaksAndWrapping.Other.PlaceLinqExpressionOnSingleLine && node.Parent is QueryBodySyntax ) _writer.Break(true); _writer.WriteKeyword(PrinterKeyword.From); _writer.WriteSpace(); if (node.Type != null) { node.Type.Accept(this); _writer.WriteSpace(); } _writer.WriteIdentifier(node.Identifier); _writer.WriteSpace(); _writer.WriteKeyword(PrinterKeyword.In); _writer.WriteSpace(); node.Expression.Accept(this); }
public void VisitFromClause(FromClauseSyntax node) { if (node == null) { throw new ArgumentNullException("node"); } if ( !_writer.Configuration.LineBreaksAndWrapping.Other.PlaceLinqExpressionOnSingleLine && node.Parent is QueryBodySyntax ) { _writer.Break(true); } _writer.WriteKeyword(PrinterKeyword.From); _writer.WriteSpace(); if (node.Type != null) { node.Type.Accept(this); _writer.WriteSpace(); } _writer.WriteIdentifier(node.Identifier); _writer.WriteSpace(); _writer.WriteKeyword(PrinterKeyword.In); _writer.WriteSpace(); node.Expression.Accept(this); }
public override void VisitFromClause(FromClauseSyntax node) { IncrementNodeCount(2); // direct equivalent of SQL `FROM` clause AddOperator("from"); base.VisitFromClause(node); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { if (CollectionName != null) { return(node); } var docsExpression = node.Expression as MemberAccessExpressionSyntax; if (docsExpression == null) { var invocationExpression = node.Expression as InvocationExpressionSyntax; if (invocationExpression != null) { var methodSyntax = MethodSyntax; var newInvocationExpression = (InvocationExpressionSyntax)methodSyntax.VisitInvocationExpression(invocationExpression); CollectionName = methodSyntax.CollectionName; return(node.WithExpression(newInvocationExpression)); } return(node); } var docsIdentifier = docsExpression.Expression as IdentifierNameSyntax; if (string.Equals(docsIdentifier?.Identifier.Text, "docs", StringComparison.OrdinalIgnoreCase) == false) { return(node); } CollectionName = docsExpression.Name.Identifier.Text; return(node.WithExpression(docsExpression.Expression)); }
private ExpressionSyntax GetQuerySource(FromClauseSyntax fromClause) { var node = fromClause.Expression; ExpressionSyntax source = RemoveParenthesized(node); var memberAccess = node.DescendantNodesAndSelf(). OfType <InvocationExpressionSyntax>(). FirstOrDefault()?.Expression as MemberAccessExpressionSyntax; if (memberAccess == null) { return(node); } List <ExpressionSyntax> invocations = new List <ExpressionSyntax> { node }; do { invocations.Add(memberAccess.Expression); memberAccess = (memberAccess.Expression as InvocationExpressionSyntax)?.Expression as MemberAccessExpressionSyntax; } while (memberAccess != null); // Add here your own logic to get the right collection source return(source); }
public override void VisitFromClause(FromClauseSyntax node) { node.Type?.Accept(this); node.Expression?.Accept(this); base.VisitFromClause(node); }
private static bool ReportQueryInferenceFailedSelectMany(FromClauseSyntax fromClause, string methodName, BoundExpression receiver, AnalyzedArguments arguments, ImmutableArray <Symbol> symbols, DiagnosticBag diagnostics) { Debug.Assert(methodName == "SelectMany"); // Estimate the return type of Select's lambda argument BoundExpression arg = arguments.Argument(arguments.IsExtensionMethodInvocation ? 1 : 0); TypeSymbol type = null; if (arg.Kind == BoundKind.UnboundLambda) { var unbound = (UnboundLambda)arg; foreach (var t in unbound.Data.InferredReturnTypes()) { if (!t.IsErrorType()) { type = t; break; } } } if ((object)type == null || type.IsErrorType()) { return(false); } TypeSymbol receiverType = receiver != null ? receiver.Type : null; diagnostics.Add(new DiagnosticInfoWithSymbols( ErrorCode.ERR_QueryTypeInferenceFailedSelectMany, new object[] { type, receiverType, methodName }, symbols), fromClause.Expression.Location); return(true); }
public override Evaluation VisitFromClause(FromClauseSyntax node) { node.Type?.Accept <Evaluation>(this); node.Expression?.Accept <Evaluation>(this); return(base.VisitFromClause(node)); }
private void AddIndentBlockOperationsForFromClause(List<IndentBlockOperation> list, FromClauseSyntax fromClause) { // Only add the indent block operation if the 'in' keyword is present. Otherwise, we'll get the following: // // from x // in args // // Rather than: // // from x // in args // // However, we want to get the following result if the 'in' keyword is present to allow nested queries // to be formatted properly. // // from x in // args if (fromClause.InKeyword.IsMissing) { return; } var baseToken = fromClause.FromKeyword; var startToken = fromClause.Expression.GetFirstToken(includeZeroWidth: true); var endToken = fromClause.Expression.GetLastToken(includeZeroWidth: true); AddIndentBlockOperation(list, baseToken, startToken, endToken); }
public override void VisitFromClause(FromClauseSyntax node) { if (_root != default(SyntaxToken)) { base.VisitFromClause(node); } // else skip the from clause }
public new void AddChildren() { base.AddChildren(); Kind = Node.Kind(); _fromClause = ((QueryExpressionSyntax)Node).FromClause; _fromClauseIsChanged = false; _body = ((QueryExpressionSyntax)Node).Body; _bodyIsChanged = false; }
public override void VisitFromClause(FromClauseSyntax node) { // Visit Expression only for a "from" clause that starts a query, it (the expression) doesn't become a body of a lambda. var parent = node.Parent; if (parent == null || (parent.Kind == SyntaxKind.QueryExpression && ((QueryExpressionSyntax)parent).FromClause == node)) { Visit(node.Expression); } }
public static Doc Print(FromClauseSyntax node) { return(Doc.Concat( Token.PrintWithSuffix(node.FromKeyword, " "), node.Type != null ? Doc.Concat(Node.Print(node.Type), " ") : Doc.Null, Token.PrintWithSuffix(node.Identifier, " "), Token.PrintWithSuffix(node.InKeyword, " "), Node.Print(node.Expression) )); }
public override void VisitFromClause(FromClauseSyntax node) { var membersVisitor = new GetMembersVisitor(this); membersVisitor.Visit(node.Expression); _variables.Add(node.Identifier.ValueText, membersVisitor._properties); _fromVariables.Add(node.Identifier.ValueText, _linqIndex); AddProperties(membersVisitor._properties); _proceed = true; }
/// <summary> /// This is a clone of the Dev10 logic for reporting query errors. /// </summary> internal void ReportQueryLookupFailed( CSharpSyntaxNode queryClause, BoundExpression instanceArgument, string name, ImmutableArray <Symbol> symbols, DiagnosticBag diagnostics) { FromClauseSyntax fromClause = null; for (CSharpSyntaxNode node = queryClause; ; node = node.Parent) { var e = node as QueryExpressionSyntax; if (e != null) { fromClause = e.FromClause; break; } } HashSet <DiagnosticInfo> useSiteDiagnostics = null; if (instanceArgument.Type.IsDynamic()) { // CS1979: Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed diagnostics.Add( new DiagnosticInfoWithSymbols(ErrorCode.ERR_BadDynamicQuery, SpecializedCollections.EmptyObjects, symbols), new SourceLocation(queryClause)); } else if (ImplementsStandardQueryInterface(instanceArgument.Type, name, ref useSiteDiagnostics)) { // Could not find an implementation of the query pattern for source type '{0}'. '{1}' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? diagnostics.Add(new DiagnosticInfoWithSymbols( ErrorCode.ERR_QueryNoProviderStandard, new object[] { instanceArgument.Type, name }, symbols), new SourceLocation(fromClause != null ? fromClause.Expression : queryClause)); } else if (fromClause != null && fromClause.Type == null && HasCastToQueryProvider(instanceArgument.Type, ref useSiteDiagnostics)) { // Could not find an implementation of the query pattern for source type '{0}'. '{1}' not found. Consider explicitly specifying the type of the range variable '{2}'. diagnostics.Add(new DiagnosticInfoWithSymbols( ErrorCode.ERR_QueryNoProviderCastable, new object[] { instanceArgument.Type, name, fromClause.Identifier.ValueText }, symbols), new SourceLocation(fromClause.Expression)); } else { // Could not find an implementation of the query pattern for source type '{0}'. '{1}' not found. diagnostics.Add(new DiagnosticInfoWithSymbols( ErrorCode.ERR_QueryNoProvider, new object[] { instanceArgument.Type, name }, symbols), new SourceLocation(fromClause != null ? fromClause.Expression : queryClause)); } diagnostics.Add(queryClause, useSiteDiagnostics); }
private VariableState VisitFromClause(FromClauseSyntax fromClauseSyntax, ExecutionState state) { var finalState = new VariableState(fromClauseSyntax, VariableTaint.Unset); foreach (var variable in fromClauseSyntax.Variables) { finalState.MergeTaint(VisitNode(variable, state).Taint); } return(finalState); }
public override LuaSyntaxNode VisitFromClause(FromClauseSyntax node) { var expression = (LuaExpressionSyntax)node.Expression.Accept(this); if (node.Type != null) { var typeName = (LuaExpressionSyntax)node.Type.Accept(this); expression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.LinqCast, expression, typeName); } return(expression); }
private Doc PrintFromClauseSyntax(FromClauseSyntax node) { return(Concat( this.PrintSyntaxToken(node.FromKeyword, " "), node.Type != null ? Concat(this.Print(node.Type), " ") : Doc.Null, this.PrintSyntaxToken(node.Identifier, " "), this.PrintSyntaxToken(node.InKeyword, " "), this.Print(node.Expression) )); }
void ReduceFrom(FromClauseSyntax from, QueryTranslationState state, DiagnosticBag diagnostics) { var x1 = state.rangeVariable; TypeSymbol castType = from.Type == null ? null : BindTypeArgument(from.Type, diagnostics); BoundExpression lambda1 = MakeQueryUnboundLambda(state.RangeVariableMap(), x1, from.Expression, from.Type, castType); var x2 = state.AddRangeVariable(this, from.Identifier, diagnostics); if (state.clauses.IsEmpty() && state.selectOrGroup.Kind == SyntaxKind.SelectClause) { // A query expression with a second from clause followed by a select clause // from x1 in e1 // from x2 in e2 // select v // is translated into // ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => v ) var select = state.selectOrGroup as SelectClauseSyntax; BoundExpression lambda2 = MakeQueryUnboundLambda(state.RangeVariableMap(), Args(x1, x2), select.Expression); var invocation = MakeQueryInvocation(from, state.fromExpression, "SelectMany", Args(lambda1, lambda2), diagnostics); BoundExpression castInvocation = (object)castType != null?ExtractCastInvocation(invocation) : null; var arguments = invocation.Arguments.ToArray(); // Adjust the second-to-last parameter to be a query clause. (if it was an extension method, an extra parameter was added) arguments[arguments.Length - 2] = MakeQueryClause(from, arguments[arguments.Length - 2], x2, invocation, castInvocation); invocation = invocation.Update(invocation.ReceiverOpt, invocation.Method, Args(arguments)); state.Clear(); state.fromExpression = MakeQueryClause(from, invocation, definedSymbol: x2, queryInvocation: invocation); state.fromExpression = MakeQueryClause(select, state.fromExpression); } else { // A query expression with a second from clause followed by something other than a select clause: // from x1 in e1 // from x2 in e2 // ... // is translated into // from * in ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => new { x1 , x2 } ) // ... // We use a slightly different translation strategy. We produce // from * in ( e ) . SelectMany ( x1 => e2, ( x1 , x2 ) => new Pair<X1,X2>(x1, x2) ) // Where X1 is the type of x1, and X2 is the type of x2. // Subsequently, x1 (or members of x1, if it is a transparent identifier) // are accessed as TRID.Item1 (or members of that), and x2 is accessed // as TRID.Item2, where TRID is the compiler-generated identifier used // to represent the transparent identifier in the result. var lambda2 = MakePairLambda(from, state, x1, x2); var invocation = MakeQueryInvocation(from, state.fromExpression, "SelectMany", Args(lambda1, lambda2), diagnostics); BoundExpression castInvocation = (object)castType != null?ExtractCastInvocation(invocation) : null; state.fromExpression = MakeQueryClause(from, invocation, x2, invocation, castInvocation); } }
public override void VisitFromClause(FromClauseSyntax node) { var paramInfo = m_LinqParamInfoStack.Peek(); var paramNames = paramInfo.ParamNames; CodeBuilder.AppendFormat("from(function({0}){{ return(", string.Join(", ", paramNames.ToArray())); var opd = m_Model.GetOperation(node.Expression) as IConversionExpression; OutputExpressionSyntax(node.Expression, opd); CodeBuilder.Append("); })"); paramNames.Add(node.Identifier.Text); }
public override void VisitFromClause(FromClauseSyntax node) { if (!PreVisit(node)) { return; } node.Type?.Accept(this); node.Expression?.Accept(this); base.VisitFromClause(node); PostVisit(node); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { if (CollectionNames != null) { return(node); } if (node.Expression is MemberAccessExpressionSyntax docsExpression) { var docsIdentifier = docsExpression.Expression as IdentifierNameSyntax; if (string.Equals(docsIdentifier?.Identifier.Text, "docs", StringComparison.OrdinalIgnoreCase) == false) { return(node); } CollectionNames = new[] { docsExpression.Name.Identifier.Text }; return(node.WithExpression(docsExpression.Expression)); } if (node.Expression is ElementAccessExpressionSyntax indexer) { var list = new List <string>(); foreach (ArgumentSyntax item in indexer.ArgumentList.Arguments) { if (item.Expression is LiteralExpressionSyntax les) { list.Add(les.Token.ValueText); } } CollectionNames = list.ToArray(); return(node.WithExpression(indexer.Expression)); } var invocationExpression = node.Expression as InvocationExpressionSyntax; if (invocationExpression != null) { var methodSyntax = MethodSyntax; var newExpression = (ExpressionSyntax)methodSyntax.VisitInvocationExpression(invocationExpression); CollectionNames = methodSyntax.CollectionNames; return(node.WithExpression(newExpression)); } return(node); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { var fromExpression = node.Expression.ToString(); if (fromExpression == "docs" || fromExpression == "results") // from order in docs.Orders or from result in results { return(base.VisitFromClause(node)); } // 2nd from clause var toCast = node.Expression; // order.Lines var castExpression = (CastExpressionSyntax)SyntaxFactory.ParseExpression($"(IEnumerable<dynamic>)({toCast})"); return(base.VisitFromClause(node.ReplaceNode(toCast, castExpression))); }
private VariableState VisitFromClause(FromClauseSyntax fromClauseSyntax, ExecutionState state) { var fromClauseState = VisitExpression(fromClauseSyntax.Expression, state); var fromSymbol = SyntaxNodeHelper.GetSymbol(fromClauseSyntax.Expression, state.AnalysisContext.SemanticModel); if (fromSymbol != null) { switch (fromSymbol) { case IPropertySymbol propertyFromSymbol when propertyFromSymbol.Type.IsTaintType(ProjectConfiguration.Behavior): case IFieldSymbol fieldFromSymbol when fieldFromSymbol.Type.IsTaintType(ProjectConfiguration.Behavior): return(new VariableState(fromClauseSyntax, VariableTaint.Tainted)); } } return(fromClauseState); }
private void VisitQueryInternal(FromClauseSyntax fromClause, QueryBodySyntax body) { // This is somewhat ornery: we need to collect all the locals being introduced // since they're all in scope throught all parts of the query. var tokens = new List <SyntaxToken>(); if (fromClause != null) { tokens.Add(fromClause.Identifier); } foreach (var clause in body.Clauses) { switch (clause.CSharpKind()) { case SyntaxKind.FromClause: tokens.Add(((FromClauseSyntax)clause).Identifier); break; case SyntaxKind.LetClause: tokens.Add(((LetClauseSyntax)clause).Identifier); break; } } tracker.AddIdentifiers(tokens); // We have to be careful that the query continuation of this query isn't visited // as everything there is actually an independent scope. if (fromClause != null) { Visit(fromClause); } foreach (var child in body.ChildNodes().Where(c => c.CSharpKind() != SyntaxKind.QueryContinuation)) { Visit(child); } tracker.RemoveIdentifiers(tokens); // And now we must visit the continuation Visit(body.Continuation); }
private InvocationExpressionSyntax CreateSelectMany(FromClauseSyntax currentFrom) { var expression = (ExpressionSyntax)Visit(currentFrom.Expression); List <SyntaxToken> lambdaParameters = new List <SyntaxToken> { GetLambdaParameterToken(expression), currentFrom.Identifier }; var firstLambda = BuildSimpleLambdaExpression(expression); var secondLambda = BuildLambdaExpression(lambdaParameters, BuildAnonymousObject(lambdaParameters)); var selectMany = BuildFluentInvocation("SelectMany", firstLambda, secondLambda); SetAnonymousState(currentFrom.Identifier); return(selectMany); }
private LuaExpressionSyntax BuildFromClause(LuaExpressionSyntax collection, FromClauseSyntax node, ref IQueryRangeVariable rangeVariable, out bool isOver) { var collectionSelector = new LuaFunctionExpressionSyntax(); PushFunction(collectionSelector); collectionSelector.AddParameter(rangeVariable.Name); var expression = (LuaExpressionSyntax)node.Expression.Accept(this); collectionSelector.AddStatement(new LuaReturnStatementSyntax(expression)); PopFunction(); var rangeVariable2 = AddRangeIdentifier(node.Identifier); var resultSelector = new LuaFunctionExpressionSyntax(); PushFunction(resultSelector); resultSelector.AddParameter(rangeVariable.Name); resultSelector.AddParameter(rangeVariable2.Name); LuaExpressionSyntax resultSelectorExpression; LuaExpressionSyntax resultSelectorType; var parentNode = (QueryBodySyntax)node.Parent; if (IsSpecialQueryNode(parentNode)) { var selectClause = (SelectClauseSyntax)parentNode.SelectOrGroup; resultSelectorExpression = (LuaExpressionSyntax)selectClause.Expression.Accept(this); var type = semanticModel_.GetTypeInfo(selectClause.Expression).Type; resultSelectorType = GetTypeName(type); isOver = true; } else { resultSelectorExpression = CreateQueryAnonymousType(rangeVariable.Name, rangeVariable.Name, rangeVariable2.Name, rangeVariable2.Name); resultSelectorType = LuaIdentifierNameSyntax.AnonymousType; rangeVariable = new QueryPackVariable(rangeVariable, rangeVariable2); isOver = false; } resultSelector.AddStatement(new LuaReturnStatementSyntax(resultSelectorExpression)); PopFunction(); return(new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.LinqSelectMany, collection, collectionSelector, resultSelector, resultSelectorType)); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { if (_visited) { return(base.VisitFromClause(node)); } _visited = true; var resultsIdentifer = node.Expression as IdentifierNameSyntax; if (resultsIdentifer == null) { return(node); } if (ResultsVariable.Equals(resultsIdentifer.Identifier.Text, StringComparison.Ordinal)) { return(base.VisitFromClause(node)); } return(node.ReplaceNode(resultsIdentifer, SyntaxFactory.ParseExpression(ResultsVariable))); }
//public override void VisitForStatement(ForStatementSyntax node) //{ // base.VisitForStatement(node); //} public override void VisitFromClause(FromClauseSyntax node) { VisitType(node.Type); //base.VisitFromClause(node); }
public override void VisitFromClause(FromClauseSyntax node) { base.VisitFromClause(node); Add(node.Identifier); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitFromClause(FromClauseSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitFromClause(node); }
public override void VisitFromClause(FromClauseSyntax node) { base.VisitFromClause(node); Add(node.Identifier); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { if (Collections != null) { return(node); } var nodeAsString = node.Expression.ToString(); if (nodeAsString.StartsWith(_nodePrefix) == false) { if (nodeAsString.StartsWith(_nodePrefix, StringComparison.OrdinalIgnoreCase) == false) { return(node); } nodeAsString = nodeAsString.Substring(_nodePrefix.Length); nodeAsString = _nodePrefix + nodeAsString; var newExpression = SyntaxFactory.ParseExpression(nodeAsString); // normalizing timeSeries which could be lowercased node = node.WithExpression(newExpression); } if (node.Expression is IdentifierNameSyntax) // from ts in timeSeries { return(node); } if (node.Expression is MemberAccessExpressionSyntax timeSeriesExpression) { if (timeSeriesExpression.Expression is MemberAccessExpressionSyntax collectionExpression) // from ts in timeSeries.Companies.HeartRate { var timeSeriesIdentifier = collectionExpression.Expression as IdentifierNameSyntax; if (string.Equals(timeSeriesIdentifier?.Identifier.Text, _nodePrefix, StringComparison.OrdinalIgnoreCase) == false) { return(node); } Collections = new HashSet <Collection> { { new Collection(collectionExpression.Name.Identifier.Text, timeSeriesExpression.Name.Identifier.Text) } }; return(node.WithExpression(collectionExpression.Expression)); } else if (timeSeriesExpression.Expression is IdentifierNameSyntax identifierNameSyntax) // from ts in timeSeries.Companies { Collections = new HashSet <Collection> { { new Collection(timeSeriesExpression.Name.Identifier.Text, null) } }; return(node.WithExpression(identifierNameSyntax)); } else if (timeSeriesExpression.Expression is ElementAccessExpressionSyntax collectionNameIndexer) // from ts in timeSeries[@""].HeartRate { Collections = new HashSet <Collection> { { new Collection(ExtractName(collectionNameIndexer, "collection"), ExtractName(timeSeriesExpression)) } }; return(node.WithExpression(collectionNameIndexer.Expression)); } } else if (node.Expression is ElementAccessExpressionSyntax indexer) { if (indexer.Expression is ElementAccessExpressionSyntax collectionNameIndexer) // from ts in timeSeries[@""][@""] { Collections = new HashSet <Collection> { { new Collection(ExtractName(collectionNameIndexer, "collection"), ExtractName(indexer, _itemName)) } }; return(node.WithExpression(collectionNameIndexer.Expression)); } else if (indexer.Expression is MemberAccessExpressionSyntax collectionName) // from ts in timeSeries.Companies[@""] { Collections = new HashSet <Collection> { { new Collection(ExtractName(collectionName), ExtractName(indexer, _itemName)) } }; return(node.WithExpression(collectionName.Expression)); } else if (indexer.Expression is IdentifierNameSyntax) // from ts in timeSeries[@""] { Collections = new HashSet <Collection> { { new Collection(ExtractName(indexer, "collection"), null) } }; return(node.WithExpression(indexer.Expression)); } } else if (node.Expression is InvocationExpressionSyntax invocation) // from ts in timeSeries.Companies.HeartRate.Where(x => true) { var methodSyntax = new MethodSyntaxRewriter(_nodePrefix, _itemName); var newExpression = (ExpressionSyntax)methodSyntax.VisitInvocationExpression(invocation); Collections = methodSyntax.Collections; return(node.WithExpression(newExpression)); } throw new NotImplementedException("Not supported syntax exception. This might be a bug."); }
public override void VisitFromClause(FromClauseSyntax node) { var saveCurrentScope = currentScope; // Visit Expression in the current scope only for a "from" clause that starts a query, it (the expression) doesn't become a body of a lambda. var parent = node.Parent; if (parent != null && (parent.Kind != SyntaxKind.QueryExpression || ((QueryExpressionSyntax)parent).FromClause != node)) { currentScope = new DeclarationScope(currentScope); } Visit(node.Expression); currentScope = saveCurrentScope; }
private static bool ReportQueryInferenceFailedSelectMany(FromClauseSyntax fromClause, string methodName, BoundExpression receiver, AnalyzedArguments arguments, ImmutableArray<Symbol> symbols, DiagnosticBag diagnostics) { Debug.Assert(methodName == "SelectMany"); // Estimate the return type of Select's lambda argument BoundExpression arg = arguments.Argument(arguments.IsExtensionMethodInvocation ? 1 : 0); TypeSymbol type = null; if (arg.Kind == BoundKind.UnboundLambda) { var unbound = (UnboundLambda)arg; foreach (var t in unbound.Data.InferredReturnTypes()) { if (!t.IsErrorType()) { type = t; break; } } } if ((object)type == null || type.IsErrorType()) { return false; } TypeSymbol receiverType = receiver?.Type; diagnostics.Add(new DiagnosticInfoWithSymbols( ErrorCode.ERR_QueryTypeInferenceFailedSelectMany, new object[] { type, receiverType, methodName }, symbols), fromClause.Expression.Location); return true; }
private void VisitQueryInternal(FromClauseSyntax fromClause, QueryBodySyntax body) { // This is somewhat ornery: we need to collect all the locals being introduced // since they're all in scope throught all parts of the query. var tokens = new List<SyntaxToken>(); if (fromClause != null) { tokens.Add(fromClause.Identifier); } foreach (var clause in body.Clauses) { switch (clause.CSharpKind()) { case SyntaxKind.FromClause: tokens.Add(((FromClauseSyntax)clause).Identifier); break; case SyntaxKind.LetClause: tokens.Add(((LetClauseSyntax)clause).Identifier); break; } } tracker.AddIdentifiers(tokens); // We have to be careful that the query continuation of this query isn't visited // as everything there is actually an independent scope. if (fromClause != null) { Visit(fromClause); } foreach (var child in body.ChildNodes().Where(c => c.CSharpKind() != SyntaxKind.QueryContinuation)) { Visit(child); } tracker.RemoveIdentifiers(tokens); // And now we must visit the continuation Visit(body.Continuation); }
public override void VisitFromClause(FromClauseSyntax node) { var membersVisitor = new GetMembersVisitor(this); membersVisitor.Visit(node.Expression); _variables.Add(node.Identifier.ValueText, membersVisitor._properties); _fromVariables.Add(node.Identifier.ValueText, _linqIndex); AddProperties(membersVisitor._properties); _proceed = true; }
private void ReduceFrom(FromClauseSyntax from, QueryTranslationState state, DiagnosticBag diagnostics) { var x1 = state.rangeVariable; BoundExpression collectionSelectorLambda; if (from.Type == null) { collectionSelectorLambda = MakeQueryUnboundLambda(state.RangeVariableMap(), x1, from.Expression); } else { collectionSelectorLambda = MakeQueryUnboundLambdaWithCast(state.RangeVariableMap(), x1, from.Expression, from.Type, BindTypeArgument(from.Type, diagnostics)); } var x2 = state.AddRangeVariable(this, from.Identifier, diagnostics); if (state.clauses.IsEmpty() && state.selectOrGroup.IsKind(SyntaxKind.SelectClause)) { var select = (SelectClauseSyntax)state.selectOrGroup; // A query expression with a second from clause followed by a select clause // from x1 in e1 // from x2 in e2 // select v // is translated into // ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => v ) var resultSelectorLambda = MakeQueryUnboundLambda(state.RangeVariableMap(), ImmutableArray.Create(x1, x2), select.Expression); var invocation = MakeQueryInvocation( from, state.fromExpression, "SelectMany", ImmutableArray.Create(collectionSelectorLambda, resultSelectorLambda), diagnostics); // Adjust the second-to-last parameter to be a query clause (if it was an extension method, an extra parameter was added) BoundExpression castInvocation = (from.Type != null) ? ExtractCastInvocation(invocation) : null; var arguments = invocation.Arguments; invocation = invocation.Update( invocation.ReceiverOpt, invocation.Method, arguments.SetItem(arguments.Length - 2, MakeQueryClause(from, arguments[arguments.Length - 2], x2, invocation, castInvocation))); state.Clear(); state.fromExpression = MakeQueryClause(from, invocation, definedSymbol: x2, queryInvocation: invocation); state.fromExpression = MakeQueryClause(select, state.fromExpression); } else { // A query expression with a second from clause followed by something other than a select clause: // from x1 in e1 // from x2 in e2 // ... // is translated into // from * in ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => new { x1 , x2 } ) // ... // We use a slightly different translation strategy. We produce // from * in ( e ) . SelectMany ( x1 => e2, ( x1 , x2 ) => new Pair<X1,X2>(x1, x2) ) // Where X1 is the type of x1, and X2 is the type of x2. // Subsequently, x1 (or members of x1, if it is a transparent identifier) // are accessed as TRID.Item1 (or members of that), and x2 is accessed // as TRID.Item2, where TRID is the compiler-generated identifier used // to represent the transparent identifier in the result. var resultSelectorLambda = MakePairLambda(from, state, x1, x2); var invocation = MakeQueryInvocation( from, state.fromExpression, "SelectMany", ImmutableArray.Create(collectionSelectorLambda, resultSelectorLambda), diagnostics); BoundExpression castInvocation = (from.Type != null) ? ExtractCastInvocation(invocation) : null; state.fromExpression = MakeQueryClause(from, invocation, x2, invocation, castInvocation); } }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitFromClause(FromClauseSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitFromClause(node); }
public override SyntaxNode VisitFromClause(FromClauseSyntax node) { this.AppendCompileIssue(node, IssueType.Error, IssueId.LinqNotSupport); return node; }
public override void VisitFromClause(FromClauseSyntax node) { this.Found |= node.Identifier.ValueText == this.name; base.VisitFromClause(node); }
public override void VisitFromClause(FromClauseSyntax node) { this.Found |= node.Identifier.ValueText == this.name; base.VisitFromClause(node); }
public override void VisitFromClause(FromClauseSyntax node) { map.Add(node.Identifier.ValueText, node.Identifier); base.VisitFromClause(node); }