本文整理汇总了C#中Dot42.CompilerLib.XModel.XTypeReference.IsWide方法的典型用法代码示例。如果您正苦于以下问题:C# XTypeReference.IsWide方法的具体用法?C# XTypeReference.IsWide怎么用?C# XTypeReference.IsWide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dot42.CompilerLib.XModel.XTypeReference
的用法示例。
在下文中一共展示了XTypeReference.IsWide方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertNumericToEnum
/// <summary>
/// Convert the given node that holds a numeric value and convert it to it's enum instance.
/// </summary>
private static void ConvertNumericToEnum(AstExpression node, XTypeDefinition enumType, XTypeReference enumNumericType)
{
// Call Enum.GetValue(enumType, value)
var enumValue = new AstExpression(node);
node.SetCode(enumNumericType.IsWide() ? AstCode.Long_to_enum : AstCode.Int_to_enum).SetArguments(enumValue).SetType(enumType);
node.Operand = null;
}
示例2: CreateLoadValueSequence
/// <summary>
/// Create code to load a value from an annotation interface.
/// </summary>
/// <returns>The register(s) holding the value</returns>
private static Register[] CreateLoadValueSequence(
ISourceLocation seqp,
MethodBody body,
XTypeReference valueType,
Register annotationReg,
MethodDefinition getter,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
out Instruction branchIfNotSet)
{
// NOTE: It would be better if we wouldn't get the values as object arrays
// but as arrays of the actual type.
// Apparently though the DexWriter will not write our attributes
// if they contain arrays not of type object[]. Therefore the
// conversion code below.
// All in all it would be much cleaner if we could emit Ast code here
// instead of RL code.
List<Register> result = new List<Register>();
// get the array.
Register regObject = body.AllocateRegister(RCategory.Temp, RType.Object);
Register regIntVal = body.AllocateRegister(RCategory.Temp, RType.Value);
body.Instructions.Add(seqp, RCode.Invoke_interface, getter, annotationReg);
body.Instructions.Add(seqp, RCode.Move_result_object, regObject);
// allocate result, initialize to default value.
if (valueType.IsWide())
{
Tuple<Register, Register> regs = body.AllocateWideRegister(RCategory.Temp);
body.Instructions.Add(seqp, RCode.Const_wide, 0, regs.Item1);
result.Add(regs.Item1);
result.Add(regs.Item2);
}
else if (valueType.IsPrimitive)
{
Register reg = body.AllocateRegister(RCategory.Temp, RType.Value);
body.Instructions.Add(seqp, RCode.Const, 0, reg);
result.Add(reg);
}
else // object
{
Register reg = body.AllocateRegister(RCategory.Temp, RType.Object);
body.Instructions.Add(seqp, RCode.Const, 0, reg);
result.Add(reg);
}
// check if value is unset (array length 0) or null (array length 2)
body.Instructions.Add(seqp, RCode.Array_length, regIntVal, regObject);
branchIfNotSet = body.Instructions.Add(seqp, RCode.If_eqz, regIntVal);
body.Instructions.Add(seqp, RCode.Rsub_int, 1, regIntVal, regIntVal);
var branchOnNull = body.Instructions.Add(seqp, RCode.If_nez, regIntVal);
// get the (boxed) value
body.Instructions.Add(seqp, RCode.Const, 0, regIntVal);
// convert to target type.
if (valueType.IsArray)
{
Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
Register regType = body.AllocateRegister(RCategory.Temp, RType.Object);
var helper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName);
var convertArray = helper.Resolve().Methods.First(p => p.Name == "ConvertArray" && p.Parameters.Count == 2)
.GetReference(targetPackage);
var underlying = valueType.ElementType.GetReference(targetPackage);
body.Instructions.Add(seqp, RCode.Aget_object, regTmp, regObject, regIntVal);
body.Instructions.Add(seqp, RCode.Const_class, underlying, regType);
body.Instructions.Add(seqp, RCode.Invoke_static, convertArray, regTmp, regType);
body.Instructions.Add(seqp, RCode.Move_result_object, result[0]);
body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
}
else if (valueType.IsEnum())
{
Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
Register regType = body.AllocateRegister(RCategory.Temp, RType.Object);
var getFromObject = compiler.GetDot42InternalType("Enum").Resolve()
.Methods.Single(p=>p.Name == "GetFromObject")
.GetReference(targetPackage);
body.Instructions.Add(seqp, RCode.Aget_object, regTmp, regObject, regIntVal);
body.Instructions.Add(seqp, RCode.Const_class, valueType.GetReference(targetPackage), regType);
body.Instructions.Add(seqp, RCode.Invoke_static, getFromObject, regType, regTmp);
body.Instructions.Add(seqp, valueType.MoveResult(), result[0]);
body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
}
else if(!valueType.IsPrimitive)
{
body.Instructions.Add(seqp, RCode.Aget_object, result[0], regObject, regIntVal);
body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
}
else
{
Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
//.........这里部分代码省略.........
示例3: CreateInitializeValueInstructions
/// <summary>
/// Create code to initialize a value from an attribute.
/// </summary>
/// <returns>The register(s) holding the value</returns>
private static Register[] CreateInitializeValueInstructions(ISourceLocation seqp, MethodBody body, XTypeReference targetType, CustomAttributeArgument value, AssemblyCompiler compiler, DexTargetPackage targetPackage)
{
List<Register> result = new List<Register>();
// allocate result, initialize to default value.
if (targetType.IsWide())
{
Tuple<Register, Register> regs = body.AllocateWideRegister(RCategory.Temp);
//body.Instructions.Add(seqp, RCode.Const_wide, 0, regs.Item1);
result.Add(regs.Item1);
result.Add(regs.Item2);
}
else if (targetType.IsPrimitive)
{
Register reg = body.AllocateRegister(RCategory.Temp, RType.Value);
//body.Instructions.Add(seqp, RCode.Const, 0, reg);
result.Add(reg);
}
else // object
{
Register reg = body.AllocateRegister(RCategory.Temp, RType.Object);
//body.Instructions.Add(seqp, RCode.Const, 0, reg);
result.Add(reg);
}
// load data
if (value.Value == null) // must be a reference type
{
body.Instructions.Add(seqp, RCode.Const, 0, result[0]);
body.Instructions.Add(seqp, RCode.Check_cast, targetType.GetReference(targetPackage), result[0]);
return result.ToArray();
}
var valueType = XBuilder.AsTypeReference(compiler.Module, value.Type);
if (value.Value is CustomAttributeArgument)
{
// this happens if a type conversion is neccessary
var nestedValue = (CustomAttributeArgument)value.Value;
valueType = XBuilder.AsTypeReference(compiler.Module, nestedValue.Type);
var rOrigValue = CreateInitializeValueInstructions(seqp, body, valueType, nestedValue, compiler, targetPackage);
if (!nestedValue.Type.IsPrimitive)
{
body.Instructions.Add(seqp, RCode.Move_object, result[0], rOrigValue[0]);
body.Instructions.Add(seqp, RCode.Check_cast, targetType.GetReference(targetPackage), result[0]);
}
else if(!targetType.IsPrimitive)
{
body.Instructions.Add(seqp, RCode.Invoke_static, valueType.GetBoxValueOfMethod(), rOrigValue);
body.Instructions.Add(seqp, RCode.Move_result_object, result[0]);
body.Instructions.Add(seqp, RCode.Check_cast, targetType.GetReference(targetPackage), result[0]);
}
else
{
throw new Exception(string.Format("type converstion in attribute {0}=>{1} not yet supported", valueType.FullName, targetType.FullName));
}
}
else if (valueType.IsArray)
{
var array = (CustomAttributeArgument[])value.Value;
var elementType = valueType.ElementType;
Register rIndex = body.AllocateRegister(RCategory.Temp, RType.Value);
body.Instructions.Add(seqp, RCode.Const, array.Length, rIndex);
body.Instructions.Add(seqp, RCode.New_array, valueType.GetReference(targetPackage), result[0], rIndex);
// iterate through each value
for (int i = 0; i < array.Length; i++)
{
Register rLoaded = CreateInitializeValueInstructions(seqp, body, elementType, array[i], compiler, targetPackage)[0];
body.Instructions.Add(seqp, RCode.Const, i, rIndex);
body.Instructions.Add(seqp, valueType.APut(), rLoaded, result[0], rIndex);
}
}
else if (targetType.IsEnum())
{
var enumClass = (targetType.IsEnum()? targetType:valueType).GetReference(targetPackage) ;
Register rEnumClass = body.AllocateRegister(RCategory.Temp, RType.Object);
body.Instructions.Add(seqp, RCode.Const_class, enumClass, rEnumClass);
long lVal = Convert.ToInt64(value.Value);
if (lVal <= int.MaxValue && lVal >= int.MinValue)
{
Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Value);
body.Instructions.Add(seqp, RCode.Const, (int)lVal, regTmp);
var get = compiler.GetDot42InternalType("Enum").Resolve()
.Methods.Single(p => p.Name == "Get" && p.Parameters.Count == 2 && !p.Parameters[1].ParameterType.IsWide())
.GetReference(targetPackage);
body.Instructions.Add(seqp, RCode.Invoke_static, get, rEnumClass, regTmp);
body.Instructions.Add(seqp, targetType.MoveResult(), result[0]);
}
//.........这里部分代码省略.........