예제 #1
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     WriteIndented("unless ");
     Switch(node.Condition);
     WriteLine(":");
     Switch(node.Block);
 }
예제 #2
0
        public static Statement MapStatementModifier(StatementModifier modifier, out Block block)
        {
            switch (modifier.Type)
            {
            case StatementModifierType.If:
            {
                IfStatement stmt = new IfStatement(modifier.LexicalInfo);
                stmt.Condition = modifier.Condition;
                stmt.TrueBlock = new Block();
                block          = stmt.TrueBlock;
                return(stmt);
            }

            case StatementModifierType.Unless:
            {
                UnlessStatement stmt = new UnlessStatement(modifier.LexicalInfo);
                stmt.Condition = modifier.Condition;
                block          = stmt.Block;
                return(stmt);
            }

            case StatementModifierType.While:
            {
                WhileStatement stmt = new WhileStatement(modifier.LexicalInfo);
                stmt.Condition = modifier.Condition;
                block          = stmt.Block;
                return(stmt);
            }
            }
            throw CompilerErrorFactory.NotImplemented(modifier, string.Format("modifier {0} supported", modifier.Type));
        }
예제 #3
0
        public override Statement Expand(MacroStatement macro)
        {
            int argc = macro.Arguments.Count;

            if (argc != 1 && argc != 2)
            {
                // TODO: localize this message
                throw new System.ArgumentException(
                          Boo.Lang.ResourceManager.Format("AssertArgCount", argc));
            }

            // figure out the msg for the exception
            Expression condition = macro.Arguments[0];
            Expression message   = (argc == 1) ?
                                   new StringLiteralExpression(
                condition.LexicalInfo, condition.ToString()) :
                                   macro.Arguments[1];

            // unless <condition>:
            //     raise Boo.AssertionFailedException(<msg>)
            UnlessStatement stmt = new UnlessStatement(macro.LexicalInfo);

            stmt.Condition = condition;
            stmt.Block     = new Block(macro.LexicalInfo);

            RaiseStatement raise = new RaiseStatement(macro.LexicalInfo);

            raise.Exception =
                AstUtil.CreateMethodInvocationExpression(ExceptionTypeReference, message);
            stmt.Block.Add(raise);

            return(stmt);
        }
예제 #4
0
        public override void Switch(IAstTransformer transformer, out Node resultingNode)
        {
            UnlessStatement thisNode           = (UnlessStatement)this;
            Statement       resultingTypedNode = thisNode;

            transformer.OnUnlessStatement(thisNode, ref resultingTypedNode);
            resultingNode = resultingTypedNode;
        }
        public async Task IfCanProcessWhenFalse()
        {
            var e = new UnlessStatement(
                FALSE,
                new[] { new TextStatement("x") }
                );

            var sw = new StringWriter();
            await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());

            Assert.Equal("x", sw.ToString());
        }
        public async Task UnlessDoesntProcessWhenTrue()
        {
            var e = new UnlessStatement(
                TRUE,
                new[] { new TextStatement("x") }
                );

            var sw = new StringWriter();
            await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());

            Assert.Equal("", sw.ToString());
        }
예제 #7
0
        public async Task UnlessShouldProcessElseWhenFalse()
        {
            var e = new UnlessStatement(
                FALSE,
                new List <Statement> {
                new TextSpanStatement("x")
            },
                new ElseStatement(new List <Statement> {
                new TextSpanStatement("y")
            }));

            var sw = new StringWriter();
            await e.WriteToAsync(sw, HtmlEncoder.Default, new TemplateContext());

            Assert.Equal("x", sw.ToString());
        }
예제 #8
0
 override public void OnUnlessStatement(UnlessStatement node)
 {
     WriteConditionalBlock("unless", node.Condition, node.Block);
 }
 public override void OnUnlessStatement(UnlessStatement node)
 {
 }
예제 #10
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     base.OnUnlessStatement(node);
     node.Condition = FixCondition(node.Condition);
 }
예제 #11
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     throw new NotImplementedException();
 }
예제 #12
0
        private void CreateMoveNext()
        {
            BooMethodBuilder method = _enumerator.AddVirtualMethod("MoveNext", TypeSystemServices.BoolType);

            Expression moveNext = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateReference((InternalField)_enumeratorField.Entity),
                TypeSystemServices.Map(Methods.InstanceFunctionOf <IEnumerator, bool>(e => e.MoveNext)));

            Expression current = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateReference((InternalField)_enumeratorField.Entity),
                ((IProperty)GetMember(_sourceEnumeratorType, "Current", EntityType.Property)).GetGetMethod());

            Statement filter = null;
            Statement stmt;
            Block     outerBlock;
            Block     innerBlock;

            if (null == _generator.Filter)
            {
                IfStatement istmt = new IfStatement(moveNext, new Block(), null);
                outerBlock = innerBlock = istmt.TrueBlock;

                stmt = istmt;
            }
            else
            {
                WhileStatement wstmt = new WhileStatement(moveNext);
                outerBlock = wstmt.Block;

                if (StatementModifierType.If == _generator.Filter.Type)
                {
                    IfStatement ifstmt = new IfStatement(_generator.Filter.Condition, new Block(), null);
                    innerBlock = ifstmt.TrueBlock;
                    filter     = ifstmt;
                }
                else
                {
                    UnlessStatement ustmt = new UnlessStatement(_generator.Filter.Condition);
                    innerBlock = ustmt.Block;
                    filter     = ustmt;
                }

                stmt = wstmt;
            }

            DeclarationCollection declarations = _generator.Declarations;

            if (declarations.Count > 1)
            {
                NormalizeIterationStatements.UnpackExpression(CodeBuilder,
                                                              method.Method,
                                                              outerBlock,
                                                              current,
                                                              declarations);

                foreach (Declaration declaration in declarations)
                {
                    method.Locals.Add(((InternalLocal)declaration.Entity).Local);
                }
            }
            else
            {
                InternalLocal local = (InternalLocal)declarations[0].Entity;
                method.Locals.Add(local.Local);
                outerBlock.Add(CodeBuilder.CreateAssignment(
                                   CodeBuilder.CreateReference(local),
                                   current));
            }

            if (null != filter)
            {
                outerBlock.Add(filter);
            }

            innerBlock.Add(CodeBuilder.CreateAssignment(
                               CodeBuilder.CreateReference((InternalField)_current.Entity),
                               _generator.Expression));
            innerBlock.Add(new ReturnStatement(new BoolLiteralExpression(true)));

            method.Body.Add(stmt);
            method.Body.Add(new ReturnStatement(new BoolLiteralExpression(false)));
        }
 override public void LeaveUnlessStatement(UnlessStatement node)
 {
     node.Condition = AssertBoolContext(node.Condition);
 }
예제 #14
0
 override public void LeaveUnlessStatement(UnlessStatement node)
 {
     OnStatement(node);
 }
예제 #15
0
 public override void LeaveUnlessStatement(UnlessStatement node)
 {
     CheckNotConstant(node.Condition);
 }
예제 #16
0
 public override void OnUnlessStatement(UnlessStatement node)
 {
     base.OnUnlessStatement(node);
     Check(node);
 }