QilScopedVisitor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / QIL / QilScopedVisitor.cs / 1305376 / QilScopedVisitor.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
using System; 
using System.Collections.Generic; 

namespace System.Xml.Xsl.Qil { 

    /// 
    /// Adds iterator and function scoping to the QilVisitor implementation.
    ///  
    internal class QilScopedVisitor : QilVisitor {
 
        //----------------------------------------------- 
        // QilScopedVisitor methods
        //----------------------------------------------- 

        /// 
        /// Called when a variable, parameter, or function enters scope.
        ///  
        protected virtual void BeginScope(QilNode node) {
        } 
 
        /// 
        /// Called when a variable, parameter, or function exits scope. 
        /// 
        protected virtual void EndScope(QilNode node) {
        }
 
        /// 
        /// Called at the beginning of Visit(). 
        ///  
        protected virtual void BeforeVisit(QilNode node) {
            QilExpression qil; 

            switch (node.NodeType) {
                case QilNodeType.QilExpression:
                    // Put all global functions, variables, and parameters in scope 
                    qil = (QilExpression) node;
                    foreach (QilNode param in qil.GlobalParameterList) BeginScope(param); 
                    foreach (QilNode var in qil.GlobalVariableList) BeginScope(var); 
                    foreach (QilNode func in qil.FunctionList) BeginScope(func);
                    break; 

                case QilNodeType.Function:
                    // Put all formal arguments in scope
                    foreach (QilNode arg in ((QilFunction) node).Arguments) BeginScope(arg); 
                    break;
 
                case QilNodeType.Loop: 
                case QilNodeType.Filter:
                case QilNodeType.Sort: 
                    // Put loop iterator in scope
                    BeginScope(((QilLoop) node).Variable);
                    break;
            } 
        }
 
        ///  
        /// Called at the end of Visit().
        ///  
        protected virtual void AfterVisit(QilNode node) {
            QilExpression qil;

            switch (node.NodeType) { 
                case QilNodeType.QilExpression:
                    // Remove all global functions, variables, and parameters from scope 
                    qil = (QilExpression) node; 
                    foreach (QilNode func in qil.FunctionList) EndScope(func);
                    foreach (QilNode var in qil.GlobalVariableList) EndScope(var); 
                    foreach (QilNode param in qil.GlobalParameterList) EndScope(param);
                    break;

                case QilNodeType.Function: 
                    // Remove all formal arguments from scope
                    foreach (QilNode arg in ((QilFunction) node).Arguments) EndScope(arg); 
                    break; 

                case QilNodeType.Loop: 
                case QilNodeType.Filter:
                case QilNodeType.Sort:
                    // Remove loop iterator in scope
                    EndScope(((QilLoop) node).Variable); 
                    break;
            } 
        } 

 
        //-----------------------------------------------
        // QilVisitor overrides
        //-----------------------------------------------
 
        /// 
        /// Call BeforeVisit() and AfterVisit(). 
        ///  
        protected override QilNode Visit(QilNode n) {
            QilNode ret; 
            BeforeVisit(n);
            ret = base.Visit(n);
            AfterVisit(n);
            return ret; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK