示例#1
0
文件: ThirdPass.cs 项目: goric/cflat
        public override void VisitIfThenElse(ASTIfThenElse n)
        {
            CFlatType condType = CheckSubTree(n.Condition);

            if (condType is TypeBool)
            {
                CheckSubTree(n.Then);
                CheckSubTree(n.Else);
            }
            else
            {
                ReportError(n.Location, "If statement must evaluate to boolean. Got type '{0}'", TypeToFriendlyName(condType));
            }
        }
示例#2
0
        public override void VisitIfThenElse(ASTIfThenElse n)
        {
            Label elseLabel = _gen.DefineLabel();
            Label jumpOver  = _gen.DefineLabel();

            //check condition
            n.Condition.Visit(this);

            //go to else on false
            _gen.Emit(OpCodes.Brfalse, elseLabel);

            //walk if
            n.Then.Visit(this);
            _gen.Emit(OpCodes.Br, jumpOver);

            //transfer control here, then walk else body
            _gen.MarkLabel(elseLabel);
            //walk else statments
            n.Else.Visit(this);

            _gen.MarkLabel(jumpOver);
        }