public override void SetChildrenScopes(NovaScope scope) { TryBlock.SetScope(scope); RescueBlocks.ForEach(block => block.SetScope(scope)); EnsureBlock.SetScope(scope); ElseBlock.SetScope(scope); }
public override void WriteTo(ITextOutput output) { output.Write(".try "); TryBlock.WriteTo(output); output.Write(" fault "); faultBlock.WriteTo(output); }
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 }); }
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;", "}"); }
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); }
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); }
public void Equality_Default() { var a = new TryBlock(); var b = new TryBlock(); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public override IList <CilInstruction> GenerateInstructions() { var result = new List <CilInstruction>(); result.AddRange(TryBlock.GenerateInstructions()); result.AddRange(HandlerBlock.GenerateInstructions()); return(result); }
public TryBlock Build() { var tryBlock = new TryBlock(_block); tryBlock.Body = new OrderedBlockBuilder(_reader, "try", tryBlock).Build(); return(tryBlock); }
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); }
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(); }
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()); }
public override void WriteTo(ITextOutput output) { output.Write(".try "); TryBlock.WriteTo(output); foreach (var handler in Handlers) { output.Write(' '); handler.WriteTo(output); } }
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()); }
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()); }
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()); }
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); } }
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()) )); }
public void ChildrenIdentity() { var sut = new TryBlock { Body = { new ContinueStatement() }, CatchBlocks = { new CatchBlock() }, Finally = { new ReturnStatement() } }; AssertChildren(sut, sut.Body.First(), sut.Finally.First()); }
/// <summary> /// エラーハンドリングを行い、<c>Promise<T></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)); } }
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); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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); } }
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()); }
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) });
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); }
/// <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); } } }
/// <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(); } } }
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; }
public void AddGuardedBlock(TryBlock block) { if (null == GuardedBlocks) { GuardedBlocks = new SortedList<TryBlock.SortKey, TryBlock>(); } GuardedBlocks.Add(block.GetSortKey(), block); return; }