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

38 lines
1.1 KiB
C#

#define DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for an expression that has an operand.
/// </summary>
public abstract class UnaryExpression : Expression
{
private readonly Expression _Operand;
/// <summary>
/// The operand of the expression.
/// </summary>
public Expression Operand => _Operand;
public override bool IsConstant => Operand.IsConstant;
protected UnaryExpression(TreeType type, Expression operand, Span span)
: base(type, span)
{
Debug.Assert(type == TreeType.ParentheticalExpression || type == TreeType.TypeOfExpression || type == TreeType.CTypeExpression || type == TreeType.DirectCastExpression || type == TreeType.TryCastExpression || type == TreeType.IntrinsicCastExpression || (type >= TreeType.UnaryOperatorExpression && type <= TreeType.AddressOfExpression));
if (operand == null)
{
throw new ArgumentNullException("operand");
}
SetParent(operand);
_Operand = operand;
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, Operand);
}
}