CACAO
primitive.hpp
Go to the documentation of this file.
1 /* src/vm/primitive.hpp - primitive types
2 
3  Copyright (C) 2007-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #ifndef PRIMITIVE_HPP_
27 #define PRIMITIVE_HPP_ 1
28 
29 #include "config.h"
30 
31 #include <stdint.h>
32 
33 #include "vm/global.hpp"
34 #include "vm/linker.hpp"
35 #include "vm/utf8.hpp"
36 
37 struct classinfo;
38 
39 /* primitive data types *******************************************************/
40 
41 /**
42  * JVM types
43  *
44  * These values are used in parsed descriptors and in some other
45  * places were the different types handled internally as TYPE_INT have
46  * to be distinguished.
47  *
48  * CAUTION: Don't change the numerical values! These constants are
49  * used as indices into the primitive type table.
50  *
51  * @todo PRIMITIVETYPE_DUMMY1 is only used to keep this enum interchangeable
52  * with the Type enum. It is an artefact from the transition from C to C++
53  * (i.e. #defines to enums). Should be replaced (e.g. by a new enum).
54  */
60  PRIMITIVETYPE_DUMMY1 = TYPE_ADR, // XXX not used!
66 
67  PRIMITIVETYPE_MAX = 11 // maximum value of a primitive type
68 };
69 
70 class Primitive {
71 public:
72  static void initialize_table();
73  static void post_initialize_table();
74 
76  static classinfo* get_class_by_type(int type);
77  static classinfo* get_class_by_char(char ch);
79  static classinfo* get_arrayclass_by_type(int type);
80 
81  static int get_type_by_wrapperclass(classinfo *c);
83 
84  static java_handle_t* box(int type, imm_union value);
85 
86  static java_handle_t* box(uint8_t value);
87  static java_handle_t* box(int8_t value);
88  static java_handle_t* box(uint16_t value);
89  static java_handle_t* box(int16_t value);
90  static java_handle_t* box(int32_t value);
91  static java_handle_t* box(int64_t value);
92  static java_handle_t* box(float value);
93  static java_handle_t* box(double value);
94 
95  static imm_union unbox(java_handle_t *o);
96  static bool unbox_typed(java_handle_t *o, int type, imm_union* value);
97 
98  static uint8_t unbox_boolean(java_handle_t* o);
99  static int8_t unbox_byte(java_handle_t* o);
100  static uint16_t unbox_char(java_handle_t* o);
101  static int16_t unbox_short(java_handle_t* o);
102  static int32_t unbox_int(java_handle_t* o);
103  static int64_t unbox_long(java_handle_t* o);
104  static float unbox_float(java_handle_t* o);
105  static double unbox_double(java_handle_t* o);
106 };
107 
108 /* primitivetypeinfo **********************************************************/
109 
111  const char* cname; /* char name of primitive class */
112  Utf8String name; /* name of primitive class */
113  classinfo* class_wrap; /* class for wrapping primitive type */
114  classinfo* class_primitive; /* primitive class */
115  const char* wrapname; /* name of class for wrapping */
116  const char typesig; /* one character type signature */
117  const char* arrayname; /* name of primitive array class */
118  classinfo* arrayclass; /* primitive array class */
119 };
120 
121 /* global variables ***********************************************************/
122 
123 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
124  constants (except ARRAYTYPE_OBJECT). */
125 
127 
128 /* this function is in src/vm/primitivecore.c */
129 void primitive_init(void);
130 void primitive_postinit(void);
131 
132 
133 #endif // PRIMITIVE_HPP_
134 
135 
136 /*
137  * These are local overrides for various environment variables in Emacs.
138  * Please do not remove this and leave it at the end of the file, where
139  * Emacs will automagically detect them.
140  * ---------------------------------------------------------------------
141  * Local variables:
142  * mode: c++
143  * indent-tabs-mode: t
144  * c-basic-offset: 4
145  * tab-width: 4
146  * End:
147  * vim:noexpandtab:sw=4:ts=4:
148  */
static float unbox_float(java_handle_t *o)
Definition: primitive.cpp:803
const char * arrayname
Definition: primitive.hpp:117
static uint16_t unbox_char(java_handle_t *o)
Definition: primitive.cpp:779
static classinfo * get_class_by_type(int type)
Returns the primitive class of the given type.
Definition: primitive.cpp:253
static int32_t unbox_int(java_handle_t *o)
Definition: primitive.cpp:791
static int get_type_by_primitiveclass(classinfo *c)
Returns the primitive type of the given primitive-class.
Definition: primitive.cpp:370
const char * cname
Definition: primitive.hpp:111
const char * wrapname
Definition: primitive.hpp:115
static java_handle_t * box(int type, imm_union value)
Box a primitive of the given type.
Definition: primitive.cpp:393
static classinfo * get_arrayclass_by_type(int type)
Returns the primitive array-class of the given type.
Definition: primitive.cpp:336
static classinfo * get_class_by_name(Utf8String name)
Returns the primitive class of the given class name.
Definition: primitive.cpp:231
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
static int16_t unbox_short(java_handle_t *o)
Definition: primitive.cpp:785
static imm_union unbox(java_handle_t *o)
Unbox a primitive of the given type.
Definition: primitive.cpp:442
classinfo * class_primitive
Definition: primitive.hpp:114
classinfo * class_wrap
Definition: primitive.hpp:113
PrimitiveType
JVM types.
Definition: primitive.hpp:55
static int get_type_by_wrapperclass(classinfo *c)
Returns the primitive type of the given wrapper-class.
Definition: primitive.cpp:349
static void initialize_table()
Fill the primitive type table with the primitive-type classes, array-classes and wrapper classes...
Definition: primitive.cpp:94
static uint8_t unbox_boolean(java_handle_t *o)
Unbox a primitive type.
Definition: primitive.cpp:767
static double unbox_double(java_handle_t *o)
Definition: primitive.cpp:809
Utf8String name
Definition: primitive.hpp:112
static int64_t unbox_long(java_handle_t *o)
Definition: primitive.cpp:797
static void post_initialize_table()
Finish the primitive-type table initialization.
Definition: primitive.cpp:204
void primitive_postinit(void)
void primitive_init(void)
static classinfo * get_arrayclass_by_name(Utf8String name)
Returns the primitive array-class of the given primitive class name.
Definition: primitive.cpp:314
static bool unbox_typed(java_handle_t *o, int type, imm_union *value)
Unbox a primitive of the given type.
Definition: primitive.cpp:508
static int8_t unbox_byte(java_handle_t *o)
Definition: primitive.cpp:773
static classinfo * get_class_by_char(char ch)
Returns the primitive class of the given type.
Definition: primitive.cpp:266
primitivetypeinfo primitivetype_table[PRIMITIVETYPE_MAX]
Definition: primitive.cpp:59
const char typesig
Definition: primitive.hpp:116
classinfo * arrayclass
Definition: primitive.hpp:118