public override bool Walk(ImportStatement node) { for (int i = 0; i < node.Names.Count; i++) { // if it's an asname we don't understand it if (node.Names[i] == null) { // bad import... continue; } if (node.AsNames[i] == null) { Imports.Add(node.Names[i].MakeString()); } } return base.Walk(node); }
public override bool Walk(ImportStatement node) { foreach (var nameNode in node.Names) { var name = nameNode.MakeString(); if (!_analyzer.IsModuleResolved(_entry, name, node.ForceAbsolute)) { Imports.Add(Tuple.Create(name, nameNode)); } } return base.Walk(node); }
public override bool Walk(ImportStatement node) { Debug.Assert(_head != null); if (node.AsNames != null) { foreach (var name in node.AsNames) { if (name != null && !string.IsNullOrEmpty(name.Name)) { _head.Modules.Add(name.Name); _head.Names.Add(Tuple.Create(name.Name, Span.FromBounds(name.StartIndex, name.EndIndex))); } } } if (node.Names != null) { for (int i = 0; i < node.Names.Count; ++i) { var dottedName = node.Names[i]; var hasAsName = (node.AsNames != null && node.AsNames.Count > i) ? node.AsNames[i] != null : false; foreach (var name in dottedName.Names) { if (name != null && !string.IsNullOrEmpty(name.Name)) { if (!hasAsName) { _head.Modules.Add(name.Name); _head.Names.Add(Tuple.Create(name.Name, Span.FromBounds(name.StartIndex, name.EndIndex))); } else { // Only want to highlight this instance of the // name, since it isn't going to be bound in the // rest of the module. AddSpan(Tuple.Create(name.Name, Span.FromBounds(name.StartIndex, name.EndIndex)), PythonPredefinedClassificationTypeNames.Module); } } } } } return base.Walk(node); }
// ImportStatement public override bool Walk(ImportStatement node) { PythonVariable[] variables = new PythonVariable[node.Names.Count]; PythonReference[] references = null; if (_bindRefs) { references = new PythonReference[variables.Length]; } for (int 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, _bindRefs, references); return true; }
public override bool Walk(ImportStatement node) { UpdateLineInfo(node); return base.Walk(node); }
public override bool Walk(ImportStatement node) { for (int i = 0; i < node.Names.Count; i++) { NameExpression name = null; if (i < node.AsNames.Count && node.AsNames[i] != null) { name = node.AsNames[i]; } else if (node.Names[i].Names.Count > 0) { name = node.Names[i].Names[0]; } if (name != null) { CreateVariableInDeclaredScope(name); } } UpdateChildRanges(node); return base.Walk(node); }
public override void PostWalk(ImportStatement node) { PostWalkWorker(node); }
public RemovedImportStatement(ImportStatement removed) { _import = removed; }
public UpdatedImportStatement(ImportStatement import) { _import = import; }
public override bool Walk(ImportStatement node) { var m = _scope.Peek(); if (m != null && node.Names != null) { try { for (int i = 0; i < node.Names.Count; ++i) { var n = node.AsNames?[i] ?? node.Names[i].Names[0]; if (n != null) { m[n.Name] = new AstPythonConstant( _interpreter.GetBuiltinType(BuiltinTypeId.Module), GetLoc(node.AsNames[i]) ); } } } catch (IndexOutOfRangeException) { } } return false; }
/// <summary> /// Removes the import at the specified index (which must be in the range of /// the Names property) and returns a new ImportStatement which is the same /// as this one minus the imported name. Preserves all round-tripping metadata /// in the process. /// /// New in 1.1. /// </summary> public ImportStatement RemoveImport(PythonAst ast, int index) { if (index < 0 || index >= _names.Length) { throw new ArgumentOutOfRangeException("index"); } if (ast == null) { throw new ArgumentNullException("ast"); } ModuleName[] names = new ModuleName[_names.Length - 1]; NameExpression[] asNames = _asNames == null ? null : new NameExpression[_asNames.Length - 1]; var asNameWhiteSpace = this.GetNamesWhiteSpace(ast); var itemWhiteSpace = this.GetListWhiteSpace(ast); List<string> newAsNameWhiteSpace = new List<string>(); List<string> newListWhiteSpace = new List<string>(); int asIndex = 0; for (int i = 0, write = 0; i < _names.Length; i++) { bool includingCurrentName = i != index; // track the white space, this needs to be kept in sync w/ ToCodeString and how the // parser creates the white space. if (i > 0 && itemWhiteSpace != null) { if (includingCurrentName) { newListWhiteSpace.Add(itemWhiteSpace[i - 1]); } } if (includingCurrentName) { names[write] = _names[i]; if (_asNames != null) { asNames[write] = _asNames[i]; } write++; } if (AsNames[i] != null && includingCurrentName) { if (asNameWhiteSpace != null) { newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]); } if (_asNames[i].Name.Length != 0) { if (asNameWhiteSpace != null) { newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]); } } } } var res = new ImportStatement(names, asNames, _forceAbsolute); ast.CopyAttributes(this, res); ast.SetAttribute(res, NodeAttributes.NamesWhiteSpace, newAsNameWhiteSpace.ToArray()); ast.SetAttribute(res, NodeAttributes.ListWhiteSpace, newListWhiteSpace.ToArray()); return res; }
public override bool Walk(ImportStatement node) { var vars = node.Variables; var refs = node.GetReferences(_root); for (int i = 0; i < vars.Length; i++) { if (vars[i] != null) { _allWrites.Add(refs[i]); _allWrittenVariables.Add(vars[i]); } } return base.Walk(node); }
/// <summary> /// Removes the import at the specified index (which must be in the range of /// the Names property) and returns a new ImportStatement which is the same /// as this one minus the imported name. Preserves all round-tripping metadata /// in the process. /// /// New in 1.1. /// </summary> public ImportStatement RemoveImport(PythonAst ast, int index) { if (index < 0 || index >= _names.Length) { throw new ArgumentOutOfRangeException("index"); } if (ast == null) { throw new ArgumentNullException("ast"); } ModuleName[] names = new ModuleName[_names.Length - 1]; NameExpression[] asNames = _asNames == null ? null : new NameExpression[_asNames.Length - 1]; var asNameWhiteSpace = this.GetNamesWhiteSpace(ast); var itemWhiteSpace = this.GetListWhiteSpace(ast); List <string> newAsNameWhiteSpace = new List <string>(); List <string> newListWhiteSpace = new List <string>(); int asIndex = 0; for (int i = 0, write = 0; i < _names.Length; i++) { bool includingCurrentName = i != index; // track the white space, this needs to be kept in sync w/ ToCodeString and how the // parser creates the white space. if (i > 0 && itemWhiteSpace != null) { if (includingCurrentName) { newListWhiteSpace.Add(itemWhiteSpace[i - 1]); } } if (includingCurrentName) { names[write] = _names[i]; if (_asNames != null) { asNames[write] = _asNames[i]; } write++; } if (AsNames[i] != null && includingCurrentName) { if (asNameWhiteSpace != null) { newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]); } if (_asNames[i].Name.Length != 0) { if (asNameWhiteSpace != null) { newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]); } } } } var res = new ImportStatement(names, asNames, _forceAbsolute); ast.CopyAttributes(this, res); ast.SetAttribute(res, NodeAttributes.NamesWhiteSpace, newAsNameWhiteSpace.ToArray()); ast.SetAttribute(res, NodeAttributes.ListWhiteSpace, newListWhiteSpace.ToArray()); return(res); }
// ImportStmt public override bool Walk(ImportStatement node) { for (int i = 0; i < node.Names.Count; i++) { if (node.AsNames[i] != null) { Define(node.AsNames[i].Name); } else if (node.Names[i].Names.Count > 0) { Define(node.Names[i].Names[0].Name); } } return true; }
// import_stmt: 'import' module ['as' name"] (',' module ['as' name])* // name: identifier private ImportStatement ParseImportStmt() { Eat(TokenKind.KeywordImport); string whitespace = _tokenWhiteSpace; var start = GetStart(); List<string> asNameWhiteSpace = MakeWhiteSpaceList(); List<ModuleName> l = new List<ModuleName>(); List<NameExpression> las = new List<NameExpression>(); var modName = ParseModuleName(); var commaWhiteSpace = MakeWhiteSpaceList(); if (modName.Names.Count > 0) { l.Add(modName); las.Add(MaybeParseAsName(asNameWhiteSpace)); while (MaybeEat(TokenKind.Comma)) { if (commaWhiteSpace != null) { commaWhiteSpace.Add(_tokenWhiteSpace); } l.Add(ParseModuleName()); las.Add(MaybeParseAsName(asNameWhiteSpace)); } } ModuleName[] names = l.ToArray(); var asNames = las.ToArray(); ImportStatement ret = new ImportStatement(names, asNames, AbsoluteImports); if (_verbatim) { AddListWhiteSpace(ret, commaWhiteSpace.ToArray()); AddNamesWhiteSpace(ret, asNameWhiteSpace.ToArray()); AddPreceedingWhiteSpace(ret, whitespace); } ret.SetLoc(start, GetEnd()); return ret; }
public override bool Walk(ImportStatement node) { if (InTargetScope && !(_scopes[_scopes.Count - 1] is ClassDefinition)) { for (int i = 0; i < node.Names.Count; i++) { if (node.AsNames != null && node.AsNames[i] != null) { var name = node.AsNames[i].Name; TrackImport(node, name); } else { // only the first name becomes available TrackImport(node, node.Names[i].Names[0].Name); } } } return base.Walk(node); }
public override bool Walk(ImportStatement node) { var vars = node.Variables; for (int i = 0; i < vars.Length; i++) { if (vars[i] != null) { _names.Add(vars[i].Name); } } return base.Walk(node); }
// ImportStatement public override bool Walk(ImportStatement node) { return ShouldWalkWorker(node); }