aspclassic-core/AspClassic.Parser/ForEachBlockStatement.cs
Jelle Luteijn 484dbfc9d9 progress
2022-05-15 11:19:49 +02:00

92 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for a For Each statement.
/// </summary>
public sealed class ForEachBlockStatement : BlockStatement
{
private readonly Location _EachLocation;
private readonly Expression _ControlExpression;
private readonly VariableDeclarator _ControlVariableDeclarator;
private readonly Location _InLocation;
private readonly Expression _CollectionExpression;
private readonly NextStatement _NextStatement;
/// <summary>
/// The location of the 'Each'.
/// </summary>
public Location EachLocation => _EachLocation;
/// <summary>
/// The control expression.
/// </summary>
public Expression ControlExpression => _ControlExpression;
/// <summary>
/// The control variable declarator, if any.
/// </summary>
public VariableDeclarator ControlVariableDeclarator => _ControlVariableDeclarator;
/// <summary>
/// The location of the 'In'.
/// </summary>
public Location InLocation => _InLocation;
/// <summary>
/// The collection expression.
/// </summary>
public Expression CollectionExpression => _CollectionExpression;
/// <summary>
/// The Next statement, if any.
/// </summary>
public NextStatement NextStatement => _NextStatement;
/// <summary>
/// Constructs a new parse tree for a For Each statement.
/// </summary>
/// <param name="eachLocation">The location of the 'Each'.</param>
/// <param name="controlExpression">The control expression.</param>
/// <param name="controlVariableDeclarator">The control variable declarator, if any.</param>
/// <param name="inLocation">The location of the 'In'.</param>
/// <param name="collectionExpression">The collection expression.</param>
/// <param name="statements">The statements in the block.</param>
/// <param name="nextStatement">The Next statement, if any.</param>
/// <param name="span">The location of the parse tree.</param>
/// <param name="comments">The comments for the parse tree.</param>
public ForEachBlockStatement(Location eachLocation, Expression controlExpression, VariableDeclarator controlVariableDeclarator, Location inLocation, Expression collectionExpression, StatementCollection statements, NextStatement nextStatement, Span span, IList<Comment> comments)
: base(TreeType.ForEachBlockStatement, statements, span, comments)
{
if (controlExpression == null)
{
throw new ArgumentNullException("controlExpression");
}
SetParent(controlExpression);
SetParent(controlVariableDeclarator);
SetParent(collectionExpression);
SetParent(nextStatement);
_EachLocation = eachLocation;
_ControlExpression = controlExpression;
_ControlVariableDeclarator = controlVariableDeclarator;
_InLocation = inLocation;
_CollectionExpression = collectionExpression;
_NextStatement = nextStatement;
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, ControlExpression);
Tree.AddChild(childList, ControlVariableDeclarator);
Tree.AddChild(childList, CollectionExpression);
base.GetChildTrees(childList);
Tree.AddChild(childList, NextStatement);
}
}