public LuaSyntaxNode BuildQueryBody(QueryBodySyntax node, LuaExpressionSyntax fromClauseExpression, LuaIdentifierNameSyntax rangeVariable) { LuaExpressionSyntax collection = fromClauseExpression; foreach (var clause in node.Clauses) { switch (clause.Kind()) { case SyntaxKind.WhereClause: { collection = BuildQueryWhere(collection, (WhereClauseSyntax)clause, rangeVariable); break; } case SyntaxKind.OrderByClause: { collection = BuildQueryOrderBy(collection, (OrderByClauseSyntax)clause, rangeVariable); break; } default: { throw new NotSupportedException(); } } } if (node.SelectOrGroup.IsKind(SyntaxKind.SelectClause)) { var selectClause = (SelectClauseSyntax)node.SelectOrGroup; collection = BuildQuerySelect(collection, selectClause, rangeVariable); } else { var groupClause = (GroupClauseSyntax)node.SelectOrGroup; collection = BuildGroupClause(collection, groupClause, rangeVariable); } return(collection); }
public override void VisitQueryBody(QueryBodySyntax node) { foreach (var clause in node.Clauses) { Visit(clause); } _proceed = false; if (node.Continuation == null) { Visit(node.SelectOrGroup); _proceed = true; return; } Visit(node.SelectOrGroup); _properties.Last = _properties.Last; foreach (string variable in _fromVariables.Where(v => v.Value == _linqIndex).Select(v => v.Key).ToList()) { AddProperties(GetProperties(_variables[variable])); _fromVariables.Remove(variable); _variables.Remove(variable); } var variableDependences = new PropertyDependence(); AddProperties(_properties.Last, variableDependences); _variables.Add(node.Continuation.Identifier.ValueText, variableDependences); _fromVariables.Add(node.Continuation.Identifier.ValueText, _linqIndex); Visit(node.Continuation); _proceed = true; }
public override SyntaxNode VisitQueryBody(QueryBodySyntax node) { if (Fields != null) { return(node); } var last = node.DescendantNodes(descendIntoChildren: syntaxNode => { if (syntaxNode is AnonymousObjectCreationExpressionSyntax) { return(false); } return(true); }) .LastOrDefault(x => x.IsKind(SyntaxKind.AnonymousObjectCreationExpression)) as AnonymousObjectCreationExpressionSyntax; if (last != null) { VisitAnonymousObjectCreationExpression(last); } else { ThrowIndexingFunctionMustReturnAnonymousObject(); } return(node); }
public static IList <SyntaxNode> GetAllClauses(this QueryBodySyntax body) { var result = new List <SyntaxNode>(); result.AddRange(body.Clauses); result.Add(body.SelectOrGroup); return(result); }
public new void AddChildren() { base.AddChildren(); Kind = Node.Kind(); _fromClause = ((QueryExpressionSyntax)Node).FromClause; _fromClauseIsChanged = false; _body = ((QueryExpressionSyntax)Node).Body; _bodyIsChanged = false; }
public static QueryBodySyntax WithAllClauses( this QueryBodySyntax body, IEnumerable <SyntaxNode> allClauses) { var clauses = SyntaxFactory.List(allClauses.Take(allClauses.Count() - 1).Cast <QueryClauseSyntax>()); var selectOrGroup = (SelectOrGroupClauseSyntax)allClauses.Last(); return(body.WithClauses(clauses).WithSelectOrGroup(selectOrGroup)); }
private static void ProcessQueryBody(QueryBodySyntax body, List <SyntaxNode> queryNodes) { queryNodes.AddRange(body.Clauses); queryNodes.Add(body.SelectOrGroup); if (body.Continuation != null) { ProcessQueryBody(body.Continuation.Body, queryNodes); } }
public override void AddChildren() { Kind = Node.Kind(); _intoKeyword = ((QueryContinuationSyntax)Node).IntoKeyword; _intoKeywordIsChanged = false; _identifier = ((QueryContinuationSyntax)Node).Identifier; _identifierIsChanged = false; _body = ((QueryContinuationSyntax)Node).Body; _bodyIsChanged = false; }
public override SyntaxNode VisitQueryBody(QueryBodySyntax node) { if (Fields != null) { return(node); } CaptureFieldNames(node, x => x.VisitQueryBody(node)); return(node); }
public override SyntaxNode VisitQueryBody(QueryBodySyntax node) { if (Fields != null || (_isQueryExpression.HasValue && _isQueryExpression == false)) { return(node); } CaptureFieldNames(node, x => x.VisitQueryBody(node)); return(node); }
public override void VisitQueryBody(QueryBodySyntax node) { foreach (QueryClauseSyntax clause in node.Clauses) { clause.Accept(this); } node.SelectOrGroup?.Accept(this); node.Continuation?.Accept(this); base.VisitQueryBody(node); }
public override Evaluation VisitQueryBody(QueryBodySyntax node) { foreach (QueryClauseSyntax clause in node.Clauses) { clause.Accept <Evaluation>(this); } node.SelectOrGroup?.Accept <Evaluation>(this); node.Continuation?.Accept <Evaluation>(this); return(base.VisitQueryBody(node)); }
public override void VisitQueryBody(QueryBodySyntax node) { foreach (var clause in node.Clauses) { if (clause.Kind() == SyntaxKind.JoinClause) { Visit(((JoinClauseSyntax)clause).InExpression); } } Visit(node.Continuation); }
private static void HandleQueryBody(QueryBodySyntax body, List <SyntaxToken> tokensToCheck) { foreach (var clause in body.Clauses) { HandleQueryClause(clause, tokensToCheck); } HandleSelectOrGroup(body.SelectOrGroup, tokensToCheck); if (body.Continuation != null) { HandleContinuation(body.Continuation, tokensToCheck); } }
private IEnumerable <QueryClause> VisitLinqBody(QueryBodySyntax node) { foreach (var clause in node.Clauses) { yield return(VisitContinuationClause(clause)); } foreach (var clause in VisitLinqBody(node.Continuation.Body)) { yield return(clause); } yield return(VisitTerminationClause(node.SelectOrGroup)); }
public override void VisitQueryBody(QueryBodySyntax node) { // Variables declared in [in] expressions of top level from clause and // join clauses are in scope foreach (var clause in node.Clauses) { if (clause.Kind() == SyntaxKind.JoinClause) { VisitNodeToBind(((JoinClauseSyntax)clause).InExpression); } } Visit(node.Continuation); }
public override void VisitQueryBody(QueryBodySyntax node) { if ((node.SelectOrGroup is SelectClauseSyntax) == false) { VisitGroupClause(node.SelectOrGroup as GroupClauseSyntax); return; } var selectExpressions = new Dictionary <string, ExpressionSyntax>(); var visitor = new CaptureSelectExpressionsAndNewFieldNamesVisitor(false, new HashSet <string>(), selectExpressions); node.Accept(visitor); _indexData.SelectExpressions = selectExpressions; _indexData.NumberOfSelectClauses++; }
private static QueryBodySyntax GetNewQuery( QueryBodySyntax oldQuery, SyntaxNode oldClause, SyntaxNode newClause, LetClauseSyntax letClause) { var oldClauses = oldQuery.GetAllClauses(); var oldClauseIndex = oldClauses.IndexOf(oldClause); var newClauses = oldClauses.Take(oldClauseIndex) .Concat(letClause) .Concat(newClause) .Concat(oldClauses.Skip(oldClauseIndex + 1)).ToList(); return(oldQuery.WithAllClauses(newClauses)); }
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 static Doc Print(QueryBodySyntax node) { var docs = new List <Doc> { Doc.Join(Doc.Line, node.Clauses.Select(Node.Print)) }; if (node.Clauses.Count > 0) { docs.Add(Doc.Line); } docs.Add(Node.Print(node.SelectOrGroup)); if (node.Continuation != null) { docs.Add(" ", QueryContinuation.Print(node.Continuation)); } return(Doc.Concat(docs)); }
private Doc PrintQueryBodySyntax(QueryBodySyntax node) { var parts = new Parts(); parts.Push(Join(Line, node.Clauses.Select(this.Print))); if (node.Clauses.Count > 0) { parts.Push(Line); } parts.Push(this.Print(node.SelectOrGroup)); if (node.Continuation != null) { // TODO 1 indent when there is a group by before the into? parts.Push( " ", this.PrintQueryContinuationSyntax(node.Continuation) ); } return(Concat(parts)); }
public override SyntaxNode VisitQueryBody(QueryBodySyntax node) { if (Fields != null) { return(node); } var last = node.DescendantNodes(descendIntoChildren: syntaxNode => true) .LastOrDefault(x => x.IsKind(SyntaxKind.AnonymousObjectCreationExpression)) as AnonymousObjectCreationExpressionSyntax; if (last == null) { return(node); } // check if maybe we are nested var parent = last.Ancestors(ascendOutOfTrivia: true) .FirstOrDefault(x => x.IsKind(SyntaxKind.AnonymousObjectCreationExpression)) as AnonymousObjectCreationExpressionSyntax; Fields = RewritersHelper.ExtractFields(parent ?? last); return(node); }
public override SyntaxNode VisitQueryBody(QueryBodySyntax node) { if (!_visitQuerySyntax) { return(base.VisitQueryBody(node)); } _visitInvocation = false; // Visit each clause // Concat the result to create a Fluent query expression VisitClauses(node.Clauses); VisitClauses(new SyntaxNode[] { node.SelectOrGroup }); // If we have a continuation ("into"), // handle it like it belong to the previous clause, and continue to visit his body. // Otherwise return the the fluent expression. if (node.Continuation != null) { VisitQueryContinuation(node.Continuation); } return(node); }
public void VisitQueryBody(QueryBodySyntax node) { if (node == null) { throw new ArgumentNullException("node"); } node.Validate(); foreach (var clause in node.Clauses) { clause.Accept(this); _writer.WriteSpace(); } node.SelectOrGroup.Accept(this); if (node.Continuation != null) { _writer.WriteSpace(); node.Continuation.Accept(this); } }
public override void VisitQueryBody(QueryBodySyntax node) { // Variables declared in [in] expressions of top level from clause and // join clauses are in scope foreach (var clause in node.Clauses) { if (clause.Kind() == SyntaxKind.JoinClause) { Visit(((JoinClauseSyntax)clause).InExpression); } } Visit(node.Continuation); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitQueryBody(QueryBodySyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitQueryBody(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitQueryBody(QueryBodySyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitQueryBody(node); }
private LuaExpressionSyntax BuildQueryBody(LuaExpressionSyntax collection, QueryBodySyntax node, IQueryRangeVariable rangeVariable) { foreach (var clause in node.Clauses) { switch (clause.Kind()) { case SyntaxKind.FromClause: { bool isOver; collection = BuildFromClause(collection, (FromClauseSyntax)clause, ref rangeVariable, out isOver); if (isOver) { goto Continuation; } break; } case SyntaxKind.LetClause: { collection = BuildLetClause(collection, (LetClauseSyntax)clause, ref rangeVariable); break; } case SyntaxKind.JoinClause: { bool isOver; collection = BuildJoinClause(collection, (JoinClauseSyntax)clause, ref rangeVariable, out isOver); if (isOver) { goto Continuation; } break; } case SyntaxKind.WhereClause: { collection = BuildQueryWhere(collection, (WhereClauseSyntax)clause, rangeVariable); break; } case SyntaxKind.OrderByClause: { collection = BuildQueryOrderBy(collection, (OrderByClauseSyntax)clause, rangeVariable); break; } default: { throw new NotSupportedException(); } } } if (node.SelectOrGroup.IsKind(SyntaxKind.SelectClause)) { var selectClause = (SelectClauseSyntax)node.SelectOrGroup; collection = BuildQuerySelect(collection, selectClause, rangeVariable); } else { var groupClause = (GroupClauseSyntax)node.SelectOrGroup; collection = BuildGroupClause(collection, groupClause, rangeVariable); } Continuation: if (node.Continuation != null) { collection = BuildQueryContinuation(collection, node.Continuation); } return(collection); }
public TameQueryBodySyntax(QueryBodySyntax node) { Node = node; AddChildren(); }
public override LuaSyntaxNode VisitQueryBody(QueryBodySyntax node) { throw new InvalidOperationException(); }
private static void HandleQueryBody(QueryBodySyntax body, List<SyntaxToken> tokensToCheck) { foreach (var clause in body.Clauses) { HandleQueryClause(clause, tokensToCheck); } HandleSelectOrGroup(body.SelectOrGroup, tokensToCheck); if (body.Continuation != null) { HandleContinuation(body.Continuation, tokensToCheck); } }
public void VisitQueryBody(QueryBodySyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); foreach (var clause in node.Clauses) { clause.Accept(this); _writer.WriteSpace(); } node.SelectOrGroup.Accept(this); if (node.Continuation != null) { _writer.WriteSpace(); node.Continuation.Accept(this); } }
private static QueryBodySyntax GetNewQuery( QueryBodySyntax oldQuery, SyntaxNode oldClause, SyntaxNode newClause, LetClauseSyntax letClause) { var oldClauses = oldQuery.GetAllClauses(); var oldClauseIndex = oldClauses.IndexOf(oldClause); var newClauses = oldClauses.Take(oldClauseIndex) .Concat(letClause) .Concat(newClause) .Concat(oldClauses.Skip(oldClauseIndex + 1)).ToList(); return oldQuery.WithAllClauses(newClauses); }
public override void VisitQueryBody(QueryBodySyntax node) { base.VisitQueryBody(node); }
private bool IsSpecialQueryNode(QueryBodySyntax node) { return(node.Clauses.Count == 1 && node.SelectOrGroup.IsKind(SyntaxKind.SelectClause)); }
private static void ProcessQueryBody(QueryBodySyntax body, List<SyntaxNode> queryNodes) { queryNodes.AddRange(body.Clauses); queryNodes.Add(body.SelectOrGroup); if (body.Continuation != null) { ProcessQueryBody(body.Continuation.Body, queryNodes); } }
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 VisitQueryBody(QueryBodySyntax node) { throw new NotImplementedException(); }
public override void VisitQueryBody(QueryBodySyntax node) { foreach (var clause in node.Clauses) Visit(clause); _proceed = false; if (node.Continuation == null) { Visit(node.SelectOrGroup); _proceed = true; return; } Visit(node.SelectOrGroup); _properties.Last = _properties.Last; foreach (string variable in _fromVariables.Where(v => v.Value == _linqIndex).Select(v => v.Key).ToList()) { AddProperties(GetProperties(_variables[variable])); _fromVariables.Remove(variable); _variables.Remove(variable); } var variableDependences = new PropertyDependence(); AddProperties(_properties.Last, variableDependences); _variables.Add(node.Continuation.Identifier.ValueText, variableDependences); _fromVariables.Add(node.Continuation.Identifier.ValueText, _linqIndex); Visit(node.Continuation); _proceed = true; }