예제 #1
0
 public override Result Interpret(Context context)
 {
     context.ResultMessage += " Check text.";
     return(string.IsNullOrEmpty(context.Text)
         ? OnFalse.Interpret(context)
         : OnTrue.Interpret(context));
 }
예제 #2
0
 //Calls necessary observer methods when the value gets flatly added to
 public void setValue(float val)
 {
     if (val == 0)
     {
         return;
     }
     if (val > 0)
     {
         OnIncrement.Invoke(val);
     }
     else if (val < 0)
     {
         OnDecrement.Invoke(val);
     }
     value = val;
     OnChange.Invoke(val);
     if (ValueAsBool())
     {
         OnTrue.Invoke();
     }
     else
     {
         OnFalse.Invoke();
     }
 }
예제 #3
0
 public override Operation Coalesce()
 {
     Condition = (BooleanOperation)Condition.Coalesce();
     OnFalse   = (Block)OnFalse.Coalesce();
     OnTrue    = (Block)OnTrue.Coalesce();
     return(this);
 }
예제 #4
0
 public override Result Interpret(Context context)
 {
     context.ResultMessage += " Check above ten.";
     return(context.Value > 10
         ? OnTrue.Interpret(context)
         : OnFalse.Interpret(context));
 }
예제 #5
0
 public override Result Interpret(Context context)
 {
     context.ResultMessage += " Check if zero.";
     return((context.Value == 0)
         ? OnTrue.Interpret(context)
         : OnFalse.Interpret(context));
 }
        public override void GenerateCode(StringBuilder sb, int tabsOffset)
        {
            if (Attribute != null)
            {
                Attribute.GenerateCode(sb, tabsOffset);
            }
            sb.Append('\t', tabsOffset);
            sb.Append("if("); Condition.GenerateCode(sb, 0); sb.Append(')'); sb.AppendLine();

            int tabs = (OnTrue is BlockStatement) ? tabsOffset : tabsOffset + 1;

            OnTrue.GenerateCode(sb, tabs);
            sb.AppendLine();

            if (OnFalse != null)
            {
                sb.Append('\t', tabsOffset);
                sb.Append("else");

                tabs = (OnFalse is BlockStatement) ? tabsOffset : tabsOffset + 1;
                if (OnFalse is SelectionStatement)
                {
                    sb.Append(' ');
                }
                else
                {
                    sb.AppendLine();
                }
                OnFalse.GenerateCode(sb, tabs);
            }
        }
예제 #7
0
 public override void Build(IGraphBuilder builder)
 {
     //we already gave the proper links so just act as a forwarder
     Condition.Build(builder);
     OnTrue.Build(builder);
     OnFalse.Build(builder);
     //OnTrue and OnFalse
 }
 public override void GenerateCode(StringBuilder sb, int tabsOffset)
 {
     Condition.GenerateCode(sb, tabsOffset);
     sb.Append('?');
     OnTrue.GenerateCode(sb, 0);
     sb.Append(':');
     OnFalse.GenerateCode(sb, 0);
 }
예제 #9
0
        internal override Expression GetExpression(List <ParameterExpression> parameters, Dictionary <string, ConstantExpression> locals, List <DataContainer> dataContainers, Type dynamicContext, LabelTarget label)
        {
            CallSiteBinder binder = Binder.Convert(CSharpBinderFlags.None, typeof(bool), typeof(object));
            Expression     c      = Condition.GetExpression(parameters, locals, dataContainers, dynamicContext, label);
            Expression     t      = OnTrue.GetExpression(parameters, locals, dataContainers, dynamicContext, label);
            Expression     f      = OnFalse.GetExpression(parameters, locals, dataContainers, dynamicContext, label);

            return(Expression.Condition(Expression.Dynamic(binder, typeof(bool), c), Expression.Convert(t, typeof(object)), Expression.Convert(f, typeof(object))));
        }
예제 #10
0
 public override void InitialFulfill()
 {
     Condition.OnTrueHook = OnTrue.First();
     Condition.InitialFulfill();
     Condition.ResolveHooks(OnFalse.First());
     OnTrue.InitialFulfill();
     RegisterHook((x) => OnTrue.ResolveHooks(x));
     OnFalse.InitialFulfill();
     RegisterHook((x) => OnFalse.ResolveHooks(x));
 }
예제 #11
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("\t{0}\n", GetType().ToString());
            sb.AppendFormat("\t\t{0}\n", Condition.ToString());
            sb.AppendFormat("\t\t{0}\n", OnTrue.ToString());
            sb.AppendFormat("\t\t{0}", OnFalse.ToString());
            return(sb.ToString());
        }
 public override void CheckSemantic(Scope scope, ErrorLog log)
 {
     Condition.CheckSemantic(scope, log);
     if (!Condition.Type.Match(ShaderRuntime.Boolean))
     {
         log.Error("The condition is not or cant be converted to bool", Line, Column);
     }
     OnTrue.CheckSemantic(scope, log);
     OnFalse.CheckSemantic(scope, log);
     Type = OnTrue.Type;
 }
        public override IResultValue Evaluate()
        {
            IResultValue condition = Condition.Evaluate();

            if (condition.Type != MathType.Boolean)
            {
                throw new EvaluationException(this,
                                              "Condition part of conditional operator must be boolean.");
            }

            // See what I mean here?
            return(condition.ToBoolean() ? OnTrue.Evaluate() : OnFalse.Evaluate());
        }
예제 #14
0
 protected override void LLWrite(ICodeWriter writer, object o)
 {
     if (AddParentheses)
     {
         writer.Write('(', true);
     }
     Predicate.WriteAll(writer);
     writer.Write(" ? ", true);
     OnTrue.WriteAll(writer);
     writer.Write(" : ", true);
     OnFalse.WriteAll(writer);
     if (AddParentheses)
     {
         writer.Write(')', true);
     }
 }
예제 #15
0
        public object?ConvertBack(object?value, Type?targetType, object?parameter, CultureInfo culture)
        {
            if (value == OnNull)
            {
                return(Default(targetType));
            }
            if (value == OnFalse)
            {
                return(false);
            }
            if (value == OnTrue)
            {
                return(true);
            }
            if (value is null)
            {
                return(null);
            }

            if (OnNull is not null &&
                string.Equals(value.ToString(), OnNull.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                return(Default(targetType));
            }

            if (OnFalse is not null &&
                string.Equals(value.ToString(), OnFalse.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                return(false);
            }

            if (OnTrue is not null &&
                string.Equals(value.ToString(), OnTrue.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                return(true);
            }

            return(null);
        }
예제 #16
0
        public override void CheckSemantic(IASTContext context)
        {
            Condition.CheckSemantic(context);

            if (Condition.Type != ExpressionType.Bool)
            {
                throw new RecognitionException($"Expression at Line {Row} Col {Col} does not return boolean value");
            }

            OnTrue.CheckSemantic(context);

            OnFalse.CheckSemantic(context);

            type = ExpressionType.match(OnTrue.Type, OnFalse.Type);

            if (type == null)
            {
                throw new RecognitionException("Type mistmatch ", Col, Row);
            }

            NetType = OnTrue.NetType;
        }