本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator.TransformAndDynamicConvert方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.TransformAndDynamicConvert方法的具体用法?C# AstGenerator.TransformAndDynamicConvert怎么用?C# AstGenerator.TransformAndDynamicConvert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Compiler.Ast.AstGenerator
的用法示例。
在下文中一共展示了AstGenerator.TransformAndDynamicConvert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
MSAst.Expression test = ag.TransformAndDynamicConvert(_testExpr, typeof(bool));
MSAst.Expression ifTrue = ag.TransformAndDynamicConvert(_trueExpr, type);
MSAst.Expression ifFalse = ag.TransformAndDynamicConvert(_falseExpr, type);
// Convert both to "type" ... since they are assignable already
// it is really just a cosmetic cast.
ifTrue = AstUtils.Convert(ifTrue, type);
ifFalse = AstUtils.Convert(ifFalse, type);
return Ast.Condition(test, ifTrue, ifFalse);
}
示例2: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.Expression result;
if (_else != null) {
result = ag.Transform(_else);
} else {
result = AstUtils.Empty();
}
// Now build from the inside out
int i = _tests.Length;
while (i-- > 0) {
IfStatementTest ist = _tests[i];
result = ag.AddDebugInfoAndVoid(
Ast.Condition(
ag.TransformAndDynamicConvert(ist.Test, typeof(bool)),
ag.TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start),
result
),
new SourceSpan(ist.Start, ist.Header)
);
}
return result;
}
示例3: 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);
}
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag, MSAst.Expression body) {
return ag.AddDebugInfoAndVoid(
AstUtils.If(
ag.TransformAndDynamicConvert(_test, typeof(bool)),
body
),
Span
);
}
示例5: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
// Only the body is "in the loop" for the purposes of break/continue
// The "else" clause is outside
MSAst.LabelTarget breakLabel, continueLabel;
MSAst.Expression body = ag.TransformLoopBody(_body, out breakLabel, out continueLabel);
return AstUtils.While(
ag.AddDebugInfo(
ag.TransformAndDynamicConvert(_test, typeof(bool)),
Header
),
body,
ag.Transform(_else),
breakLabel,
continueLabel
);
}
示例6: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
// If debugging is off, return empty statement
if (ag.Optimize) {
return AstUtils.Empty();
}
// Transform into:
// if (_test) {
// } else {
// RaiseAssertionError(_message);
// }
return ag.AddDebugInfoAndVoid(
AstUtils.Unless( // if
ag.TransformAndDynamicConvert(_test, typeof(bool)), // _test
Ast.Call( // else branch
AstGenerator.GetHelperMethod("RaiseAssertionError"),
ag.TransformOrConstantNull(_message, typeof(object))
)
),
Span
);
}
示例7: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
// Only the body is "in the loop" for the purposes of break/continue
// The "else" clause is outside
MSAst.LabelTarget breakLabel, continueLabel;
ConstantExpression constTest = _test as ConstantExpression;
if (constTest != null && constTest.Value is int) {
// while 0: / while 1:
int val = (int)constTest.Value;
if (val == 0) {
// completely optimize the loop away
if (_else == null) {
return MSAst.Expression.Empty();
} else {
return ag.Transform(_else);
}
}
MSAst.Expression test = MSAst.Expression.Constant(true);
MSAst.Expression res = AstUtils.While(
test,
ag.TransformLoopBody(_body, SourceLocation.Invalid, out breakLabel, out continueLabel),
ag.Transform(_else),
breakLabel,
continueLabel
);
if (_test.Start.Line != _body.Start.Line) {
res = ag.AddDebugInfo(res, _test.Span);
}
return res;
}
return AstUtils.While(
ag.AddDebugInfo(
ag.TransformAndDynamicConvert(_test, typeof(bool)),
Header
),
ag.TransformLoopBody(_body, _test.Start, out breakLabel, out continueLabel),
ag.Transform(_else),
breakLabel,
continueLabel
);
}