private BoundExpression Negate(BoundExpression condition) { if (condition is BoundLiteralExpression literal) { var value = (bool)literal.Value; return(new BoundLiteralExpression((byte)(!value ? 1 : 0), literal.Type)); } var unaryOperator = BoundUnaryOperator.Bind(SyntaxKind.BangToken, condition.Type); return(new BoundUnaryExpression(unaryOperator, condition)); }
public static BoundConstant?Fold(BoundUnaryOperator op, BoundExpression operand) { if (operand.ConstantValue?.Value != null) { return(op.Kind switch { BoundUnaryOperatorKind.Identity => new BoundConstant(operand.ConstantValue.Value switch { char i => i, sbyte i => i, short i => i, int i => i, long i => i, byte i => i, ushort i => i, uint i => i, ulong i => i, float i => i, double i => i, decimal i => i, _ => throw new Exception("Unexpected type") }),
public BoundUnaryExpression(BoundUnaryOperator op, BoundExpression operand) { Op = op; Operand = operand; }