Esempio n. 1
0
 // FromImportStatement
 public override bool Walk(FromImportStatement node)
 {
     if (node.Names.Count != 1 || node.Names[0].Name != "*")
     {
         var variables = new PythonVariable[node.Names.Count];
         PythonReference[] references = null;
         if (BindReferences)
         {
             references = new PythonReference[node.Names.Count];
         }
         for (var i = 0; i < node.Names.Count; i++)
         {
             variables[i] = DefineName(node.AsNames[i] != null ? node.AsNames[i].Name : node.Names[i].Name);
             if (references != null)
             {
                 references[i] = Reference(variables[i].Name);
             }
         }
         node.Variables = variables;
         node.AddVariableReference(_ast, BindReferences, references);
     }
     else
     {
         Debug.Assert(_currentScope != null);
         _currentScope.ContainsImportStar       = true;
         _currentScope.NeedsLocalsDictionary    = true;
         _currentScope.HasLateBoundVariableSets = true;
     }
     return(true);
 }
Esempio n. 2
0
        internal PythonReference Reference(string /*!*/ name)
        {
            if (_references == null)
            {
                _references = new Dictionary <string, List <PythonReference> >(StringComparer.Ordinal);
            }

            if (!_references.TryGetValue(name, out var references))
            {
                _references[name] = references = new List <PythonReference>();
            }
            var reference = new PythonReference(name);

            references.Add(reference);
            return(reference);
        }
Esempio n. 3
0
        // ImportStatement
        public override bool Walk(ImportStatement node)
        {
            var variables = new PythonVariable[node.Names.Count];

            PythonReference[] references = null;
            if (BindReferences)
            {
                references = new PythonReference[variables.Length];
            }
            for (var i = 0; i < node.Names.Count; i++)
            {
                string name;

                if (node.AsNames[i] != null)
                {
                    name = node.AsNames[i].Name;
                }
                else if (node.Names[i].Names.Count > 0)
                {
                    name = node.Names[i].Names[0].Name;
                }
                else
                {
                    name = null;
                }

                if (name != null)
                {
                    variables[i] = DefineName(name);
                    if (references != null)
                    {
                        references[i] = Reference(name);
                    }
                }
            }
            node.Variables = variables;
            node.AddVariableReference(_ast, BindReferences, references);
            return(true);
        }