Example #1
0
        public override bool VisitStmtIfBase([NotNull] GamaParser.StmtIfBaseContext context)
        {
            var expr = VisitExpression(context.expr());

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

            if (expr.Type != InstanceTypes.Bool)
            {
                NamespaceContext.Context.AddError(new ErrorTypeMismatch(context.expr()));
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);

            var iftrue = Self.AddBlock("if.true");
            var ifend  = Self.AddBlock("if.end");

            Builder.BuildCondBr(expr.Value, iftrue.Block, ifend.Block);

            // Compile true block
            SetBlock(iftrue);
            Push();
            {
                Visit(context.block());
            }
            if (!iftrue.HasTerminator())
            {
                iftrue.PositionBuilderAtEnd(Builder);
                Builder.BuildBr(ifend.Block);
            }
            if (CurrentBlock != iftrue) /* Block nesting */
            {
                CurrentBlock.PositionBuilderAtEnd(Builder);
                Builder.BuildBr(ifend.Block);
            }
            Pop();
            SetBlock(ifend);

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