public override String AttrPrint()
        {
            String retVal;

            if (Utilities.attrToType(this.attrRef) == "ErrorTypeDescriptor")
            {
                retVal = String.Format("\nType: {0} (check argument in this if-statement)", Utilities.attrToType(this.attrRef));
            }
            else
            {
                SelectionStmtTypeDescriptor SSTD = this.attrRef.typeInfo;
                retVal = String.Format("\nType: {0} (If-Statement) with valid boolean argument", Utilities.attrToType(this.attrRef));
                // If we have an else path
                if (SSTD.ElsePathNode != null)
                {
                    retVal += String.Format("\nStatement Type: {0}\nElse-Path Type: {1}", Utilities.attrToType(SSTD.StatementNode.attrRef), Utilities.attrToType(SSTD.ElsePathNode.attrRef));
                }
                else
                {
                    retVal += String.Format("\nStatement Type: {0} and No Else-Path", Utilities.attrToType(SSTD.StatementNode.attrRef));
                }
            }

            return(retVal);
        }
示例#2
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();
        }