Пример #1
0
        public UnifiedElement VisitWhileStatement(
            WhileStatement stmt, object data)
        {
            var cond = stmt.Condition.TryAcceptForExpression(this);
            var body = stmt.EmbeddedStatement.TryAcceptForExpression(this).ToBlock();

            return(UnifiedWhile.Create(cond, body));
        }
        public override bool Visit(UnifiedWhile element, VisitorArgument arg)
        {
            Writer.Write("while(");
            element.Condition.TryAccept(this, arg);
            Writer.Write(")");

            element.Body.TryAccept(this, arg.Set(ForBlock));
            return(false);
        }
Пример #3
0
        public static UnifiedExpression CreateIterationStatement(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "iteration_statement");

            /*
             * iteration_statement
             * : 'while' '(' expression ')' statement
             | 'do' statement 'while' '(' expression ')' ';'
             | 'for' '(' expression_statement expression_statement expression? ')' statement
             */

            var first = node.FirstElement().Value;
            var body  =
                UnifiedBlock.Create(
                    CreateStatement(node.FirstElement("statement")));

            switch (first)
            {
            case "while":
                return
                    (UnifiedWhile.Create(
                         CreateExpression(node.NthElement(2)).First(),
                         body));

            case "do":
                return
                    (UnifiedDoWhile.Create(
                         CreateExpression(node.NthElement(4)).First(),
                         body));

            case "for":
                var step = node.Element("expression") != null?
                           CreateExpression
                           (
                    node
                    .
                    FirstElement
                    (
                        "expression"))
                           .
                           First
                               ()
                               : null;

                return(UnifiedFor.Create(
                           CreateExpressionStatement(node.NthElement(2)),
                           CreateExpressionStatement(node.NthElement(3)),
                           step, body));

            default:
                throw new InvalidOperationException();
            }
        }
Пример #4
0
        private static UnifiedExpression CreateWhile(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "while");
            var cond       = CreateExpresion(node.FirstElement());
            var secondNode = node.NthElement(1);

            if (node.LastElement().Name() == "TrueClass")
            {
                return(UnifiedWhile.Create(cond, CreateSmartBlock(secondNode)));
            }
            return(UnifiedDoWhile.Create(cond, CreateSmartBlock(secondNode)));
        }
Пример #5
0
        public override bool Visit(UnifiedWhile element, VisitorArgument arg)
        {
            Writer.Write("while ");
            element.Condition.TryAccept(this, arg);
            Writer.WriteLine(":");

            element.Body.TryAccept(this, arg.IncrementDepth());
            if (!element.ElseBody.IsEmptyOrNull())
            {
                Writer.WriteLine("else:");
                element.ElseBody.TryAccept(this, arg.IncrementDepth());
            }
            return(false);
        }
Пример #6
0
        public static UnifiedExpression CreateUntil(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "until");
            var cond =
                UnifiedUnaryExpression.Create(
                    CreateExpresion(node.FirstElement()),
                    UnifiedUnaryOperator.Create(
                        "!", UnifiedUnaryOperatorKind.Not));
            var secondNode = node.NthElement(1);

            if (node.LastElement().Name() == "TrueClass")
            {
                return(UnifiedWhile.Create(cond, CreateSmartBlock(secondNode)));
            }
            return(UnifiedDoWhile.Create(cond, CreateSmartBlock(secondNode)));
        }
        public override bool Visit(UnifiedWhile element, VisitorArgument arg)
        {
            Writer.Write("while(");
            element.Condition.TryAccept(this, arg);
            Writer.Write(")");

            element.Body.TryAccept(this, arg.Set(ForBlock));
            return false;
        }
Пример #8
0
 public static Namespace GetNamespace(UnifiedWhile whileNode)
 {
     var type = NamespaceType.TemporaryScope;
     var parents =
             DetectorHelper.GetParentTypes(type).Select(
                     t => DetectorHelper.Namespace2UnifiedType(t));
     var parentNode = DetectorHelper.GetFirstFoundNode(
             whileNode, parents);
     return new Namespace {
             Value = "(while)",
             NamespaceType = type,
             Parent = Dispatcher(parentNode)
     };
 }
        public override bool Visit(UnifiedWhile element, VisitorArgument arg)
        {
            Writer.Write("while ");
            element.Condition.TryAccept(this, arg);
            Writer.WriteLine(":");

            element.Body.TryAccept(this, arg.IncrementDepth());
            if (!element.ElseBody.IsEmptyOrNull()) {
                Writer.WriteLine("else:");
                element.ElseBody.TryAccept(this, arg.IncrementDepth());
            }
            return false;
        }