| File: Binder\BlockBinder.cs | Web Access |
| Project: src\roslyn\src\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj (Microsoft.CodeAnalysis.CSharp) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System; using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp { internal sealed class BlockBinder : LocalScopeBinder { private readonly BlockSyntax _block; public BlockBinder(Binder enclosing, BlockSyntax block) : this(enclosing, block, enclosing.Flags) { } public BlockBinder(Binder enclosing, BlockSyntax block, BinderFlags additionalFlags) : base(enclosing, enclosing.Flags | additionalFlags) { Debug.Assert(block != null); _block = block; } protected override ImmutableArray<LocalSymbol> BuildLocals() { return BuildLocals(_block.Statements, this); } protected override ImmutableArray<LocalFunctionSymbol> BuildLocalFunctions() { return BuildLocalFunctions(_block.Statements); } internal override bool IsLocalFunctionsScopeBinder { get { return true; } } protected override ImmutableArray<LabelSymbol> BuildLabels() { ArrayBuilder<LabelSymbol> labels = null; base.BuildLabels(_block.Statements, ref labels); return (labels != null) ? labels.ToImmutableAndFree() : ImmutableArray<LabelSymbol>.Empty; } internal override bool IsLabelsScopeBinder { get { return true; } } internal override ImmutableArray<LocalSymbol> GetDeclaredLocalsForScope(SyntaxNode scopeDesignator) { if (ScopeDesignator == scopeDesignator) { return this.Locals; } throw ExceptionUtilities.Unreachable(); } internal override SyntaxNode ScopeDesignator { get { return _block; } } internal override ImmutableArray<LocalFunctionSymbol> GetDeclaredLocalFunctionsForScope(CSharpSyntaxNode scopeDesignator) { if (ScopeDesignator == scopeDesignator) { return this.LocalFunctions; } throw ExceptionUtilities.Unreachable(); } } }