本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator.TransformOrConstantNull方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.TransformOrConstantNull方法的具体用法?C# AstGenerator.TransformOrConstantNull怎么用?C# AstGenerator.TransformOrConstantNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Compiler.Ast.AstGenerator
的用法示例。
在下文中一共展示了AstGenerator.TransformOrConstantNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.Expression raiseExpression;
if (_type == null && _value == null && _traceback == null) {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeRethrownException"),
ag.LocalContext
);
if (!ag._isEmittingFinally) {
raiseExpression = Ast.Block(
ag.UpdateLineUpdated(true),
raiseExpression
);
}
} else {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeException"),
ag.LocalContext,
ag.TransformOrConstantNull(_type, typeof(object)),
ag.TransformOrConstantNull(_value, typeof(object)),
ag.TransformOrConstantNull(_traceback, typeof(object))
);
}
return ag.AddDebugInfo(
Ast.Throw(raiseExpression),
Span
);
}
示例2: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return Ast.Call(
AstGenerator.GetHelperMethod("MakeSlice"), // method
ag.TransformOrConstantNull(_sliceStart, typeof(object)), // parameters
ag.TransformOrConstantNull(_sliceStop, typeof(object)),
ag.TransformOrConstantNull(_sliceStep, typeof(object))
);
}
示例3: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
// create keys & values into array and then call helper function
// which creates the dictionary
if (_items.Length != 0) {
MSAst.Expression[] parts = new MSAst.Expression[_items.Length * 2];
Type t = null;
bool heterogeneous = false;
for (int index = 0; index < _items.Length; index++) {
SliceExpression slice = _items[index];
// Eval order should be:
// { 2 : 1, 4 : 3, 6 :5 }
// This is backwards from parameter list eval, so create temporaries to swap ordering.
parts[index * 2] = ag.TransformOrConstantNull(slice.SliceStop, typeof(object));
MSAst.Expression key = parts[index * 2 + 1] = ag.TransformOrConstantNull(slice.SliceStart, typeof(object));
Type newType;
if (key.NodeType == System.Linq.Expressions.ExpressionType.Convert) {
newType = ((MSAst.UnaryExpression)key).Operand.Type;
} else {
newType = key.Type;
}
if (t == null) {
t = newType;
} else if (newType == typeof(object)) {
heterogeneous = true;
} else if (newType != t) {
heterogeneous = true;
}
}
return Ast.Call(
typeof(PythonOps).GetMethod(heterogeneous ? "MakeDictFromItems" : "MakeHomogeneousDictFromItems"),
Ast.NewArrayInit(
typeof(object),
parts
)
);
}
// empty dictionary
return Ast.Call(
typeof(PythonOps).GetMethod("MakeDict"),
Ast.Constant(0)
);
}
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
if (ag.IsGenerator) {
if (_expression != null) {
// Statements can't return null, so return a rethrow.
// Callers should detecet the ag.AddError and avoid trying to execute the tree,
// but if they accidentally do, use Throw instead of empty so that
// we'll get an exception.
return Ast.Throw(
Ast.New(
typeof(InvalidOperationException).GetConstructor(Type.EmptyTypes)
)
);
}
return ag.AddDebugInfo(AstUtils.YieldBreak(ag.GeneratorLabel), Span);
}
return ag.AddDebugInfo(
Ast.Return(
ag.ReturnLabel,
ag.TransformOrConstantNull(_expression, typeof(object))
),
Span
);
}
示例5: 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);
}
示例6: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.MethodCallExpression raiseExpression;
if (_type == null && _value == null && _traceback == null) {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeRethrownException"),
AstUtils.CodeContext()
);
} else {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeException"),
AstUtils.CodeContext(),
ag.TransformOrConstantNull(_type, typeof(object)),
ag.TransformOrConstantNull(_value, typeof(object)),
ag.TransformOrConstantNull(_traceback, typeof(object))
);
}
return ag.AddDebugInfo(
Ast.Throw(raiseExpression),
Span
);
}
示例7: 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
);
}