本文整理汇总了C#中Dot42.CompilerLib.XModel.XTypeReference.IsByte方法的典型用法代码示例。如果您正苦于以下问题:C# XTypeReference.IsByte方法的具体用法?C# XTypeReference.IsByte怎么用?C# XTypeReference.IsByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dot42.CompilerLib.XModel.XTypeReference
的用法示例。
在下文中一共展示了XTypeReference.IsByte方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Box
/// <summary>
/// Create code to box the given source value into the given type.
/// </summary>
public static RLRange Box(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame)
{
if (type.IsPrimitive)
{
if (type.IsByte()) builder.Add(sequencePoint, RCode.Int_to_byte, source.Register, source.Register);
else if (type.IsUInt16()) builder.Add(sequencePoint, RCode.Int_to_short, source.Register, source.Register);
// Call appropriate valueOf method
var boxedType = type.Module.TypeSystem.Object;
var r = frame.AllocateTemp(boxedType.GetReference(targetPackage));
var call = builder.Add(sequencePoint, RCode.Invoke_static, type.GetBoxValueOfMethod(), source.Registers);
var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
return new RLRange(call, last, r);
}
if (type.IsGenericParameter)
{
var nop = builder.Add(sequencePoint, RCode.Nop);
return new RLRange(nop, source);
}
XTypeDefinition typeDef ;
if (type.TryResolve(out typeDef) && (typeDef.IsEnum))
{
// Call appropriate valueOf method
/*var boxedType = type.Module.TypeSystem.Object;
var r = frame.AllocateTemp(boxedType.GetReference(target, nsConverter));
var call = builder.Add(sequencePoint, RCode.Invoke_static, typeDef.GetEnumUnderlyingType().GetBoxValueOfMethod(), source.Registers);
var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
return new RLRange(call, last, r);*/
}
// Just cast
var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source);
return new RLRange(checkCast, source);
}
示例2: ConvertIfNeeded
/// <summary>
/// Convert the result of the given node to uint8/uint16 if needed.
/// </summary>
private static void ConvertIfNeeded(AstExpression node, XTypeReference valueType, AstExpression parent)
{
AstCode convCode;
if (valueType.IsByte())
{
// Convert from int to uint8
convCode = AstCode.Int_to_ubyte;
}
else if (valueType.IsUInt16())
{
// Convert from int to uint16
convCode = AstCode.Int_to_ushort;
}
else if (valueType.IsChar())
{
// Convert from int to uint16
convCode = AstCode.Conv_U2;
}
else
{
// Do not convert
return;
}
// Avoid recursion
if ((parent != null) && (parent.Code == convCode))
return;
// Copy load expression
var clone = new AstExpression(node);
// Convert node
node.Code = convCode;
node.Arguments.Clear();
node.Arguments.Add(clone);
node.Operand = null;
node.InferredType = valueType;
// keep the expected type!
node.ExpectedType = clone.ExpectedType;
clone.ExpectedType = valueType;
}
示例3: ConvertTypeBeforeStore
/// <summary>
/// Emit code (if needed) to convert a value from source type to destination type.
/// This method is used in "store" opcodes such stloc, stfld, stsfld, call
/// </summary>
internal static RLRange ConvertTypeBeforeStore(this IRLBuilder builder, ISourceLocation sequencePoint, XTypeReference sourceType, XTypeReference destinationType, RegisterSpec source, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler, out bool converted)
{
converted = false;
if (sourceType.IsSame(destinationType))
{
// Unsigned conversions
if (sourceType.IsByte())
{
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
var ins = builder.Add(sequencePoint, RCode.Int_to_byte, tmp.Result, tmp.Result);
converted = true;
return new RLRange(tmp, ins, tmp.Result);
}
else if (sourceType.IsUInt16())
{
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
var ins = builder.Add(sequencePoint, RCode.Int_to_short, tmp.Result, tmp.Result);
converted = true;
return new RLRange(tmp, ins, tmp.Result);
}
return new RLRange(source);
}
if (sourceType.IsArray)
{
var compilerHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve();
var arrayType = targetPackage.DexFile.GetClass(targetPackage.NameConverter.GetConvertedFullName(compilerHelper));
var sourceArrayElementType = ((XArrayType)sourceType).ElementType;
if (destinationType.ExtendsIList())
{
// Use ArrayHelper.AsList to convert
var convertMethodName = "AsList";
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
if (destinationType.ExtendsICollection())
{
// Use ArrayHelper.AsCollection to convert
var convertMethodName = "AsCollection";
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
if (destinationType.ExtendsIEnumerable())
{
// Use ArrayHelper.As...Enumerable to convert
var convertMethodName = "AsObjectEnumerable";
if (sourceArrayElementType.IsPrimitive)
{
if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable";
else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable";
else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable";
else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable";
else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable";
else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable";
else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable";
else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable";
else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable";
else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable";
else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable";
else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType);
}
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
}
// Do not convert
return new RLRange(source);
}
示例4: GetAsEnumerableTMethodName
/// <summary>
/// Returns the method name when converting an array to an IEnumerableT in compiler helper.
///
/// (not sure if this is the best place for this method...)
/// </summary>
public static string GetAsEnumerableTMethodName(XTypeReference sourceArrayElementType)
{
var convertMethodName = "AsObjectEnumerable";
if (sourceArrayElementType.IsPrimitive)
{
if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable";
else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable";
else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable";
else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable";
else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable";
else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable";
else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable";
else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable";
else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable";
else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable";
else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable";
else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType);
}
return convertMethodName;
}
示例5: OpcodeForType
/// <summary>
/// Generate an Add opcode.
/// </summary>
private static RCode OpcodeForType(XTypeReference type, RCode[] opcodes)
{
if (type.IsInt32() || type.IsUInt32() || type.IsInt16() || type.IsUInt16() || type.IsChar() || type.IsByte() || type.IsSByte() || type.IsBoolean()) return opcodes[0];
if (type.IsInt64() || type.IsUInt64()) return opcodes[1];
if (type.IsFloat()) return opcodes[2];
if (type.IsDouble()) return opcodes[3];
XTypeDefinition typeDef;
if (type.TryResolve(out typeDef))
{
if (typeDef.IsEnum)
{
return OpcodeForType(typeDef.GetEnumUnderlyingType(), opcodes);
}
}
throw new ArgumentException("Unsupported type " + type);
}
示例6: ConvertIfNeeded
private static void ConvertIfNeeded(AstExpression arg, XTypeReference targetType)
{
var argType = arg.GetResultType();
if (!targetType.IsSame(argType))
{
if (targetType.IsByte())
{
Convert(arg, AstCode.Int_to_ubyte, targetType);
}
else if (targetType.IsSByte())
{
Convert(arg, AstCode.Conv_I1, targetType);
}
else if (targetType.IsUInt16())
{
Convert(arg, AstCode.Conv_U2, targetType);
}
else if (targetType.IsInt16())
{
Convert(arg, AstCode.Conv_I2, targetType);
}
}
}
示例7: ConvertTypeBeforeStore
/// <summary>
/// Emit code (if needed) to convert a value from source type to destination type.
/// This method is used in "store" opcodes such stloc, stfld, stsfld, call
/// </summary>
internal static RLRange ConvertTypeBeforeStore(this IRLBuilder builder, ISourceLocation sequencePoint, XTypeReference sourceType, XTypeReference destinationType, RegisterSpec source, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler, out bool converted)
{
converted = false;
if (sourceType.IsSame(destinationType))
{
// Unsigned conversions
if (sourceType.IsByte())
{
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
var ins = builder.Add(sequencePoint, RCode.Int_to_byte, tmp.Result, tmp.Result);
converted = true;
return new RLRange(tmp, ins, tmp.Result);
}
else if (sourceType.IsUInt16())
{
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
var ins = builder.Add(sequencePoint, RCode.Int_to_short, tmp.Result, tmp.Result);
converted = true;
return new RLRange(tmp, ins, tmp.Result);
}
return new RLRange(source);
}
if (sourceType.IsArray)
{
var compilerHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve();
var arrayType = targetPackage.DexFile.GetClass(targetPackage.NameConverter.GetConvertedFullName(compilerHelper));
var sourceArrayElementType = ((XArrayType)sourceType).ElementType;
if (destinationType.ExtendsIList())
{
// Use ArrayHelper.AsList to convert
var convertMethodName = "AsList";
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
if (destinationType.ExtendsICollection())
{
// Use ArrayHelper.AsCollection to convert
var convertMethodName = "AsCollection";
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
if (destinationType.ExtendsIEnumerable())
{
// Use ArrayHelper.As...Enumerable to convert
var convertMethodName = "AsObjectEnumerable";
if (sourceArrayElementType.IsPrimitive)
{
if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable";
else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable";
else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable";
else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable";
else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable";
else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable";
else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable";
else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable";
else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable";
else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable";
else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable";
else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType);
}
var convertMethod = arrayType.GetMethod(convertMethodName);
// Add code
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
builder.Add(sequencePoint, RCode.Invoke_static, convertMethod, tmp.Result.Register);
var last = builder.Add(sequencePoint, RCode.Move_result_object, tmp.Result.Register);
converted = true;
return new RLRange(tmp, last, tmp.Result);
}
}
if (sourceType.IsGenericParameter && !destinationType.IsSystemObject())
{
var gp = (XGenericParameter) sourceType;
if (gp.Constraints.Length > 0)
{
// we could find the best matching constraint here, and check if we actually
// need to cast. This would probably allow us to skip some unneccesary casts.
// We would need some sort of IsAssignableFrom though, and I'm not sure we have
// this logic with XTypeDefinition implemented yet.
// Therefore, we just assume that the original compiler has done its job well,
// and always cast to the destination type.
// Apparently dex seems not to need a cast when destinationType is an interface.
// Since i'm not to sure about this, we nevertheless insert the cast here.
// [TODO: check if this is needed]
var tmp = builder.EnsureTemp(sequencePoint, source, frame);
//.........这里部分代码省略.........