using System.Collections.Immutable; using System.Diagnostics; namespace Microsoft.CodeAnalysis.CSharp; internal class BoundStatementList : BoundStatement { protected override ImmutableArray Children { get { if (base.Kind != BoundKind.StatementList && base.Kind != BoundKind.Scope) { return ImmutableArray.Empty; } return StaticCast.From(Statements); } } public ImmutableArray Statements { get; } public static BoundStatementList Synthesized(SyntaxNode syntax, params BoundStatement[] statements) { return Synthesized(syntax, hasErrors: false, ImmutableArrayExtensions.AsImmutableOrNull(statements)); } public static BoundStatementList Synthesized(SyntaxNode syntax, bool hasErrors, params BoundStatement[] statements) { return Synthesized(syntax, hasErrors, ImmutableArrayExtensions.AsImmutableOrNull(statements)); } public static BoundStatementList Synthesized(SyntaxNode syntax, ImmutableArray statements) { return Synthesized(syntax, hasErrors: false, statements); } public static BoundStatementList Synthesized(SyntaxNode syntax, bool hasErrors, ImmutableArray statements) { return new BoundStatementList(syntax, statements, hasErrors) { WasCompilerGenerated = true }; } protected BoundStatementList(BoundKind kind, SyntaxNode syntax, ImmutableArray statements, bool hasErrors = false) : base(kind, syntax, hasErrors) { Statements = statements; } public BoundStatementList(SyntaxNode syntax, ImmutableArray statements, bool hasErrors = false) : base(BoundKind.StatementList, syntax, hasErrors || statements.HasErrors()) { Statements = statements; } [DebuggerStepThrough] public override BoundNode? Accept(BoundTreeVisitor visitor) { return visitor.VisitStatementList(this); } public BoundStatementList Update(ImmutableArray statements) { if (statements != Statements) { BoundStatementList boundStatementList = new BoundStatementList(Syntax, statements, base.HasErrors); boundStatementList.CopyAttributes(this); return boundStatementList; } return this; } }