Exemple #1
0
        // WithStatement
        public override bool Walk(WithStatement node)
        {
            node.Parent = _currentScope;
            _currentScope.ContainsExceptionHandling = true;

            node.Variable?.Walk(_define);
            return(true);
        }
        public void Visit(PyAst.WithStatement node)
        {
            var asClause = node.Variable is null ? "" : " as " + Visit(node.Variable);

            AppendLineWithIndentation($"with {Visit(node.ContextManager)}{asClause}:");
            using (new Indenter(this)) {
                Visit(node.Body);
            }
        }
Exemple #3
0
        // WithStatement
        public override bool Walk(WithStatement node)
        {
            node.Parent = _currentScope;
            _currentScope.ContainsExceptionHandling = true;

            if (node.Variable != null)
            {
                var assignError = node.Variable.CheckAssign();
                if (assignError != null)
                {
                    ReportSyntaxError(assignError, node);
                }
                node.Variable.Walk(_define);
            }
            return(true);
        }
        // WithStmt
        public override bool Walk(WithStatement node)
        {
            // Walk the expression
            node.ContextManager.Walk(this);
            BitArray save = _bits;

            _bits = new BitArray(_bits);

            // Define the Rhs
            node.Variable?.Walk(_fdef);

            // Flow the body
            node.Body.Walk(this);

            _bits = save;
            return(false);
        }
 public WithBlock(WithStatement stmt, State state)
     : base(state)
 {
     this.stmt = stmt;
 }
 public WithBlock(WithStatement stmt)
     : this(stmt, State.Try)
 {
     // With is essentially a Try-Catch-Finally, hence reuse the Try state
 }
        public override bool Walk(WithStatement node)
        {
            WithBlock wb = new WithBlock(node);
            // With is essentially a Try-Catch-Finally, hence Push Try Block for With Statement
            tryBlocks.Push(wb);
            node.Body.Walk(this);

            ExceptionBlock eb = tryBlocks.Pop();
            Debug.Assert((object)wb == (object)eb);

            return false;
        }
 public override bool Walk(WithStatement node)
 {
     sink.Add(src, "WITH statement is not supported.", node.Span, UNSUPPORTED_STATEMENT, Severity.FatalError);
     return false;
 }
 public override void PostWalk(WithStatement node)
 {
 }
Exemple #10
0
        //with_stmt: 'with' expression [ 'as' with_var ] ':' suite
        private WithStatement ParseWithStmt() {
            SkipName(Symbols.With);
            SourceLocation start = GetStart();
            Expression contextManager = ParseExpression();
            Expression var = null;
            if (PeekName(Symbols.As)) {
                SkipName(Symbols.As);
                var = ParseExpression();
            }

            SourceLocation header = GetEnd();
            Statement body = ParseSuite();
            WithStatement ret = new WithStatement(contextManager, var, body);
            ret.Header = header;
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Exemple #11
0
        //with_stmt: 'with' test [ 'as' with_var ] ':' suite
        private WithStatement ParseWithStmt()
        {
            EatName(SymbolTable.With);
            Location start = GetStart();
            Expression contextManager = ParseTest();
            Expression var = null;
            if (PeekName(SymbolTable.As)) {
                EatName(SymbolTable.As);
                var = ParseTest();
            }

            Location header = GetEnd();
            Statement body = ParseSuite();
            WithStatement ret = new WithStatement(contextManager, var, body);
            ret.Header = header;
            ret.SetLoc(GetExternal(), start, GetEnd());
            return ret;
        }
Exemple #12
0
        //with_stmt: 'with' expression [ 'as' with_var ] ':' suite
        private WithStatement ParseWithStmt() {
            Eat(TokenKind.KeywordWith);
            SourceLocation start = GetStart();
            Expression contextManager = ParseExpression();
            Expression var = null;
            if (MaybeEat(TokenKind.KeywordAs)) {
                var = ParseExpression();
            }

            SourceLocation header = GetEnd();
            Statement body = ParseSuite();
            WithStatement ret = new WithStatement(contextManager, var, body);
            ret.Header = header;
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Exemple #13
0
        // WithStatement
        public override bool Walk(WithStatement node)
        {
            node.Parent = _currentScope;
            _currentScope.ContainsExceptionHandling = true;

            if (node.Variable != null) {
                node.Variable.Walk(_define);
            }
            return true;
        }
 // WithStatement
 public override bool Walk(WithStatement node) {
     if (node.Variable != null) {
         node.Variable.Walk(_define);
     }
     return true;
 }
Exemple #15
0
        // WithStmt
        public override bool Walk(WithStatement node) {
            // Walk the expression
            node.ContextManager.Walk(this);
            BitArray save = _bits;
            _bits = new BitArray(_bits);

            // Define the Rhs
            if (node.Variable != null)
                node.Variable.Walk(_fdef);

            // Flow the body
            node.Body.Walk(this);

            _bits = save;
            return false;
        }
 public virtual void PostWalk(WithStatement node)
 {
 }
 // WithStatement
 public virtual bool Walk(WithStatement node)
 {
     return true;
 }
Exemple #18
0
        // WithStmt
        public override bool Walk(WithStatement node)
        {
            if (node.Variable != null) {
                node.Variable.Walk(define);
            }

            // Add locals
            Debug.Assert(current != null);
            current.TempsCount += WithStatement.LocalSlots;
            return true;
        }
Exemple #19
0
            internal With(WithStatement with)
                : this() {
                _context_expr = Convert(with.ContextManager);
                if (with.Variable != null)
                    _optional_vars = Convert(with.Variable);

                _body = ConvertStatements(with.Body);
            }
 public void PostWalk(WithStatement node)
 {
     PostProcess(node);
 }
Exemple #21
0
        //with_stmt: 'with' with_item (',' with_item)* ':' suite
        //with_item: test ['as' expr]
        private WithStatement ParseWithStmt() {
            Eat(TokenKind.KeywordWith);

            var withItem = ParseWithItem();
            List<WithItem> items = null;
            while (MaybeEat(TokenKind.Comma)) {
                if (items == null) {
                    items = new List<WithItem>();
                }

                items.Add(ParseWithItem());
            }
            

            var header = GetEnd();
            Statement body = ParseSuite();
            if (items != null) {
                for (int i = items.Count - 1; i >= 0; i--) {
                    var curItem = items[i];
                    var innerWith = new WithStatement(curItem.ContextManager, curItem.Variable, body);
                    innerWith.HeaderIndex = header;                    
                    innerWith.SetLoc(_globalParent, withItem.Start, GetEnd());
                    body = innerWith;
                    header = GetEnd();
                }
            }

            WithStatement ret = new WithStatement(withItem.ContextManager, withItem.Variable, body);
            ret.HeaderIndex = header;
            ret.SetLoc(_globalParent, withItem.Start, GetEnd());
            return ret;
        }
 // WithStatement
 public bool Walk(WithStatement node)
 {
     return Process(node);
 }