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

76 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for a compound assignment statement.
/// </summary>
public sealed class CompoundAssignmentStatement : Statement
{
private readonly Expression _TargetExpression;
private readonly OperatorType _CompoundOperator;
private readonly Location _OperatorLocation;
private readonly Expression _SourceExpression;
/// <summary>
/// The target of the assignment.
/// </summary>
public Expression TargetExpression => _TargetExpression;
/// <summary>
/// The compound operator.
/// </summary>
public OperatorType CompoundOperator => _CompoundOperator;
/// <summary>
/// The location of the operator.
/// </summary>
public Location OperatorLocation => _OperatorLocation;
/// <summary>
/// The source of the assignment.
/// </summary>
public Expression SourceExpression => _SourceExpression;
/// <summary>
/// Constructs a new parse tree for a compound assignment statement.
/// </summary>
/// <param name="compoundOperator">The compound operator.</param>
/// <param name="targetExpression">The target of the assignment.</param>
/// <param name="operatorLocation">The location of the operator.</param>
/// <param name="sourceExpression">The source of the assignment.</param>
/// <param name="span">The location of the parse tree.</param>
/// <param name="comments">The comments for the parse tree.</param>
public CompoundAssignmentStatement(OperatorType compoundOperator, Expression targetExpression, Location operatorLocation, Expression sourceExpression, Span span, IList<Comment> comments)
: base(TreeType.CompoundAssignmentStatement, span, comments)
{
if (compoundOperator < OperatorType.Plus || compoundOperator > OperatorType.Power)
{
throw new ArgumentOutOfRangeException("compoundOperator");
}
if (targetExpression == null)
{
throw new ArgumentNullException("targetExpression");
}
if (sourceExpression == null)
{
throw new ArgumentNullException("sourceExpression");
}
SetParent(targetExpression);
SetParent(sourceExpression);
_CompoundOperator = compoundOperator;
_TargetExpression = targetExpression;
_OperatorLocation = operatorLocation;
_SourceExpression = sourceExpression;
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, TargetExpression);
Tree.AddChild(childList, SourceExpression);
}
}