public override void SetChildrenScopes(NovaScope scope)
 {
     TryBlock.SetScope(scope);
     RescueBlocks.ForEach(block => block.SetScope(scope));
     EnsureBlock.SetScope(scope);
     ElseBlock.SetScope(scope);
 }
Example #2
0
 public override void WriteTo(ITextOutput output)
 {
     output.Write(".try ");
     TryBlock.WriteTo(output);
     output.Write(" fault ");
     faultBlock.WriteTo(output);
 }
Example #3
0
        public void TryBlock_UnnamedCatchBlock()
        {
            var sst = new TryBlock
            {
                Body = { new ThrowStatement {
                             Reference = new VariableReference{
                                 Identifier = "e"
                             }
                         } },
                CatchBlocks =
                {
                    new CatchBlock
                    {
                        Kind      = CatchBlockKind.Unnamed,
                        Parameter = Names.Parameter("[ExceptionType,P] e"),
                        Body      = { new BreakStatement() }
                    }
                }
            };

            AssertPrint(
                sst,
                "try",
                "{",
                "    throw e;",
                "}",
                "catch (ExceptionType)",
                "{",
                "    break;",
                "}");
        }
 public override ILInstruction Clone()
 {
     return(new TryFinally(TryBlock.Clone(), finallyBlock.Clone())
     {
         ILRange = this.ILRange
     });
 }
 public override ILInstruction Clone()
 {
     return(new TryFault(TryBlock.Clone(), faultBlock.Clone())
     {
         ILRange = this.ILRange
     });
 }
Example #6
0
        public void TryBlock_GeneralCatchBlock()
        {
            var sst = new TryBlock
            {
                Body = { new ThrowStatement {
                             Reference = new VariableReference{
                                 Identifier = "e"
                             }
                         } },
                CatchBlocks =
                {
                    new CatchBlock
                    {
                        Kind = CatchBlockKind.General,
                        Body ={ new BreakStatement()            }
                    }
                }
            };

            AssertPrint(
                sst,
                "try",
                "{",
                "    throw e;",
                "}",
                "catch",
                "{",
                "    break;",
                "}");
        }
Example #7
0
        public void TryBlock()
        {
            var sst = new TryBlock
            {
                Body = { new ThrowStatement {
                             Reference = new VariableReference{
                                 Identifier = "e"
                             }
                         } },
                CatchBlocks =
                {
                    new CatchBlock
                    {
                        Parameter = Names.Parameter("[ExceptionType,P] e"),
                        Body      = { new BreakStatement() }
                    }
                },
                Finally = { new ContinueStatement() }
            };

            AssertPrint(
                sst,
                "try",
                "{",
                "    throw e;",
                "}",
                "catch (ExceptionType e)",
                "{",
                "    break;",
                "}",
                "finally",
                "{",
                "    continue;",
                "}");
        }
 public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
 {
     output.Write(".try ");
     TryBlock.WriteTo(output, options);
     output.Write(" fault ");
     faultBlock.WriteTo(output, options);
 }
Example #9
0
 public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
 {
     WriteILRange(output, options);
     output.Write(".try ");
     TryBlock.WriteTo(output, options);
     output.Write(" finally ");
     finallyBlock.WriteTo(output, options);
 }
Example #10
0
        public void Equality_Default()
        {
            var a = new TryBlock();
            var b = new TryBlock();

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Example #11
0
        public override IList <CilInstruction> GenerateInstructions()
        {
            var result = new List <CilInstruction>();

            result.AddRange(TryBlock.GenerateInstructions());
            result.AddRange(HandlerBlock.GenerateInstructions());
            return(result);
        }
Example #12
0
        public TryBlock Build()
        {
            var tryBlock = new TryBlock(_block);

            tryBlock.Body = new OrderedBlockBuilder(_reader, "try", tryBlock).Build();

            return(tryBlock);
        }
Example #13
0
        public override ILInstruction Clone()
        {
            var clone = new TryCatch(TryBlock.Clone());

            clone.ILRange = this.ILRange;
            clone.Handlers.AddRange(this.Handlers.Select(h => (TryCatchHandler)h.Clone()));
            return(clone);
        }
Example #14
0
        public override void Clone(JsNode node)
        {
            base.Clone(node);
            var node2 = (JsTryStatement)node;

            node2.TryBlock     = TryBlock.Clone();
            node2.CatchClause  = CatchClause.Clone();
            node2.FinallyBlock = FinallyBlock.Clone();
        }
Example #15
0
        public void Equality_DifferentCatchs()
        {
            var a = new TryBlock();

            a.CatchBlocks.Add(new CatchBlock());
            var b = new TryBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Example #16
0
 public override void WriteTo(ITextOutput output)
 {
     output.Write(".try ");
     TryBlock.WriteTo(output);
     foreach (var handler in Handlers)
     {
         output.Write(' ');
         handler.WriteTo(output);
     }
 }
Example #17
0
        public void DefaultValues()
        {
            var sut = new TryBlock();

            Assert.AreEqual(Lists.NewList <IStatement>(), sut.Body);
            Assert.AreEqual(Lists.NewList <ICatchBlock>(), sut.CatchBlocks);
            Assert.AreEqual(Lists.NewList <IStatement>(), sut.Finally);
            Assert.AreNotEqual(0, sut.GetHashCode());
            Assert.AreNotEqual(1, sut.GetHashCode());
        }
Example #18
0
        public void Equality_DifferentFinally()
        {
            var a = new TryBlock();

            a.Finally.Add(new ReturnStatement());
            var b = new TryBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Example #19
0
        public void Equality_DifferentBody()
        {
            var a = new TryBlock();

            a.Body.Add(new ContinueStatement());
            var b = new TryBlock();

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Example #20
0
 public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
 {
     output.Write(".try ");
     TryBlock.WriteTo(output, options);
     foreach (var handler in Handlers)
     {
         output.Write(' ');
         handler.WriteTo(output, options);
     }
 }
Example #21
0
 public override AstNode Clone()
 {
     return(new TryNode(
                (Context == null ? null : Context.Clone()),
                Parser,
                (TryBlock == null ? null : TryBlock.Clone()),
                m_catchVarName,
                (CatchBlock == null ? null : CatchBlock.Clone()),
                (FinallyBlock == null ? null : FinallyBlock.Clone())
                ));
 }
Example #22
0
        public void ChildrenIdentity()
        {
            var sut = new TryBlock
            {
                Body        = { new ContinueStatement() },
                CatchBlocks = { new CatchBlock() },
                Finally     = { new ReturnStatement() }
            };

            AssertChildren(sut, sut.Body.First(), sut.Finally.First());
        }
Example #23
0
 /// <summary>
 /// エラーハンドリングを行い、<c>Promise&lt;T&gt;</c>を返却する。
 /// </summary>
 public static Promise <TR> RunCatching <T, TR>(this T self, TryBlock <T, TR> block)
 {
     try
     {
         return(new Promise <TR>(block(self)));
     }
     catch (Exception e)
     {
         return(new Promise <TR>(e));
     }
 }
Example #24
0
        public void SettingValues()
        {
            var sut = new TryBlock
            {
                Body        = { new ContinueStatement() },
                CatchBlocks = { new CatchBlock() },
                Finally     = { new ReturnStatement() }
            };

            Assert.AreEqual(Lists.NewList(new ContinueStatement()), sut.Body);
            Assert.AreEqual(Lists.NewList(new CatchBlock()), sut.CatchBlocks);
            Assert.AreEqual(Lists.NewList(new ReturnStatement()), sut.Finally);
        }
Example #25
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override void AcceptVisitor(StatementVisitor visitor)
        {
            visitor.VisitTryStatement(this);

            TryBlock.AcceptVisitor(visitor);

            foreach (var catchBlock in CatchBlocks)
            {
                catchBlock.AcceptVisitor(visitor);
            }

            if (FinallyBlock != null)
            {
                FinallyBlock.AcceptVisitor(visitor);
            }
        }
Example #26
0
        public void Equality_ReallyTheSame()
        {
            var a = new TryBlock();

            a.Body.Add(new ContinueStatement());
            a.CatchBlocks.Add(new CatchBlock());
            a.Finally.Add(new ReturnStatement());

            var b = new TryBlock();

            b.Body.Add(new ContinueStatement());
            b.CatchBlocks.Add(new CatchBlock());
            b.Finally.Add(new ReturnStatement());

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Example #27
0
        private ExceptionHandler GetExceptionHandler(TryBlock tryBlock, HandlerBlock handlerBlock)
        {
            var tryStart     = tryBlock.FirstBlock.First();
            var tryEnd       = GetNextBasicBlock(tryBlock.LastBlock.Last()) ?? throw new InvalidOperationException();
            var filterStart  = handlerBlock.Filter?.FirstBlock.First();
            var handlerStart = handlerBlock.FirstBlock.First();
            var handlerEnd   = GetNextBasicBlock(handlerBlock.LastBlock.Last());

            return(new ExceptionHandler()
            {
                TryStart = GetFirstInstruction(tryStart),
                TryEnd = GetFirstInstruction(tryEnd),
                HandlerStart = GetFirstInstruction(handlerStart),
                HandlerEnd = !(handlerEnd is null) ? GetFirstInstruction(handlerEnd) : null,
                FilterStart = !(filterStart is null) ? GetFirstInstruction(filterStart) : null,
                CatchType = handlerBlock.CatchType,
                HandlerType = GetHandlerType(handlerBlock)
            });
Example #28
0
        public override void VisitTryStatement(ITryStatement block, IList <IStatement> body)
        {
            AddIf(block, CompletionCase.EmptyCompletionBefore, body);

            var tryBlock = new TryBlock();

            body.Add(tryBlock);

            AddIf(block, CompletionCase.InBody, tryBlock.Body);
            AddIf(block, CompletionCase.InFinally, tryBlock.Finally);
            VisitBlock(block.Try, tryBlock.Body);
            VisitBlock(block.FinallyBlock, tryBlock.Finally);

            foreach (var clause in block.Catches)
            {
                var catchBlock = new CatchBlock();
                tryBlock.CatchBlocks.Add(catchBlock);

                AddIf(clause, CompletionCase.InBody, catchBlock.Body);

                VisitBlock(clause.Body, catchBlock.Body);

                var generalClause = clause as IGeneralCatchClause;
                if (generalClause != null)
                {
                    catchBlock.Kind = CatchBlockKind.General;
                    continue;
                }

                var specificClause = clause as ISpecificCatchClause;
                if (specificClause != null)
                {
                    var varDecl   = specificClause.ExceptionDeclaration;
                    var isUnnamed = varDecl == null;

                    var typeName = specificClause.ExceptionType.GetName();
                    var varName  = isUnnamed ? "?" : varDecl.DeclaredName;
                    catchBlock.Parameter = Names.Parameter("[{0}] {1}", typeName, varName);
                    catchBlock.Kind      = isUnnamed ? CatchBlockKind.Unnamed : CatchBlockKind.Default;
                }
            }

            AddIf(block, CompletionCase.EmptyCompletionAfter, body);
        }
Example #29
0
 /// <summary>
 /// Executes the task.
 /// </summary>
 protected override void ExecuteTask()
 {
     try {
         if (TryBlock != null)
         {
             TryBlock.Execute(this.CallStack);
         }
     } catch (BuildException be) {
         if (CatchBlock != null)
         {
             CatchBlock.Catch(be, this.CallStack, this.PropertyAccessor);
         }
         else
         {
             throw;
         }
     } finally {
         if (FinallyBlock != null)
         {
             FinallyBlock.Execute(this.CallStack);
         }
     }
 }
Example #30
0
 /// <summary>
 /// Executes the task.
 /// </summary>
 protected override void ExecuteTask()
 {
     try {
         if (TryBlock != null)
         {
             TryBlock.Execute();
         }
     } catch (BuildException be) {
         if (CatchBlock != null)
         {
             CatchBlock.Catch(be);
         }
         else
         {
             throw;
         }
     } finally {
         if (FinallyBlock != null)
         {
             FinallyBlock.Execute();
         }
     }
 }
Example #31
0
        public override bool Walk(TryStatement node)
        {
            TryBlock tb = null;

            if (!Options.Python25 && node.Handlers == null)
                tb = new TryBlock(node, true);
            else
                tb = new TryBlock(node, false);

            tryBlocks.Push(tb);
            node.Body.Walk(this);

            if (node.Handlers != null) {
                tb.state = TryBlock.State.Handler;
                foreach (TryStatementHandler handler in node.Handlers) {
                    handler.Walk(this);
                }
            }

            if (node.ElseStatement != null) {
                tb.state = TryBlock.State.Else;
                node.ElseStatement.Walk(this);
            }

            if (node.FinallyStatement != null) {
                tb.state = TryBlock.State.Finally;
                node.FinallyStatement.Walk(this);
            }

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

            return false;
        }
Example #32
0
 public void AddGuardedBlock(TryBlock block)
 {
     if (null == GuardedBlocks) { GuardedBlocks = new SortedList<TryBlock.SortKey, TryBlock>(); }
     GuardedBlocks.Add(block.GetSortKey(), block);
     return;
 }