public override Result Interpret(Context context) { context.ResultMessage += " Check text."; return(string.IsNullOrEmpty(context.Text) ? OnFalse.Interpret(context) : OnTrue.Interpret(context)); }
//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(); } }
public override Operation Coalesce() { Condition = (BooleanOperation)Condition.Coalesce(); OnFalse = (Block)OnFalse.Coalesce(); OnTrue = (Block)OnTrue.Coalesce(); return(this); }
public override Result Interpret(Context context) { context.ResultMessage += " Check above ten."; return(context.Value > 10 ? OnTrue.Interpret(context) : OnFalse.Interpret(context)); }
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); } }
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); }
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)))); }
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)); }
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()); }
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); } }
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); }
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; }