52 BOX_INT = box(CD_int, CD_Integer),
53 BOX_LONG = box(CD_long, CD_Long),
54 BOX_FLOAT = box(CD_float, CD_Float),
55 BOX_DOUBLE = box(CD_double, CD_Double);
56
57 private static MethodRefEntry unbox(ClassDesc owner, String methodName, ClassDesc primitiveTarget) {
58 return CP.methodRefEntry(owner, methodName, MethodTypeDescImpl.ofValidated(primitiveTarget));
59 }
60
61 private static final MethodRefEntry UNBOX_BOOLEAN = unbox(CD_Boolean, "booleanValue", CD_boolean),
62 UNBOX_BYTE = unbox(CD_Number, "byteValue", CD_byte),
63 UNBOX_SHORT = unbox(CD_Number, "shortValue", CD_short),
64 UNBOX_CHAR = unbox(CD_Character, "charValue", CD_char),
65 UNBOX_INT = unbox(CD_Number, "intValue", CD_int),
66 UNBOX_LONG = unbox(CD_Number, "longValue", CD_long),
67 UNBOX_FLOAT = unbox(CD_Number, "floatValue", CD_float),
68 UNBOX_DOUBLE = unbox(CD_Number, "doubleValue", CD_double);
69 }
70
71 private static TypeKind primitiveTypeKindFromClass(Class<?> type) {
72 if (type == int.class) return TypeKind.IntType;
73 if (type == long.class) return TypeKind.LongType;
74 if (type == boolean.class) return TypeKind.BooleanType;
75 if (type == short.class) return TypeKind.ShortType;
76 if (type == byte.class) return TypeKind.ByteType;
77 if (type == char.class) return TypeKind.CharType;
78 if (type == float.class) return TypeKind.FloatType;
79 if (type == double.class) return TypeKind.DoubleType;
80 return null;
81 }
82
83 static void boxIfTypePrimitive(CodeBuilder cob, TypeKind tk) {
84 box(cob, tk);
85 }
86
87 static void widen(CodeBuilder cob, TypeKind ws, TypeKind wt) {
88 ws = ws.asLoadable();
89 wt = wt.asLoadable();
90 if (ws != wt) {
91 cob.conversion(ws, wt);
92 }
93 }
94
95 static void box(CodeBuilder cob, TypeKind tk) {
96 switch (tk) {
97 case BooleanType -> cob.invokestatic(BoxHolder.BOX_BOOLEAN);
98 case ByteType -> cob.invokestatic(BoxHolder.BOX_BYTE);
99 case CharType -> cob.invokestatic(BoxHolder.BOX_CHAR);
|
52 BOX_INT = box(CD_int, CD_Integer),
53 BOX_LONG = box(CD_long, CD_Long),
54 BOX_FLOAT = box(CD_float, CD_Float),
55 BOX_DOUBLE = box(CD_double, CD_Double);
56
57 private static MethodRefEntry unbox(ClassDesc owner, String methodName, ClassDesc primitiveTarget) {
58 return CP.methodRefEntry(owner, methodName, MethodTypeDescImpl.ofValidated(primitiveTarget));
59 }
60
61 private static final MethodRefEntry UNBOX_BOOLEAN = unbox(CD_Boolean, "booleanValue", CD_boolean),
62 UNBOX_BYTE = unbox(CD_Number, "byteValue", CD_byte),
63 UNBOX_SHORT = unbox(CD_Number, "shortValue", CD_short),
64 UNBOX_CHAR = unbox(CD_Character, "charValue", CD_char),
65 UNBOX_INT = unbox(CD_Number, "intValue", CD_int),
66 UNBOX_LONG = unbox(CD_Number, "longValue", CD_long),
67 UNBOX_FLOAT = unbox(CD_Number, "floatValue", CD_float),
68 UNBOX_DOUBLE = unbox(CD_Number, "doubleValue", CD_double);
69 }
70
71 private static TypeKind primitiveTypeKindFromClass(Class<?> type) {
72 if (type == Integer.class) return TypeKind.IntType;
73 if (type == Long.class) return TypeKind.LongType;
74 if (type == Boolean.class) return TypeKind.BooleanType;
75 if (type == Short.class) return TypeKind.ShortType;
76 if (type == Byte.class) return TypeKind.ByteType;
77 if (type == Character.class) return TypeKind.CharType;
78 if (type == Float.class) return TypeKind.FloatType;
79 if (type == Double.class) return TypeKind.DoubleType;
80 return null;
81 }
82
83 static void boxIfTypePrimitive(CodeBuilder cob, TypeKind tk) {
84 box(cob, tk);
85 }
86
87 static void widen(CodeBuilder cob, TypeKind ws, TypeKind wt) {
88 ws = ws.asLoadable();
89 wt = wt.asLoadable();
90 if (ws != wt) {
91 cob.conversion(ws, wt);
92 }
93 }
94
95 static void box(CodeBuilder cob, TypeKind tk) {
96 switch (tk) {
97 case BooleanType -> cob.invokestatic(BoxHolder.BOX_BOOLEAN);
98 case ByteType -> cob.invokestatic(BoxHolder.BOX_BYTE);
99 case CharType -> cob.invokestatic(BoxHolder.BOX_CHAR);
|