This commit is contained in:
Jelle Luteijn 2022-05-15 11:19:49 +02:00
parent 16e76d6b31
commit 484dbfc9d9
529 changed files with 113694 additions and 0 deletions

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for a binary operator expression.
/// </summary>
public sealed class BinaryOperatorExpression : Expression
{
private readonly Expression _LeftOperand;
private readonly OperatorType _Operator;
private readonly Location _OperatorLocation;
private readonly Expression _RightOperand;
/// <summary>
/// The left operand expression.
/// </summary>
public Expression LeftOperand => _LeftOperand;
/// <summary>
/// The operator.
/// </summary>
public OperatorType Operator => _Operator;
/// <summary>
/// The location of the operator.
/// </summary>
public Location OperatorLocation => _OperatorLocation;
/// <summary>
/// The right operand expression.
/// </summary>
public Expression RightOperand => _RightOperand;
public override bool IsConstant => LeftOperand.IsConstant && RightOperand.IsConstant;
/// <summary>
/// Constructs a new parse tree for a binary operation.
/// </summary>
/// <param name="leftOperand">The left operand expression.</param>
/// <param name="operator">The operator.</param>
/// <param name="operatorLocation">The location of the operator.</param>
/// <param name="rightOperand">The right operand expression.</param>
/// <param name="span">The location of the parse tree.</param>
public BinaryOperatorExpression(Expression leftOperand, OperatorType @operator, Location operatorLocation, Expression rightOperand, Span span)
: base(TreeType.BinaryOperatorExpression, span)
{
if (@operator < OperatorType.Plus || @operator > OperatorType.GreaterThanEquals)
{
throw new ArgumentOutOfRangeException("operator");
}
if (leftOperand == null)
{
throw new ArgumentNullException("leftOperand");
}
if (rightOperand == null)
{
throw new ArgumentNullException("rightOperand");
}
SetParent(leftOperand);
SetParent(rightOperand);
_LeftOperand = leftOperand;
_Operator = @operator;
_OperatorLocation = operatorLocation;
_RightOperand = rightOperand;
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, LeftOperand);
Tree.AddChild(childList, RightOperand);
}
}