From 5a4aaebe9c42f444beef98110aea314e04b21330 Mon Sep 17 00:00:00 2001 From: Christian Thalinger Date: Tue, 8 Jul 2008 16:35:11 +0200 Subject: [PATCH] * src/vm/primitive.c: Removed. * src/vm/primitive.h: Likewise. * src/vm/primitive.cpp: New file. * src/vm/primitive.hpp: Likewise. * src/vm/Makefile.am (libvm_la_SOURCES): Removed primitive.[ch], added primitive.{cpp,hpp}. * src/cacaoh/dummy.c, src/native/jni.c, src/native/vm/gnuclasspath/java_lang_VMClassLoader.c, src/native/vm/gnuclasspath/java_lang_reflect_VMField.c, src/vm/array.c, src/vm/array.h, src/vm/builtin.c, src/vm/jit/argument.c, src/vm/jit/verify/typecheck-stackbased.c, src/vm/jit/verify/typecheck-typeinferer.c, src/vm/jit/verify/typecheck.c, src/vm/jit/verify/typeinfo.c, src/vm/resolve.c src/vm/string.c, src/vm/vm.c, src/vmcore/annotation.c, src/vmcore/class.c, src/vmcore/descriptor.c, src/vmcore/field.c, src/vmcore/linker.c, src/vmcore/loader.c, src/vmcore/primitivecore.c: Use new primitive header file and function names. --HG-- rename : src/vm/primitive.c => src/vm/primitive.cpp rename : src/vm/primitive.h => src/vm/primitive.hpp --- src/cacaoh/dummy.c | 8 +- src/native/jni.c | 2 +- .../vm/gnuclasspath/java_lang_VMClassLoader.c | 4 +- .../gnuclasspath/java_lang_reflect_VMField.c | 6 +- src/vm/Makefile.am | 4 +- src/vm/array.c | 6 +- src/vm/array.h | 2 +- src/vm/builtin.c | 2 +- src/vm/jit/argument.c | 24 +- src/vm/jit/verify/typecheck-stackbased.c | 2 +- src/vm/jit/verify/typecheck-typeinferer.c | 8 +- src/vm/jit/verify/typecheck.c | 2 +- src/vm/jit/verify/typeinfo.c | 2 +- src/vm/{primitive.c => primitive.cpp} | 222 ++++++++++-------- src/vm/{primitive.h => primitive.hpp} | 92 ++++---- src/vm/resolve.c | 4 +- src/vm/string.c | 6 +- src/vm/vm.c | 4 +- src/vmcore/annotation.c | 4 +- src/vmcore/class.c | 2 +- src/vmcore/descriptor.c | 2 +- src/vmcore/field.c | 4 +- src/vmcore/linker.c | 2 +- src/vmcore/loader.c | 4 +- src/vmcore/primitivecore.c | 2 +- 25 files changed, 226 insertions(+), 194 deletions(-) rename src/vm/{primitive.c => primitive.cpp} (61%) rename src/vm/{primitive.h => primitive.hpp} (65%) diff --git a/src/cacaoh/dummy.c b/src/cacaoh/dummy.c index 90168f788..c0522d53c 100644 --- a/src/cacaoh/dummy.c +++ b/src/cacaoh/dummy.c @@ -41,7 +41,7 @@ #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/vm.h" #include "vm/jit/code.h" @@ -581,18 +581,18 @@ void Package_add(utf *packagename) /* primitive ******************************************************************/ -classinfo *primitive_arrayclass_get_by_type(int type) +classinfo *Primitive_get_arrayclass_by_type(int type) { return NULL; } -classinfo *primitive_class_get_by_type(int type) +classinfo *Primitive_get_class_by_type(int type) { abort(); return NULL; } -classinfo *primitive_class_get_by_char(char ch) +classinfo *Primitive_get_class_by_char(char ch) { abort(); return NULL; diff --git a/src/native/jni.c b/src/native/jni.c index c2cf660c8..519c56eae 100644 --- a/src/native/jni.c +++ b/src/native/jni.c @@ -105,7 +105,7 @@ struct java_lang_ClassLoader; #include "vm/exceptions.h" #include "vm/global.h" #include "vm/initialize.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/stringlocal.h" #include "vm/vm.h" diff --git a/src/native/vm/gnuclasspath/java_lang_VMClassLoader.c b/src/native/vm/gnuclasspath/java_lang_VMClassLoader.c index b8af074be..66d33ab1d 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMClassLoader.c +++ b/src/native/vm/gnuclasspath/java_lang_VMClassLoader.c @@ -54,7 +54,7 @@ #include "vm/builtin.h" #include "vm/exceptions.h" #include "vm/initialize.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/stringlocal.h" #include "vm/vm.h" @@ -195,7 +195,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClassLoader_getPrimitiveClas { classinfo *c; - c = primitive_class_get_by_char(type); + c = Primitive_get_class_by_char(type); if (c == NULL) { exceptions_throw_classnotfoundexception(utf_null); diff --git a/src/native/vm/gnuclasspath/java_lang_reflect_VMField.c b/src/native/vm/gnuclasspath/java_lang_reflect_VMField.c index b3da6215e..39a3c5e87 100644 --- a/src/native/vm/gnuclasspath/java_lang_reflect_VMField.c +++ b/src/native/vm/gnuclasspath/java_lang_reflect_VMField.c @@ -1,4 +1,4 @@ -/* src/native/vm/gnu/java_lang_reflect_VMField.c +/* src/native/vm/gnuclasspath/java_lang_reflect_VMField.c Copyright (C) 1996-2005, 2006, 2007, 2008 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO @@ -58,7 +58,7 @@ #include "vm/exceptions.h" #include "vm/global.h" #include "vm/initialize.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/stringlocal.h" @@ -355,7 +355,7 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *e /* Now box the primitive types. */ - object = primitive_box(f->parseddesc->decltype, value); + object = Primitive_box(f->parseddesc->decltype, value); return (java_lang_Object *) object; } diff --git a/src/vm/Makefile.am b/src/vm/Makefile.am index cd56a115f..31319fa50 100644 --- a/src/vm/Makefile.am +++ b/src/vm/Makefile.am @@ -65,8 +65,8 @@ libvm_la_SOURCES = \ jit_interface.h \ package.cpp \ package.hpp \ - primitive.c \ - primitive.h \ + primitive.cpp \ + primitive.hpp \ properties.c \ properties.h \ resolve.c \ diff --git a/src/vm/array.c b/src/vm/array.c index 30f231d3e..07d8c3440 100644 --- a/src/vm/array.c +++ b/src/vm/array.c @@ -32,7 +32,7 @@ #include "vm/array.h" #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/vm.h" @@ -60,7 +60,7 @@ java_handle_t *array_element_get(java_handle_t *a, int32_t index) value = array_element_primitive_get(a, index); - o = primitive_box(type, value); + o = Primitive_box(type, value); return o; } @@ -76,7 +76,7 @@ void array_element_set(java_handle_t *a, int32_t index, java_handle_t *o) { imm_union value; - value = primitive_unbox(o); + value = Primitive_unbox(o); array_element_primitive_set(a, index, value); } diff --git a/src/vm/array.h b/src/vm/array.h index a5e037541..132855ce8 100644 --- a/src/vm/array.h +++ b/src/vm/array.h @@ -35,7 +35,7 @@ extern "C" { #endif #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" /* array types ****************************************************************/ diff --git a/src/vm/builtin.c b/src/vm/builtin.c index 417aced8f..62099a7b8 100644 --- a/src/vm/builtin.c +++ b/src/vm/builtin.c @@ -65,7 +65,7 @@ #include "vm/exceptions.h" #include "vm/global.h" #include "vm/initialize.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/stringlocal.h" #include "vm/jit/asmpart.h" diff --git a/src/vm/jit/argument.c b/src/vm/jit/argument.c index 8705e6be1..bc0e4bdde 100644 --- a/src/vm/jit/argument.c +++ b/src/vm/jit/argument.c @@ -1,9 +1,7 @@ /* src/vm/jit/argument.c - argument passing from and to JIT methods - Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel, - C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, - E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, - J. Wenninger, Institut f. Computersprachen - TU Wien + Copyright (C) 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -38,7 +36,7 @@ #include "vm/array.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/vm.h" @@ -599,7 +597,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, /* convert the value according to its declared type */ LLNI_class_get(param, c); - type = primitive_type_get_by_wrapperclass(c); + type = Primitive_get_type_by_wrapperclass(c); switch (td->decltype) { case PRIMITIVETYPE_BOOLEAN: @@ -660,7 +658,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, td->decltype); } - value = primitive_unbox(param); + value = Primitive_unbox(param); argument_vmarray_store_int(array, pd, value.i); break; @@ -669,7 +667,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; LLNI_class_get(param, c); - type = primitive_type_get_by_wrapperclass(c); + type = Primitive_get_type_by_wrapperclass(c); assert(td->decltype == PRIMITIVETYPE_LONG); @@ -684,7 +682,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; } - value = primitive_unbox(param); + value = Primitive_unbox(param); argument_vmarray_store_lng(array, pd, value.l); break; @@ -693,7 +691,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; LLNI_class_get(param, c); - type = primitive_type_get_by_wrapperclass(c); + type = Primitive_get_type_by_wrapperclass(c); assert(td->decltype == PRIMITIVETYPE_FLOAT); @@ -705,7 +703,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; } - value = primitive_unbox(param); + value = Primitive_unbox(param); argument_vmarray_store_flt(array, pd, value.l); break; @@ -714,7 +712,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; LLNI_class_get(param, c); - type = primitive_type_get_by_wrapperclass(c); + type = Primitive_get_type_by_wrapperclass(c); assert(td->decltype == PRIMITIVETYPE_DOUBLE); @@ -727,7 +725,7 @@ uint64_t *argument_vmarray_from_objectarray(methodinfo *m, java_handle_t *o, return NULL; } - value = primitive_unbox(param); + value = Primitive_unbox(param); argument_vmarray_store_dbl(array, pd, value.l); break; diff --git a/src/vm/jit/verify/typecheck-stackbased.c b/src/vm/jit/verify/typecheck-stackbased.c index 5141dd871..ed24ea78f 100644 --- a/src/vm/jit/verify/typecheck-stackbased.c +++ b/src/vm/jit/verify/typecheck-stackbased.c @@ -34,7 +34,7 @@ #include "vm/array.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/jit/parse.h" #include "vm/jit/show.h" diff --git a/src/vm/jit/verify/typecheck-typeinferer.c b/src/vm/jit/verify/typecheck-typeinferer.c index 35005828c..15c1a2514 100644 --- a/src/vm/jit/verify/typecheck-typeinferer.c +++ b/src/vm/jit/verify/typecheck-typeinferer.c @@ -1,9 +1,7 @@ /* src/vm/jit/verify/typecheck-typeinferer.c - type inference pass - Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel, - C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, - E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, - J. Wenninger, Institut f. Computersprachen - TU Wien + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -41,7 +39,7 @@ #include "vm/access.h" #include "vm/builtin.h" #include "vm/exceptions.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/vm.h" diff --git a/src/vm/jit/verify/typecheck.c b/src/vm/jit/verify/typecheck.c index e679e9526..f76e75226 100644 --- a/src/vm/jit/verify/typecheck.c +++ b/src/vm/jit/verify/typecheck.c @@ -152,7 +152,7 @@ error reporting. #include "vm/builtin.h" #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/jit/jit.h" diff --git a/src/vm/jit/verify/typeinfo.c b/src/vm/jit/verify/typeinfo.c index f31c4c958..a235941e7 100644 --- a/src/vm/jit/verify/typeinfo.c +++ b/src/vm/jit/verify/typeinfo.c @@ -34,7 +34,7 @@ #include "vm/array.h" #include "vm/exceptions.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/jit/jit.h" diff --git a/src/vm/primitive.c b/src/vm/primitive.cpp similarity index 61% rename from src/vm/primitive.c rename to src/vm/primitive.cpp index ca55726f1..d513a6b01 100644 --- a/src/vm/primitive.c +++ b/src/vm/primitive.cpp @@ -1,4 +1,4 @@ -/* src/vm/primitive.c - primitive types +/* src/vm/primitive.cpp - primitive types Copyright (C) 2007, 2008 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO @@ -42,20 +42,21 @@ #include "vm/builtin.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/vm.h" #include "vmcore/class.h" #include "vmcore/utf8.h" -/* primitive_class_get_by_name ************************************************* - - Returns the primitive class of the given class name. - -*******************************************************************************/ - -classinfo *primitive_class_get_by_name(utf *name) +/** + * Returns the primitive class of the given class name. + * + * @param name Name of the class. + * + * @return Class structure. + */ +classinfo* Primitive::get_class_by_name(utf *name) { int i; @@ -71,25 +72,27 @@ classinfo *primitive_class_get_by_name(utf *name) } -/* primitive_class_get_by_type ************************************************* - - Returns the primitive class of the given type. - -*******************************************************************************/ - -classinfo *primitive_class_get_by_type(int type) +/** + * Returns the primitive class of the given type. + * + * @param type Integer type of the class. + * + * @return Class structure. + */ +classinfo* Primitive::get_class_by_type(int type) { return primitivetype_table[type].class_primitive; } -/* primitive_class_get_by_char ************************************************* - - Returns the primitive class of the given type. - -*******************************************************************************/ - -classinfo *primitive_class_get_by_char(char ch) +/** + * Returns the primitive class of the given type. + * + * @param ch + * + * @return Class structure. + */ +classinfo* Primitive::get_class_by_char(char ch) { int index; @@ -129,14 +132,15 @@ classinfo *primitive_class_get_by_char(char ch) } -/* primitive_arrayclass_get_by_name ******************************************** - - Returns the primitive array-class of the given primitive class - name. - -*******************************************************************************/ - -classinfo *primitive_arrayclass_get_by_name(utf *name) +/** + * Returns the primitive array-class of the given primitive class + * name. + * + * @param name Name of the class. + * + * @return Class structure. + */ +classinfo* Primitive::get_arrayclass_by_name(utf *name) { int i; @@ -152,25 +156,27 @@ classinfo *primitive_arrayclass_get_by_name(utf *name) } -/* primitive_arrayclass_get_by_type ******************************************** - - Returns the primitive array-class of the given type. - -*******************************************************************************/ - -classinfo *primitive_arrayclass_get_by_type(int type) +/** + * Returns the primitive array-class of the given type. + * + * @param type Integer type of the class. + * + * @return Class structure. + */ +classinfo* Primitive::get_arrayclass_by_type(int type) { return primitivetype_table[type].arrayclass; } -/* primitive_type_get_by_wrapperclass ****************************************** - - Returns the primitive type of the given wrapper-class. - -*******************************************************************************/ - -int primitive_type_get_by_wrapperclass(classinfo *c) +/** + * Returns the primitive type of the given wrapper-class. + * + * @param c Class structure. + * + * @return Integer type of the class. + */ +int Primitive::get_type_by_wrapperclass(classinfo *c) { int i; @@ -186,44 +192,46 @@ int primitive_type_get_by_wrapperclass(classinfo *c) } -/* primitive_box *************************************************************** - - Box a primitive of the given type. If the type is an object, - simply return it. - -*******************************************************************************/ - -java_handle_t *primitive_box(int type, imm_union value) +/** + * Box a primitive of the given type. If the type is an object, + * simply return it. + * + * @param type Type of the passed value. + * @param value Value to box. + * + * @return Handle of the boxing Java object. + */ +java_handle_t* Primitive::box(int type, imm_union value) { - java_handle_t *o; + java_handle_t* o; switch (type) { case PRIMITIVETYPE_BOOLEAN: - o = primitive_box_boolean(value.i); + o = box((uint8_t) value.i); break; case PRIMITIVETYPE_BYTE: - o = primitive_box_byte(value.i); + o = box((int8_t) value.i); break; case PRIMITIVETYPE_CHAR: - o = primitive_box_char(value.i); + o = box((uint16_t) value.i); break; case PRIMITIVETYPE_SHORT: - o = primitive_box_short(value.i); + o = box((int16_t) value.i); break; case PRIMITIVETYPE_INT: - o = primitive_box_int(value.i); + o = box(value.i); break; case PRIMITIVETYPE_LONG: - o = primitive_box_long(value.l); + o = box(value.l); break; case PRIMITIVETYPE_FLOAT: - o = primitive_box_float(value.f); + o = box(value.f); break; case PRIMITIVETYPE_DOUBLE: - o = primitive_box_double(value.d); + o = box(value.d); break; case PRIMITIVETYPE_VOID: - o = value.a; + o = (java_handle_t*) value.a; break; default: o = NULL; @@ -234,60 +242,61 @@ java_handle_t *primitive_box(int type, imm_union value) } -/* primitive_unbox ************************************************************* - - Unbox a primitive of the given type. If the type is an object, - simply return it. - -*******************************************************************************/ - -imm_union primitive_unbox(java_handle_t *o) +/** + * Unbox a primitive of the given type. If the type is an object, + * simply return it. + * + * @param h Handle of the Java object. + * + * @return Unboxed value as union. + */ +imm_union Primitive::unbox(java_handle_t *h) { classinfo *c; int type; imm_union value; - if (o == NULL) { + if (h == NULL) { value.a = NULL; return value; } - LLNI_class_get(o, c); + LLNI_class_get(h, c); - type = primitive_type_get_by_wrapperclass(c); + type = get_type_by_wrapperclass(c); switch (type) { case PRIMITIVETYPE_BOOLEAN: - value.i = primitive_unbox_boolean(o); + value.i = unbox_boolean(h); break; case PRIMITIVETYPE_BYTE: - value.i = primitive_unbox_byte(o); + value.i = unbox_byte(h); break; case PRIMITIVETYPE_CHAR: - value.i = primitive_unbox_char(o); + value.i = unbox_char(h); break; case PRIMITIVETYPE_SHORT: - value.i = primitive_unbox_short(o); + value.i = unbox_short(h); break; case PRIMITIVETYPE_INT: - value.i = primitive_unbox_int(o); + value.i = unbox_int(h); break; case PRIMITIVETYPE_LONG: - value.l = primitive_unbox_long(o); + value.l = unbox_long(h); break; case PRIMITIVETYPE_FLOAT: - value.f = primitive_unbox_float(o); + value.f = unbox_float(h); break; case PRIMITIVETYPE_DOUBLE: - value.d = primitive_unbox_double(o); + value.d = unbox_double(h); break; case -1: /* If type is -1 the object is not a primitive box but a normal object. */ - value.a = o; + value.a = h; break; default: - vm_abort("primitive_unbox: invalid primitive type %d", type); + vm_abort("Primitive::unbox: invalid primitive type %d", type); } return value; @@ -300,8 +309,8 @@ imm_union primitive_unbox(java_handle_t *o) *******************************************************************************/ -#define PRIMITIVE_BOX_TYPE(name, object, type) \ -java_handle_t *primitive_box_##name(type value) \ +#define PRIMITIVE_BOX_TYPE(name, object, type) \ +java_handle_t* Primitive::box(type value) \ { \ java_handle_t *o; \ java_lang_##object *jo; \ @@ -313,15 +322,15 @@ java_handle_t *primitive_box_##name(type value) \ \ jo = (java_lang_##object *) o; \ \ - LLNI_field_set_val(jo, value, value); \ + LLNI_field_set_val(jo, value, value); \ \ return o; \ } -PRIMITIVE_BOX_TYPE(boolean, Boolean, int32_t) -PRIMITIVE_BOX_TYPE(byte, Byte, int32_t) -PRIMITIVE_BOX_TYPE(char, Character, int32_t) -PRIMITIVE_BOX_TYPE(short, Short, int32_t) +PRIMITIVE_BOX_TYPE(boolean, Boolean, uint8_t) +PRIMITIVE_BOX_TYPE(byte, Byte, int8_t) +PRIMITIVE_BOX_TYPE(char, Character, uint16_t) +PRIMITIVE_BOX_TYPE(short, Short, int16_t) PRIMITIVE_BOX_TYPE(int, Integer, int32_t) PRIMITIVE_BOX_TYPE(long, Long, int64_t) PRIMITIVE_BOX_TYPE(float, Float, float) @@ -334,36 +343,51 @@ PRIMITIVE_BOX_TYPE(double, Double, double) *******************************************************************************/ -#define PRIMITIVE_UNBOX_TYPE(name, object, type) \ -type primitive_unbox_##name(java_handle_t *o) \ +#define PRIMITIVE_UNBOX_TYPE(name, object, type) \ +type Primitive::unbox_##name(java_handle_t *h) \ { \ java_lang_##object *jo; \ type value; \ \ - jo = (java_lang_##object *) o; \ + jo = (java_lang_##object *) h; \ \ LLNI_field_get_val(jo, value, value); \ \ return value; \ } -PRIMITIVE_UNBOX_TYPE(boolean, Boolean, int32_t) -PRIMITIVE_UNBOX_TYPE(byte, Byte, int32_t) -PRIMITIVE_UNBOX_TYPE(char, Character, int32_t) -PRIMITIVE_UNBOX_TYPE(short, Short, int32_t) +PRIMITIVE_UNBOX_TYPE(boolean, Boolean, uint8_t) +PRIMITIVE_UNBOX_TYPE(byte, Byte, int8_t) +PRIMITIVE_UNBOX_TYPE(char, Character, uint16_t) +PRIMITIVE_UNBOX_TYPE(short, Short, int16_t) PRIMITIVE_UNBOX_TYPE(int, Integer, int32_t) PRIMITIVE_UNBOX_TYPE(long, Long, int64_t) PRIMITIVE_UNBOX_TYPE(float, Float, float) PRIMITIVE_UNBOX_TYPE(double, Double, double) +// Legacy C interface. + +extern "C" { + + classinfo* Primitive_get_class_by_name(utf *name) { return Primitive::get_class_by_name(name); } +classinfo* Primitive_get_class_by_type(int type) { return Primitive::get_class_by_type(type); } +classinfo* Primitive_get_class_by_char(char ch) { return Primitive::get_class_by_char(ch); } +classinfo* Primitive_get_arrayclass_by_name(utf *name) { return Primitive::get_arrayclass_by_name(name); } +classinfo* Primitive_get_arrayclass_by_type(int type) { return Primitive::get_arrayclass_by_type(type); } +int Primitive_get_type_by_wrapperclass(classinfo *c) { return Primitive::get_type_by_wrapperclass(c); } +java_handle_t* Primitive_box(int type, imm_union value) { return Primitive::box(type, value); } +imm_union Primitive_unbox(java_handle_t *h) { return Primitive::unbox(h); } +} + + /* * These are local overrides for various environment variables in Emacs. * Please do not remove this and leave it at the end of the file, where * Emacs will automagically detect them. * --------------------------------------------------------------------- * Local variables: - * mode: c + * mode: c++ * indent-tabs-mode: t * c-basic-offset: 4 * tab-width: 4 diff --git a/src/vm/primitive.h b/src/vm/primitive.hpp similarity index 65% rename from src/vm/primitive.h rename to src/vm/primitive.hpp index 1b6ff4cf3..2615b3c9b 100644 --- a/src/vm/primitive.h +++ b/src/vm/primitive.hpp @@ -1,4 +1,4 @@ -/* src/vm/primitive.c - primitive types +/* src/vm/primitive.hpp - primitive types Copyright (C) 2007, 2008 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO @@ -23,17 +23,13 @@ */ -#ifndef _PRIMITIVE_H -#define _PRIMITIVE_H +#ifndef _PRIMITIVE_HPP +#define _PRIMITIVE_HPP #include "config.h" #include -#ifdef __cplusplus -extern "C" { -#endif - #include "vm/global.h" #include "vmcore/class.h" @@ -41,6 +37,43 @@ extern "C" { #include "vmcore/utf8.h" +#ifdef __cplusplus + +class Primitive { +public: + static classinfo* get_class_by_name(utf *name); + static classinfo* get_class_by_type(int type); + static classinfo* get_class_by_char(char ch); + static classinfo* get_arrayclass_by_name(utf* name); + static classinfo* get_arrayclass_by_type(int type); + + static int get_type_by_wrapperclass(classinfo *c); + + static java_handle_t* box(int type, imm_union value); + + static java_handle_t* box(uint8_t value); + static java_handle_t* box(int8_t value); + static java_handle_t* box(uint16_t value); + static java_handle_t* box(int16_t value); + static java_handle_t* box(int32_t value); + static java_handle_t* box(int64_t value); + static java_handle_t* box(float value); + static java_handle_t* box(double value); + + static imm_union unbox(java_handle_t *o); + + static uint8_t unbox_boolean(java_handle_t* o); + static int8_t unbox_byte(java_handle_t* o); + static uint16_t unbox_char(java_handle_t* o); + static int16_t unbox_short(java_handle_t* o); + static int32_t unbox_int(java_handle_t* o); + static int64_t unbox_long(java_handle_t* o); + static float unbox_float(java_handle_t* o); + static double unbox_double(java_handle_t* o); +}; + +#endif + /* primitive data types *******************************************************/ /* These values are used in parsed descriptors and in some other @@ -86,48 +119,27 @@ struct primitivetypeinfo { extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT]; - -/* function prototypes ********************************************************/ +#ifndef __cplusplus +// Legacy C interface. /* this function is in src/vmcore/primitivecore.c */ void primitive_init(void); void primitive_postinit(void); -classinfo *primitive_class_get_by_name(utf *name); -classinfo *primitive_class_get_by_type(int type); -classinfo *primitive_class_get_by_char(char ch); - -classinfo *primitive_arrayclass_get_by_name(utf *name); -classinfo *primitive_arrayclass_get_by_type(int type); +classinfo *Primitive_get_class_by_name(utf *name); +classinfo *Primitive_get_class_by_type(int type); +classinfo *Primitive_get_class_by_char(char ch); -int primitive_type_get_by_wrapperclass(classinfo *c); +classinfo *Primitive_get_arrayclass_by_name(utf *name); +classinfo *Primitive_get_arrayclass_by_type(int type); -java_handle_t *primitive_box(int type, imm_union value); -imm_union primitive_unbox(java_handle_t *o); +int Primitive_get_type_by_wrapperclass(classinfo *c); -java_handle_t *primitive_box_boolean(int32_t value); -java_handle_t *primitive_box_byte(int32_t value); -java_handle_t *primitive_box_char(int32_t value); -java_handle_t *primitive_box_short(int32_t value); -java_handle_t *primitive_box_int(int32_t value); -java_handle_t *primitive_box_long(int64_t value); -java_handle_t *primitive_box_float(float value); -java_handle_t *primitive_box_double(double value); - -int32_t primitive_unbox_boolean(java_handle_t *o); -int32_t primitive_unbox_byte(java_handle_t *o); -int32_t primitive_unbox_char(java_handle_t *o); -int32_t primitive_unbox_short(java_handle_t *o); -int32_t primitive_unbox_int(java_handle_t *o); -int64_t primitive_unbox_long(java_handle_t *o); -float primitive_unbox_float(java_handle_t *o); -double primitive_unbox_double(java_handle_t *o); - -#ifdef __cplusplus -} +java_handle_t *Primitive_box(int type, imm_union value); +imm_union Primitive_unbox(java_handle_t *h); #endif -#endif /* _PRIMITIVE_H */ +#endif // _PRIMITIVE_HPP /* @@ -136,7 +148,7 @@ double primitive_unbox_double(java_handle_t *o); * Emacs will automagically detect them. * --------------------------------------------------------------------- * Local variables: - * mode: c + * mode: c++ * indent-tabs-mode: t * c-basic-offset: 4 * tab-width: 4 diff --git a/src/vm/resolve.c b/src/vm/resolve.c index b125bdefc..2506af917 100644 --- a/src/vm/resolve.c +++ b/src/vm/resolve.c @@ -34,7 +34,7 @@ #include "vm/access.h" #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/jit/jit.h" @@ -500,7 +500,7 @@ bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, class else { /* a primitive type */ - cls = primitive_class_get_by_type(d->decltype); + cls = Primitive_get_class_by_type(d->decltype); assert(cls->state & CLASS_LOADED); diff --git a/src/vm/string.c b/src/vm/string.c index f24e411e0..744008282 100644 --- a/src/vm/string.c +++ b/src/vm/string.c @@ -45,7 +45,7 @@ #include "vm/array.h" #include "vm/builtin.h" #include "vm/exceptions.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/stringlocal.h" #include "vm/vm.h" @@ -141,7 +141,7 @@ void stringtable_update(void) if (!a->header.objheader.vftbl) /* vftbl of character-array is NULL */ a->header.objheader.vftbl = - primitive_arrayclass_get_by_type(ARRAYTYPE_CHAR)->vftbl; + Primitive_get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl; /* follow link in external hash chain */ s = s->hashlink; @@ -589,7 +589,7 @@ static java_object_t *literalstring_u2(java_chararray_t *a, u4 length, /* location in hashtable found, complete arrayheader */ ca->header.objheader.vftbl = - primitive_arrayclass_get_by_type(ARRAYTYPE_CHAR)->vftbl; + Primitive_get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl; ca->header.size = length; assert(class_java_lang_String); diff --git a/src/vm/vm.c b/src/vm/vm.c index 6c192e277..65c5c234b 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -76,7 +76,7 @@ #include "vm/global.h" #include "vm/initialize.h" #include "vm/package.hpp" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/properties.h" #include "vm/signallocal.h" #include "vm/stringlocal.h" @@ -2631,7 +2631,7 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o, /* box the return value if necesarry */ if (m->parseddesc->returntype.decltype != TYPE_ADR) - ro = primitive_box(m->parseddesc->returntype.decltype, value); + ro = Primitive_box(m->parseddesc->returntype.decltype, value); /* check for an exception */ diff --git a/src/vmcore/annotation.c b/src/vmcore/annotation.c index 4d7021d4d..41350371a 100644 --- a/src/vmcore/annotation.c +++ b/src/vmcore/annotation.c @@ -33,7 +33,7 @@ #include "vm/types.h" #include "vm/array.h" #include "vm/builtin.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "mm/memory.h" @@ -80,7 +80,7 @@ static java_handle_objectarray_t *annotation_bytearrays_resize( } newbas = builtin_anewarray(size, - primitive_arrayclass_get_by_type(PRIMITIVETYPE_BYTE)); + Primitive_get_arrayclass_by_type(PRIMITIVETYPE_BYTE)); /* is there a old byte array array? */ if (newbas != NULL && bytearrays != NULL) { diff --git a/src/vmcore/class.c b/src/vmcore/class.c index ec8432278..53aa72702 100644 --- a/src/vmcore/class.c +++ b/src/vmcore/class.c @@ -1683,7 +1683,7 @@ classinfo *class_get_componenttype(classinfo *c) if (ad->arraytype == ARRAYTYPE_OBJECT) component = ad->componentvftbl->clazz; else - component = primitive_class_get_by_type(ad->arraytype); + component = Primitive_get_class_by_type(ad->arraytype); return component; } diff --git a/src/vmcore/descriptor.c b/src/vmcore/descriptor.c index f49e05012..01574f489 100644 --- a/src/vmcore/descriptor.c +++ b/src/vmcore/descriptor.c @@ -35,7 +35,7 @@ #include "vm/exceptions.h" #include "vm/jit_interface.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/vm.h" #include "vmcore/descriptor.h" diff --git a/src/vmcore/field.c b/src/vmcore/field.c index 00c0680e9..e1ee69c93 100644 --- a/src/vmcore/field.c +++ b/src/vmcore/field.c @@ -39,7 +39,7 @@ #include "vm/builtin.h" #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/stringlocal.h" #include "vm/vm.h" @@ -364,7 +364,7 @@ classinfo *field_get_type(fieldinfo *f) c = load_class_from_classloader(u, f->clazz->classloader); } else { - c = primitive_class_get_by_type(td->decltype); + c = Primitive_get_class_by_type(td->decltype); } return c; diff --git a/src/vmcore/linker.c b/src/vmcore/linker.c index abf018cc8..22d116d2d 100644 --- a/src/vmcore/linker.c +++ b/src/vmcore/linker.c @@ -41,7 +41,7 @@ #include "vm/access.h" #include "vm/array.h" #include "vm/exceptions.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/stringlocal.h" #include "vm/vm.h" diff --git a/src/vmcore/loader.c b/src/vmcore/loader.c index c303485d0..eaf99ca3d 100644 --- a/src/vmcore/loader.c +++ b/src/vmcore/loader.c @@ -44,7 +44,7 @@ #include "vm/exceptions.h" #include "vm/global.h" #include "vm/package.hpp" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/resolve.h" #include "vm/stringlocal.h" #include "vm/vm.h" @@ -2100,7 +2100,7 @@ classinfo *load_newly_created_array(classinfo *c, classloader_t *loader) /* check for cases like `[II' and whether the character is a valid primitive type */ - if ((namelen > 2) || (primitive_class_get_by_char(text[1]) == NULL)) { + if ((namelen > 2) || (Primitive_get_class_by_char(text[1]) == NULL)) { exceptions_throw_classnotfoundexception(c->name); return NULL; } diff --git a/src/vmcore/primitivecore.c b/src/vmcore/primitivecore.c index d55da764f..3e9baad47 100644 --- a/src/vmcore/primitivecore.c +++ b/src/vmcore/primitivecore.c @@ -29,7 +29,7 @@ #include #include "vm/global.h" -#include "vm/primitive.h" +#include "vm/primitive.hpp" #include "vm/vm.h" #include "vmcore/class.h" -- 2.25.1