本文整理汇总了C#中AstExpression.Add方法的典型用法代码示例。如果您正苦于以下问题:C# AstExpression.Add方法的具体用法?C# AstExpression.Add怎么用?C# AstExpression.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstExpression
的用法示例。
在下文中一共展示了AstExpression.Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitExpression
/// <summary>
/// Generate code for the given expression.
/// </summary>
private RLRange VisitExpression(AstExpression node, List<RLRange> args, AstNode parent)
{
switch (node.Code)
{
case AstCode.Nop:
case AstCode.Endfinally:
case AstCode.Endfilter:
return new RLRange(this.Add(node.SourceLocation, RCode.Nop), null);
case AstCode.Ldexception:
throw new InvalidOperationException("ldexception should not occur");
case AstCode.Dup:
return new RLRange(this.Add(node.SourceLocation, RCode.Nop), args[0].Result);
#region Constants
case AstCode.Ldc_I4:
case AstCode.Ldc_R4:
{
var type = node.GetResultType();
var converter = type.ConstValueConverter(true);
var value = converter(node.Operand);
var r = frame.AllocateTemp(type.IsFloat() ? PrimitiveType.Float : PrimitiveType.Int);
var first = this.Add(node.SourceLocation, RCode.Const, value, r);
return new RLRange(first, r);
}
case AstCode.Ldc_I8:
case AstCode.Ldc_R8:
{
var type = node.GetResultType();
var converter = type.ConstValueConverter(false);
var value = converter(node.Operand);
var r = frame.AllocateTemp(type.IsDouble() ? PrimitiveType.Double : PrimitiveType.Long);
return new RLRange(args, this.Add(node.SourceLocation, RCode.Const_wide, value, r), r);
}
case AstCode.Ldnull:
{
//Debugger.Launch();
var r = frame.AllocateTemp(node.GetResultType().GetReference(targetPackage));
return new RLRange(args, this.Add(node.SourceLocation, RCode.Const, 0, r), r);
}
case AstCode.Ldstr:
{
var str = (string) node.Operand;
var r = frame.AllocateTemp(node.GetResultType().GetReference(targetPackage));
return new RLRange(args, this.Add(node.SourceLocation, RCode.Const_string, str, r), r);
}
case AstCode.DefaultValue:
{
var type = (XTypeReference) node.Operand;
if (type.IsPrimitive)
{
var r = frame.AllocateTemp(type.GetReference(targetPackage));
return new RLRange(args, this.Add(node.SourceLocation, node.Arguments[0].Const(), 0, r), r);
}
if (type.IsEnum())
{
var r = frame.AllocateTemp(type.GetReference(targetPackage));
var denumType = type.GetClassReference(targetPackage);
var defaultField = new FieldReference(denumType, NameConstants.Enum.DefaultFieldName, denumType);
return new RLRange(this.Add(node.SourceLocation, RCode.Sget_object, defaultField, r), r);
}
else
{
var r = frame.AllocateTemp(type.GetReference(targetPackage));
return new RLRange(args, this.Add(node.SourceLocation, RCode.Const, 0, r), r);
}
}
case AstCode.TypeOf:
{
var type = (XTypeReference) node.Operand;
var dtype = type.IsVoid() ? PrimitiveType.Void : type.GetReference(targetPackage);
var typeReg = frame.AllocateTemp(FrameworkReferences.Class);
var first = this.Add(node.SourceLocation, RCode.Const_class, dtype, typeReg);
return new RLRange(first, typeReg);
}
case AstCode.BoxedTypeOf:
{
var type = (XTypeReference) node.Operand;
var typeReg = frame.AllocateTemp(FrameworkReferences.Class);
var first = this.Add(node.SourceLocation, RCode.Const_class, type.GetBoxedType(), typeReg);
return new RLRange(first, typeReg);
}
#endregion
#region Arithmetic
case AstCode.Neg:
{
var tmp = this.EnsureTemp(node.SourceLocation, args[0].Result, frame);
return new RLRange(args, this.Add(node.SourceLocation, node.Neg(), tmp.Result, tmp.Result),
tmp.Result);
}
case AstCode.Not:
{
var tmp = this.EnsureTemp(node.SourceLocation, args[0].Result, frame);
//.........这里部分代码省略.........