Пример #1
0
        // ClassDefinition
        public override bool Walk(ClassDefinition node)
        {
            if (node.Name != null)
            {
                node.Variable = DefineName(node.Name);
                node.AddVariableReference(_globalScope, _bindRefs, Reference(node.Name));
            }

            if (node.Bases != null)
            {
                // Base references are in the outer context
                foreach (var b in node.Bases)
                {
                    b.Expression.Walk(this);
                }
            }

            // process the decorators in the outer context
            if (node.Decorators != null)
            {
                foreach (Expression dec in node.Decorators.Decorators)
                {
                    if (dec != null)
                    {
                        dec.Walk(this);
                    }
                }
            }

            PushScope(node);

            node.ModuleNameVariable = _globalScope.EnsureGlobalVariable("__name__");

            // define the __doc__ and the __module__
            if (node.Body.Documentation != null)
            {
                node.DocVariable = DefineName("__doc__");
            }
            node.ModVariable = DefineName("__module__");
            if (_langVersion.Is3x())
            {
                node.ClassVariable = DefineName("__class__");
            }

            // Walk the body
            node.Body.Walk(this);
            return(false);
        }
Пример #2
0
        // ClassDefinition
        public override bool Walk(ClassDefinition node)
        {
            if (node.Name != null)
            {
                node.PythonVariable = DefineName(node.Name);
            }

            if (node.Bases != null)
            {
                // Base references are in the outer context
                foreach (Expression b in node.Bases)
                {
                    b.Walk(this);
                }
            }

            // process the decorators in the outer context
            if (node.Decorators != null)
            {
                foreach (Expression dec in node.Decorators)
                {
                    dec.Walk(this);
                }
            }

            PushScope(node);

            node.ModuleNameVariable = _globalScope.EnsureGlobalVariable("__name__");

            // define the __doc__ and the __module__
            if (node.Body.Documentation != null)
            {
                node.DocVariable = DefineName("__doc__");
            }
            node.ModVariable = DefineName("__module__");

            // Walk the body
            node.Body.Walk(this);
            return(false);
        }