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

82 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for an assignment statement.
/// </summary>
public sealed class AssignmentStatement : Statement
{
private readonly Expression _TargetExpression;
private readonly Location _OperatorLocation;
private readonly Expression _SourceExpression;
private readonly bool _IsSetStatement;
/// <summary>
/// The target of the assignment.
/// </summary>
public Expression TargetExpression => _TargetExpression;
/// <summary>
/// The location of the operator.
/// </summary>
public Location OperatorLocation => _OperatorLocation;
/// <summary>
/// The source of the assignment.
/// </summary>
public Expression SourceExpression => _SourceExpression;
public bool IsSetStatement => _IsSetStatement;
/// <summary>
/// Constructs a new parse tree for an assignment statement.
/// </summary>
/// <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>
/// <param name="isSetStatement">Whether is is a set statement</param>
public AssignmentStatement(Expression targetExpression, Location operatorLocation, Expression sourceExpression, Span span, IList<Comment> comments, bool isSetStatement)
: base(TreeType.AssignmentStatement, span, comments)
{
if (targetExpression == null)
{
throw new ArgumentNullException("targetExpression");
}
if (sourceExpression == null)
{
throw new ArgumentNullException("sourceExpression");
}
SetParent(targetExpression);
SetParent(sourceExpression);
_TargetExpression = targetExpression;
_OperatorLocation = operatorLocation;
_SourceExpression = sourceExpression;
_IsSetStatement = isSetStatement;
}
/// <summary>
/// Constructs a new parse tree for an assignment statement.
/// </summary>
/// <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 AssignmentStatement(Expression targetExpression, Location operatorLocation, Expression sourceExpression, Span span, IList<Comment> comments)
: this(targetExpression, operatorLocation, sourceExpression, span, comments, isSetStatement: false)
{
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, TargetExpression);
Tree.AddChild(childList, SourceExpression);
}
}