Beispiel #1
0
        /// <summary>
        /// Visits try catch statement and connects thrown exceptions to catch blocks or function sink.
        /// </summary>
        /// <param name="x">TryStmt</param>
        public override void VisitTryStmt(TryStmt x)
        {
            BasicBlock followingBlock = new BasicBlock();

            TryBasicBlock tryBlock = new TryBasicBlock();

            BasicBlockEdge.ConnectDirectEdge(currentBasicBlock, tryBlock);
            currentBasicBlock = tryBlock;

            //throwBlocks.Push(new List<BasicBlock>());
            VisitStatementList(x.Statements);
            currentBasicBlock.EndIngTryBlocks.Add(tryBlock);
            BasicBlockEdge.ConnectDirectEdge(currentBasicBlock, followingBlock);


            foreach (var catchItem in x.Catches)
            {
                CatchBasicBlock catchBlock = new CatchBasicBlock(catchItem.Variable, catchItem.ClassName);

                tryBlock.catchBlocks.Add(catchBlock);
                currentBasicBlock = catchBlock;
                VisitStatementList(catchItem.Statements);
                BasicBlockEdge.ConnectDirectEdge(currentBasicBlock, followingBlock);
            }


            //throwBlocks.Pop();
            currentBasicBlock = followingBlock;
        }
Beispiel #2
0
        public override void VisitTryStmt(TryStmt x)
        {
            // try {
            //   x.Body
            // }
            // catch (E1) { body }
            // catch (E2) { body }
            // finally { body }
            // end

            var end  = NewBlock();
            var body = NewBlock();

            // init catch blocks and finally block
            var        catchBlocks  = new CatchBlock[(x.Catches == null) ? 0 : x.Catches.Length];
            BoundBlock finallyBlock = null;

            for (int i = 0; i < catchBlocks.Length; i++)
            {
                catchBlocks[i] = NewBlock(x.Catches[i]);
            }

            if (x.FinallyItem != null)
            {
                finallyBlock = NewBlock();
            }

            // TryCatchEdge // Connects _current to body, catch blocks and finally
            var edge = new TryCatchEdge(_current, body, catchBlocks, finallyBlock, end);

            // build try body
            OpenTryScope(edge);
            OpenScope(body);
            _current = WithNewOrdinal(body);
            VisitElement(x.Body);
            CloseScope();
            CloseTryScope();
            _current = Leave(_current, finallyBlock ?? end);

            // built catches
            for (int i = 0; i < catchBlocks.Length; i++)
            {
                _current = WithOpenScope(WithNewOrdinal(catchBlocks[i]));
                VisitElement(x.Catches[i].Body);
                CloseScope();
                _current = Leave(_current, finallyBlock ?? end);
            }

            // build finally
            if (finallyBlock != null)
            {
                _current = WithOpenScope(WithNewOrdinal(finallyBlock));
                VisitElement(x.FinallyItem.Body);
                CloseScope();
                _current = Leave(_current, end);
            }

            // _current == end
            _current.Ordinal = NewOrdinal();
        }
Beispiel #3
0
 public override void VisitTryStmt(TryStmt x)
 {
     using (new ScopeHelper(this, x))
     {
         base.VisitTryStmt(x);
     }
 }
 private static TryExpression ToTryExpression(TryStmt e)
 {
     return(new TryExpression(
                Parse(e.Body),
                e.Catches.Select(c => ToCatchExpression(c)).ToImmutableArray(),
                Parse(e.FinallyItem?.Body)
                ));
 }
Beispiel #5
0
 public override void VisitTryStmt(TryStmt x)
 {
     using (new ScopeHelper(this, x))
     {
         ConsumeToken(Tokens.T_TRY, "try", x.Span.Start);
         VisitElement(x.Body);
         VisitList(x.Catches);
         VisitElement(x.FinallyItem);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Visit statements and catches.
        /// </summary>
        /// <param name="x"></param>
        virtual public void VisitTryStmt(TryStmt x)
        {
            // try body
            VisitElement(x.Body);

            // visit catch blocks
            VisitList(x.Catches);

            // visit finally block
            VisitElement(x.FinallyItem);
        }
Beispiel #7
0
        override public void VisitTryStmt(TryStmt x)
        {
            _serializer.StartSerialize(typeof(TryStmt).Name, SerializeSpan(x.Span));
            SerializeOptionalProperty("Body", x.Body);

            _serializer.StartSerialize("Catches");
            if (x.Catches != null)
            {
                foreach (CatchItem c in x.Catches)
                {
                    VisitElement(c);
                }
            }
            _serializer.EndSerialize();
            VisitElement(x.FinallyItem);
            _serializer.EndSerialize();
        }
        public override void VisitTryStmt(TryStmt x)
        {
            // try {
            //   x.Body
            // }
            // catch (E1) { body }
            // catch (E2) { body }
            // finally { body }
            // end

            var end  = NewBlock();
            var body = NewBlock();

            // init catch blocks and finally block
            var catchBlocks = ImmutableArray <CatchBlock> .Empty;

            if (x.Catches != null)
            {
                var catchBuilder = ImmutableArray.CreateBuilder <CatchBlock>(x.Catches.Length);
                for (int i = 0; i < x.Catches.Length; i++)
                {
                    catchBuilder.Add(NewBlock(x.Catches[i]));
                }

                catchBlocks = catchBuilder.MoveToImmutable();
            }

            BoundBlock finallyBlock = null;

            if (x.FinallyItem != null)
            {
                finallyBlock = NewBlock();
            }

            // TryCatchEdge // Connects _current to body, catch blocks and finally
            var edge = new TryCatchEdge(_current, body, catchBlocks, finallyBlock, end);

            // build try body
            OpenTryScope(edge);
            OpenScope(body);
            _current = WithNewOrdinal(body);
            VisitElement(x.Body);
            CloseScope();
            CloseTryScope();
            _current = Leave(_current, finallyBlock ?? end);

            // built catches
            for (int i = 0; i < catchBlocks.Length; i++)
            {
                _current = WithOpenScope(WithNewOrdinal(catchBlocks[i]));
                VisitElement(x.Catches[i].Body);
                CloseScope();
                _current = Leave(_current, finallyBlock ?? end);
            }

            // build finally
            if (finallyBlock != null)
            {
                _current = WithOpenScope(WithNewOrdinal(finallyBlock));
                VisitElement(x.FinallyItem.Body);
                CloseScope();
                _current = Leave(_current, end);
            }

            // _current == end
            _current.Ordinal = NewOrdinal();
        }
Beispiel #9
0
        public override void VisitTryStmt(TryStmt x)
        {
            // try {
            //   x.Body
            // }
            // catch (E1) { body }
            // catch (E2) { body }
            // finally { body }
            // end

            var end  = NewBlock();
            var body = NewBlock();

            // init catch blocks and finally block
            var catchBlocks = ImmutableArray <CatchBlock> .Empty;

            if (x.Catches != null)
            {
                var catchBuilder = ImmutableArray.CreateBuilder <CatchBlock>(x.Catches.Length);
                for (int i = 0; i < x.Catches.Length; i++)
                {
                    catchBuilder.Add(NewBlock(x.Catches[i]));
                }

                catchBlocks = catchBuilder.MoveToImmutable();
            }

            BoundBlock finallyBlock = null;

            if (x.FinallyItem != null)
            {
                finallyBlock = NewBlock();
            }

            // TryCatchEdge // Connects _current to body, catch blocks and finally
            var edge = new TryCatchEdge(_current, body, catchBlocks, finallyBlock, end);

            var oldstates0 = _binder.StatesCount;

            // build try body
            OpenTryScope(edge);
            OpenScope(body, LocalScope.Try);
            _current = WithNewOrdinal(body);
            VisitElement(x.Body);
            CloseScope();
            CloseTryScope();
            _current = Leave(_current, finallyBlock ?? end);

            var oldstates1 = _binder.StatesCount;

            // built catches
            for (int i = 0; i < catchBlocks.Length; i++)
            {
                _current = WithOpenScope(WithNewOrdinal(catchBlocks[i]), LocalScope.Catch);
                VisitElement(x.Catches[i].Body);
                CloseScope();
                _current = Leave(_current, finallyBlock ?? end);
            }

            // build finally
            var oldReturnCount = _returnCounter;

            if (finallyBlock != null)
            {
                _current = WithOpenScope(WithNewOrdinal(finallyBlock), LocalScope.Finally);
                VisitElement(x.FinallyItem.Body);
                CloseScope();
                _current = Leave(_current, end);
            }

            //
            if ((oldstates0 != oldstates1 && finallyBlock != null) ||   // yield in "try" with "finally" block
                oldstates1 != _binder.StatesCount ||                    // yield in "catch" or "finally"
                oldReturnCount != _returnCounter)                       // return in "finally"
            {
                // catch or finally introduces new states to the state machine
                // or there is "return" in finally block:

                // catch/finally must not be handled by CLR
                edge.EmitCatchFinallyOutsideScope = true;
            }

            // _current == end
            _current.Ordinal = NewOrdinal();
        }