Esempio n. 1
0
 public ForStatement(Expression left, Expression list, Statement body, Statement else_)
 {
     _left = left;
     _list = list;
     _body = body;
     _else = else_;
 }
Esempio n. 2
0
        internal static IEnumerable<IScopeNode> EnumerateBody(PythonAst ast, Statement body, bool includeAssignments = true) {
            SuiteStatement suite = body as SuiteStatement;
            if (suite != null) {
                foreach (Statement stmt in suite.Statements) {
                    ClassDefinition klass = stmt as ClassDefinition;
                    if (klass != null) {
                        yield return new ClassScopeNode(klass);
                        continue;
                    }

                    FunctionDefinition func = stmt as FunctionDefinition;
                    if (func != null) {
                        yield return new FunctionScopeNode(func);
                        continue;
                    }

                    AssignmentStatement assign;
                    if (includeAssignments && (assign = stmt as AssignmentStatement) != null) {
                        foreach (var target in assign.Left) {
                            NameExpression name = target as NameExpression;
                            if (name != null) {
                                yield return new AssignmentScopeNode(ast, assign, name);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public PythonAst(Statement body, int[] lineLocations, PythonLanguageVersion langVersion) {
     if (body == null) {
         throw new ArgumentNullException("body");
     }
     _langVersion = langVersion;
     _body = body;
     _lineLocations = lineLocations;
 }
Esempio n. 4
0
 /// <summary>
 /// Returns the expression contained by the statement.
 /// 
 /// Returns null if it's not an expression statement or return statement.
 /// 
 /// New in 1.1.
 /// </summary>
 public static Expression GetExpression(Statement statement) {
     if (statement is ExpressionStatement) {
         return ((ExpressionStatement)statement).Expression;
     } else if (statement is ReturnStatement) {
         return ((ReturnStatement)statement).Expression;
     } else {
         return null;
     }
 }
Esempio n. 5
0
        public FunctionDefinition(NameExpression name, Parameter[] parameters, Statement body, DecoratorStatement decorators = null) {
            if (name == null) {
                _name = new NameExpression("<lambda>");
                _isLambda = true;
            } else {
                _name = name;
            }

            _parameters = parameters;
            _body = body;
            _decorators = decorators;
        }
Esempio n. 6
0
        /// <summary>
        /// Returns a new SuiteStatement which is composed of a subset of the statements in this suite statement.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public SuiteStatement CloneSubset(PythonAst ast, int start, int end) {
            Statement[] statements = new Statement[end - start + 1];
            for (int i = start; i <= end; i++) {
                statements[i - start] = Statements[i];
            }

            var res = new SuiteStatement(statements);

            // propagate white space so we stay mostly the same...
            var itemWhiteSpace = this.GetListWhiteSpace(ast);
            var colonWhiteSpace = this.GetProceedingWhiteSpaceDefaultNull(ast);

            if (itemWhiteSpace != null) {
                // semi-colon list of statements, must end in a new line, but the original new line
                // could be multiple lines.
                ast.SetAttribute(res, NodeAttributes.ListWhiteSpace, new string[0]);
            } else {
                ast.SetAttribute(res, NodeAttributes.IsAltFormValue, NodeAttributes.IsAltFormValue);
            }

            return res;
        }
Esempio n. 7
0
 private static AP.Navigation GetNavigation(Statement stmt) {
     string type, name;
     FunctionDefinition funcDef = stmt as FunctionDefinition;
     if (funcDef != null) {
         name = funcDef.Name;
         type = "function";
         if (funcDef.Decorators != null && funcDef.Decorators.Decorators.Count == 1) {
             foreach (var decorator in funcDef.Decorators.Decorators) {
                 NameExpression nameExpr = decorator as NameExpression;
                 if (nameExpr != null) {
                     if (nameExpr.Name == "property") {
                         type = "property";
                         break;
                     } else if (nameExpr.Name == "staticmethod") {
                         type = "staticmethod";
                         break;
                     } else if (nameExpr.Name == "classmethod") {
                         type = "classmethod";
                         break;
                     }
                 }
             }
         }
     } else {
         name = ((ClassDefinition)stmt).Name;
         type = "class";
     }
     return new AP.Navigation() {
         type = type,
         name = name,
         startIndex = stmt.StartIndex,
         endIndex = stmt.EndIndex
     };
 }
Esempio n. 8
0
File: Node.cs Progetto: xNUTs/PTVS
 internal virtual string GetDocumentation(Statement /*!*/ stmt)
 {
     return(stmt.Documentation);
 }
Esempio n. 9
0
 public WithStatement(WithItem[] items, Statement body) {
     _items = items;
     _body = body;
 }
Esempio n. 10
0
 public ErrorStatement(Statement[] preceeding) {
     _preceeding = preceeding;
 }
Esempio n. 11
0
 public ForStatement(Expression left, Expression list, Statement body, Statement else_, bool isAsync)
     : this(left, list, body, else_)
 {
     _isAsync = isAsync;
 }
Esempio n. 12
0
 private Statement FinishSmallStmt(Statement stmt) {
     NextToken();
     stmt.SetLoc(GetStart(), GetEnd());
     if (_verbatim) {
         AddPreceedingWhiteSpace(stmt, _tokenWhiteSpace);
     }
     return stmt;
 }
Esempio n. 13
0
 private Statement ParseFinallySuite(Statement finallySuite) {
     bool inFinally = _inFinally;
     try {
         _inFinally = true;
         finallySuite = ParseSuite();
     } finally {
         _inFinally = inFinally;
     }
     return finallySuite;
 }
Esempio n. 14
0
File: Node.cs Progetto: RussBaz/PTVS
 internal virtual string GetDocumentation(Statement/*!*/ stmt) {
     return stmt.Documentation;
 }
Esempio n. 15
0
 public TryStatementHandler(Expression test, Expression target, Statement body)
 {
     Test   = test;
     Target = target;
     Body   = body;
 }
Esempio n. 16
0
 public WhileStatement(Expression test, Statement body, Statement else_) {
     _test = test;
     _body = body;
     _else = else_;
 }
Esempio n. 17
0
 public TryStatementHandler(Expression test, Expression target, Statement body)
 {
     _test   = test;
     _target = target;
     _body   = body;
 }
Esempio n. 18
0
 public TryStatement(Statement body, TryStatementHandler[] handlers, Statement else_, Statement finally_)
 {
     _body     = body;
     _handlers = handlers;
     _else     = else_;
     _finally  = finally_;
 }
Esempio n. 19
0
 public WithStatement(WithItem[] items, Statement body, bool isAsync) : this(items, body)
 {
     _isAsync = isAsync;
 }
Esempio n. 20
0
 public WithStatement(WithItem[] items, Statement body)
 {
     _items = items;
     _body  = body;
 }
Esempio n. 21
0
        private bool IsCoroutine(Statement body) {
            if (_ast.LanguageVersion < PythonLanguageVersion.V35) {
                return false;
            }

            var walker = new AwaitWalker();
            body.Walk(walker);
            return walker.SeenAwait;
        }
Esempio n. 22
0
        private PythonAst CreateAst(Statement ret) {
            var ast = new PythonAst(ret, _tokenizer.GetLineLocations(), _tokenizer.LanguageVersion);
            ast.HasVerbatim = _verbatim;
            ast.PrivatePrefix = _privatePrefix;
            if (_token.Token != null) {
                ast.SetLoc(0, GetEnd());
            }
            if (_verbatim) {
                AddExtraVerbatimText(ast, _lookaheadWhiteSpace + _lookahead.Token.VerbatimImage);
            }
            foreach (var keyValue in _attributes) {
                foreach (var nodeAttr in keyValue.Value) {
                    ast.SetAttribute(keyValue.Key, nodeAttr.Key, nodeAttr.Value);
                }
            }
            
            PythonNameBinder.BindAst(_langVersion, ast, _errors, _bindReferences);

            return ast;
        }
Esempio n. 23
0
 internal void SetBody(Statement body) {
     _body = body;
 }
Esempio n. 24
0
 private static Statement NestGenExpr(Statement current, Statement nested) {
     ForStatement fes = current as ForStatement;
     IfStatement ifs;
     if (fes != null) {
         fes.Body = nested;
     } else if ((ifs = current as IfStatement) != null) {
         ifs.Tests[0].Body = nested;
     }
     return nested;
 }
Esempio n. 25
0
 public TryStatementHandler(Expression test, Expression target, Statement body) {
     _test = test;
     _target = target;
     _body = body;
 }
Esempio n. 26
0
 public DropDownEntryInfo(Statement body) {
     Body = body;
 }
        private Expression ParseSubExpression(string expr)
        {
            var parser = Parser.CreateParser(new StringReader(expr), LanguageVersion);

            return(Statement.GetExpression(parser.ParseTopExpression()?.Body));
        }
Esempio n. 28
0
 public ImportStatementInfo(Statement statement, StrongBox<int> siblings) {
     Statement = statement;
     Siblings = siblings;
 }
Esempio n. 29
0
            private void TrackImport(Statement node, string name) {
                var parent = _scopes[_scopes.Count - 1];
                StrongBox<int> statementCount;

                if (!_statementCount.TryGetValue(parent, out statementCount)) {
                    PythonAst outerParent = parent as PythonAst;
                    if (outerParent != null) {
                        // we don't care about the number of children at the top level
                        statementCount = new StrongBox<int>(-1);
                    } else {
                        FunctionDefinition funcDef = parent as FunctionDefinition;
                        if (funcDef != null) {
                            statementCount = GetNumberOfChildStatements(funcDef.Body);
                        } else {
                            var classDef = (ClassDefinition)parent;
                            statementCount = GetNumberOfChildStatements(classDef.Body);
                        }
                    }
                    _statementCount[parent] = statementCount;
                }

                List<ImportStatementInfo> imports;
                if (!_importedNames.TryGetValue(name, out imports)) {
                    _importedNames[name] = imports = new List<ImportStatementInfo>();
                }
                imports.Add(new ImportStatementInfo(node, statementCount));
            }
Esempio n. 30
0
 public SuiteStatement(Statement[] statements) {
     _statements = statements;
 }
Esempio n. 31
0
 private static StrongBox<int> GetNumberOfChildStatements(Statement body) {
     if (body is SuiteStatement) {
         return new StrongBox<int>(((SuiteStatement)body).Statements.Count);
     } else {
         return new StrongBox<int>(1);
     }
 }
Esempio n. 32
0
 public IfStatementTest(Expression test, Statement body) {
     _test = test;
     _body = body;
 }
Esempio n. 33
0
 public ForStatement(Expression left, Expression list, Statement body, Statement else_, bool isAsync)
     : this(left, list, body, else_) {
     _isAsync = isAsync;
 }
Esempio n. 34
0
 public TryStatement(Statement body, TryStatementHandler[] handlers, Statement else_, Statement finally_) {
     _body = body;
     _handlers = handlers;
     _else = else_;
     _finally = finally_;
 }
Esempio n. 35
0
        private void UpdateChildRanges(Statement node) {
            var declScope = _curUnit.Scope;
            var prevScope = declScope.Children.LastOrDefault();
            StatementScope prevStmtScope;
            IsInstanceScope prevInstanceScope;

            if ((prevStmtScope = prevScope as StatementScope) != null) {
                prevStmtScope.EndIndex = node.EndIndex;
            } else if ((prevInstanceScope = prevScope as IsInstanceScope) != null) {
                prevInstanceScope.EndIndex = node.EndIndex;
            } else {
                declScope.Children.Add(new StatementScope(node.StartIndex, declScope));
            }
        }
Esempio n. 36
0
 private static NameExpression GetFirstNameExpression(Statement stmt) {
     return GetFirstNameExpression(Statement.GetExpression(stmt));
 }
Esempio n. 37
0
        private PythonVariable _classVariable;      // Variable for the classes __class__ cell var on 3.x

        public ClassDefinition(NameExpression/*!*/ name, Arg[] bases, Statement body) {           
            _name = name;
            _bases = bases;
            _body = body;
        }
Esempio n. 38
0
 public WithStatement(WithItem[] items, Statement body, bool isAsync) : this(items, body) {
     _isAsync = isAsync;
 }
Esempio n. 39
0
 public IfStatement(IfStatementTest[] tests, Statement else_)
 {
     _tests = tests;
     _else  = else_;
 }