public LambdaSymbol( Binder binder, CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray <TypeWithAnnotations> parameterTypes, ImmutableArray <RefKind> parameterRefKinds, RefKind refKind, TypeWithAnnotations returnType) : base(unboundLambda.Syntax.GetReference()) { Debug.Assert(syntaxReferenceOpt is not null); Debug.Assert(containingSymbol.DeclaringCompilation == compilation); _binder = binder; _containingSymbol = containingSymbol; _messageID = unboundLambda.Data.MessageID; _syntax = unboundLambda.Syntax; if (!unboundLambda.HasExplicitReturnType(out _refKind, out _returnType)) { _refKind = refKind; _returnType = !returnType.HasType ? TypeWithAnnotations.Create(ReturnTypeIsBeingInferred) : returnType; } _isSynthesized = unboundLambda.WasCompilerGenerated; _isAsync = unboundLambda.IsAsync; _isStatic = unboundLambda.IsStatic; // No point in making this lazy. We are always going to need these soon after creation of the symbol. _parameters = MakeParameters(compilation, unboundLambda, parameterTypes, parameterRefKinds); _declarationDiagnostics = new BindingDiagnosticBag(); }
public LambdaSymbol( CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray <TypeWithAnnotations> parameterTypes, ImmutableArray <RefKind> parameterRefKinds, RefKind refKind, TypeWithAnnotations returnType ) { _containingSymbol = containingSymbol; _messageID = unboundLambda.Data.MessageID; _syntax = unboundLambda.Syntax; _refKind = refKind; _returnType = !returnType.HasType ? TypeWithAnnotations.Create(ReturnTypeIsBeingInferred) : returnType; _isSynthesized = unboundLambda.WasCompilerGenerated; _isAsync = unboundLambda.IsAsync; _isStatic = unboundLambda.IsStatic; // No point in making this lazy. We are always going to need these soon after creation of the symbol. _parameters = MakeParameters( compilation, unboundLambda, parameterTypes, parameterRefKinds ); }
public UnboundLambdaState(Binder binder, UnboundLambda unboundLambdaOpt) { Debug.Assert(binder != null); // might be initialized later (for query lambdas) _unboundLambda = unboundLambdaOpt; this.binder = binder; }
UnboundLambda MakeQueryUnboundLambda(QueryVariableMap qvm, ReadOnlyArray <QueryVariableSymbol> parameters, SyntaxNode node, LambdaBodyResolver resolver) { var state = new QueryUnboundLambdaState(null, this, qvm, parameters, resolver); var lambda = new UnboundLambda(node, SyntaxTree, state, false); state.SetUnboundLambda(lambda); return(lambda); }
UnboundLambda MakeQueryUnboundLambda(QueryVariableMap qvm, ReadOnlyArray <QueryVariableSymbol> parameters, ExpressionSyntax expression, TypeSyntax castTypeSyntaxOpt, TypeSymbol castTypeOpt) { var state = (castTypeOpt == null) ? new QueryUnboundLambdaState(null, this, qvm, parameters, expression) : new QueryUnboundLambdaState(null, this, qvm, parameters, expression, castTypeSyntaxOpt, castTypeOpt); var lambda = new UnboundLambda(expression, SyntaxTree, state, false); state.SetUnboundLambda(lambda); return(lambda); }
private ImmutableArray <ParameterSymbol> MakeParameters( CSharpCompilation compilation, UnboundLambda unboundLambda, ImmutableArray <ParameterSymbol> delegateParameters) { if (!unboundLambda.HasSignature || unboundLambda.ParameterCount == 0) { // The parameters may be omitted in source, but they are still present on the symbol. return(delegateParameters.SelectAsArray(CopyParameter, this)); } var builder = ArrayBuilder <ParameterSymbol> .GetInstance(); var hasExplicitlyTypedParameterList = unboundLambda.HasExplicitlyTypedParameterList; var numDelegateParameters = delegateParameters.IsDefault ? 0 : delegateParameters.Length; for (int p = 0; p < unboundLambda.ParameterCount; ++p) { // If there are no types given in the lambda then used the delegate type. // If the lambda is typed then the types probably match the delegate types; // if they do not, use the lambda types for binding. Either way, if we // can, then we use the lambda types. (Whatever you do, do not use the names // in the delegate parameters; they are not in scope!) TypeSymbol type; RefKind refKind; if (hasExplicitlyTypedParameterList) { type = unboundLambda.ParameterType(p); refKind = unboundLambda.RefKind(p); } else if (p < numDelegateParameters) { ParameterSymbol delegateParameter = delegateParameters[p]; type = delegateParameter.Type; refKind = delegateParameter.RefKind; } else { type = new ExtendedErrorTypeSymbol(compilation, name: string.Empty, arity: 0, errorInfo: null); refKind = RefKind.None; } var name = unboundLambda.ParameterName(p); var location = unboundLambda.ParameterLocation(p); var locations = ImmutableArray.Create <Location>(location); var parameter = new SourceSimpleParameterSymbol(this, type, p, refKind, name, locations); builder.Add(parameter); } var result = builder.ToImmutableAndFree(); return(result); }
public BoundLambda(SyntaxNode syntax, UnboundLambda unboundLambda, BoundBlock body, ImmutableArray <Diagnostic> diagnostics, Binder binder, TypeSymbol delegateType, InferredLambdaReturnType inferredReturnType) : this(syntax, unboundLambda, (LambdaSymbol)binder.ContainingMemberOrLambda, body, diagnostics, binder, delegateType) { InferredReturnType = inferredReturnType; Debug.Assert( syntax.IsAnonymousFunction() || // lambda expressions syntax is ExpressionSyntax && LambdaUtilities.IsLambdaBody(syntax, allowReducedLambdas: true) || // query lambdas LambdaUtilities.IsQueryPairLambda(syntax) // "pair" lambdas in queries ); }
internal PlainUnboundLambdaState( UnboundLambda unboundLambda, Binder binder, ImmutableArray <string> parameterNames, ImmutableArray <TypeSymbol> parameterTypes, ImmutableArray <RefKind> parameterRefKinds, bool isAsync) : base(binder, unboundLambda) { _parameterNames = parameterNames; _parameterTypes = parameterTypes; _parameterRefKinds = parameterRefKinds; _isAsync = isAsync; }
public LambdaSymbol( CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray<ParameterSymbol> delegateParameters, TypeSymbol returnType) { this.containingSymbol = containingSymbol; this.messageID = unboundLambda.Data.MessageID; this.syntax = unboundLambda.Syntax; this.returnType = returnType; this.isSynthesized = unboundLambda.WasCompilerGenerated; this.isAsync = unboundLambda.IsAsync; // No point in making this lazy. We are always going to need these soon after creation of the symbol. this.parameters = MakeParameters(compilation, unboundLambda, delegateParameters); }
public LambdaSymbol( CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray <ParameterSymbol> delegateParameters, TypeSymbol returnType) { this.containingSymbol = containingSymbol; this.messageID = unboundLambda.Data.MessageID; this.syntax = unboundLambda.Syntax; this.returnType = returnType; this.isSynthesized = unboundLambda.WasCompilerGenerated; this.isAsync = unboundLambda.IsAsync; // No point in making this lazy. We are always going to need these soon after creation of the symbol. this.parameters = MakeParameters(compilation, unboundLambda, delegateParameters); }
public LambdaSymbol( CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray <TypeSymbol> parameterTypes, ImmutableArray <RefKind> parameterRefKinds, RefKind refKind, TypeSymbol returnType, DiagnosticBag diagnostics) { _containingSymbol = containingSymbol; _messageID = unboundLambda.Data.MessageID; _syntax = unboundLambda.Syntax; _refKind = refKind; _returnType = returnType; _isSynthesized = unboundLambda.WasCompilerGenerated; _isAsync = unboundLambda.IsAsync; // No point in making this lazy. We are always going to need these soon after creation of the symbol. _parameters = MakeParameters(compilation, unboundLambda, parameterTypes, parameterRefKinds, diagnostics); }
private ImmutableArray <ParameterSymbol> MakeParameters( CSharpCompilation compilation, UnboundLambda unboundLambda, ImmutableArray <TypeSymbol> parameterTypes, ImmutableArray <RefKind> parameterRefKinds, DiagnosticBag diagnostics) { Debug.Assert(parameterTypes.Length == parameterRefKinds.Length); if (!unboundLambda.HasSignature || unboundLambda.ParameterCount == 0) { // The parameters may be omitted in source, but they are still present on the symbol. return(parameterTypes.SelectAsArray((type, ordinal, arg) => SynthesizedParameterSymbol.Create( arg.owner, type, ordinal, arg.refKinds[ordinal], GeneratedNames.LambdaCopyParameterName(ordinal)), // Make sure nothing binds to this. (owner: this, refKinds: parameterRefKinds))); } var builder = ArrayBuilder <ParameterSymbol> .GetInstance(); var hasExplicitlyTypedParameterList = unboundLambda.HasExplicitlyTypedParameterList; var numDelegateParameters = parameterTypes.Length; for (int p = 0; p < unboundLambda.ParameterCount; ++p) { // If there are no types given in the lambda then used the delegate type. // If the lambda is typed then the types probably match the delegate types; // if they do not, use the lambda types for binding. Either way, if we // can, then we use the lambda types. (Whatever you do, do not use the names // in the delegate parameters; they are not in scope!) TypeSymbol type; RefKind refKind; if (hasExplicitlyTypedParameterList) { type = unboundLambda.ParameterType(p); refKind = unboundLambda.RefKind(p); } else if (p < numDelegateParameters) { type = parameterTypes[p]; refKind = parameterRefKinds[p]; } else { type = new ExtendedErrorTypeSymbol(compilation, name: string.Empty, arity: 0, errorInfo: null); refKind = RefKind.None; } var name = unboundLambda.ParameterName(p); var location = unboundLambda.ParameterLocation(p); var locations = ImmutableArray.Create <Location>(location); var parameter = new SourceSimpleParameterSymbol(this, type, p, refKind, name, locations); builder.Add(parameter); } var result = builder.ToImmutableAndFree(); return(result); }
private ImmutableArray<ParameterSymbol> MakeParameters( CSharpCompilation compilation, UnboundLambda unboundLambda, ImmutableArray<ParameterSymbol> delegateParameters) { if (!unboundLambda.HasSignature || unboundLambda.ParameterCount == 0) { // The parameters may be omitted in source, but they are still present on the symbol. return delegateParameters.SelectAsArray(CopyParameter, this); } var builder = ArrayBuilder<ParameterSymbol>.GetInstance(); var hasExplicitlyTypedParameterList = unboundLambda.HasExplicitlyTypedParameterList; var numDelegateParameters = delegateParameters.IsDefault ? 0 : delegateParameters.Length; for (int p = 0; p < unboundLambda.ParameterCount; ++p) { // If there are no types given in the lambda then used the delegate type. // If the lambda is typed then the types probably match the delegate types; // if they do not, use the lambda types for binding. Either way, if we // can, then we use the lambda types. (Whatever you do, do not use the names // in the delegate parameters; they are not in scope!) TypeSymbol type; RefKind refKind; if (hasExplicitlyTypedParameterList) { type = unboundLambda.ParameterType(p); refKind = unboundLambda.RefKind(p); } else if (p < numDelegateParameters) { ParameterSymbol delegateParameter = delegateParameters[p]; type = delegateParameter.Type; refKind = delegateParameter.RefKind; } else { type = new ExtendedErrorTypeSymbol(compilation, name: string.Empty, arity: 0, errorInfo: null); refKind = RefKind.None; } var name = unboundLambda.ParameterName(p); var location = unboundLambda.ParameterLocation(p); var locations = ImmutableArray.Create<Location>(location); var parameter = new SourceSimpleParameterSymbol(this, type, p, refKind, name, locations); builder.Add(parameter); } var result = builder.ToImmutableAndFree(); return result; }
public void SetUnboundLambda(UnboundLambda unbound) { Debug.Assert(unbound != null); Debug.Assert(_unboundLambda == null); _unboundLambda = unbound; }
public override object VisitUnboundLambda(UnboundLambda node, object arg) { // The presence of this node suggests an error detected in an earlier phase. return(null); }