当前位置: 首页>>代码示例>>C#>>正文


C# AstGenerator.PushLineUpdated方法代码示例

本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator.PushLineUpdated方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.PushLineUpdated方法的具体用法?C# AstGenerator.PushLineUpdated怎么用?C# AstGenerator.PushLineUpdated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IronPython.Compiler.Ast.AstGenerator的用法示例。


在下文中一共展示了AstGenerator.PushLineUpdated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Transform

        internal override MSAst.Expression Transform(AstGenerator ag) {
            // allocated all variables here so they won't be shared w/ other 
            // locals allocated during the body or except blocks.
            MSAst.ParameterExpression noNestedException = null;
            if (_finally != null) {
                noNestedException = ag.GetTemporary("$noException", typeof(bool));
            }

            MSAst.ParameterExpression lineUpdated = null;
            MSAst.ParameterExpression runElse = null;

            if (_else != null || (_handlers != null && _handlers.Length > 0)) {
                lineUpdated = ag.GetTemporary("$lineUpdated", typeof(bool));
                if (_else != null) {
                    runElse = ag.GetTemporary("run_else", typeof(bool));
                }
            }

            // don't allocate locals below here...
            MSAst.Expression body = ag.Transform(_body);
            MSAst.Expression @else = ag.Transform(_else);

            if (body == null) {
                return null;
            }

            MSAst.ParameterExpression exception;
            MSAst.Expression @catch = TransformHandlers(ag, out exception);
            MSAst.Expression result;

            // We have else clause, must generate guard around it
            if (@else != null) {
                Debug.Assert(@catch != null);

                //  run_else = true;
                //  try {
                //      try_body
                //  } catch ( ... ) {
                //      run_else = false;
                //      catch_body
                //  }
                //  if (run_else) {
                //      else_body
                //  }
                result =
                    Ast.Block(
                        Ast.Assign(runElse, Ast.Constant(true)),
                        // save existing line updated, we could choose to do this only for nested exception handlers.
                        ag.PushLineUpdated(false, lineUpdated),
                        AstUtils.Try(
                            ag.AddDebugInfo(Ast.Empty(), new SourceSpan(Span.Start, _header)),
                            body
                        ).Catch(exception,
                            Ast.Assign(runElse, Ast.Constant(false)),
                            @catch,
                            // restore existing line updated after exception handler completes
                            ag.PopLineUpdated(lineUpdated),
                            Ast.Default(body.Type)
                        ),
                        AstUtils.IfThen(runElse,
                            @else
                        ),
                        Ast.Empty()
                    );

            } else if (@catch != null) {        // no "else" clause
                //  try {
                //      <try body>
                //  } catch (Exception e) {
                //      ... catch handling ...
                //  }
                //
                result = AstUtils.Try(
                        ag.AddDebugInfo(Ast.Empty(), new SourceSpan(Span.Start, _header)),
                        // save existing line updated
                        ag.PushLineUpdated(false, lineUpdated),
                        body
                    ).Catch(exception,
                        @catch,
                        // restore existing line updated after exception handler completes
                        ag.PopLineUpdated(lineUpdated),
                        Ast.Default(body.Type)
                    );
            } else {
                result = body;
            }

            try {
                return AddFinally(ag, result, noNestedException);
            } finally {
                // free all locals here after the children nodes have been generated
                if (lineUpdated != null) {
                    ag.FreeTemp(lineUpdated);
                }
                if (runElse != null) {
                    ag.FreeTemp(@runElse);
                }
            }
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:99,代码来源:TryStatement.cs

示例2: Transform


//.........这里部分代码省略.........
            //******************************************************************
            // 4. exc = True
            //******************************************************************
            MSAst.ParameterExpression exc = ag.GetTemporary("with_exc", typeof(bool));
            statements[3] = ag.MakeAssignment(
                exc,
                AstUtils.Constant(true)
            );

            //******************************************************************
            //  5. The final try statement:
            //
            //  try:
            //      VAR = value  # Only if "as VAR" is present
            //      BLOCK
            //  except:
            //      # The exceptional case is handled here
            //      exc = False
            //      if not exit(*sys.exc_info()):
            //          raise
            //      # The exception is swallowed if exit() returns true
            //  finally:
            //      # The normal and non-local-goto cases are handled here
            //      if exc:
            //          exit(None, None, None)
            //******************************************************************

            MSAst.ParameterExpression exception = ag.GetTemporary("exception", typeof(Exception));
            MSAst.ParameterExpression nestedFrames = ag.GetTemporary("$nestedFrames", typeof(List<DynamicStackFrame>));
            statements[4] =
                // try:
                AstUtils.Try(
                    AstUtils.Try(// try statement body
                        ag.PushLineUpdated(false, lineUpdated),
                        _var != null ?
                            ag.AddDebugInfo(
                                Ast.Block(
                    // VAR = value
                                    _var.TransformSet(ag, SourceSpan.None, value, PythonOperationKind.None),
                    // BLOCK
                                    ag.Transform(_body),
                                    AstUtils.Empty()
                                ),
                                _body.Span
                            ) :
                    // BLOCK
                            ag.Transform(_body) // except:, // try statement location
                    ).Catch(exception,
                    // Python specific exception handling code
                        TryStatement.GetTracebackHeader(                        
                            ag,
                            exception,
                            ag.AddDebugInfo(
                                Ast.Block(
                                    // exc = False
                                    ag.MakeAssignment(
                                        exc,
                                        AstUtils.Constant(false)
                                    ),
                                    Ast.Assign(
                                        nestedFrames,
                                        Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
                                    ),
                                    //  if not exit(*sys.exc_info()):
                                    //      raise
                                    AstUtils.IfThen(
开发者ID:m4dc4p,项目名称:ironruby,代码行数:67,代码来源:WithStatement.cs


注:本文中的IronPython.Compiler.Ast.AstGenerator.PushLineUpdated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。