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


C# AstGenerator.TransformAsObject方法代码示例

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


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

示例1: Transform

        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.MethodCallExpression call;

            if (_locals == null && _globals == null) {
                // exec code
                call = Ast.Call(
                    AstGenerator.GetHelperMethod("UnqualifiedExec"), 
                    AstUtils.CodeContext(), 
                    ag.TransformAsObject(_code)
                );
            } else {
                // exec code in globals [ , locals ]
                // We must have globals now (locals is last and may be absent)
                Debug.Assert(_globals != null);
                call = Ast.Call(
                    AstGenerator.GetHelperMethod("QualifiedExec"), 
                    AstUtils.CodeContext(), 
                    ag.TransformAsObject(_code), 
                    ag.TransformAndDynamicConvert(_globals, typeof(IAttributesCollection)), 
                    ag.TransformOrConstantNull(_locals, typeof(object))
                );
            }

            return ag.AddDebugInfo(call, Span);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:25,代码来源:ExecStatement.cs

示例2: Transform

 internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
     return Ast.Call(
         AstGenerator.GetHelperMethod("Repr"),   // method
         Microsoft.Scripting.Ast.Utils.CodeContext(),
         ag.TransformAsObject(_expression)       // args
     );                                  
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:BackQuoteExpression.cs

示例3: Transform

        internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
            MSAst.ParameterExpression list = ag.GetTemporary("list_comprehension_list", typeof(List));

            // 1. Initialization code - create list and store it in the temp variable
            MSAst.Expression initialize =
                Ast.Assign(
                    list,
                    Ast.Call(
                        AstGenerator.GetHelperMethod("MakeList", Type.EmptyTypes) // method
                    )                    
                );

            // 2. Create body from _item:   list.Append(_item)
            MSAst.Expression body = ag.AddDebugInfo(
                Ast.Call(
                    AstGenerator.GetHelperMethod("ListAddForComprehension"),
                    list,
                    ag.TransformAsObject(_item)
                ),
                _item.Span
            );

            // 3. Transform all iterators in reverse order, building the true body:
            int current = _iterators.Length;
            while (current-- > 0) {
                ListComprehensionIterator iterator = _iterators[current];
                body = iterator.Transform(ag, body);
            }

            return Ast.Block(
                initialize,
                body,
                list                        // result
            );
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:35,代码来源:ListComprehension.cs

示例4: Transform

 internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
     return Ast.Call(
         AstGenerator.GetHelperMethod("Repr"),   // method
         ag.LocalContext,
         ag.TransformAsObject(_expression)       // args
     );                                  
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:BackQuoteExpression.cs

示例5: Transform

        internal override MSAst.Expression Transform(AstGenerator ag) {
            MSAst.Expression destination = ag.TransformAsObject(_dest);

            if (_expressions.Length == 0) {
                MSAst.Expression result;
                if (destination != null) {
                    result = Ast.Call(
                        AstGenerator.GetHelperMethod("PrintNewlineWithDest"),
                        ag.LocalContext,
                        destination
                    );
                } else {
                    result = Ast.Call(
                        AstGenerator.GetHelperMethod("PrintNewline"),
                        ag.LocalContext
                    );
                }
                return ag.AddDebugInfo(result, Span);
            } else {
                // Create list for the individual statements
                List<MSAst.Expression> statements = new List<MSAst.Expression>();

                // Store destination in a temp, if we have one
                if (destination != null) {
                    MSAst.ParameterExpression temp = ag.GetTemporary("destination");

                    statements.Add(
                        ag.MakeAssignment(temp, destination)
                    );

                    destination = temp;
                }
                for (int i = 0; i < _expressions.Length; i++) {
                    string method = (i < _expressions.Length - 1 || _trailingComma) ? "PrintComma" : "Print";
                    Expression current = _expressions[i];
                    MSAst.MethodCallExpression mce;

                    if (destination != null) {
                        mce = Ast.Call(
                            AstGenerator.GetHelperMethod(method + "WithDest"),
                            ag.LocalContext,
                            destination,
                            ag.TransformAsObject(current)
                        );
                    } else {
                        mce = Ast.Call(
                            AstGenerator.GetHelperMethod(method),
                            ag.LocalContext,
                            ag.TransformAsObject(current)
                        );
                    }

                    statements.Add(mce);
                }

                statements.Add(AstUtils.Empty());
                return ag.AddDebugInfo(Ast.Block(statements.ToArray()), Span);
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:59,代码来源:PrintStatement.cs

示例6: Transform

        internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
            MSAst.Expression func = _function.TransformToFunctionExpression(ag);

            return Ast.Call(
                AstGenerator.GetHelperMethod("MakeGeneratorExpression"),
                func,
                ag.TransformAsObject(_iterable)
            );
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:GeneratorExpression.cs

示例7: Transform

        internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
            MSAst.Expression func = _function.TransformToFunctionExpression(ag);

            return ag.Invoke(
                typeof(object),
                new CallSignature(1),
                func,
                ag.TransformAsObject(_iterable)
            );
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:10,代码来源:GeneratorExpression.cs

示例8: Transform

        internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
            MSAst.Expression func = _function.TransformToFunctionExpression(ag);

            Debug.Assert(func.Type == typeof(PythonFunction));
            // Generator expressions always return functions.  We could do even better here when all PythonFunction's are in the same class.

            return Binders.Invoke(
                ag.BinderState,
                typeof(object),
                new CallSignature(1),
                func,
                ag.TransformAsObject(_iterable)
            );
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:14,代码来源:GeneratorExpression.cs

示例9: TransformForStatement

        internal static MSAst.Expression TransformForStatement(AstGenerator ag, MSAst.ParameterExpression enumerator,
                                                    Expression list, Expression left, MSAst.Expression body,
                                                    Statement else_, SourceSpan span, SourceLocation header,
                                                    MSAst.LabelTarget breakLabel, MSAst.LabelTarget continueLabel) {
            // enumerator = PythonOps.GetEnumeratorForIteration(list)
            MSAst.Expression init = Ast.Assign(
                    enumerator, 
                    ag.Operation(
                        typeof(IEnumerator),
                        PythonOperationKind.GetEnumeratorForIteration,
                        ag.TransformAsObject(list)
                    )
                );

            // while enumerator.MoveNext():
            //    left = enumerator.Current
            //    body
            // else:
            //    else
            MSAst.Expression ls = AstUtils.Loop(
                    ag.AddDebugInfo(Ast.Call(
                        enumerator,
                        typeof(IEnumerator).GetMethod("MoveNext")
                    ), left.Span),
                    null,
                    Ast.Block(
                        left.TransformSet(
                            ag,
                            SourceSpan.None,
                            Ast.Call(
                                enumerator,
                                typeof(IEnumerator).GetProperty("Current").GetGetMethod()
                            ),
                            PythonOperationKind.None
                        ),
                        body,
                        ag.UpdateLineNumber(list.Start.Line),
                        AstUtils.Empty()
                    ), 
                    ag.Transform(else_),
                    breakLabel, 
                    continueLabel
            );

            return Ast.Block(
                init,
                ls,
                AstUtils.Empty()
            );
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:50,代码来源:ForStatement.cs

示例10: TransformHandlers

        /// <summary>
        /// Transform multiple python except handlers for a try block into a single catch body.
        /// </summary>
        /// <param name="ag"></param>
        /// <param name="variable">The variable for the exception in the catch block.</param>
        /// <returns>Null if there are no except handlers. Else the statement to go inside the catch handler</returns>
        private MSAst.Expression TransformHandlers(AstGenerator ag, out MSAst.ParameterExpression variable) {
            if (_handlers == null || _handlers.Length == 0) {
                variable = null;
                return null;
            }

            MSAst.ParameterExpression exception = ag.GetTemporary("exception", typeof(Exception));
            MSAst.ParameterExpression extracted = ag.GetTemporary("extracted", typeof(object));

            // The variable where the runtime will store the exception.
            variable = exception;

            var tests = new List<Microsoft.Scripting.Ast.IfStatementTest>(_handlers.Length);
            MSAst.ParameterExpression converted = null;
            MSAst.Expression catchAll = null;

            for (int index = 0; index < _handlers.Length; index++) {
                TryStatementHandler tsh = _handlers[index];

                if (tsh.Test != null) {
                    Microsoft.Scripting.Ast.IfStatementTest ist;

                    //  translating:
                    //      except Test ...
                    //
                    //  generate following AST for the Test (common part):
                    //      CheckException(exception, Test)
                    MSAst.Expression test =
                        Ast.Call(
                            AstGenerator.GetHelperMethod("CheckException"),
                            extracted,
                            ag.TransformAsObject(tsh.Test)
                        );

                    if (tsh.Target != null) {
                        //  translating:
                        //      except Test, Target:
                        //          <body>
                        //  into:
                        //      if ((converted = CheckException(exception, Test)) != null) {
                        //          Target = converted;
                        //          traceback-header
                        //          <body>
                        //      }

                        if (converted == null) {
                            converted = ag.GetTemporary("converted");
                        }

                        ist = AstUtils.IfCondition(
                            Ast.NotEqual(
                                Ast.Assign(converted, test),
                                Ast.Constant(null)
                            ),
                            Ast.Block(
                                tsh.Target.TransformSet(ag, SourceSpan.None, converted, Operators.None),
                                GetTracebackHeader(
                                    new SourceSpan(tsh.Start, tsh.Header),
                                    ag,
                                    exception,
                                    ag.Transform(tsh.Body)
                                ),
                                Ast.Empty()
                            )
                        );
                    } else {
                        //  translating:
                        //      except Test:
                        //          <body>
                        //  into:
                        //      if (CheckException(exception, Test) != null) {
                        //          traceback-header
                        //          <body>
                        //      }
                        ist = AstUtils.IfCondition(
                            Ast.NotEqual(
                                test,
                                Ast.Constant(null)
                            ),
                            GetTracebackHeader(
                                new SourceSpan(tsh.Start, tsh.Header),
                                ag,
                                exception,
                                ag.Transform(tsh.Body)
                            )
                        );
                    }

                    // Add the test to the if statement test cascade
                    tests.Add(ist);
                } else {
                    Debug.Assert(index == _handlers.Length - 1);
                    Debug.Assert(catchAll == null);

//.........这里部分代码省略.........
开发者ID:octavioh,项目名称:ironruby,代码行数:101,代码来源:TryStatement.cs


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