Example #1
0
 public void VisitNode(IterationStatement node)
 {
     Console.Write("<" + node.ClassName() + ">: ");
     Console.ForegroundColor = ConsoleColor.Green;
     Console.Write("WHILE");
     Console.ResetColor();
     PrintAttribute(node);
 }
Example #2
0
        private void VisitNode(IterationStatement node)
        {
            AbstractNode cond_exp  = node.Child;
            AbstractNode body_stmt = cond_exp.Sib;

            ++_whileCount;
            File.WriteLine("br.s {0}{1}", WHILE_COND, _whileCount);
            File.WriteLine(WHILE_TRUE + _whileCount + ":");
            body_stmt.Accept(this);
            File.WriteLine(WHILE_COND + _whileCount + ":");
            cond_exp.Accept(this);
            File.WriteLine("brtrue.s {0}{1}", WHILE_TRUE, _whileCount);
        }
Example #3
0
        private void VisitNode(IterationStatement node)
        {
            AbstractNode whileExp = node.Child;
            AbstractNode bodyStmt = whileExp.Sib;

            IterationStatementDescriptor iterDesc =
                new IterationStatementDescriptor();

            // while expression
            whileExp.Accept(this);
            iterDesc.WhileDescriptor = whileExp.TypeDescriptor;
            PrimitiveTypeBooleanDescriptor whileBoolDesc =
                whileExp.TypeDescriptor as PrimitiveTypeBooleanDescriptor;

            if (whileBoolDesc == null)
            {
                iterDesc.TypeDescriptor = new ErrorDescriptor("If statement " +
                                                              "does not evaluate to a Boolean expression. (Has type: " +
                                                              GetSimpleName(whileExp.TypeDescriptor) + ")");
            }
            // if body stmt empty, infinite loop error
            bodyStmt.Accept(this);
            bodyStmt.TypeDescriptor = bodyStmt.Child.TypeDescriptor;
            iterDesc.BodyDescriptor = bodyStmt.TypeDescriptor;

            // propagate up errors as needed
            if (iterDesc.WhileDescriptor is ErrorDescriptor ||
                iterDesc.BodyDescriptor is ErrorDescriptor)
            {
                if (iterDesc.WhileDescriptor is ErrorDescriptor)
                {
                    iterDesc.TypeDescriptor = iterDesc.WhileDescriptor;
                    if (iterDesc.BodyDescriptor is ErrorDescriptor)
                    {
                        ((ErrorDescriptor)iterDesc.TypeDescriptor).CombineErrors(
                            (ErrorDescriptor)iterDesc.BodyDescriptor);
                    }
                }
                else
                {
                    iterDesc.TypeDescriptor = iterDesc.BodyDescriptor;
                }
            }
            // otherwise assign appropriate iteration statement descriptor
            else
            {
                iterDesc.TypeDescriptor = iterDesc.WhileDescriptor;
            }
            node.TypeDescriptor = iterDesc;
        }
Example #4
0
 private void VisitNode(IterationStatement node)
 {
     node.Accept(SemanticsVisitor);
 }