Пример #1
0
        public static Expression TransformNullOpToConditionalOp(this NullOp s, Essentials types, Namescope scope)
        {
            // a ?? b -> (temp = a, temp != null ? temp : b)
            //   OR   -> a != null ? a : b

            var left  = s.Left;
            var right = s.Right;
            var ind   = TryCreateIndirection(scope, ref left);

            var cond   = new ReferenceOp(s.Source, types.Bool, EqualityType.NotEqual, left, new Constant(s.Source, left.ReturnType, null));
            var result = new ConditionalOp(s.Source, cond, left, right);

            return(ind != null
                ? (Expression) new SequenceOp(ind, result)
                : result);
        }
Пример #2
0
        public virtual void WriteReferenceOp(ReferenceOp s, ExpressionUsage u)
        {
            Begin(u);
            WriteExpression(s.Left, ExpressionUsage.Operand);

            switch (s.EqualityType)
            {
            case EqualityType.Equal:
                Write(Equals);
                break;

            case EqualityType.NotEqual:
                Write(NotEquals);
                break;

            default:
                throw new SourceException(s.Source, "Invalid EqualityType: " + s.EqualityType);
            }

            WriteExpression(s.Right, ExpressionUsage.Operand);
            End(u);
        }