protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, RangeVariableSymbol qv, DiagnosticBag diagnostics)
            {
                Debug.Assert(!qv.IsTransparent);

                BoundExpression translation;
                ImmutableArray<string> path;
                if (_rangeVariableMap.TryGetValue(qv, out path))
                {
                    if (path.IsEmpty)
                    {
                        // the range variable maps directly to a use of the parameter of that name
                        var value = base.parameterMap[qv.Name];
                        Debug.Assert(value.Count == 1);
                        translation = new BoundParameter(node, value.Single()) { WasCompilerGenerated = true };
                    }
                    else
                    {
                        // if the query variable map for this variable is non empty, we always start with the current
                        // lambda's first parameter, which is a transparent identifier.
                        Debug.Assert(base.lambdaSymbol.Parameters[0].Name.StartsWith(transparentIdentifierPrefix));
                        translation = new BoundParameter(node, base.lambdaSymbol.Parameters[0]) { WasCompilerGenerated = true };
                        for (int i = path.Length - 1; i >= 0; i--)
                        {
                            var nextField = path[i];
                            translation = SelectField(node, translation, nextField, diagnostics);
                            translation.WasCompilerGenerated = true;
                        }
                    }

                    return new BoundRangeVariable(node, qv, translation, translation.Type);
                }

                return base.BindRangeVariable(node, qv, diagnostics);
            }
Exemple #2
0
            internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identifier, DiagnosticBag diagnostics)
            {
                string name   = identifier.ValueText;
                var    result = new RangeVariableSymbol(name, binder.ContainingMemberOrLambda, identifier.GetLocation());
                bool   error  = false;

                foreach (var existingRangeVariable in allRangeVariables.Keys)
                {
#if XSHARP
                    if (XSharpString.Equals(existingRangeVariable.Name, name))
#else
                    if (existingRangeVariable.Name == name)
#endif
                    {
                        diagnostics.Add(ErrorCode.ERR_QueryDuplicateRangeVariable, identifier.GetLocation(), name);
                        error = true;
                    }
                }

                if (!error)
                {
                    var collisionDetector = new LocalScopeBinder(binder);
                    collisionDetector.ValidateDeclarationNameConflictsInScope(result, diagnostics);
                }

                allRangeVariables.Add(result, ArrayBuilder <string> .GetInstance());
                return(result);
            }
Exemple #3
0
        private UnboundLambda MakeQueryUnboundLambdaWithCast(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression, TypeSyntax castTypeSyntax, TypeSymbol castType)
        {
            return(MakeQueryUnboundLambda(expression, new QueryUnboundLambdaState(this, qvm, ImmutableArray.Create(parameter), (LambdaSymbol lambdaSymbol, ref Binder lambdaBodyBinder, DiagnosticBag diagnostics) =>
            {
                BoundExpression boundExpression = lambdaBodyBinder.BindValue(expression, diagnostics, BindValueKind.RValue);

                // We transform the expression from "expr" to "expr.Cast<castTypeOpt>()".
                boundExpression = lambdaBodyBinder.MakeQueryInvocation(expression, boundExpression, "Cast", castTypeSyntax, castType, diagnostics);

                return lambdaBodyBinder.CreateBlockFromExpression(expression, lambdaBodyBinder.Locals, expression, boundExpression, diagnostics);
            })));
        }
Exemple #4
0
 public void Clear()
 {
     fromExpression = null;
     rangeVariable  = null;
     selectOrGroup  = null;
     foreach (var b in allRangeVariables.Values)
     {
         b.Free();
     }
     allRangeVariables.Clear();
     clauses.Clear();
 }
Exemple #5
0
        private UnboundLambda MakeQueryUnboundLambdaWithCast(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression, TypeSyntax castTypeSyntax, TypeWithAnnotations castType)
        {
            return(MakeQueryUnboundLambda(expression, new QueryUnboundLambdaState(this, qvm, ImmutableArray.Create(parameter), (LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag diagnostics) =>
            {
                lambdaBodyBinder = lambdaBodyBinder.GetBinder(expression);
                Debug.Assert(lambdaBodyBinder != null);
                BoundExpression boundExpression = lambdaBodyBinder.BindValue(expression, diagnostics, BindValueKind.RValue);

                // We transform the expression from "expr" to "expr.Cast<castTypeOpt>()".
                boundExpression = lambdaBodyBinder.MakeQueryInvocation(expression, boundExpression, "Cast", castTypeSyntax, castType, diagnostics);

                return lambdaBodyBinder.CreateLambdaBlockForQueryClause(expression, boundExpression, diagnostics);
            })));
        }
Exemple #6
0
 public BoundQueryClause(
     SyntaxNode syntax,
     BoundExpression value,
     RangeVariableSymbol definedSymbol,
     BoundExpression queryInvocation,
     BoundExpression castInvocation,
     Binder binder,
     BoundExpression unoptimizedForm,
     TypeSymbol type,
     bool hasErrors = false)
     : this(syntax, value, definedSymbol, binder, type, hasErrors)
 {
     this.Operation       = queryInvocation;
     this.Cast            = castInvocation;
     this.UnoptimizedForm = unoptimizedForm;
 }
Exemple #7
0
 public BoundQueryClause(
     CSharpSyntaxNode syntax,
     BoundExpression value,
     RangeVariableSymbol definedSymbol,
     BoundExpression queryInvocation,
     BoundExpression castInvocation,
     Binder binder,
     BoundExpression unoptimizedForm,
     TypeSymbol type,
     bool hasErrors = false)
     : this(syntax, value, definedSymbol, binder, type, hasErrors)
 {
     this.Operation = queryInvocation;
     this.Cast = castInvocation;
     this.UnoptimizedForm = unoptimizedForm;
 }
 public BoundQueryClause Update(
     BoundExpression value,
     RangeVariableSymbol definedSymbol,
     BoundExpression queryInvocation,
     BoundExpression castInvocation,
     Binder binder,
     BoundExpression unoptimizedForm,
     TypeSymbol type)
 {
     if (value != this.Value || definedSymbol != this.DefinedSymbol || queryInvocation != this.Operation || castInvocation != this.Cast || binder != this.Binder || unoptimizedForm != this.UnoptimizedForm || type != this.Type)
     {
         var result = new BoundQueryClause(this.Syntax, value, definedSymbol, queryInvocation, castInvocation, binder, unoptimizedForm, type, this.HasErrors);
         result.WasCompilerGenerated = this.WasCompilerGenerated;
         return(result);
     }
     return(this);
 }
Exemple #9
0
 public BoundQueryClause Update(
     BoundExpression value,
     RangeVariableSymbol definedSymbol,
     BoundExpression queryInvocation,
     BoundExpression castInvocation,
     Binder binder,
     BoundExpression unoptimizedForm,
     TypeSymbol type)
 {
     if (value != this.Value || definedSymbol != this.DefinedSymbol || queryInvocation != this.Operation || castInvocation != this.Cast || binder != this.Binder || unoptimizedForm != this.UnoptimizedForm || type != this.Type)
     {
         var result = new BoundQueryClause(this.Syntax, value, definedSymbol, queryInvocation, castInvocation, binder, unoptimizedForm, type, this.HasErrors);
         result.WasCompilerGenerated = this.WasCompilerGenerated;
         return result;
     }
     return this;
 }
            protected override BoundExpression BindRangeVariable(
                SimpleNameSyntax node,
                RangeVariableSymbol qv,
                BindingDiagnosticBag diagnostics
                )
            {
                Debug.Assert(!qv.IsTransparent);

                BoundExpression         translation;
                ImmutableArray <string> path;

                if (_rangeVariableMap.TryGetValue(qv, out path))
                {
                    if (path.IsEmpty)
                    {
                        // the range variable maps directly to a use of the parameter of that name
                        var value = base.parameterMap[qv.Name];
                        Debug.Assert(value.Count == 1);
                        translation = new BoundParameter(node, value.Single());
                    }
                    else
                    {
                        // if the query variable map for this variable is non empty, we always start with the current
                        // lambda's first parameter, which is a transparent identifier.
                        Debug.Assert(
                            base.lambdaSymbol.Parameters[0].Name.StartsWith(
                                transparentIdentifierPrefix,
                                StringComparison.Ordinal
                                )
                            );
                        translation = new BoundParameter(node, base.lambdaSymbol.Parameters[0]);
                        for (int i = path.Length - 1; i >= 0; i--)
                        {
                            translation.WasCompilerGenerated = true;
                            var nextField = path[i];
                            translation = SelectField(node, translation, nextField, diagnostics);
                        }
                    }

                    return(new BoundRangeVariable(node, qv, translation, translation.Type));
                }

                return(base.BindRangeVariable(node, qv, diagnostics));
            }
Exemple #11
0
 private BoundQueryClause MakeQueryClause(
     CSharpSyntaxNode syntax,
     BoundExpression expression,
     RangeVariableSymbol definedSymbol = null,
     BoundExpression queryInvocation   = null,
     BoundExpression castInvocation    = null,
     BoundExpression unoptimizedForm   = null)
 {
     if (unoptimizedForm != null && unoptimizedForm.HasAnyErrors && !expression.HasAnyErrors)
     {
         unoptimizedForm = null;
     }
     return(new BoundQueryClause(
                syntax: syntax, value: expression,
                definedSymbol: definedSymbol,
                queryInvocation: queryInvocation,
                binder: this,
                castInvocation: castInvocation, unoptimizedForm: unoptimizedForm,
                type: TypeOrError(expression)));
 }
            internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identifier, DiagnosticBag diagnostics)
            {
                string name = identifier.ValueText;
                var result = new RangeVariableSymbol(name, binder.ContainingMemberOrLambda, identifier.GetLocation());
                bool error = false;

                foreach (var existingRangeVariable in allRangeVariables.Keys)
                {
                    if (existingRangeVariable.Name == name)
                    {
                        diagnostics.Add(ErrorCode.ERR_QueryDuplicateRangeVariable, identifier.GetLocation(), name);
                        error = true;
                    }
                }

                if (!error)
                {
                    var collisionDetector = new LocalScopeBinder(binder);
                    collisionDetector.ValidateDeclarationNameConflictsInScope(result, diagnostics);
                }

                allRangeVariables.Add(result, ArrayBuilder<string>.GetInstance());
                return result;
            }
Exemple #13
0
 public virtual void VisitRangeVariable(RangeVariableSymbol symbol)
 {
     DefaultVisit(symbol);
 }
Exemple #14
0
        private UnboundLambda MakeQueryUnboundLambdaWithCast(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression, TypeSyntax castTypeSyntax, TypeSymbol castType)
        {
            return MakeQueryUnboundLambda(expression, new QueryUnboundLambdaState(this, qvm, ImmutableArray.Create(parameter), (LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag diagnostics) =>
            {
                lambdaBodyBinder = lambdaBodyBinder.GetBinder(expression);
                Debug.Assert(lambdaBodyBinder != null);

                BoundExpression boundExpression = lambdaBodyBinder.BindValue(expression, diagnostics, BindValueKind.RValue);

                // We transform the expression from "expr" to "expr.Cast<castTypeOpt>()".
                boundExpression = lambdaBodyBinder.MakeQueryInvocation(expression, boundExpression, "Cast", castTypeSyntax, castType, diagnostics);

                return lambdaBodyBinder.CreateBlockFromExpression(expression, lambdaBodyBinder.GetDeclaredLocalsForScope(expression), RefKind.None, boundExpression, expression, diagnostics);
            }));
        }
 public void Clear()
 {
     fromExpression = null;
     rangeVariable = null;
     selectOrGroup = null;
     foreach (var b in allRangeVariables.Values) b.Free();
     allRangeVariables.Clear();
     clauses.Clear();
 }
Exemple #16
0
 UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, CSharpSyntaxNode node, LambdaBodyResolver resolver)
 {
     return(MakeQueryUnboundLambda(qvm, Args(parameter), node, resolver));
 }
Exemple #17
0
 UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression, TypeSyntax castTypeSyntaxOpt, TypeSymbol castTypeOpt)
 {
     return(MakeQueryUnboundLambda(qvm, Args(parameter), expression, castTypeSyntaxOpt, castTypeOpt));
 }
Exemple #18
0
        private UnboundLambda MakePairLambda(CSharpSyntaxNode node, QueryTranslationState state, RangeVariableSymbol x1, RangeVariableSymbol x2)
        {
            Debug.Assert(LambdaUtilities.IsQueryPairLambda(node));

            LambdaBodyFactory bodyFactory = (LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag d) =>
            {
                var x1Expression = new BoundParameter(node, lambdaSymbol.Parameters[0]) { WasCompilerGenerated = true };
                var x2Expression = new BoundParameter(node, lambdaSymbol.Parameters[1]) { WasCompilerGenerated = true };
                var construction = MakePair(node, x1.Name, x1Expression, x2.Name, x2Expression, state, d);
                return lambdaBodyBinder.CreateBlockFromExpression(node, ImmutableArray<LocalSymbol>.Empty, RefKind.None, construction, null, d);
            };

            var result = MakeQueryUnboundLambda(state.RangeVariableMap(), ImmutableArray.Create(x1, x2), node, bodyFactory);
            state.rangeVariable = state.TransparentRangeVariable(this);
            state.AddTransparentIdentifier(x1.Name);
            var x2m = state.allRangeVariables[x2];
            x2m[x2m.Count - 1] = x2.Name;
            return result;
        }
Exemple #19
0
 private UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression)
 {
     return MakeQueryUnboundLambda(qvm, ImmutableArray.Create(parameter), expression);
 }
Exemple #20
0
 public virtual TResult VisitRangeVariable(RangeVariableSymbol symbol)
 {
     return(DefaultVisit(symbol));
 }
Exemple #21
0
 public virtual TResult VisitRangeVariable(RangeVariableSymbol symbol, TArgument argument)
 {
     return(DefaultVisit(symbol, argument));
 }
Exemple #22
0
 private BoundQueryClause MakeQueryClause(
     CSharpSyntaxNode syntax,
     BoundExpression expression,
     RangeVariableSymbol definedSymbol = null,
     BoundExpression queryInvocation = null,
     BoundExpression castInvocation = null,
     BoundExpression unoptimizedForm = null)
 {
     if (unoptimizedForm != null && unoptimizedForm.HasAnyErrors && !expression.HasAnyErrors) unoptimizedForm = null;
     return new BoundQueryClause(
         syntax: syntax, value: expression,
         definedSymbol: definedSymbol,
         queryInvocation: queryInvocation,
         binder: this,
         castInvocation: castInvocation, unoptimizedForm: unoptimizedForm,
         type: TypeOrError(expression));
 }
Exemple #23
0
        private UnboundLambda MakePairLambda(CSharpSyntaxNode node, QueryTranslationState state, RangeVariableSymbol x1, RangeVariableSymbol x2)
        {
            Debug.Assert(LambdaUtilities.IsQueryPairLambda(node));

            LambdaBodyFactory bodyFactory = (LambdaSymbol lambdaSymbol, Binder lambdaBodyBinder, DiagnosticBag d) =>
            {
                var x1Expression = new BoundParameter(node, lambdaSymbol.Parameters[0])
                {
                    WasCompilerGenerated = true
                };
                var x2Expression = new BoundParameter(node, lambdaSymbol.Parameters[1])
                {
                    WasCompilerGenerated = true
                };
                var construction = MakePair(node, x1.Name, x1Expression, x2.Name, x2Expression, state, d);
                return(lambdaBodyBinder.CreateBlockFromExpression(node, ImmutableArray <LocalSymbol> .Empty, RefKind.None, construction, null, d));
            };

            var result = MakeQueryUnboundLambda(state.RangeVariableMap(), ImmutableArray.Create(x1, x2), node, bodyFactory);

            state.rangeVariable = state.TransparentRangeVariable(this);
            state.AddTransparentIdentifier(x1.Name);
            var x2m = state.allRangeVariables[x2];

            x2m[x2m.Count - 1] = x2.Name;
            return(result);
        }
Exemple #24
0
        UnboundLambda MakePairLambda(CSharpSyntaxNode node, QueryTranslationState state, RangeVariableSymbol x1, RangeVariableSymbol x2)
        {
            LambdaBodyResolver resolver = (LambdaSymbol lambdaSymbol, ref Binder lambdaBodyBinder, DiagnosticBag d) =>
            {
                var x1Expression = new BoundParameter(node, lambdaSymbol.Parameters[0])
                {
                    WasCompilerGenerated = true
                };
                var x2Expression = new BoundParameter(node, lambdaSymbol.Parameters[1])
                {
                    WasCompilerGenerated = true
                };
                var construction = MakePair(node, x1.Name, x1Expression, x2.Name, x2Expression, state, d);
                return(lambdaBodyBinder.CreateBlockFromExpression(ImmutableArray <LocalSymbol> .Empty, construction, node, d));
            };
            var result = MakeQueryUnboundLambda(state.RangeVariableMap(), Args(x1, x2), node, resolver);

            state.rangeVariable = state.TransparentRangeVariable(this);
            state.AddTransparentIdentifier(x1.Name);
            var x2m = state.allRangeVariables[x2];

            x2m[x2m.Count - 1] = x2.Name;
            return(result);
        }
Exemple #25
0
 private UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression)
 {
     return(MakeQueryUnboundLambda(qvm, ImmutableArray.Create(parameter), expression));
 }
Exemple #26
0
 UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression)
 {
     return(MakeQueryUnboundLambda(qvm, Args(parameter), expression));
 }