Beispiel #1
0
        public override AstNode Visit(DoWhileStatement node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Get the condition and the job.
            Expression cond = node.GetCondition();
            AstNode job = node.GetJob();

            // Create the basic blocks.
            BasicBlock condBlock = CreateBasicBlock();
            BasicBlock contentBlock = CreateBasicBlock();
            BasicBlock endBlock = CreateBasicBlock();

            // Set the blocks names.
            condBlock.SetName("cond");
            contentBlock.SetName("content");
            endBlock.SetName("end");

            // Store the old break and continue.
            BasicBlock oldBreak = currentBreak;
            BasicBlock oldContinue = currentContinue;

            // Set the new break and continue.
            currentBreak = endBlock;
            currentContinue = condBlock;

            // Branch into the content.
            builder.CreateJmp(contentBlock);

            // Write the content.
            builder.SetBlock(contentBlock);
            job.Accept(this);

            // Branch into the condition.
            if(!builder.IsLastTerminator())
                builder.CreateJmp(condBlock);

            // Write the condition.
            builder.SetBlock(condBlock);
            cond.Accept(this);

            // Cast the condition.
            IChelaType condType = cond.GetNodeType();
            if(condType != ChelaType.GetBoolType())
                Cast(node, cond.GetNodeValue(), condType, ChelaType.GetBoolType());

            // Close the loop.
            builder.CreateBr(contentBlock, endBlock);

            // Continue with the normal flow.
            builder.SetBlock(endBlock);

            // Restore the break and continue blocks.
            currentBreak = oldBreak;
            currentContinue = oldContinue;

            return builder.EndNode();
        }
Beispiel #2
0
        public override AstNode Visit(DoWhileStatement node)
        {
            // Visit children.
            VisitList(node.GetJob());

            return node;
        }
Beispiel #3
0
        public override AstNode Visit(DoWhileStatement node)
        {
            // Get the condition and the job.
            Expression condition = node.GetCondition();
            AstNode job = node.GetJob();

            // Visit the condition and the job.
            condition.Accept(this);
            job.Accept(this);

            // Check the condition type.
            IChelaType condType = condition.GetNodeType();
            if(condType != ChelaType.GetBoolType() &&
               Coerce(condType, ChelaType.GetBoolType()) != ChelaType.GetBoolType())
                Error(node, "condition must be a boolean expression.");

            return node;
        }