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); }
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); }
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); }))); }
public void Clear() { fromExpression = null; rangeVariable = null; selectOrGroup = null; foreach (var b in allRangeVariables.Values) { b.Free(); } allRangeVariables.Clear(); clauses.Clear(); }
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); }))); }
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; }
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); }
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)); }
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; }
public virtual void VisitRangeVariable(RangeVariableSymbol symbol) { DefaultVisit(symbol); }
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(); }
UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, CSharpSyntaxNode node, LambdaBodyResolver resolver) { return(MakeQueryUnboundLambda(qvm, Args(parameter), node, resolver)); }
UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression, TypeSyntax castTypeSyntaxOpt, TypeSymbol castTypeOpt) { return(MakeQueryUnboundLambda(qvm, Args(parameter), expression, castTypeSyntaxOpt, castTypeOpt)); }
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; }
private UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression) { return MakeQueryUnboundLambda(qvm, ImmutableArray.Create(parameter), expression); }
public virtual TResult VisitRangeVariable(RangeVariableSymbol symbol) { return(DefaultVisit(symbol)); }
public virtual TResult VisitRangeVariable(RangeVariableSymbol symbol, TArgument argument) { return(DefaultVisit(symbol, argument)); }
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)); }
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); }
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); }
private UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression) { return(MakeQueryUnboundLambda(qvm, ImmutableArray.Create(parameter), expression)); }
UnboundLambda MakeQueryUnboundLambda(RangeVariableMap qvm, RangeVariableSymbol parameter, ExpressionSyntax expression) { return(MakeQueryUnboundLambda(qvm, Args(parameter), expression)); }