using System; using System.Collections.Generic; namespace AspClassic.Parser; /// /// A parse tree for a binary operator expression. /// public sealed class BinaryOperatorExpression : Expression { private readonly Expression _LeftOperand; private readonly OperatorType _Operator; private readonly Location _OperatorLocation; private readonly Expression _RightOperand; /// /// The left operand expression. /// public Expression LeftOperand => _LeftOperand; /// /// The operator. /// public OperatorType Operator => _Operator; /// /// The location of the operator. /// public Location OperatorLocation => _OperatorLocation; /// /// The right operand expression. /// public Expression RightOperand => _RightOperand; public override bool IsConstant => LeftOperand.IsConstant && RightOperand.IsConstant; /// /// Constructs a new parse tree for a binary operation. /// /// The left operand expression. /// The operator. /// The location of the operator. /// The right operand expression. /// The location of the parse tree. 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 childList) { Tree.AddChild(childList, LeftOperand); Tree.AddChild(childList, RightOperand); } }