Пример #1
0
 public override MSAst TransformCore(ScriptGenerator generator)
 {
     return(MSAst.Condition(
                Test.Transform(generator),
                IfTrue.Transform(generator),
                IfFalse.Transform(generator)));
 }
Пример #2
0
 public override void Dump(SourceWriter sw, int indentChange)
 {
     Test.Dump(sw, indentChange);
     sw.Write(" ? ");
     IfTrue.Dump(sw, indentChange);
     sw.Write(" : ");
     IfFalse.Dump(sw, indentChange);
 }
        public override ICollection <Type> GetKnownTypes([Optional] Container container)
        {
            Console.WriteLine("Conditional Expression Node KnownType");

            var totalTypes = base.GetKnownTypes(container).Concat(new [] { this.GetType() })
                             .Concat(Test?.GetKnownTypes(container) ?? Enumerable.Empty <Type>())
                             .Concat(IfTrue?.GetKnownTypes(container) ?? Enumerable.Empty <Type>())
                             .Concat(IfFalse?.GetKnownTypes(container) ?? Enumerable.Empty <Type>())
                             .ToList();

            return(totalTypes);
        }
Пример #4
0
        public override double GetValue(double x, double y)
        {
            double a = SourceModule1.GetValue(x, y);
            double b = SourceModule2.GetValue(x, y);

            if (a != b)
            {
                return(IfTrue.GetValue(x, y));
            }

            return(IfFalse.GetValue(x, y));
        }
Пример #5
0
        public override double GetWrapped(double x, double y, int wrap)
        {
            double a = SourceModule1.GetWrapped(x, y, wrap);
            double b = SourceModule2.GetWrapped(x, y, wrap);

            if (a != b)
            {
                return(IfTrue.GetWrapped(x, y, wrap));
            }

            return(IfFalse.GetWrapped(x, y, wrap));
        }
Пример #6
0
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Read colour:
            UnityEngine.Color col1 = SourceModule1.GetColour(x, y);

            // Read colour:
            UnityEngine.Color col2 = SourceModule2.GetColour(x, y);

            // T:
            UnityEngine.Color t = IfTrue.GetColour(x, y);

            // False:
            UnityEngine.Color f = IfFalse.GetColour(x, y);

            // Pick:
            if (col1.r != col2.r)
            {
                col1.r = t.r;
            }
            else
            {
                col1.r = f.r;
            }

            if (col1.g != col2.g)
            {
                col1.g = t.g;
            }
            else
            {
                col1.g = f.g;
            }

            if (col1.b != col2.b)
            {
                col1.b = t.b;
            }
            else
            {
                col1.b = f.b;
            }

            if (col1.a != col2.a)
            {
                col1.a = t.a;
            }
            else
            {
                col1.a = f.a;
            }

            return(col1);
        }
Пример #7
0
 /// <summary>
 /// Builds a <see langword="string"/> representing the <see cref="Expression"/>.
 /// </summary>
 /// <param name="builder">A <see cref="System.Text.StringBuilder"/> to add the created <see langword="string"/>.</param>
 internal override void BuildString(StringBuilder builder)
 {
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     builder.Append("IIF(");
     Test.BuildString(builder);
     builder.Append(", ");
     IfTrue.BuildString(builder);
     builder.Append(", ");
     IfFalse.BuildString(builder);
     builder.Append(")");
 }
Пример #8
0
 /// <summary>
 /// 添加到表达式池
 /// </summary>
 internal override void pushPool()
 {
     Test.PushCountPool();
     Test = null;
     if (IfTrue != null)
     {
         IfTrue.PushCountPool();
         IfTrue = null;
     }
     if (Test != null)
     {
         IfFalse.PushCountPool();
         IfFalse = null;
     }
     typePool <ConditionalExpression> .PushNotNull(this);
 }
Пример #9
0
        /// <summary>
        /// 每次获取的结果极有可能不一样。
        /// </summary>
        public bool Assert(IfElseResult result)
        {
            IfElseResult r;

            try {
                var v = Condition?.Invoke() == Expect;
                if (v == true)
                {
                    try {
                        IfTrue?.Invoke();
                        r = IfElseResult.TC0;
                    } catch {
                        r = IfElseResult.TC1;
                    }
                }
                else
                {
                    try {
                        IfFalse?.Invoke();
                        r = IfElseResult.FC0;
                    } catch {
                        r = IfElseResult.FC1;
                    }
                }
            } catch {
                try {
                    if (IfError == null)
                    {
                        if (IfFalseAsIfError)
                        {
                            IfFalse?.Invoke();
                        }
                    }
                    else
                    {
                        IfError?.Invoke();
                    }
                    r = IfElseResult.E0;
                } catch {
                    r = IfElseResult.E1;
                }
            }
            return((r | result) == r);
        }
        public async Task <IReadOnlyList <OnCondition> > Select(SequenceContext context, CancellationToken cancel = default)
        {
            var dcState = context.GetState();

            var(eval, _) = Condition.TryGetValue(dcState);
            ITriggerSelector selector;

            if (eval)
            {
                selector = IfTrue;
                IfTrue.Initialize(_conditionals, _evaluate);
            }
            else
            {
                selector = IfFalse;
                IfFalse.Initialize(_conditionals, _evaluate);
            }

            return(await selector.Select(context, cancel).ConfigureAwait(false));
        }
Пример #11
0
        public override bool SatisfiesConstraint(T input)
        {
            var result = Operand.SatisfiesConstraint(input);

            if (result)
            {
                if (IfTrue != null)
                {
                    return(IfTrue.SatisfiesConstraint(input));
                }
            }
            else
            {
                if (IfFalse != null)
                {
                    return(IfFalse.SatisfiesConstraint(input));
                }
            }

            return(result);
        }
 /// <summary>
 /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public override bool Equals(object obj)
 {
     if (ReferenceEquals(this, obj))
     {
         return(true);
     }
     if (obj is TernaryOperatorNode tn)
     {
         if (!Condition.Equals(tn.Condition))
         {
             return(false);
         }
         if (!IfTrue.Equals(tn.IfTrue))
         {
             return(false);
         }
         if (!IfFalse.Equals(tn.IfFalse))
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
 public override Expression FromNode([Optional] Container container)
 {
     Console.WriteLine(NodeType);
     return(Expression.Condition(Test.FromNode(container), IfTrue.FromNode(container), IfFalse.FromNode(container), Type.FromNode()));
 }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode() => NodeType.GetHashCode() ^ Condition.GetHashCode() ^ (IfTrue.GetHashCode() * 13) ^ (IfFalse.GetHashCode() * 13 * 13);
Пример #15
0
 public override void SetChildrenScopes(KumaScope scope)
 {
     Test.SetScope(scope);
     IfTrue.SetScope(scope);
     IfFalse.SetScope(scope);
 }
Пример #16
0
        public override Expression DoResolve(ParseContext parseContext)
        {
            Test    = Test.Resolve(parseContext);
            IfTrue  = IfTrue.Resolve(parseContext);
            IfFalse = IfFalse.Resolve(parseContext);

            if (Test == null || IfTrue == null || IfFalse == null)
            {
                return(null);
            }

            ExpressionClass = ExpressionClass.Value;

            var trueType  = IfTrue.Type;
            var falseType = IfFalse.Type;

            Type = trueType;

            // First, if an implicit conversion exists from IfTrue to IfFalse, then the result type is of type IfFalse.Type
            if (!TypeManager.IsEqual(trueType, falseType))
            {
                var conv = ConvertExpression.MakeImplicitConversion(parseContext, IfTrue, falseType, Span);
                if (conv != null)
                {
                    // Check if both can convert implicitly to each other's type
                    Type = falseType;

                    if (ConvertExpression.MakeImplicitConversion(parseContext, IfFalse, trueType, Span) != null)
                    {
                        parseContext.ReportError(
                            CompilerErrors.ConditionalOperandsBothHaveImplicitConversions,
                            IfTrue.Span,
                            trueType,
                            falseType);

                        return(null);
                    }

                    IfTrue = conv;
                }
                else if ((conv = ConvertExpression.MakeImplicitConversion(parseContext, IfFalse, trueType, Span)) != null)
                {
                    IfFalse = conv;
                }
                else
                {
                    parseContext.ReportError(
                        CompilerErrors.ConditionalOperandsHaveNoImplicitConversion,
                        IfTrue.Span,
                        trueType,
                        falseType);

                    return(null);
                }
            }

            // Dead code optimalization
            var c = Test as ConstantExpression;

            if (c != null)
            {
                var isFalse = c.IsDefaultValue;

                parseContext.ReportError(
                    CompilerErrors.UnreachableExpression,
                    isFalse ? IfTrue.Span : IfFalse.Span);

                return(ReducedExpression.Create(isFalse ? IfFalse : IfTrue, this).Resolve(parseContext));
            }

            return(this);
        }
 /// <summary>
 /// Converts this instance to an expression.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public override Expression ToExpression(IExpressionContext context)
 {
     return(Expression.Condition(Test.ToExpression(context), IfTrue.ToExpression(context), IfFalse.ToExpression(context)));
 }
 public override ConditionalExpression DoToExpression()
 {
     return(Expression.Condition(Test.ToExpression(), IfTrue.ToExpression(), IfFalse.ToExpression()));
 }