public Block BuildDocument(int indentation) { Paragraph p = new Paragraph(); p.Inlines.Add(new Run("if") { Foreground = StyleSettings.KeyWordColor }); p.Inlines.Add(" ("); p.Inlines.AddRange(CheckExpression.BuildDocument()); p.Inlines.Add(")"); Section s = new Section() { Margin = new Thickness(indentation, 0, 0, 0) }; s.Blocks.Add(p); s.Blocks.Add(IfTrueBody.BuildDocument(indentation)); s.Blocks.Add(new Paragraph(new Run("else") { Foreground = StyleSettings.KeyWordColor })); s.Blocks.Add(IfFalseBody.BuildDocument(indentation)); return(s); }
public void TypeCheck(ITypeEnvironment env) { if (!CheckExpression.TypeCheck(env).CompatibleWith(ExpressionType)) { env.ReportError("Unable to evaluate 'if/else'. Expression must be of type bool!", SourceStartPosition, SourceEndPosition); } IfTrueBody.TypeCheck(env); IfFalseBody.TypeCheck(env); }
public override bool Equals(object obj) { if (!(obj is IfElseStmnt)) { return(false); } IfElseStmnt other = (IfElseStmnt)obj; return(CheckExpression.Equals(other.CheckExpression) && IfTrueBody.Equals(other.IfTrueBody) && IfFalseBody.Equals(other.IfFalseBody)); }
public FrameworkElement BuildForm(IValueEnvironment vEnv, ITypeEnvironment tEnv) { ValueContainer value = CheckExpression.Evaluate(vEnv); FrameworkElement trueElem = IfTrueBody.BuildForm(vEnv, tEnv); FrameworkElement falseElem = IfFalseBody.BuildForm(vEnv, tEnv); Action onValueChanged = () => { bool boolValue = Convert.ToBoolean(value.Value); trueElem.Visibility = boolValue ? Visibility.Visible : Visibility.Collapsed; falseElem.Visibility = !boolValue ? Visibility.Visible : Visibility.Collapsed; }; value.ValueChanged += onValueChanged; onValueChanged(); StackPanel sp = new StackPanel(); sp.Children.Add(trueElem); sp.Children.Add(falseElem); return(sp); }
public override int GetHashCode() { return(CheckExpression.GetHashCode() ^ IfTrueBody.GetHashCode() ^ IfFalseBody.GetHashCode()); }