Beispiel #1
0
        public void VisitNode(Expr node)
        {
            Utilities.TypeVisitAllChildren(node);

            Attributes exprAttr = new Attributes("Expr");

            node.attrRef = exprAttr;

            ErrorTypeDescriptor ETD = new ErrorTypeDescriptor();

            switch (node.Name)
            {
            case "-":
            case "+":
            case "/":
            case "*":
            case "%":
            case "|":
            case "&":
            case "^":
                IntegerTypeDescriptor ITD = new IntegerTypeDescriptor();
                if (allChildrenAreInts(node) == true)
                {
                    exprAttr.typeInfo = ITD;
                }
                else
                {
                    exprAttr.typeInfo = ETD;
                }
                break;

            case "<":
            case ">":
            case "<=":
            case ">=":
            case "||":
            case "&&":
            case "==":
            case "!=":
                BooleanTypeDescriptor BTD = new BooleanTypeDescriptor();
                if (allChildrenAreSame(node) == true)
                {
                    exprAttr.typeInfo = BTD;
                }
                else
                {
                    exprAttr.typeInfo = ETD;
                }
                break;

            case null:
                ContainerTypeDescriptor CTD = new ContainerTypeDescriptor();
                exprAttr.typeInfo = CTD;

                break;
            }
        }
Beispiel #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();
        }
Beispiel #3
0
        public void VisitNode(MethodCall node)
        {
            Attributes a = new Attributes("MethodCall");
            MethodCallTypeDescriptor MTD = new MethodCallTypeDescriptor();
            ErrorTypeDescriptor      ETD = new ErrorTypeDescriptor();

            node.attrRef = a;

            /* --------------- Type Check Qualified Name and extract data -----------------*/
            // Get Name
            String name = GetMethCallName(node);

            /* ----------------------- Semantics Visit ArgList (if exists)--------------------------*/
            // Go to ArgList
            List <ArgList> argListChildren = Utilities.GetChildren(node, typeof(ArgList)).Cast <ArgList>().ToList();

            // If Args exist...
            if (argListChildren.Count > 0)
            {
                // Type check the argument Node
                argListChildren[0].Accept(this);
                // Record it in our type ref
                MTD.argsRoot = argListChildren[0];
            }


            /* ------------ Configure Attributes ----------------*/
            // Put the descriptor in the attributes structure
            a.typeInfo = MTD;

            /* --------- Configure Type Descriptor --------------*/
            MTD.name = name;
            Attributes attr = currentSymbolTable.lookup(name);

            // If method exists in symbol table
            if (attr != null)
            {
                MTD.returnType   = attr.typeInfo.returnType;
                MTD.nameSpaceVar = attr.typeInfo.nameSpaceVar;
                a.typeInfo       = MTD;
            }
            // Method not found in symbol table
            else
            {
                a.typeInfo = ETD;
            }

            // Decorate AST with attrRef
            node.attrRef = a;
        }
Beispiel #4
0
        public void VisitNode(Stmt node)
        {
            // Iteration statements handled here
            if (node.Name != null && node.Name.Contains("Iteration"))
            {
                // Dcl-Visit all children
                Utilities.DclVisitAllChildren(node, this);
                // We always have an expression
                // We always have a block

                Attributes a = new Attributes("IterationStmt");
                IterationStmtTypeDescriptor ITD = new IterationStmtTypeDescriptor();
                ITD.BlockNode     = null;
                ITD.ConditionNode = 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")
                {
                    a.typeInfo = ITD;
                }
                // Get all children
                AbstractNode an;
                an = node.Child;
                while (an != null)
                {
                    // Filter out all expr from this
                    if (an.NodeType.Name == "Expr")
                    {
                        ITD.ConditionNode = an;
                    }
                    if (an.NodeType.Name == "Block")
                    {
                        ITD.BlockNode = an;
                    }
                    an = an.Sib;
                }


                node.attrRef = a;

                //currentSymbolTable.decrNestLevel();
            }
        }