Пример #1
0
        private IfStmt ParseIfStatement()
        {
            Match(TokenType.KwIf);
            IfStmt statement = new IfStmt(AcceptedToken);

            statement.TestExpr = ParseExpression();
            Match(TokenType.KwThen);
            statement.TrueStatement = ParseStatement();
            if (Accept(TokenType.KwElse))
            {
                statement.FalseStatement = ParseStatement();
            }
            return(statement);
        }
Пример #2
0
        private void Visit(IfStmt ifStmt)
        {
            Visit((dynamic)ifStmt.TestExpr);
            TypeInfo testType = TypeStack.Pop();

            if (IsNotVoid(testType) && testType.BasicType != ExprType.Bool)
            {
                AddError("If test expression has to be of type Bool", ifStmt);
            }
            Visit((dynamic)ifStmt.TrueStatement);
            if (ifStmt.FalseStatement != null)
            {
                Visit((dynamic)ifStmt.FalseStatement);
            }
        }
Пример #3
0
        private void Visit(IfStmt ifStmt)
        {
            var il       = CurrentMethodIL;
            var falseLbl = il.DefineLabel();
            var doneLbl  = il.DefineLabel();

            Visit((dynamic)ifStmt.TestExpr);
            il.Emit(OpCodes.Brfalse, falseLbl);
            Visit((dynamic)ifStmt.TrueStatement);
            il.Emit(OpCodes.Br, doneLbl);
            il.MarkLabel(falseLbl);
            if (ifStmt.FalseStatement != null)
            {
                Visit((dynamic)ifStmt.FalseStatement);
            }
            else
            {
                il.Emit(OpCodes.Nop);
            }
            il.MarkLabel(doneLbl);
        }