Beispiel #1
0
            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));
            }
Beispiel #2
0
 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")
             }),
Beispiel #3
0
 public BoundUnaryExpression(BoundUnaryOperator op, BoundExpression operand)
 {
     Op      = op;
     Operand = operand;
 }