1 /* src/vmcore/primitive.c - primitive types
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: linker.c 8042 2007-06-07 17:43:29Z twisti $
35 #include "vm/global.h"
37 #include "vmcore/class.h"
38 #include "vmcore/primitive.h"
39 #include "vmcore/utf8.h"
42 /* primitivetype_table *********************************************************
44 Structure for primitive classes: contains the class for wrapping
45 the primitive type, the primitive class, the name of the class for
46 wrapping, the one character type signature and the name of the
49 CAUTION: Don't change the order of the types. This table is indexed
50 by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
52 *******************************************************************************/
54 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = {
55 { "int" , NULL, NULL, NULL, "java/lang/Integer", 'I', "[I", NULL },
56 { "long" , NULL, NULL, NULL, "java/lang/Long", 'J', "[J", NULL },
57 { "float" , NULL, NULL, NULL, "java/lang/Float", 'F', "[F", NULL },
58 { "double" , NULL, NULL, NULL, "java/lang/Double", 'D', "[D", NULL },
59 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
60 { "byte" , NULL, NULL, NULL, "java/lang/Byte", 'B', "[B", NULL },
61 { "char" , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
62 { "short" , NULL, NULL, NULL, "java/lang/Short", 'S', "[S", NULL },
63 { "boolean" , NULL, NULL, NULL, "java/lang/Boolean", 'Z', "[Z", NULL },
64 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
65 #if defined(ENABLE_JAVASE)
66 { "void" , NULL, NULL, NULL, "java/lang/Void", 'V', NULL, NULL }
68 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
73 /* primitive_init **************************************************************
75 Create classes representing primitive types.
77 *******************************************************************************/
79 bool primitive_init(void)
86 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
89 if (primitivetype_table[i].cname == NULL)
92 /* create UTF-8 name */
94 name = utf_new_char(primitivetype_table[i].cname);
96 primitivetype_table[i].name = name;
98 /* create primitive class */
100 c = class_create_classinfo(name);
102 /* primitive classes don't have a super class */
106 /* set flags and mark it as primitive class */
108 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
110 /* prevent loader from loading primitive class */
112 c->state |= CLASS_LOADED;
114 /* INFO: don't put primitive classes into the classcache */
119 primitivetype_table[i].class_primitive = c;
121 /* create class for wrapping the primitive type */
123 u = utf_new_char(primitivetype_table[i].wrapname);
124 c = load_class_bootstrap(u);
129 primitivetype_table[i].class_wrap = c;
131 /* create the primitive array class */
133 if (primitivetype_table[i].arrayname) {
134 u = utf_new_char(primitivetype_table[i].arrayname);
135 c = class_create_classinfo(u);
136 c = load_newly_created_array(c, NULL);
141 primitivetype_table[i].arrayclass = c;
143 assert(c->state & CLASS_LOADED);
145 if (!(c->state & CLASS_LINKED))
155 /* primitive_class_get_by_name *************************************************
157 Returns the primitive class of the given class name.
159 *******************************************************************************/
161 classinfo *primitive_class_get_by_name(utf *name)
165 /* search table of primitive classes */
167 for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
168 if (primitivetype_table[i].name == name)
169 return primitivetype_table[i].class_primitive;
171 /* keep compiler happy */
177 /* primitive_class_get_by_type *************************************************
179 Returns the primitive class of the given type.
181 *******************************************************************************/
183 classinfo *primitive_class_get_by_type(int32_t type)
185 return primitivetype_table[type].class_primitive;
189 /* primitive_class_get_by_char *************************************************
191 Returns the primitive class of the given type.
193 *******************************************************************************/
195 classinfo *primitive_class_get_by_char(char ch)
201 index = PRIMITIVETYPE_INT;
204 index = PRIMITIVETYPE_LONG;
207 index = PRIMITIVETYPE_FLOAT;
210 index = PRIMITIVETYPE_DOUBLE;
213 index = PRIMITIVETYPE_BYTE;
216 index = PRIMITIVETYPE_CHAR;
219 index = PRIMITIVETYPE_SHORT;
222 index = PRIMITIVETYPE_BOOLEAN;
225 index = PRIMITIVETYPE_VOID;
231 return primitivetype_table[index].class_primitive;
235 /* primitive_arrayclass_get_by_name ********************************************
237 Returns the primitive array-class of the given primitive class
240 *******************************************************************************/
242 classinfo *primitive_arrayclass_get_by_name(utf *name)
246 /* search table of primitive classes */
248 for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
249 if (primitivetype_table[i].name == name)
250 return primitivetype_table[i].arrayclass;
252 /* keep compiler happy */
258 /* primitive_arrayclass_get_by_type ********************************************
260 Returns the primitive array-class of the given type.
262 *******************************************************************************/
264 classinfo *primitive_arrayclass_get_by_type(int32_t type)
266 return primitivetype_table[type].arrayclass;
271 * These are local overrides for various environment variables in Emacs.
272 * Please do not remove this and leave it at the end of the file, where
273 * Emacs will automagically detect them.
274 * ---------------------------------------------------------------------
277 * indent-tabs-mode: t
281 * vim:noexpandtab:sw=4:ts=4: