本文整理汇总了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);
}
示例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
);
}
示例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
);
}
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return Ast.Call(
AstGenerator.GetHelperMethod("Repr"), // method
ag.LocalContext,
ag.TransformAsObject(_expression) // args
);
}
示例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);
}
}
示例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)
);
}
示例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)
);
}
示例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)
);
}
示例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()
);
}
示例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);
//.........这里部分代码省略.........