本文整理汇总了C#中IronRuby.Compiler.Ast.AstGenerator.LeaveRescueClause方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.LeaveRescueClause方法的具体用法?C# AstGenerator.LeaveRescueClause怎么用?C# AstGenerator.LeaveRescueClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronRuby.Compiler.Ast.AstGenerator
的用法示例。
在下文中一共展示了AstGenerator.LeaveRescueClause方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformExceptionHandling
private MSA.Expression/*!*/ TransformExceptionHandling(AstGenerator/*!*/ gen, ResultOperation resultOperation) {
Assert.NotNull(gen);
MSA.Expression exceptionThrownVariable = gen.CurrentScope.DefineHiddenVariable("#exception-thrown", typeof(bool));
MSA.ParameterExpression exceptionVariable = gen.CurrentScope.DefineHiddenVariable("#exception", typeof(Exception));
MSA.Expression exceptionRethrowVariable = gen.CurrentScope.DefineHiddenVariable("#exception-rethrow", typeof(bool));
MSA.Expression retryingVariable = gen.CurrentScope.DefineHiddenVariable("#retrying", typeof(bool));
MSA.ParameterExpression evalUnwinder = gen.CurrentScope.DefineHiddenVariable("#unwinder", typeof(EvalUnwinder));
MSA.Expression oldExceptionVariable = gen.CurrentScope.DefineHiddenVariable("#old-exception", typeof(Exception));
MSA.Expression transformedBody;
MSA.Expression transformedEnsure;
MSA.Expression transformedElse;
if (_ensureStatements != null) {
transformedEnsure = Ast.Block(
// ensure:
Ast.Assign(oldExceptionVariable, Methods.GetCurrentException.OpCall(gen.CurrentScopeVariable)),
gen.TransformStatements(_ensureStatements, ResultOperation.Ignore),
Methods.SetCurrentException.OpCall(gen.CurrentScopeVariable, oldExceptionVariable),
// rethrow:
AstUtils.IfThen(
Ast.AndAlso(
exceptionRethrowVariable,
Ast.NotEqual(oldExceptionVariable, AstUtils.Constant(null))
),
Ast.Throw(oldExceptionVariable)
),
AstUtils.Empty()
);
} else {
// rethrow:
transformedEnsure = AstUtils.IfThen(
Ast.AndAlso(
exceptionRethrowVariable,
Ast.NotEqual(
Ast.Assign(oldExceptionVariable, Methods.GetCurrentException.OpCall(gen.CurrentScopeVariable)),
AstUtils.Constant(null, typeof(Exception)))
),
Ast.Throw(oldExceptionVariable)
);
}
if (_elseStatements != null) {
transformedElse = gen.TransformStatements(_elseStatements, resultOperation);
} else {
transformedElse = AstUtils.Empty();
}
// body should do return, but else-clause is present => we cannot do return from the guarded statements:
// (the value of the last expression in the body cannot be the last executed expression statement => we can ignore it):
transformedBody = gen.TransformStatements(_statements, (_elseStatements != null) ? ResultOperation.Ignore : resultOperation);
MSA.Expression setInRescueFlag = null, clearInRescueFlag = null;
var breakLabel = Ast.Label();
var continueLabel = Ast.Label();
// make rescue clause:
MSA.Expression transformedRescue;
if (_rescueClauses != null) {
// outer-most EH blocks sets and clears runtime flag RuntimeFlowControl.InTryRescue:
if (gen.CurrentRescue == null) {
setInRescueFlag = Ast.Assign(Ast.Field(gen.CurrentRfcVariable, RuntimeFlowControl.InRescueField), AstUtils.Constant(true));
clearInRescueFlag = Ast.Assign(Ast.Field(gen.CurrentRfcVariable, RuntimeFlowControl.InRescueField), AstUtils.Constant(false));
} else {
setInRescueFlag = clearInRescueFlag = AstUtils.Empty();
}
gen.EnterRescueClause(retryingVariable, breakLabel, continueLabel);
var handlers = new IfStatementTest[_rescueClauses.Count];
for (int i = 0; i < handlers.Length; i++) {
handlers[i] = _rescueClauses[i].Transform(gen, resultOperation);
}
transformedRescue = Ast.Block(
setInRescueFlag,
AstUtils.Try(
AstUtils.If(handlers, Ast.Assign(exceptionRethrowVariable, AstUtils.Constant(true)))
).Filter(evalUnwinder, Ast.Equal(Ast.Field(evalUnwinder, EvalUnwinder.ReasonField), AstUtils.Constant(BlockReturnReason.Retry)),
Ast.Block(
Ast.Assign(retryingVariable, AstUtils.Constant(true)),
Ast.Continue(continueLabel),
AstUtils.Empty()
)
)
);
gen.LeaveRescueClause();
} else {
transformedRescue = Ast.Assign(exceptionRethrowVariable, AstUtils.Constant(true));
}
if (_elseStatements != null) {
transformedElse = AstUtils.Unless(exceptionThrownVariable, transformedElse);
}
var result = AstFactory.Infinite(breakLabel, continueLabel,
//.........这里部分代码省略.........