コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
        }
コード例 #5
0
 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));
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
 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;
 }
コード例 #9
0
        public override SyntaxNode VisitQueryBody(QueryBodySyntax node)
        {
            if (Fields != null)
            {
                return(node);
            }

            CaptureFieldNames(node, x => x.VisitQueryBody(node));

            return(node);
        }
コード例 #10
0
        public override SyntaxNode VisitQueryBody(QueryBodySyntax node)
        {
            if (Fields != null || (_isQueryExpression.HasValue && _isQueryExpression == false))
            {
                return(node);
            }

            CaptureFieldNames(node, x => x.VisitQueryBody(node));

            return(node);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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));
        }
コード例 #13
0
ファイル: LocalBinderFactory.cs プロジェクト: tmds/roslyn
        public override void VisitQueryBody(QueryBodySyntax node)
        {
            foreach (var clause in node.Clauses)
            {
                if (clause.Kind() == SyntaxKind.JoinClause)
                {
                    Visit(((JoinClauseSyntax)clause).InExpression);
                }
            }

            Visit(node.Continuation);
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
ファイル: Visitor.LINQ.cs プロジェクト: piotrbrzuska/Cometary
        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));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: IndexVisitor.cs プロジェクト: zuhuizou/DotNetDAL
        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));
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        public override void VisitQueryBody(QueryBodySyntax node)
        {
            foreach (var clause in node.Clauses)
            {
                if (clause.Kind() == SyntaxKind.JoinClause)
                {
                    Visit(((JoinClauseSyntax)clause).InExpression);
                }
            }

            Visit(node.Continuation);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitQueryBody(QueryBodySyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitQueryBody(node);
 }
コード例 #28
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitQueryBody(QueryBodySyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitQueryBody(node);
 }
コード例 #29
0
        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);
        }
コード例 #30
0
 public TameQueryBodySyntax(QueryBodySyntax node)
 {
     Node = node;
     AddChildren();
 }
コード例 #31
0
 public override LuaSyntaxNode VisitQueryBody(QueryBodySyntax node)
 {
     throw new InvalidOperationException();
 }
コード例 #32
0
        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);
            }
        }
コード例 #33
0
        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);
        }
コード例 #35
0
 public override void VisitQueryBody(QueryBodySyntax node)
 {
     base.VisitQueryBody(node);
 }
コード例 #36
0
 private bool IsSpecialQueryNode(QueryBodySyntax node)
 {
     return(node.Clauses.Count == 1 && node.SelectOrGroup.IsKind(SyntaxKind.SelectClause));
 }
コード例 #37
0
        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);
            }
        }
コード例 #38
0
        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);
        }
コード例 #39
0
 public override void VisitQueryBody(QueryBodySyntax node)
 {
     throw new NotImplementedException();
 }
コード例 #40
0
ファイル: GetMembersVisitor.cs プロジェクト: bnjMichel/waqs
        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;
        }