示例#1
0
 public FunctionDefinition(NameExpression name, Parameter[] parameters)
     : this(name, parameters, (Statement)null)
 {
 }
 private static bool IsNotIgnoredName(NameExpression name) => IsNotIgnoredName(name.Name);
 public override void PostWalk(NameExpression node)
 {
 }
示例#4
0
 public ClassDefinition(NameExpression /*!*/ name, ImmutableArray <Arg> bases, Statement body)
 {
     _name = name;
     Bases = bases;
     _body = body;
 }
 public virtual void PostWalk(NameExpression node)
 {
 }
 // NameExpression
 public override bool Walk(NameExpression node)
 {
     return(false);
 }
 // NameExpression
 public override bool Walk(NameExpression node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
 // NameExpression
 public virtual bool Walk(NameExpression node)
 {
     return(true);
 }
 public override bool Walk(NameExpression node)
 {
     _binder.DefineDeleted(node.Name);
     return(false);
 }
 public override bool Walk(NameExpression node)
 {
     node.AddVariableReference(GlobalScope, BindReferences, Reference(node.Name));
     return(true);
 }
 public ClassDefinition(NameExpression /*!*/ name, Arg[] bases, Statement body)
 {
     _name  = name;
     _bases = bases;
     _body  = body;
 }
 internal virtual void AppendParameterName(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace)
 => NameExpression?.AppendCodeString(res, ast, format, leadingWhiteSpace);
 public Parameter(NameExpression name, ParameterKind kind)
 {
     NameExpression = name;
     Kind           = kind;
 }
示例#14
0
        /// <summary>
        /// Returns a new FromImport statement that is identical to this one but has
        /// removed the specified import statement.  Otherwise preserves any attributes
        /// for the statement.
        ///
        /// New in 1.1.
        /// <param name="ast">The parent AST whose attributes should be updated for the new node.</param>
        /// <param name="index">The index in Names of the import to be removed.</param>
        /// </summary>
        public FromImportStatement RemoveImport(PythonAst ast, int index)
        {
            if (index < 0 || index >= Names.Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            if (ast == null)
            {
                throw new ArgumentNullException("ast");
            }

            var names               = new NameExpression[Names.Count - 1];
            var asNames             = AsNames == null ? null : new NameExpression[AsNames.Count - 1];
            var asNameWhiteSpace    = this.GetNamesWhiteSpace(ast);
            var newAsNameWhiteSpace = new List <string>();
            var importIndex         = ImportIndex;
            var asIndex             = 0;

            for (int i = 0, write = 0; i < Names.Count; i++)
            {
                var 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 (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                {
                    if (write > 0)
                    {
                        if (includingCurrentName)
                        {
                            newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                        }
                        else
                        {
                            asIndex++;
                        }
                    }
                    else if (i > 0)
                    {
                        asIndex++;
                    }
                }

                if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                {
                    if (includingCurrentName)
                    {
                        if (newAsNameWhiteSpace.Count == 0)
                        {
                            // no matter what we want the 1st entry to have the whitespace after the import keyword
                            newAsNameWhiteSpace.Add(asNameWhiteSpace[0]);
                            asIndex++;
                        }
                        else
                        {
                            newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                        }
                    }
                    else
                    {
                        asIndex++;
                    }
                }

                if (includingCurrentName)
                {
                    names[write] = Names[i];

                    if (AsNames != null)
                    {
                        asNames[write] = AsNames[i];
                    }

                    write++;
                }

                if (AsNames != null && AsNames[i] != null)
                {
                    if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                    {
                        if (i != index)
                        {
                            newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                        }
                        else
                        {
                            asIndex++;
                        }
                    }

                    if (AsNames[i].Name.Length != 0)
                    {
                        if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
                        {
                            if (i != index)
                            {
                                newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                            }
                            else
                            {
                                asIndex++;
                            }
                        }
                    }
                    else
                    {
                        asIndex++;
                    }
                }
            }

            if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length)
            {
                // trailing comma
                newAsNameWhiteSpace.Add(asNameWhiteSpace[asNameWhiteSpace.Length - 1]);
            }

            var res = new FromImportStatement(Root, names, asNames, IsFromFuture, ForceAbsolute, importIndex);

            ast.CopyAttributes(this, res);
            ast.SetAttribute(res, NodeAttributes.NamesWhiteSpace, newAsNameWhiteSpace.ToArray());

            return(res);
        }
 internal void AddNonLocalVariable(NameExpression name)
 {
     _nonLocalVars = _nonLocalVars ?? new List <NameExpression>();
     _nonLocalVars.Add(name);
 }