Exemplo n.º 1
0
 public static ITypeSymbol GetTypeSymbol(
     this SemanticModel semanticModel,
     SelectOrGroupClauseSyntax selectOrGroupClause,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(semanticModel
            .GetTypeInfo(selectOrGroupClause, cancellationToken)
            .Type);
 }
Exemplo n.º 2
0
 public static ITypeSymbol GetTypeSymbol(
     this SemanticModel semanticModel,
     SelectOrGroupClauseSyntax selectOrGroupClause,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Microsoft.CodeAnalysis.CSharp.CSharpExtensions
            .GetTypeInfo(semanticModel, selectOrGroupClause, cancellationToken)
            .Type);
 }
 public override void AddChildren()
 {
     Kind                    = Node.Kind();
     _clauses                = ((QueryBodySyntax)Node).Clauses;
     _clausesIsChanged       = false;
     _clausesCount           = _clauses.Count;
     _selectOrGroup          = ((QueryBodySyntax)Node).SelectOrGroup;
     _selectOrGroupIsChanged = false;
     _continuation           = ((QueryBodySyntax)Node).Continuation;
     _continuationIsChanged  = false;
 }
Exemplo n.º 4
0
 public void Clear()
 {
     fromExpression = null;
     rangeVariable  = null;
     selectOrGroup  = null;
     foreach (var b in allRangeVariables.Values)
     {
         b.Free();
     }
     allRangeVariables.Clear();
     clauses.Clear();
 }
Exemplo n.º 5
0
        private QueryClause VisitTerminationClause(SelectOrGroupClauseSyntax node)
        {
            if (node is SelectClauseSyntax select)
            {
                return(Expressive.Select(Visit(select.Expression)));
            }
            if (node is GroupClauseSyntax group)
            {
                return(Expressive.GroupBy(null, Visit(group.GroupExpression)));
            }

            throw new ArgumentException();
        }
Exemplo n.º 6
0
        private static void HandleSelectOrGroup(SelectOrGroupClauseSyntax selectOrGroup, List <SyntaxToken> tokensToCheck)
        {
            switch (selectOrGroup.Kind())
            {
            case SyntaxKind.SelectClause:
                var selectClause = (SelectClauseSyntax)selectOrGroup;
                tokensToCheck.Add(selectClause.SelectKeyword);
                break;

            case SyntaxKind.GroupClause:
                var groupClause = (GroupClauseSyntax)selectOrGroup;
                tokensToCheck.Add(groupClause.GroupKeyword);
                break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// When queries are translated into expressions select and group-by expressions such that
        /// 1) select/group-by expression is the same identifier as the "source" identifier and
        /// 2) at least one Where or OrderBy clause but no other clause is present in the contained query body or
        ///    the expression in question is a group-by expression and the body has no clause
        ///
        /// do not translate into lambdas.
        /// By "source" identifier we mean the identifier specified in the from clause that initiates the query or the query continuation that includes the body.
        ///
        /// The above condition can be derived from the language specification (chapter 7.16.2) as follows:
        /// - In order for 7.16.2.5 "Select clauses" to be applicable the following conditions must hold:
        ///   - There has to be at least one clause in the body, otherwise the query is reduced into a final form by 7.16.2.3 "Degenerate query expressions".
        ///   - Only where and order-by clauses may be present in the query body, otherwise a transformation in 7.16.2.4 "From, let, where, join and orderby clauses"
        ///     produces pattern that doesn't match the requirements of 7.16.2.5.
        ///
        /// - In order for 7.16.2.6 "Groupby clauses" to be applicable the following conditions must hold:
        ///   - Only where and order-by clauses may be present in the query body, otherwise a transformation in 7.16.2.4 "From, let, where, join and orderby clauses"
        ///     produces pattern that doesn't match the requirements of 7.16.2.5.
        /// </summary>
        private static bool IsReducedSelectOrGroupByClause(SelectOrGroupClauseSyntax selectOrGroupClause, ExpressionSyntax selectOrGroupExpression)
        {
            if (!selectOrGroupExpression.IsKind(SyntaxKind.IdentifierName))
            {
                return(false);
            }

            var selectorIdentifier = ((IdentifierNameSyntax)selectOrGroupExpression).Identifier;

            SyntaxToken     sourceIdentifier;
            QueryBodySyntax containingBody;

            var containingQueryOrContinuation = selectOrGroupClause.Parent.Parent;

            if (containingQueryOrContinuation.IsKind(SyntaxKind.QueryExpression))
            {
                var containingQuery = (QueryExpressionSyntax)containingQueryOrContinuation;
                containingBody   = containingQuery.Body;
                sourceIdentifier = containingQuery.FromClause.Identifier;
            }
            else
            {
                var containingContinuation = (QueryContinuationSyntax)containingQueryOrContinuation;
                sourceIdentifier = containingContinuation.Identifier;
                containingBody   = containingContinuation.Body;
            }

            if (!SyntaxFactory.AreEquivalent(sourceIdentifier, selectorIdentifier))
            {
                return(false);
            }

            if (selectOrGroupClause.IsKind(SyntaxKind.SelectClause) && containingBody.Clauses.Count == 0)
            {
                return(false);
            }

            foreach (var clause in containingBody.Clauses)
            {
                if (!clause.IsKind(SyntaxKind.WhereClause) && !clause.IsKind(SyntaxKind.OrderByClause))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 8
0
 public override TypeInfo GetTypeInfo(SelectOrGroupClauseSyntax node, CancellationToken cancellationToken = default(CancellationToken))
 {
     var bound = GetBoundQueryClause(node);
     return GetTypeInfoForQuery(bound);
 }
Exemplo n.º 9
0
 public abstract TypeInfo GetTypeInfo(SelectOrGroupClauseSyntax node, CancellationToken cancellationToken = default(CancellationToken));
 private static bool ProjectsIntoAnynomousType([NotNull] SelectOrGroupClauseSyntax selectOrGroupClause)
 {
     return(selectOrGroupClause is SelectClauseSyntax selectClause &&
            selectClause.Expression is AnonymousObjectCreationExpressionSyntax);
 }
 private static bool ProjectsIntoGroup([NotNull] SelectOrGroupClauseSyntax selectOrGroupClause)
 {
     return(selectOrGroupClause is GroupClauseSyntax);
 }
Exemplo n.º 12
0
 public SymbolInfo GetSymbolInfo(SelectOrGroupClauseSyntax node,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return GetSemanticModel(node).GetSymbolInfo(node, cancellationToken);
 }
 public TameSelectOrGroupClauseSyntax(SelectOrGroupClauseSyntax node)
 {
     Node = node;
     AddChildren();
 }
 public void Clear()
 {
     fromExpression = null;
     rangeVariable = null;
     selectOrGroup = null;
     foreach (var b in allRangeVariables.Values) b.Free();
     allRangeVariables.Clear();
     clauses.Clear();
 }
Exemplo n.º 15
0
        /// <summary>
        /// When queries are translated into expressions select and group-by expressions such that
        /// 1) select/group-by expression is the same identifier as the "source" identifier and
        /// 2) at least one Where or OrderBy clause but no other clause is present in the contained query body or
        ///    the expression in question is a group-by expression and the body has no clause
        /// 
        /// do not translate into lambdas.
        /// By "source" identifier we mean the identifier specified in the from clause that initiates the query or the query continuation that includes the body.
        /// 
        /// The above condition can be derived from the language specification (chapter 7.16.2) as follows:
        /// - In order for 7.16.2.5 "Select clauses" to be applicable the following conditions must hold:
        ///   - There has to be at least one clause in the body, otherwise the query is reduced into a final form by 7.16.2.3 "Degenerate query expressions".
        ///   - Only where and order-by clauses may be present in the query body, otherwise a transformation in 7.16.2.4 "From, let, where, join and orderby clauses"
        ///     produces pattern that doesn't match the requirements of 7.16.2.5.
        ///   
        /// - In order for 7.16.2.6 "Groupby clauses" to be applicable the following conditions must hold:
        ///   - Only where and order-by clauses may be present in the query body, otherwise a transformation in 7.16.2.4 "From, let, where, join and orderby clauses"
        ///     produces pattern that doesn't match the requirements of 7.16.2.5.
        /// </summary>
        private static bool IsReducedSelectOrGroupByClause(SelectOrGroupClauseSyntax selectOrGroupClause, ExpressionSyntax selectOrGroupExpression)
        {
            if (!selectOrGroupExpression.IsKind(SyntaxKind.IdentifierName))
            {
                return false;
            }

            var selectorIdentifier = ((IdentifierNameSyntax)selectOrGroupExpression).Identifier;

            SyntaxToken sourceIdentifier;
            QueryBodySyntax containingBody;

            var containingQueryOrContinuation = selectOrGroupClause.Parent.Parent;
            if (containingQueryOrContinuation.IsKind(SyntaxKind.QueryExpression))
            {
                var containingQuery = (QueryExpressionSyntax)containingQueryOrContinuation;
                containingBody = containingQuery.Body;
                sourceIdentifier = containingQuery.FromClause.Identifier;
            }
            else
            {
                var containingContinuation = (QueryContinuationSyntax)containingQueryOrContinuation;
                sourceIdentifier = containingContinuation.Identifier;
                containingBody = containingContinuation.Body;
            }

            if (!SyntaxFactory.AreEquivalent(sourceIdentifier, selectorIdentifier))
            {
                return false;
            }

            if (selectOrGroupClause.IsKind(SyntaxKind.SelectClause) && containingBody.Clauses.Count == 0)
            {
                return false;
            }

            foreach (var clause in containingBody.Clauses)
            {
                if (!clause.IsKind(SyntaxKind.WhereClause) && !clause.IsKind(SyntaxKind.OrderByClause))
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 16
0
 public override TypeInfo GetTypeInfo(SelectOrGroupClauseSyntax node, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetTypeInfo, message: this.SyntaxTree.FilePath, cancellationToken: cancellationToken))
     {
         CheckSyntaxNode(node);
         var model = this.GetMemberModel(node);
         return (model == null) ? default(TypeInfo) : model.GetTypeInfo(node, cancellationToken);
     }
 }
Exemplo n.º 17
0
 public override TypeInfo GetTypeInfo(SelectOrGroupClauseSyntax node, CancellationToken cancellationToken = default(CancellationToken))
 {
     CheckSyntaxNode(node);
     var model = this.GetMemberModel(node);
     return (model == null) ? default(TypeInfo) : model.GetTypeInfo(node, cancellationToken);
 }
 private static void HandleSelectOrGroup(SelectOrGroupClauseSyntax selectOrGroup, List<SyntaxToken> tokensToCheck)
 {
     switch (selectOrGroup.Kind())
     {
     case SyntaxKind.SelectClause:
         var selectClause = (SelectClauseSyntax)selectOrGroup;
         tokensToCheck.Add(selectClause.SelectKeyword);
         break;
     case SyntaxKind.GroupClause:
         var groupClause = (GroupClauseSyntax)selectOrGroup;
         tokensToCheck.Add(groupClause.GroupKeyword);
         break;
     }
 }