예제 #1
0
        public override bool VisitStmtWhileBase([NotNull] GamaParser.StmtWhileBaseContext context)
        {
            var wlecontrol = Self.AddBlock("while.if");
            var wleblock   = Self.AddBlock("while.loop");
            var wleend     = Self.AddBlock("while.end");

            CurrentBlock.PositionBuilderAtEnd(Builder);
            Builder.BuildBr(wlecontrol.Block);

            SetBlock(wlecontrol);
            CurrentBlock.PositionBuilderAtEnd(Builder);
            var expr = VisitExpression(context.expr());

            if (expr == null)
            {
                return(false);
            }

            if (expr.Type != InstanceTypes.Bool)
            {
                NamespaceContext.Context.AddError(new ErrorTypeMismatch(context.expr()));
                return(false);
            }
            Builder.BuildCondBr(expr.Value, wleblock.Block, wleend.Block);

            SetBlock(wleblock);
            Push();
            {
                Visit(context.block());
            }
            if (!wleblock.HasTerminator())
            {
                wleblock.PositionBuilderAtEnd(Builder);
                Builder.BuildBr(wlecontrol.Block);
            }
            if (CurrentBlock != wleblock) /* Block nesting */
            {
                CurrentBlock.PositionBuilderAtEnd(Builder);
                Builder.BuildBr(wlecontrol.Block);
            }
            Pop();
            if (wleend != CurrentBlock)
            {
                if (!CurrentBlock.HasTerminator())
                {
                    CurrentBlock.PositionBuilderAtEnd(Builder);
                    Builder.BuildBr(wleend.Block);
                }
            }
            SetBlock(wleend);

            return(true);
        }
예제 #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>StmtWhileBase</c>
 /// labeled alternative in <see cref="GamaParser.stmtWhile"/>.
 /// <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 VisitStmtWhileBase([NotNull] GamaParser.StmtWhileBaseContext context)
 {
     return(VisitChildren(context));
 }
예제 #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>StmtWhileBase</c>
 /// labeled alternative in <see cref="GamaParser.stmtWhile"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitStmtWhileBase([NotNull] GamaParser.StmtWhileBaseContext context)
 {
 }