本文整理汇总了Java中sun.invoke.util.Wrapper.bitWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Wrapper.bitWidth方法的具体用法?Java Wrapper.bitWidth怎么用?Java Wrapper.bitWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.invoke.util.Wrapper
的用法示例。
在下文中一共展示了Wrapper.bitWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitPrimCast
import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
* Emit a type conversion bytecode casting from "from" to "to".
*/
private void emitPrimCast(Wrapper from, Wrapper to) {
// Here's how.
// - indicates forbidden
// <-> indicates implicit
// to ----> boolean byte short char int long float double
// from boolean <-> - - - - - - -
// byte - <-> i2s i2c <-> i2l i2f i2d
// short - i2b <-> i2c <-> i2l i2f i2d
// char - i2b i2s <-> <-> i2l i2f i2d
// int - i2b i2s i2c <-> i2l i2f i2d
// long - l2i,i2b l2i,i2s l2i,i2c l2i <-> l2f l2d
// float - f2i,i2b f2i,i2s f2i,i2c f2i f2l <-> f2d
// double - d2i,i2b d2i,i2s d2i,i2c d2i d2l d2f <->
if (from == to) {
// no cast required, should be dead code anyway
return;
}
if (from.isSubwordOrInt()) {
// cast from {byte,short,char,int} to anything
emitI2X(to);
} else {
// cast from {long,float,double} to anything
if (to.isSubwordOrInt()) {
// cast to {byte,short,char,int}
emitX2I(from);
if (to.bitWidth() < 32) {
// targets other than int require another conversion
emitI2X(to);
}
} else {
// cast to {long,float,double} - this is verbose
boolean error = false;
switch (from) {
case LONG:
switch (to) {
case FLOAT: mv.visitInsn(Opcodes.L2F); break;
case DOUBLE: mv.visitInsn(Opcodes.L2D); break;
default: error = true; break;
}
break;
case FLOAT:
switch (to) {
case LONG : mv.visitInsn(Opcodes.F2L); break;
case DOUBLE: mv.visitInsn(Opcodes.F2D); break;
default: error = true; break;
}
break;
case DOUBLE:
switch (to) {
case LONG : mv.visitInsn(Opcodes.D2L); break;
case FLOAT: mv.visitInsn(Opcodes.D2F); break;
default: error = true; break;
}
break;
default:
error = true;
break;
}
if (error) {
throw new IllegalStateException("unhandled prim cast: " + from + "2" + to);
}
}
}
}