public override IVecValue VisitIfstmt([NotNull] VectorizeParser.IfstmtContext context) { var conds = context.expression(); var stmts = context.statement(); bool anyMatch = false; foreach (var(condition, statement) in conds.Zip(stmts, (c, s) => (condition: c, statement: s))) { bool value = ((VecBool)condition.Accept(this)).Value; if (value) { anyMatch = true; statement.Accept(this); break; } } if (!anyMatch && stmts.Length == conds.Length + 1) // is else present? { var elseBranch = stmts.Last(); elseBranch.Accept(this); } return(VecNull.Value); }
/// <summary> /// Exit a parse tree produced by <see cref="VectorizeParser.ifstmt"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitIfstmt([NotNull] VectorizeParser.IfstmtContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="VectorizeParser.ifstmt"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitIfstmt([NotNull] VectorizeParser.IfstmtContext context) { return(VisitChildren(context)); }