public LocalFunctionSymbol( Binder binder, Symbol containingSymbol, LocalFunctionStatementSyntax syntax) { _syntax = syntax; _containingSymbol = containingSymbol; _declarationModifiers = DeclarationModifiers.Private | DeclarationModifiers.Static | syntax.Modifiers.ToDeclarationModifiers(); var diagnostics = DiagnosticBag.GetInstance(); if (_syntax.TypeParameterList != null) { binder = new WithMethodTypeParametersBinder(this, binder); _typeParameters = MakeTypeParameters(diagnostics); } else { _typeParameters = ImmutableArray <TypeParameterSymbol> .Empty; } if (IsExtensionMethod) { diagnostics.Add(ErrorCode.ERR_BadExtensionAgg, Locations[0]); } _binder = binder; _refKind = (syntax.ReturnType.Kind() == SyntaxKind.RefType) ? RefKind.Ref : RefKind.None; _diagnostics = diagnostics.ToReadOnlyAndFree(); }
public LocalFunctionSymbol( Binder binder, Symbol containingSymbol, LocalFunctionStatementSyntax syntax) { _syntax = syntax; _containingSymbol = containingSymbol; _declarationDiagnostics = new DiagnosticBag(); _declarationModifiers = DeclarationModifiers.Private | syntax.Modifiers.ToDeclarationModifiers(diagnostics: _declarationDiagnostics); this.CheckUnsafeModifier(_declarationModifiers, _declarationDiagnostics); ScopeBinder = binder; binder = binder.WithUnsafeRegionIfNecessary(syntax.Modifiers); if (_syntax.TypeParameterList != null) { binder = new WithMethodTypeParametersBinder(this, binder); _typeParameters = MakeTypeParameters(_declarationDiagnostics); } else { _typeParameters = ImmutableArray <SourceMethodTypeParameterSymbol> .Empty; ReportErrorIfHasConstraints(_syntax.ConstraintClauses, _declarationDiagnostics); } if (IsExtensionMethod) { _declarationDiagnostics.Add(ErrorCode.ERR_BadExtensionAgg, Locations[0]); } foreach (var param in syntax.ParameterList.Parameters) { ReportAttributesDisallowed(param.AttributeLists, _declarationDiagnostics); } if (syntax.ReturnType.Kind() == SyntaxKind.RefType) { var returnType = (RefTypeSyntax)syntax.ReturnType; if (returnType.ReadOnlyKeyword.Kind() == SyntaxKind.ReadOnlyKeyword) { _refKind = RefKind.RefReadOnly; } else { _refKind = RefKind.Ref; } } else { _refKind = RefKind.None; } _binder = binder; }
public LocalFunctionSymbol( Binder binder, Symbol containingSymbol, LocalFunctionStatementSyntax syntax) { _syntax = syntax; _containingSymbol = containingSymbol; _declarationModifiers = DeclarationModifiers.Private | DeclarationModifiers.Static | syntax.Modifiers.ToDeclarationModifiers(); var diagnostics = DiagnosticBag.GetInstance(); if (_syntax.TypeParameterList != null) { binder = new WithMethodTypeParametersBinder(this, binder); _typeParameters = MakeTypeParameters(diagnostics); } else { _typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } if (IsExtensionMethod) { diagnostics.Add(ErrorCode.ERR_BadExtensionAgg, Locations[0]); } _binder = binder; _refKind = (syntax.ReturnType.Kind() == SyntaxKind.RefType) ? RefKind.Ref : RefKind.None; _diagnostics = diagnostics.ToReadOnlyAndFree(); }
private IEnumerable <TypeParameterBuilder> MakeTypeParameterBuilders(MethodSymbol current) { if (SyntaxArity == 0) { return(SpecializedCollections.EmptyEnumerable <TypeParameterBuilder>()); } var withParams = new WithMethodTypeParametersBinder(current, Next); return (SyntaxTypeParameters .Select(ta => new TypeParameterBuilder(ta, current, withParams.Location(ta)))); }
private SourceMemberMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, Binder bodyBinder, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); // NOTE: by creating a WithMethodTypeParametersBinder, we are effectively duplicating the // functionality of the BinderFactory. Unfortunately, we cannot use the BinderFactory // because it depends on having access to the member list of our containing type and // that list cannot be complete because we're not finished constructing this member. // TODO: at least keep this in sync with BinderFactory.VisitMethodDeclaration. bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers); Binder withTypeParamsBinder; if (syntax.Arity == 0) { withTypeParamsBinder = bodyBinder; _typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } else { var parameterBinder = new WithMethodTypeParametersBinder(this, bodyBinder); withTypeParamsBinder = parameterBinder; _typeParameters = MakeTypeParameters(syntax, diagnostics); } bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (this.IsPartial) { // Partial methods must be completed early because they are matched up // by signature while producing the enclosing type's member list. However, // that means any type parameter constraints will be bound before the method // is added to the containing type. To enable binding of constraints before the // .ctor completes we hold on to the current binder while the .ctor is executing. // If we change the handling of partial methods, so that partial methods are // completed lazily, the 'constraintClauseBinder' field should be removed. _constraintClauseBinder = withTypeParamsBinder; state.NotePartComplete(CompletionPart.StartMethodChecks); MethodChecks(syntax, withTypeParamsBinder, diagnostics); state.NotePartComplete(CompletionPart.FinishMethodChecks); _constraintClauseBinder = null; } }
private SourceMemberMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, Binder bodyBinder, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); // NOTE: by creating a WithMethodTypeParametersBinder, we are effectively duplicating the // functionality of the BinderFactory. Unfortunately, we cannot use the BinderFactory // because it depends on having access to the member list of our containing type and // that list cannot be complete because we're not finished constructing this member. // TODO: at least keep this in sync with BinderFactory.VisitMethodDeclaration. bodyBinder = bodyBinder.WithUnsafeRegionIfNecessary(modifiers); Binder withTypeParamsBinder; if (syntax.Arity == 0) { withTypeParamsBinder = bodyBinder; _typeParameters = ImmutableArray <TypeParameterSymbol> .Empty; } else { var parameterBinder = new WithMethodTypeParametersBinder(this, bodyBinder); withTypeParamsBinder = parameterBinder; _typeParameters = MakeTypeParameters(syntax, diagnostics); } bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } if (this.IsPartial) { // Partial methods must be completed early because they are matched up // by signature while producing the enclosing type's member list. However, // that means any type parameter constraints will be bound before the method // is added to the containing type. To enable binding of constraints before the // .ctor completes we hold on to the current binder while the .ctor is executing. // If we change the handling of partial methods, so that partial methods are // completed lazily, the 'constraintClauseBinder' field should be removed. _constraintClauseBinder = withTypeParamsBinder; state.NotePartComplete(CompletionPart.StartMethodChecks); MethodChecks(syntax, withTypeParamsBinder, diagnostics); state.NotePartComplete(CompletionPart.FinishMethodChecks); _constraintClauseBinder = null; } }
private IEnumerable<TypeParameterBuilder> MakeTypeParameterBuilders(MethodSymbol current) { if (SyntaxArity == 0) { return SpecializedCollections.EmptyEnumerable<TypeParameterBuilder>(); } var withParams = new WithMethodTypeParametersBinder(current, Next); return SyntaxTypeParameters .Select(ta => new TypeParameterBuilder(ta, current, withParams.Location(ta))); }