Example #1
0
        public override void Visit(AST_kary node)
        {
            int children = node.NumChildren;

            switch (node.Tag)
            {
            case NodeType.UsingList:
                for (int i = 0; i < children; i++)
                {
                    if (((AST_leaf)node[i]).Sval != "CbRuntime")
                    {
                        ReportError(node[0].LineNumber, "Invalid using identifier: '{0}' (only allowed identifier is CbRuntime)", ((AST_leaf)node[i]).Sval);
                    }
                }
                break;

            case NodeType.DeclList:
                for (int i = 0; i < children; i++)
                {
                    node[i].Accept(this);
                }
                break;

            case NodeType.FieldList:
                // already handled by prePass
                break;

            case NodeType.IdList:
                // already handled in NodeType.LocalDecl
                break;

            case NodeType.Formals:
                // visit all statements
                for (int i = 0; i < children; i++)
                {
                    node[i].Accept(this);
                }
                break;

            case NodeType.Block:
                // change scope
                localSymbols.Enter();

                // accept all statements
                for (int i = 0; i < children; i++)
                {
                    node[i].Accept(this);
                }

                // change scope
                localSymbols.Exit();
                break;

            case NodeType.Actuals:
                node.Type = CbType.Void;
                // visit all parameters
                for (int i = 0; i < children; i++)
                {
                    node[i].Accept(this);
                    if (node[i].Type == CbType.Error)
                    {
                        node.Type = CbType.Error;
                    }
                }
                break;

            case NodeType.Return:
                node.Type = CbType.Void;
                if (node.NumChildren > 0)
                {
                    node[0].Accept(this);
                    node.Type = node[0].Type;
                }
                break;

            default:
                throw new Exception("{0} is not a tag compatible with an AST_kary node");
            }
        }