Beispiel #1
0
        public void VisitNode(SelectionStmt node)
        {
            //currentSymbolTable.incrNestLevel();
            // Dcl-Visit all children
            Utilities.DclVisitAllChildren(node, this);
            // We always have an expression
            // We always have a statement
            // We sometimes have an else statement

            Attributes a = new Attributes("SelectionStmt");
            SelectionStmtTypeDescriptor STD = new SelectionStmtTypeDescriptor();

            STD.StatementNode = null;
            STD.ElsePathNode  = null;
            STD.StatementNode = null;
            ErrorTypeDescriptor ETD = new ErrorTypeDescriptor();

            // If our expression is a boolean, we are valid
            a.typeInfo = ETD;
            List <Expr> matchingChildren = Utilities.GetChildren(node, typeof(Expr)).Cast <Expr>().ToList();

            if (Utilities.attrToType(matchingChildren[0].attrRef) == "BooleanTypeDescriptor")
            {
                STD.StatementNode = matchingChildren[0];
                a.typeInfo        = STD;
            }
            // Get all children
            AbstractNode an;

            an = node.Child;
            while (an != null)
            {
                // Filter out all expr from this
                if (Utilities.attrToType(an.attrRef) != "BooleanTypeDescriptor")
                {
                    // Add the else to the else in the type descp
                    if (an.Name != null && an.Name.Contains("Else"))
                    {
                        STD.ElsePathNode = an;
                    }
                    else
                    {
                        STD.StatementNode = an;
                    }
                }
                an = an.Sib;
            }


            node.attrRef = a;

            //currentSymbolTable.decrNestLevel();
        }
        protected void VisitNode(SelectionStmt node)
        {
            // Visit boolean EXPR
            Utilities.VisitSpecificChild(node, typeof(Expr), this);
            InsertIntoFile("brfalse.s\t\t" + Label(labelNumber) + "\n");

            // Visit Then Clause
            Utilities.VisitThenChildren(node, this);
            InsertIntoFile("br.s\t\t" + Label(labelNumber + 1) + "\n");
            InsertIntoFile(Label((labelNumber)) + ":\t\t nop\n");

            // Visit Else Clause
            Utilities.VisitElseChildren(node, this);
            InsertIntoFile(Label(labelNumber + 1) + ":\t\t nop\n");
            labelNumber += 2;
        }
Beispiel #3
0
        internal static void VisitThenChildren(SelectionStmt node, CodeGenVisitor codeGenVisitor)
        {
            AbstractNode an;

            an = node.Child;
            while (an != null)
            {
                if (an.Name == null || !an.Name.Contains("Else"))
                {
                    if (an.GetType() != typeof(Expr))
                    {
                        an.Accept(codeGenVisitor);
                    }
                }

                if (an.Sib != an)
                {
                    an = an.Sib;
                }
            }
        }